1# Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import dbus 6import dbus.service 7 8from autotest_lib.client.cros.cellular import mm1_constants 9from autotest_lib.client.cros.cellular.pseudomodem import dbus_std_ifaces 10from autotest_lib.client.cros.cellular.pseudomodem import pm_constants 11from autotest_lib.client.cros.cellular.pseudomodem import utils 12 13class Testing(dbus_std_ifaces.DBusProperties): 14 """ 15 The testing object allows the pseudomodem to be configured on the fly 16 over D-Bus. It exposes a basic set of commands that can be used to 17 simulate network events (such as SMS) or various other modem configurations 18 that are needed for testing/debugging. 19 20 """ 21 22 def __init__(self, modem, bus): 23 self._modem = modem 24 dbus_std_ifaces.DBusProperties.__init__(self, 25 pm_constants.TESTING_PATH, 26 bus) 27 28 29 @utils.log_dbus_method() 30 @dbus.service.method(pm_constants.I_TESTING, out_signature='b') 31 def IsAlive(self): 32 """ 33 A heartbeat method. 34 35 This method can be called by clients to check that pseudomodem is alive. 36 37 @returns: True, always. 38 39 """ 40 return True 41 42 43 def _InitializeProperties(self): 44 return { pm_constants.I_TESTING: { 'Modem': self._modem.path } } 45 46 47 @utils.log_dbus_method() 48 @dbus.service.method(pm_constants.I_TESTING, in_signature='ss') 49 def ReceiveSms(self, sender, text): 50 """ 51 Simulates a fake SMS. 52 53 @param sender: String containing the phone number of the sender. 54 @param text: String containing the SMS message contents. 55 56 """ 57 self._modem.sms_handler.receive_sms(text, sender) 58 59 60 @utils.log_dbus_method() 61 @dbus.service.method(pm_constants.I_TESTING, in_signature='a(ubay)') 62 def UpdatePco(self, pco_value): 63 """ 64 Sets the Pco to the specified value. If the Modem.Modem3gpp 65 properties are currently not exposed (e.g. due to a locked or absent 66 SIM), this method will do nothing. 67 68 @param pco_value: The PCO list. 69 70 """ 71 if mm1_constants.I_MODEM_3GPP in self._modem.properties: 72 self._modem.AssignPco(pco_value) 73 74 @utils.log_dbus_method() 75 @dbus.service.method(pm_constants.I_TESTING, in_signature='u') 76 def SetSubscriptionState(self, 77 registered_subscription_state): 78 """ 79 Sets the Pco to something denoting the requested subscription state. 80 If the Modem.Modem3gpp properties are currently not exposed (e.g. due 81 to a locked or absent SIM), this method will do nothing. 82 83 @param registered_subscription_state: This value is returned as the 84 subscription state when the modem is registered on the network. 85 See mm1_constants.MM_MODEM_3GPP_SUBSCRIPTION_STATE_*. 86 87 """ 88 if mm1_constants.I_MODEM_3GPP in self._modem.properties: 89 self._modem.AssignSubscriptionState(registered_subscription_state) 90