1import time
2from acts import utils
3from acts import signals
4from acts.base_test import BaseTestClass
5from acts.test_utils.tel.tel_defines import EventSmsSentSuccess
6from acts.test_utils.tel.tel_test_utils import get_iccid_by_adb
7from acts.test_utils.tel.tel_test_utils import is_sim_ready_by_adb
8
9
10class GnssSimInventoryTest(BaseTestClass):
11    """ GNSS SIM Inventory Tests"""
12    def setup_class(self):
13        super().setup_class()
14        self.ad = self.android_devices[0]
15        req_params = ["sim_inventory_recipient", "sim_inventory_ldap"]
16        self.unpack_userparams(req_param_names=req_params)
17
18    def check_device_status(self):
19        if int(self.ad.adb.shell("settings get global airplane_mode_on")) != 0:
20            self.ad.log.info("Force airplane mode off")
21            utils.force_airplane_mode(self.ad, False)
22        if not is_sim_ready_by_adb(self.ad.log, self.ad):
23            raise signals.TestFailure("SIM card is not loaded and ready.")
24
25    def test_gnss_sim_inventory(self):
26        self.check_device_status()
27        imsi = str(self.ad.adb.shell("service call iphonesubinfo 7"))
28        if not imsi:
29            raise signals.TestFailure("Couldn't get imsi")
30        iccid = str(get_iccid_by_adb(self.ad))
31        if not iccid:
32            raise signals.TestFailure("Couldn't get iccid")
33        sms_message = "imsi: %s, iccid: %s, ldap: %s, model: %s, sn: %s" % \
34                      (imsi, iccid, self.sim_inventory_ldap, self.ad.model,
35                       self.ad.serial)
36        self.ad.log.info(sms_message)
37        try:
38            self.ad.log.info("Send SMS by SL4A.")
39            self.ad.droid.smsSendTextMessage(self.sim_inventory_recipient,
40                                             sms_message, True)
41            self.ad.ed.pop_event(EventSmsSentSuccess, 10)
42        except Exception as e:
43            raise signals.TestFailure(e)
44