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        android_version = int(self.ad.adb.getprop("ro.build.version.release"))
28        if android_version == 10:
29            imsi = str(self.ad.adb.shell("service call iphonesubinfo 7"))
30        elif android_version == 11:
31            imsi = str(self.ad.adb.shell("service call iphonesubinfo 8"))
32        else:
33            raise signals.TestFailure("Couldn't get imsi")
34        iccid = str(get_iccid_by_adb(self.ad))
35        if not isinstance(iccid, int):
36            self.ad.log.info("Unable to get iccid via adb. Changed to isub.")
37            iccid = str(self.ad.adb.shell(
38                "dumpsys isub | grep iccid")).split(" ")[4].strip(",")
39        if not iccid:
40            raise signals.TestFailure("Couldn't get iccid")
41        sms_message = "imsi: %s, iccid: %s, ldap: %s, model: %s, sn: %s" % \
42                      (imsi, iccid, self.sim_inventory_ldap, self.ad.model,
43                       self.ad.serial)
44        self.ad.log.info(sms_message)
45        try:
46            self.ad.log.info("Send SMS by SL4A.")
47            self.ad.droid.smsSendTextMessage(self.sim_inventory_recipient,
48                                             sms_message, True)
49            self.ad.ed.pop_event(EventSmsSentSuccess, 10)
50        except Exception as e:
51            raise signals.TestFailure(e)
52