• 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_contrib.test_utils.net import ui_utils
28from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
29from acts_contrib.test_utils.tel.tel_defines import GEN_4G
30from acts_contrib.test_utils.tel.tel_defines import MAX_WAIT_TIME_FOR_STATE_CHANGE
31from acts_contrib.test_utils.tel.tel_bootloader_utils import flash_radio
32from acts_contrib.test_utils.tel.tel_logging_utils import set_qxdm_logger_command
33from acts_contrib.test_utils.tel.tel_subscription_utils import get_slot_index_from_subid
34from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phones_idle
35from acts_contrib.test_utils.tel.tel_phone_setup_utils import ensure_phone_subscription
36from acts_contrib.test_utils.tel.tel_test_utils import dumpsys_carrier_config
37from acts_contrib.test_utils.tel.tel_test_utils import get_outgoing_voice_sub_id
38from acts_contrib.test_utils.tel.tel_test_utils import is_sim_locked
39from acts_contrib.test_utils.tel.tel_test_utils import power_off_sim
40from acts_contrib.test_utils.tel.tel_test_utils import power_on_sim
41from acts_contrib.test_utils.tel.tel_test_utils import print_radio_info
42from acts_contrib.test_utils.tel.tel_test_utils import revert_default_telephony_setting
43from acts_contrib.test_utils.tel.tel_test_utils import system_file_push
44from acts_contrib.test_utils.tel.tel_test_utils import unlock_sim
45from acts_contrib.test_utils.tel.tel_test_utils import verify_default_telephony_setting
46from acts_contrib.test_utils.tel.tel_settings_utils import att_apn_test
47from acts_contrib.test_utils.tel.tel_settings_utils import tmo_apn_test
48from acts_contrib.test_utils.tel.tel_settings_utils import toggle_mobile_data_test
49from acts_contrib.test_utils.tel.tel_settings_utils import toggle_sim_test
50from acts.utils import set_mobile_data_always_on
51from acts.libs.utils.multithread import multithread_func
52
53
54class TelLiveSettingsTest(TelephonyBaseTest):
55    def setup_class(self):
56        TelephonyBaseTest.setup_class(self)
57        self.dut = self.android_devices[0]
58        self.number_of_devices = 1
59        self.stress_test_number = self.get_stress_test_number()
60        self.carrier_configs = dumpsys_carrier_config(self.dut)
61        self.dut_subID = get_outgoing_voice_sub_id(self.dut)
62        self.dut_capabilities = self.dut.telephony["subscription"][
63            self.dut_subID].get("capabilities", [])
64
65    def teardown_test(self):
66        ensure_phones_idle(self.log, self.android_devices)
67
68    @test_tracker_info(uuid="c6149bd6-7080-453d-af37-1f9bd350a764")
69    @TelephonyBaseTest.tel_test_wrap
70    def test_telephony_factory_reset(self):
71        """Test VOLTE is enabled WFC is disabled after telephony factory reset.
72
73        Steps:
74        1. Setup DUT with various dataroaming, mobiledata, and default_network.
75        2. Call telephony factory reset.
76        3. Verify DUT back to factory default.
77
78        Expected Results: dataroaming is off, mobiledata is on, network
79                          preference is back to default.
80        """
81        revert_default_telephony_setting(self.dut)
82        self.dut.log.info("Call telephony factory reset")
83        self.dut.droid.telephonyFactoryReset()
84        time.sleep(MAX_WAIT_TIME_FOR_STATE_CHANGE)
85        return verify_default_telephony_setting(self.dut)
86
87    @test_tracker_info(uuid="3afa2070-564f-4e6c-b08d-12dd4381abb9")
88    @TelephonyBaseTest.tel_test_wrap
89    def test_check_carrier_config(self):
90        """Check the carrier_config and network setting for different carrier.
91
92        Steps:
93        1. Device loaded with different SIM cards.
94        2. Check the carrier_configs are expected value.
95
96        """
97
98    @test_tracker_info(uuid="64deba57-c1c2-422f-b771-639c95edfbc0")
99    @TelephonyBaseTest.tel_test_wrap
100    def test_disable_mobile_data_always_on(self):
101        """Verify mobile_data_always_on can be disabled.
102
103        Steps:
104        1. Disable mobile_data_always_on by adb.
105        2. Verify the mobile data_always_on state.
106
107        Expected Results: mobile_data_always_on return 0.
108        """
109        self.dut.log.info("Disable mobile_data_always_on")
110        set_mobile_data_always_on(self.dut, False)
111        time.sleep(1)
112        return self.dut.adb.shell(
113            "settings get global mobile_data_always_on") == "0"
114
115    @test_tracker_info(uuid="56ddcd5a-92b0-46c7-9c2b-d743794efb7c")
116    @TelephonyBaseTest.tel_test_wrap
117    def test_enable_mobile_data_always_on(self):
118        """Verify mobile_data_always_on can be enabled.
119
120        Steps:
121        1. Enable mobile_data_always_on by adb.
122        2. Verify the mobile data_always_on state.
123
124        Expected Results: mobile_data_always_on return 1.
125        """
126        self.dut.log.info("Enable mobile_data_always_on")
127        set_mobile_data_always_on(self.dut, True)
128        time.sleep(1)
129        return "1" in self.dut.adb.shell(
130            "settings get global mobile_data_always_on")
131
132    @test_tracker_info(uuid="c2cc5b66-40af-4ba6-81cb-6c44ae34cbbb")
133    @TelephonyBaseTest.tel_test_wrap
134    def test_push_new_radio_or_mbn(self):
135        """Verify new mdn and radio can be push to device.
136
137        Steps:
138        1. If new radio path is given, flash new radio on the device.
139        2. Verify the radio version.
140        3. If new mbn path is given, push new mbn to device.
141        4. Verify the installed mbn version.
142
143        Expected Results:
144        radio and mbn can be pushed to device and mbn.ver is available.
145        """
146        result = True
147        paths = {}
148        for path_key, dst_name in zip(["radio_image", "mbn_path"],
149                                      ["radio.img", "mcfg_sw"]):
150            path = self.user_params.get(path_key)
151            if not path:
152                continue
153            elif isinstance(path, list):
154                if not path[0]:
155                    continue
156                path = path[0]
157            if "dev/null" in path:
158                continue
159            if not os.path.exists(path):
160                self.log.error("path %s does not exist", path)
161                self.log.info(self.user_params)
162                path = os.path.join(
163                    self.user_params[Config.key_config_path.value], path)
164                if not os.path.exists(path):
165                    self.log.error("path %s does not exist", path)
166                    continue
167
168            self.log.info("%s path = %s", path_key, path)
169            if "zip" in path:
170                self.log.info("Unzip %s", path)
171                file_path, file_name = os.path.split(path)
172                dest_path = os.path.join(file_path, dst_name)
173                os.system("rm -rf %s" % dest_path)
174                unzip_maintain_permissions(path, file_path)
175                path = dest_path
176            os.system("chmod -R 777 %s" % path)
177            paths[path_key] = path
178        if not paths:
179            self.log.info("No radio_path or mbn_path is provided")
180            raise signals.TestSkip("No radio_path or mbn_path is provided")
181        self.log.info("paths = %s", paths)
182        for ad in self.android_devices:
183            if paths.get("radio_image"):
184                print_radio_info(ad, "Before flash radio, ")
185                flash_radio(ad, paths["radio_image"])
186                print_radio_info(ad, "After flash radio, ")
187            if not paths.get("mbn_path") or "mbn" not in ad.adb.shell(
188                    "ls /vendor"):
189                ad.log.info("No need to push mbn files")
190                continue
191            push_result = True
192            try:
193                mbn_ver = ad.adb.shell(
194                    "cat /vendor/mbn/mcfg/configs/mcfg_sw/mbn.ver")
195                if mbn_ver:
196                    ad.log.info("Before push mbn, mbn.ver = %s", mbn_ver)
197                else:
198                    ad.log.info(
199                        "There is no mbn.ver before push, unmatching device")
200                    continue
201            except:
202                ad.log.info(
203                    "There is no mbn.ver before push, unmatching device")
204                continue
205            print_radio_info(ad, "Before push mbn, ")
206            for i in range(2):
207                if not system_file_push(ad, paths["mbn_path"],
208                                        "/vendor/mbn/mcfg/configs/"):
209                    if i == 1:
210                        ad.log.error("Failed to push mbn file")
211                        push_result = False
212                else:
213                    ad.log.info("The mbn file is pushed to device")
214                    break
215            if not push_result:
216                result = False
217                continue
218            print_radio_info(ad, "After push mbn, ")
219            try:
220                new_mbn_ver = ad.adb.shell(
221                    "cat /vendor/mbn/mcfg/configs/mcfg_sw/mbn.ver")
222                if new_mbn_ver:
223                    ad.log.info("new mcfg_sw mbn.ver = %s", new_mbn_ver)
224                    if new_mbn_ver == mbn_ver:
225                        ad.log.error(
226                            "mbn.ver is the same before and after push")
227                        result = False
228                else:
229                    ad.log.error("Unable to get new mbn.ver")
230                    result = False
231            except Exception as e:
232                ad.log.error("cat mbn.ver with error %s", e)
233                result = False
234        return result
235
236    @TelephonyBaseTest.tel_test_wrap
237    def test_set_qxdm_log_mask_ims(self):
238        """Set the QXDM Log mask to IMS_DS_CNE_LnX_Golden.cfg"""
239        tasks = [(set_qxdm_logger_command, [ad, "IMS_DS_CNE_LnX_Golden.cfg"])
240                 for ad in self.android_devices]
241        return multithread_func(self.log, tasks)
242
243    @TelephonyBaseTest.tel_test_wrap
244    def test_set_qxdm_log_mask_qc_default(self):
245        """Set the QXDM Log mask to QC_Default.cfg"""
246        tasks = [(set_qxdm_logger_command, [ad, " QC_Default.cfg"])
247                 for ad in self.android_devices]
248        return multithread_func(self.log, tasks)
249
250    @test_tracker_info(uuid="e2734d66-6111-4e76-aa7b-d3b4cbcde4f1")
251    @TelephonyBaseTest.tel_test_wrap
252    def test_check_carrier_id(self):
253        """Verify mobile_data_always_on can be enabled.
254
255        Steps:
256        1. Enable mobile_data_always_on by adb.
257        2. Verify the mobile data_always_on state.
258
259        Expected Results: mobile_data_always_on return 1.
260        """
261        result = True
262        if self.dut.adb.getprop("ro.build.version.release")[0] in ("8", "O",
263                                                                   "7", "N"):
264            raise signals.TestSkip("Not supported in this build")
265        old_carrier_id = self.dut.droid.telephonyGetSimCarrierId()
266        old_carrier_name = self.dut.droid.telephonyGetSimCarrierIdName()
267        self.result_detail = "carrier_id = %s, carrier_name = %s" % (
268            old_carrier_id, old_carrier_name)
269        self.dut.log.info(self.result_detail)
270        sub_id = get_outgoing_voice_sub_id(self.dut)
271        slot_index = get_slot_index_from_subid(self.dut, sub_id)
272
273        if self.dut.model in ("angler", "bullhead", "marlin", "sailfish"):
274            msg = "Power off SIM slot is not supported"
275            self.dut.log.warning("%s, test finished", msg)
276            self.result_detail = "%s, %s" % (self.result_detail, msg)
277            return result
278
279        if power_off_sim(self.dut, slot_index):
280            for i in range(3):
281                carrier_id = self.dut.droid.telephonyGetSimCarrierId()
282                carrier_name = self.dut.droid.telephonyGetSimCarrierIdName()
283                msg = "After SIM power down, carrier_id = %s(expecting -1), " \
284                      "carrier_name = %s(expecting None)" % (carrier_id, carrier_name)
285                if carrier_id != -1 or carrier_name:
286                    if i == 2:
287                        self.dut.log.error(msg)
288                        self.result_detail = "%s, %s" % (self.result_detail,
289                                                         msg)
290                        result = False
291                    else:
292                        time.sleep(5)
293                else:
294                    self.dut.log.info(msg)
295                    break
296        else:
297            msg = "Power off SIM slot is not working"
298            self.dut.log.error(msg)
299            result = False
300            self.result_detail = "%s, %s" % (self.result_detail, msg)
301
302        if not power_on_sim(self.dut, slot_index):
303            self.dut.log.error("Fail to power up SIM")
304            result = False
305            setattr(self.dut, "reboot_to_recover", True)
306        else:
307            if is_sim_locked(self.dut):
308                self.dut.log.info("Sim is locked")
309                carrier_id = self.dut.droid.telephonyGetSimCarrierId()
310                carrier_name = self.dut.droid.telephonyGetSimCarrierIdName()
311                msg = "In locked SIM, carrier_id = %s(expecting -1), " \
312                      "carrier_name = %s(expecting None)" % (carrier_id, carrier_name)
313                if carrier_id != -1 or carrier_name:
314                    self.dut.log.error(msg)
315                    self.result_detail = "%s, %s" % (self.result_detail, msg)
316                    result = False
317                else:
318                    self.dut.log.info(msg)
319                unlock_sim(self.dut)
320            elif getattr(self.dut, "is_sim_locked", False):
321                self.dut.log.error(
322                    "After SIM slot power cycle, SIM in not in locked state")
323                return False
324
325            if not ensure_phone_subscription(self.log, self.dut):
326                self.dut.log.error("Unable to find a valid subscription!")
327                result = False
328            time.sleep(15)
329            new_carrier_id = self.dut.droid.telephonyGetSimCarrierId()
330            new_carrier_name = self.dut.droid.telephonyGetSimCarrierIdName()
331            msg = "After SIM power up, new_carrier_id = %s, " \
332                  "new_carrier_name = %s" % (new_carrier_id, new_carrier_name)
333            if old_carrier_id != new_carrier_id or (old_carrier_name !=
334                                                    new_carrier_name):
335                self.dut.log.error(msg)
336                self.result_detail = "%s, %s" % (self.result_detail, msg)
337                result = False
338            else:
339                self.dut.log.info(msg)
340        return result
341
342    @test_tracker_info(uuid='7b6d145f-2497-4842-96db-67f9053943ce')
343    @TelephonyBaseTest.tel_test_wrap
344    def test_disable_enable_sim_lte(self):
345        """Test sim disable and enable
346
347        Steps:
348            1. Provision device to LTE
349            2. Launch Settings - Network & Internet
350            3. Click on SIMs
351            4. Toggle Use SIM switch to Disable
352            5. Verify Use SIM switch is disabled
353            6. Toggle Use SIM switch to Enable
354            7. Verify Use SIM switch is Enabled
355            8. Verify SIM is connected to LTE
356
357        Returns:
358            True is tests passes else False
359        """
360        ad = self.android_devices[0]
361        return toggle_sim_test(ad, GEN_4G)
362
363    @test_tracker_info(uuid='dc0d381b-2dbf-4e25-87a4-53ec657e12d1')
364    @TelephonyBaseTest.tel_test_wrap
365    def test_disable_enable_mobile_data_lte(self):
366        """Test sim disable and enable
367
368        Steps:
369            1. Provision device to LTE
370            2. Launch Settings - Network & Internet
371            3. Click on SIMs
372            4. Toggle Mobile Data switch to Disable
373            5. Verify Mobile Data switch is disabled
374            6. Toggle Mobile Data switch to Enable
375            7. Verify Mobile Data switch is Enabled
376            8. Verify Mobile Data is connected to LTE
377
378        Returns:
379            True is tests passes else False
380        """
381        ad = self.android_devices[0]
382
383        return toggle_mobile_data_test(ad, GEN_4G)
384
385    @test_tracker_info(uuid='9f0cb1cd-6dff-4736-a7f7-3d08af782575')
386    @TelephonyBaseTest.tel_test_wrap
387    def test_att_apn_settings_sms_lte(self):
388        """Test ATT APN and SMS
389
390        Steps:
391            1. Provision device to LTE
392            2. Launch Settings - Network & Internet
393            3. Click on SIMs
394            4. Click on Access Point Names
395            5. Add New APN
396            6. Save New APN
397            7. Switch APN to New APN
398            8. Check Network is connected to LTE
399            9. Send SMS
400
401        Returns:
402            True is tests passes else False
403        """
404        caller, callee = self.android_devices[0], self.android_devices[1]
405
406        return att_apn_test(self.log, caller, callee, GEN_4G, msg_type='sms')
407
408    @test_tracker_info(uuid='7ba6eccd-5115-495a-8298-a1b41e5115d8')
409    @TelephonyBaseTest.tel_test_wrap
410    def test_att_apn_settings_mms_lte(self):
411        """Test ATT APN and MMS
412
413        Steps:
414            1. Provision device to LTE
415            2. Launch Settings - Network & Internet
416            3. Click on SIMs
417            4. Click on Access Point Names
418            5. Add New APN
419            6. Add ATT APN details and Save
420            7. Switch APN to New APN
421            8. Check Network is connected to LTE
422            9. Send MMS
423
424        Returns:
425            True is tests passes else False
426        """
427        caller, callee = self.android_devices[0], self.android_devices[1]
428
429        return att_apn_test(self.log, caller, callee, GEN_4G, msg_type='mms')
430
431    @test_tracker_info(uuid='ea6886e0-5a34-4b62-9a2b-d81d109284ae')
432    @TelephonyBaseTest.tel_test_wrap
433    def test_tmo_apn_settings_sms_lte(self):
434        """Test TMO APN and SMS
435
436        Steps:
437            1. Provision device to LTE
438            2. Launch Settings - Network & Internet
439            3. Click on SIMs
440            4. Click on Access Point Names
441            5. Add New APN
442            6. Add TMO APN details and Save New APN
443            7. Switch APN to New APN
444            8. Check Network is connected to LTE
445            9. Send SMS
446
447        Returns:
448            True is tests passes else False
449        """
450        caller, callee = self.android_devices[0], self.android_devices[1]
451
452        return tmo_apn_test(self.log, caller, callee, GEN_4G, msg_type='sms')
453
454    @test_tracker_info(uuid='08b4b549-cacb-481a-b6ea-7368b5608009')
455    @TelephonyBaseTest.tel_test_wrap
456    def test_tmo_apn_settings_mms_lte(self):
457        """Test APN test and MMS
458
459        Steps:
460            1. Provision device to LTE
461            2. Launch Settings - Network & Internet
462            3. Click on SIMs
463            4. Click on Access Point Names
464            5. Add New APN
465            6. Add TMO APN details and Save
466            7. Switch APN to New APN
467            8. Check Network is connected to LTE
468            9. Send MMS
469
470        Returns:
471            True is tests passes else False
472        """
473        caller, callee = self.android_devices[0], self.android_devices[1]
474
475        return tmo_apn_test(self.log, caller, callee, GEN_4G, msg_type='mms')
476