3
# oFono - Open Source Telephony - RIL Modem test
5
# Copyright (C) 2014 Canonical Ltd.
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License version 2 as
9
# published by the Free Software Foundation.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
# This test ensures that basic modem information is available
21
# when the modem is online and has a valid, unlocked SIM present.
23
"""Tests SIM removal detection/notification
25
This module contains a functional test which checks a running
26
ofono/rilmodem/mtkmodem instance to ensure that the correct
27
DBus signals are generated and the correct properties updated
28
when a SIM is removed from a running device. The script by
29
default will wait for 60 seconds for the SIM to be removed after
32
NOTE - this test by default verifies the removal of a SIM from
33
a single modem. If the device is multi-SIM, the first modem
34
will be used by default. The -m argument can be used to specify
35
the second modem if needed.
45
* -t / --timer - specify a timeout after which the script
49
* If run on the emulator, make this script use console
50
commands to configure the modem(s) for the required
51
conditions ( ie. no SIM(s), online )
54
import dbus.mainloop.glib
57
from gi.repository import GLib
58
from simtestutil import *
62
parser = argparse.ArgumentParser()
64
parser.add_argument("-t",
67
help="""Specify a timeout which causes
68
the script to exit""",
72
return simtestutil.parse_args(parser)
74
class TestSimRemovalNotification(SimTestCase):
76
def modem_listener(self, name, value, path=None):
78
print("Modem property: '%s' changed to '%s'"
81
if name == "Interfaces":
82
if "org.ofono.SimManager" in value:
83
if (self.check_no_sim_present(path) != True):
84
self.sim_present_failure = True
88
def sim_listener(self, name, value):
90
print("SIM property: '%s' changed to '%s'"
95
self.sim_present_signal_failure = True
101
self.product = get_product()
103
self.sim_present_failure = False
104
self.sim_present_signal_failure = False
105
self.timeout_failure = False
107
self.mainloop = GLib.MainLoop()
109
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
111
SimTestCase.setUp(self)
113
interval_ms = 1000 * int(self.args.timeout)
114
GLib.timeout_add(interval_ms, self.timeout_cb)
116
def timeout_cb(self):
118
print("ALL DONE - timer fired!!!")
120
self.timeout_failure = True
123
def validate_modem(self, path):
124
modem = self.validate_modem_properties(path, True, True)
126
if self.if_supports_sim_offline() == True:
128
# valid SimManager properties
129
simmanager = self.get_simmanager(path)
131
simmanager.connect_to_signal("PropertyChanged",
134
modem.connect_to_signal("PropertyChanged",
140
print ("ro.build.product: %s" % self.product)
142
if len(args.modem) > 0:
143
self.validate_modem(args.modem)
145
self.validate_modem(self.modems[0][0])
149
self.assertFalse(self.timeout_failure)
150
self.assertFalse(self.sim_present_failure)
151
self.assertFalse(self.sim_present_signal_failure)
153
if __name__ == "__main__":
156
sim_unittest_main(args)