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 the abilty to unlock a locked SIM for use.
25
This module contains a functional test which checks an
26
ofono/rilmodem/mtkmodem instance to ensure that the a
27
SIM PIN can be entered and thus unlock the SIM for use.
29
NOTE - this test by default tries to unlock the PIN of a
30
single SIM. If the device is multi-SIM, the first modem
31
will be used by default. The -m argument can be used to
32
specify the second modem if needed.
36
* a SIM with PIN-locking enabled
38
* the current PIN code for the SIM
42
* Ensure that FlightMode is NOT enabled
44
* Ensure that at least one SIM with PIN-locking
45
enabled is inserted in the phone AND STILL LOCKED!
46
( ie. the PIN hasn't been entered yet )
51
* If run on the emulator, make this script use console
52
commands to configure the modem(s) for the required
53
conditions ( ie. no SIM(s), online )
56
import dbus.mainloop.glib
59
from gi.repository import GLib
60
from simtestutil import *
62
def parse_test_args():
64
parser = argparse.ArgumentParser()
66
parser.add_argument("--pin",
68
help="""Specify the SIM PIN code""",
72
parser.add_argument("-t",
75
help="""Specify a timeout which causes
76
the script to exit""",
80
return parse_args(parser)
82
class TestSimPukUnlock(SimTestCase):
86
self.product = get_product()
89
self.mainloop = GLib.MainLoop()
91
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
93
SimTestCase.setUp(self)
95
interval_ms = 1000 * int(self.args.timeout)
96
GLib.timeout_add(interval_ms, self.timeout_cb)
98
def pin_unlock(self, path):
101
print("pin_unlock called,"
102
"pin: {}".format(self.args.pin))
104
simmanager = self.get_simmanager(path)
105
simmanager.connect_to_signal("PropertyChanged",
108
properties = simmanager.GetProperties()
110
locked_pins = properties["LockedPins"]
111
self.assertTrue(len(locked_pins) == 1)
112
self.assertTrue(locked_pins[0] == "pin")
114
self.assertTrue(properties["PinRequired"] == "pin")
116
simmanager.EnterPin("pin", self.args.pin)
118
def sim_listener(self, name, value):
120
print("SIM property: {} changed "
121
"to {}".format(name, str(value)))
123
if name == "PinRequired":
124
self.assertTrue(value == "none")
127
def timeout_cb(self):
129
print("ALL DONE - timer fired!!!")
134
def validate_modem(self, path):
136
self.pin_unlock(path)
140
self.assertTrue(self.timer == False)
145
if __name__ == "__main__":
146
args = parse_test_args()
148
sim_unittest_main(args)