• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
8import dbus_std_ifaces
9import pm_constants
10import utils
11
12from autotest_lib.client.cros.cellular import mm1_constants
13
14class Testing(dbus_std_ifaces.DBusProperties):
15    """
16    The testing object allows the pseudomodem to be configured on the fly
17    over D-Bus. It exposes a basic set of commands that can be used to
18    simulate network events (such as SMS) or various other modem configurations
19    that are needed for testing/debugging.
20
21    """
22
23    def __init__(self, modem, bus):
24        self._modem = modem
25        dbus_std_ifaces.DBusProperties.__init__(self,
26                                                pm_constants.TESTING_PATH,
27                                                bus)
28
29
30    @utils.log_dbus_method()
31    @dbus.service.method(pm_constants.I_TESTING, out_signature='b')
32    def IsAlive(self):
33        """
34        A heartbeat method.
35
36        This method can be called by clients to check that pseudomodem is alive.
37
38        @returns: True, always.
39
40        """
41        return True
42
43
44    def _InitializeProperties(self):
45        return { pm_constants.I_TESTING: { 'Modem': self._modem.path } }
46
47
48    @utils.log_dbus_method()
49    @dbus.service.method(pm_constants.I_TESTING, in_signature='ss')
50    def ReceiveSms(self, sender, text):
51        """
52        Simulates a fake SMS.
53
54        @param sender: String containing the phone number of the sender.
55        @param text: String containing the SMS message contents.
56
57        """
58        self._modem.sms_handler.receive_sms(text, sender)
59
60
61    @utils.log_dbus_method()
62    @dbus.service.method(pm_constants.I_TESTING, in_signature='s')
63    def UpdatePcoInfo(self, pco_value):
64        """
65        Sets the VendorPcoInfo to the specified value. If the Modem.Modem3gpp
66        properties are currently not exposed (e.g. due to a locked or absent
67        SIM), this method will do nothing.
68
69        @param pco_value: The PCO string.
70
71        """
72        if mm1_constants.I_MODEM_3GPP in self._modem.properties:
73            self._modem.AssignPcoValue(pco_value)
74
75    @utils.log_dbus_method()
76    @dbus.service.method(pm_constants.I_TESTING, in_signature='uu')
77    def SetSubscriptionState(self,
78                             unregistered_subscription_state,
79                             registered_subscription_state):
80        """
81        Sets the SubscriptionState to the specified value. If the
82        Modem.Modem3gpp properties are currently not exposed (e.g. due to a
83        locked or absent SIM), this method will do nothing.
84
85        @param unregistered_subscription_state: This value is returned as the
86                subscription state when the modem is not registered on the
87                network. See mm1_constants.MM_MODEM_3GPP_SUBSCRIPTION_STATE_*.
88        @param registered_subscription_state: This value is returned as the
89                subscription state when the modem is registered on the network.
90                See mm1_constants.MM_MODEM_3GPP_SUBSCRIPTION_STATE_*.
91
92        """
93        if mm1_constants.I_MODEM_3GPP in self._modem.properties:
94            self._modem.AssignSubscriptionState(unregistered_subscription_state,
95                                                registered_subscription_state)
96