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='a(ubay)')
63    def UpdatePco(self, pco_value):
64        """
65        Sets the Pco 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 list.
70
71        """
72        if mm1_constants.I_MODEM_3GPP in self._modem.properties:
73            self._modem.AssignPco(pco_value)
74
75    @utils.log_dbus_method()
76    @dbus.service.method(pm_constants.I_TESTING, in_signature='u')
77    def SetSubscriptionState(self,
78                             registered_subscription_state):
79        """
80        Sets the Pco to something denoting the requested subscription state.
81        If the Modem.Modem3gpp properties are currently not exposed (e.g. due
82        to a locked or absent SIM), this method will do nothing.
83
84        @param registered_subscription_state: This value is returned as the
85                subscription state when the modem is registered on the network.
86                See mm1_constants.MM_MODEM_3GPP_SUBSCRIPTION_STATE_*.
87
88        """
89        if mm1_constants.I_MODEM_3GPP in self._modem.properties:
90            self._modem.AssignSubscriptionState(registered_subscription_state)
91