• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2016 - Google
4#
5#   Licensed under the Apache License, Version 2.0 (the "License");
6#   you may not use this file except in compliance with the License.
7#   You may obtain a copy of the License at
8#
9#       http://www.apache.org/licenses/LICENSE-2.0
10#
11#   Unless required by applicable law or agreed to in writing, software
12#   distributed under the License is distributed on an "AS IS" BASIS,
13#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14#   See the License for the specific language governing permissions and
15#   limitations under the License.
16"""
17    Test Script for Telephony Settings
18"""
19
20import os
21import time
22
23from acts import signals
24from acts.keys import Config
25from acts.utils import unzip_maintain_permissions
26from acts.test_decorators import test_tracker_info
27from acts.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
28from acts.test_utils.tel.tel_defines import MAX_WAIT_TIME_FOR_STATE_CHANGE
29from acts.test_utils.tel.tel_test_utils import dumpsys_carrier_config
30from acts.test_utils.tel.tel_test_utils import ensure_phone_subscription
31from acts.test_utils.tel.tel_test_utils import flash_radio
32from acts.test_utils.tel.tel_test_utils import get_outgoing_voice_sub_id
33from acts.test_utils.tel.tel_test_utils import get_slot_index_from_subid
34from acts.test_utils.tel.tel_test_utils import is_sim_locked
35from acts.test_utils.tel.tel_test_utils import multithread_func
36from acts.test_utils.tel.tel_test_utils import power_off_sim
37from acts.test_utils.tel.tel_test_utils import power_on_sim
38from acts.test_utils.tel.tel_test_utils import print_radio_info
39from acts.test_utils.tel.tel_test_utils import revert_default_telephony_setting
40from acts.test_utils.tel.tel_test_utils import set_qxdm_logger_command
41from acts.test_utils.tel.tel_test_utils import system_file_push
42from acts.test_utils.tel.tel_test_utils import unlock_sim
43from acts.test_utils.tel.tel_test_utils import verify_default_telephony_setting
44from acts.utils import set_mobile_data_always_on
45
46
47class TelLiveSettingsTest(TelephonyBaseTest):
48    def setup_class(self):
49        TelephonyBaseTest.setup_class(self)
50        self.dut = self.android_devices[0]
51        self.number_of_devices = 1
52        self.stress_test_number = self.get_stress_test_number()
53        self.carrier_configs = dumpsys_carrier_config(self.dut)
54        self.dut_capabilities = self.dut.telephony.get("capabilities", [])
55
56    @test_tracker_info(uuid="c6149bd6-7080-453d-af37-1f9bd350a764")
57    @TelephonyBaseTest.tel_test_wrap
58    def test_telephony_factory_reset(self):
59        """Test VOLTE is enabled WFC is disabled after telephony factory reset.
60
61        Steps:
62        1. Setup DUT with various dataroaming, mobiledata, and default_network.
63        2. Call telephony factory reset.
64        3. Verify DUT back to factory default.
65
66        Expected Results: dataroaming is off, mobiledata is on, network
67                          preference is back to default.
68        """
69        revert_default_telephony_setting(self.dut)
70        self.dut.log.info("Call telephony factory reset")
71        self.dut.droid.telephonyFactoryReset()
72        time.sleep(MAX_WAIT_TIME_FOR_STATE_CHANGE)
73        return verify_default_telephony_setting(self.dut)
74
75    @test_tracker_info(uuid="3afa2070-564f-4e6c-b08d-12dd4381abb9")
76    @TelephonyBaseTest.tel_test_wrap
77    def test_check_carrier_config(self):
78        """Check the carrier_config and network setting for different carrier.
79
80        Steps:
81        1. Device loaded with different SIM cards.
82        2. Check the carrier_configs are expected value.
83
84        """
85        pass
86
87    @test_tracker_info(uuid="64deba57-c1c2-422f-b771-639c95edfbc0")
88    @TelephonyBaseTest.tel_test_wrap
89    def test_disable_mobile_data_always_on(self):
90        """Verify mobile_data_always_on can be disabled.
91
92        Steps:
93        1. Disable mobile_data_always_on by adb.
94        2. Verify the mobile data_always_on state.
95
96        Expected Results: mobile_data_always_on return 0.
97        """
98        self.dut.log.info("Disable mobile_data_always_on")
99        set_mobile_data_always_on(self.dut, False)
100        time.sleep(1)
101        return self.dut.adb.shell(
102            "settings get global mobile_data_always_on") == "0"
103
104    @test_tracker_info(uuid="56ddcd5a-92b0-46c7-9c2b-d743794efb7c")
105    @TelephonyBaseTest.tel_test_wrap
106    def test_enable_mobile_data_always_on(self):
107        """Verify mobile_data_always_on can be enabled.
108
109        Steps:
110        1. Enable mobile_data_always_on by adb.
111        2. Verify the mobile data_always_on state.
112
113        Expected Results: mobile_data_always_on return 1.
114        """
115        self.dut.log.info("Enable mobile_data_always_on")
116        set_mobile_data_always_on(self.dut, True)
117        time.sleep(1)
118        return "1" in self.dut.adb.shell(
119            "settings get global mobile_data_always_on")
120
121    @test_tracker_info(uuid="c2cc5b66-40af-4ba6-81cb-6c44ae34cbbb")
122    @TelephonyBaseTest.tel_test_wrap
123    def test_push_new_radio_or_mbn(self):
124        """Verify new mdn and radio can be push to device.
125
126        Steps:
127        1. If new radio path is given, flash new radio on the device.
128        2. Verify the radio version.
129        3. If new mbn path is given, push new mbn to device.
130        4. Verify the installed mbn version.
131
132        Expected Results:
133        radio and mbn can be pushed to device and mbn.ver is available.
134        """
135        result = True
136        paths = {}
137        for path_key, dst_name in zip(["radio_image", "mbn_path"],
138                                      ["radio.img", "mcfg_sw"]):
139            path = self.user_params.get(path_key)
140            if not path:
141                continue
142            elif isinstance(path, list):
143                if not path[0]:
144                    continue
145                path = path[0]
146            if "dev/null" in path:
147                continue
148            if not os.path.exists(path):
149                self.log.error("path %s does not exist", path)
150                self.log.info(self.user_params)
151                path = os.path.join(self.user_params[Config.key_config_path],
152                                    path)
153                if not os.path.exists(path):
154                    self.log.error("path %s does not exist", path)
155                    continue
156
157            self.log.info("%s path = %s", path_key, path)
158            if "zip" in path:
159                self.log.info("Unzip %s", path)
160                file_path, file_name = os.path.split(path)
161                dest_path = os.path.join(file_path, dst_name)
162                os.system("rm -rf %s" % dest_path)
163                unzip_maintain_permissions(path, file_path)
164                path = dest_path
165            os.system("chmod -R 777 %s" % path)
166            paths[path_key] = path
167        if not paths:
168            self.log.info("No radio_path or mbn_path is provided")
169            raise signals.TestSkip("No radio_path or mbn_path is provided")
170        self.log.info("paths = %s", paths)
171        for ad in self.android_devices:
172            if paths.get("radio_image"):
173                print_radio_info(ad, "Before flash radio, ")
174                flash_radio(ad, paths["radio_image"])
175                print_radio_info(ad, "After flash radio, ")
176            if not paths.get("mbn_path") or "mbn" not in ad.adb.shell(
177                    "ls /vendor"):
178                ad.log.info("No need to push mbn files")
179                continue
180            push_result = True
181            try:
182                mbn_ver = ad.adb.shell(
183                    "cat /vendor/mbn/mcfg/configs/mcfg_sw/mbn.ver")
184                if mbn_ver:
185                    ad.log.info("Before push mbn, mbn.ver = %s", mbn_ver)
186                else:
187                    ad.log.info(
188                        "There is no mbn.ver before push, unmatching device")
189                    continue
190            except:
191                ad.log.info(
192                    "There is no mbn.ver before push, unmatching device")
193                continue
194            print_radio_info(ad, "Before push mbn, ")
195            for i in range(2):
196                if not system_file_push(ad, paths["mbn_path"],
197                                        "/vendor/mbn/mcfg/configs/"):
198                    if i == 1:
199                        ad.log.error("Failed to push mbn file")
200                        push_result = False
201                else:
202                    ad.log.info("The mbn file is pushed to device")
203                    break
204            if not push_result:
205                result = False
206                continue
207            print_radio_info(ad, "After push mbn, ")
208            try:
209                new_mbn_ver = ad.adb.shell(
210                    "cat /vendor/mbn/mcfg/configs/mcfg_sw/mbn.ver")
211                if new_mbn_ver:
212                    ad.log.info("new mcfg_sw mbn.ver = %s", new_mbn_ver)
213                    if new_mbn_ver == mbn_ver:
214                        ad.log.error(
215                            "mbn.ver is the same before and after push")
216                        result = False
217                else:
218                    ad.log.error("Unable to get new mbn.ver")
219                    result = False
220            except Exception as e:
221                ad.log.error("cat mbn.ver with error %s", e)
222                result = False
223        return result
224
225    @TelephonyBaseTest.tel_test_wrap
226    def test_set_qxdm_log_mask_ims(self):
227        """Set the QXDM Log mask to IMS_DS_CNE_LnX_Golden.cfg"""
228        tasks = [(set_qxdm_logger_command, [ad, "IMS_DS_CNE_LnX_Golden.cfg"])
229                 for ad in self.android_devices]
230        return multithread_func(self.log, tasks)
231
232    @TelephonyBaseTest.tel_test_wrap
233    def test_set_qxdm_log_mask_qc_default(self):
234        """Set the QXDM Log mask to QC_Default.cfg"""
235        tasks = [(set_qxdm_logger_command, [ad, " QC_Default.cfg"])
236                 for ad in self.android_devices]
237        return multithread_func(self.log, tasks)
238
239    @test_tracker_info(uuid="e2734d66-6111-4e76-aa7b-d3b4cbcde4f1")
240    @TelephonyBaseTest.tel_test_wrap
241    def test_check_carrier_id(self):
242        """Verify mobile_data_always_on can be enabled.
243
244        Steps:
245        1. Enable mobile_data_always_on by adb.
246        2. Verify the mobile data_always_on state.
247
248        Expected Results: mobile_data_always_on return 1.
249        """
250        result = True
251        if self.dut.adb.getprop("ro.build.version.release")[0] in ("8", "O",
252                                                                   "7", "N"):
253            raise signals.TestSkip("Not supported in this build")
254        old_carrier_id = self.dut.droid.telephonyGetSimCarrierId()
255        old_carrier_name = self.dut.droid.telephonyGetSimCarrierIdName()
256        self.result_detail = "carrier_id = %s, carrier_name = %s" % (
257            old_carrier_id, old_carrier_name)
258        self.dut.log.info(self.result_detail)
259        sub_id = get_outgoing_voice_sub_id(self.dut)
260        slot_index = get_slot_index_from_subid(self.log, self.dut, sub_id)
261
262        if self.dut.model in ("angler", "bullhead", "marlin", "sailfish"):
263            msg = "Power off SIM slot is not supported"
264            self.dut.log.warning("%s, test finished", msg)
265            self.result_detail = "%s, %s" % (self.result_detail, msg)
266            return result
267
268        if power_off_sim(self.dut, slot_index):
269            for i in range(3):
270                carrier_id = self.dut.droid.telephonyGetSimCarrierId()
271                carrier_name = self.dut.droid.telephonyGetSimCarrierIdName()
272                msg = "After SIM power down, carrier_id = %s(expecting -1), " \
273                      "carrier_name = %s(expecting None)" % (carrier_id, carrier_name)
274                if carrier_id != -1 or carrier_name:
275                    if i == 2:
276                        self.dut.log.error(msg)
277                        self.result_detail = "%s, %s" % (self.result_detail,
278                                                         msg)
279                        result = False
280                    else:
281                        time.sleep(5)
282                else:
283                    self.dut.log.info(msg)
284                    break
285        else:
286            msg = "Power off SIM slot is not working"
287            self.dut.log.error(msg)
288            result = False
289            self.result_detail = "%s, %s" % (self.result_detail, msg)
290
291        if not power_on_sim(self.dut, slot_index):
292            self.dut.log.error("Fail to power up SIM")
293            result = False
294            setattr(self.dut, "reboot_to_recover", True)
295        else:
296            if is_sim_locked(self.dut):
297                self.dut.log.info("Sim is locked")
298                carrier_id = self.dut.droid.telephonyGetSimCarrierId()
299                carrier_name = self.dut.droid.telephonyGetSimCarrierIdName()
300                msg = "In locked SIM, carrier_id = %s(expecting -1), " \
301                      "carrier_name = %s(expecting None)" % (carrier_id, carrier_name)
302                if carrier_id != -1 or carrier_name:
303                    self.dut.log.error(msg)
304                    self.result_detail = "%s, %s" % (self.result_detail, msg)
305                    result = False
306                else:
307                    self.dut.log.info(msg)
308                unlock_sim(self.dut)
309            elif getattr(self.dut, "is_sim_locked", False):
310                self.dut.log.error(
311                    "After SIM slot power cycle, SIM in not in locked state")
312                return False
313
314            if not ensure_phone_subscription(self.log, self.dut):
315                self.dut.log.error("Unable to find a valid subscription!")
316                result = False
317            time.sleep(15)
318            new_carrier_id = self.dut.droid.telephonyGetSimCarrierId()
319            new_carrier_name = self.dut.droid.telephonyGetSimCarrierIdName()
320            msg = "After SIM power up, new_carrier_id = %s, " \
321                  "new_carrier_name = %s" % (new_carrier_id, new_carrier_name)
322            if old_carrier_id != new_carrier_id or (old_carrier_name !=
323                                                    new_carrier_name):
324                self.dut.log.error(msg)
325                self.result_detail = "%s, %s" % (self.result_detail, msg)
326                result = False
327            else:
328                self.dut.log.info(msg)
329        return result
330