• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3.4
2#
3#   Copyright 2018 - 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 Pre Check In Sanity
18"""
19
20import collections
21import time
22import os
23import re
24
25from acts import signals
26from acts.utils import unzip_maintain_permissions
27from acts.utils import exe_cmd
28from acts.controllers.android_device import SL4A_APK_NAME
29from acts.controllers.android_device import list_adb_devices
30from acts.controllers.android_device import list_fastboot_devices
31from acts.test_decorators import test_tracker_info
32from acts_contrib.test_utils.tel.TelephonyBaseTest import TelephonyBaseTest
33from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_FOR_BOOT_COMPLETE
34from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_FOR_CARRIERCONFIG_CHANGE
35from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_FOR_CARRIERID_CHANGE
36from acts_contrib.test_utils.tel.tel_defines import VZW_CARRIER_CONFIG_VERSION
37from acts_contrib.test_utils.tel.tel_defines import ATT_CARRIER_CONFIG_VERSION
38from acts_contrib.test_utils.tel.tel_defines import CARRIER_ID_METADATA_URL
39from acts_contrib.test_utils.tel.tel_defines import CARRIER_ID_CONTENT_URL
40from acts_contrib.test_utils.tel.tel_defines import CARRIER_ID_VERSION
41from acts_contrib.test_utils.tel.tel_defines import ER_DB_ID_VERSION
42from acts_contrib.test_utils.tel.tel_defines import WAIT_TIME_FOR_ER_DB_CHANGE
43from acts_contrib.test_utils.tel.tel_defines import CARRIER_ID_METADATA_URL_P
44from acts_contrib.test_utils.tel.tel_defines import CARRIER_ID_CONTENT_URL_P
45from acts_contrib.test_utils.tel.tel_defines import CARRIER_ID_VERSION_P
46from acts_contrib.test_utils.tel.tel_bootloader_utils import fastboot_wipe
47from acts_contrib.test_utils.tel.tel_lookup_tables import device_capabilities
48from acts_contrib.test_utils.tel.tel_lookup_tables import operator_capabilities
49from acts_contrib.test_utils.tel.tel_phone_setup_utils import phone_setup_volte
50from acts_contrib.test_utils.tel.tel_subscription_utils import get_cbrs_and_default_sub_id
51from acts_contrib.test_utils.tel.tel_test_utils import lock_lte_band_by_mds
52from acts_contrib.test_utils.tel.tel_test_utils import get_model_name
53from acts_contrib.test_utils.tel.tel_test_utils import get_operator_name
54from acts_contrib.test_utils.tel.tel_test_utils import reboot_device
55from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode
56from acts_contrib.test_utils.tel.tel_test_utils import trigger_modem_crash_by_modem
57from acts_contrib.test_utils.tel.tel_test_utils import bring_up_sl4a
58from acts_contrib.test_utils.tel.tel_test_utils import get_carrier_config_version
59from acts_contrib.test_utils.tel.tel_test_utils import get_carrier_id_version
60from acts_contrib.test_utils.tel.tel_test_utils import get_er_db_id_version
61from acts_contrib.test_utils.tel.tel_test_utils import get_database_content
62from acts_contrib.test_utils.tel.tel_test_utils import install_googleaccountutil_apk
63from acts_contrib.test_utils.tel.tel_test_utils import add_whitelisted_account
64from acts_contrib.test_utils.tel.tel_test_utils import adb_disable_verity
65from acts_contrib.test_utils.tel.tel_test_utils import install_carriersettings_apk
66from acts_contrib.test_utils.tel.tel_test_utils import cleanup_configupdater
67from acts_contrib.test_utils.tel.tel_test_utils import pull_carrier_id_files
68from acts_contrib.test_utils.tel.tel_wifi_utils import ensure_wifi_connected
69from acts_contrib.test_utils.tel.tel_wifi_utils import wifi_toggle_state
70from acts.utils import get_current_epoch_time
71from acts.keys import Config
72
73
74class TelLiveNoQXDMLogTest(TelephonyBaseTest):
75    def setup_class(self):
76        super().setup_class()
77        self.dut = self.android_devices[0]
78        if len(self.android_devices) > 1:
79            self.ad_reference = self.android_devices[1]
80            setattr(self.ad_reference, "qxdm_log", False)
81        else:
82            self.ad_reference = None
83        setattr(self.dut, "qxdm_log", False)
84        self.stress_test_number = int(
85            self.user_params.get("stress_test_number", 5))
86        self.skip_reset_between_cases = False
87        self.dut_model = get_model_name(self.dut)
88        self.dut_operator = get_operator_name(self.log, self.dut)
89        self.dut_capabilities = set(
90            device_capabilities.get(
91                self.dut_model, device_capabilities["default"])) & set(
92                    operator_capabilities.get(
93                        self.dut_operator, operator_capabilities["default"]))
94        self.dut.log.info("DUT capabilities: %s", self.dut_capabilities)
95        self.user_params["check_crash"] = False
96        self.skip_reset_between_cases = False
97        self.path = self.user_params['account_util'][0]
98        self.user_account = "commsteltest1"
99        self.user_password = "tellivetest2"
100
101    def _get_list_average(self, input_list):
102        total_sum = float(sum(input_list))
103        total_count = float(len(input_list))
104        if input_list == []:
105            return False
106        return float(total_sum / total_count)
107
108    def _telephony_bootup_time_test(self):
109        """Telephony Bootup Perf Test
110
111        Arguments:
112            check_lte_data: whether to check the LTE data.
113            check_volte: whether to check Voice over LTE.
114            check_wfc: whether to check Wifi Calling.
115
116        Expected Results:
117            Time
118
119        Returns:
120            True is pass, False if fail.
121        """
122        self.number_of_devices = 1
123        ad = self.dut
124        toggle_airplane_mode(self.log, ad, False)
125        if not phone_setup_volte(self.log, ad):
126            ad.log.error("Failed to setup VoLTE.")
127            return False
128        fail_count = collections.defaultdict(int)
129        test_result = True
130        keyword_time_dict = {}
131
132        text_search_mapping = {
133            'boot_complete': "ModemService: Received: android.intent.action.BOOT_COMPLETED",
134            'Voice_Reg': "< VOICE_REGISTRATION_STATE {.regState = REG_HOME",
135            'Data_Reg': "< DATA_REGISTRATION_STATE {.regState = REG_HOME",
136            'Data_Call_Up': "onSetupConnectionCompleted result=SUCCESS",
137            'VoLTE_Enabled': "isVolteEnabled=true",
138        }
139
140        text_obj_mapping = {
141            "boot_complete": None,
142            "Voice_Reg": None,
143            "Data_Reg": None,
144            "Data_Call_Up": None,
145            "VoLTE_Enabled": None,
146        }
147        blocked_for_calculate = ["boot_complete"]
148        for i in range(1, self.stress_test_number + 1):
149            ad.log.info("Telephony Bootup Time Test %s Iteration: %d / %d",
150                        self.test_name, i, self.stress_test_number)
151            begin_time = get_current_epoch_time()
152            ad.log.debug("Begin Time is %s", begin_time)
153            ad.log.info("reboot!")
154            reboot_device(ad)
155            iteration_result = "pass"
156
157            time.sleep(WAIT_TIME_FOR_BOOT_COMPLETE)
158
159            dict_match = ad.search_logcat(
160                text_search_mapping['boot_complete'], begin_time=begin_time)
161            if len(dict_match) != 0:
162                text_obj_mapping['boot_complete'] = dict_match[0][
163                    'datetime_obj']
164                ad.log.debug("Datetime for boot_complete is %s",
165                             text_obj_mapping['boot_complete'])
166                bootup_time = dict_match[0]['datetime_obj'].strftime('%s')
167                bootup_time = int(bootup_time) * 1000
168                ad.log.info("Bootup Time is %d", bootup_time)
169            else:
170                ad.log.error("TERMINATE- boot_complete not seen in logcat")
171                return False
172
173            for tel_state in text_search_mapping:
174                if tel_state == "boot_complete":
175                    continue
176                dict_match = ad.search_logcat(
177                    text_search_mapping[tel_state], begin_time=bootup_time)
178                if len(dict_match) != 0:
179                    text_obj_mapping[tel_state] = dict_match[0]['datetime_obj']
180                    ad.log.debug("Datetime for %s is %s", tel_state,
181                                 text_obj_mapping[tel_state])
182                else:
183                    ad.log.error("Cannot Find Text %s in logcat",
184                                 text_search_mapping[tel_state])
185                    blocked_for_calculate.append(tel_state)
186                    ad.log.debug("New Blocked %s", blocked_for_calculate)
187
188            ad.log.info("List Blocked %s", blocked_for_calculate)
189            for tel_state in text_search_mapping:
190                if tel_state not in blocked_for_calculate:
191                    time_diff = text_obj_mapping[tel_state] - \
192                                text_obj_mapping['boot_complete']
193                    ad.log.info("Time Diff is %d for %s", time_diff.seconds,
194                                tel_state)
195                    if tel_state in keyword_time_dict:
196                        keyword_time_dict[tel_state].append(time_diff.seconds)
197                    else:
198                        keyword_time_dict[tel_state] = [
199                            time_diff.seconds,
200                        ]
201                    ad.log.debug("Keyword Time Dict %s", keyword_time_dict)
202
203            ad.log.info("Telephony Bootup Time Test %s Iteration: %d / %d %s",
204                        self.test_name, i, self.stress_test_number,
205                        iteration_result)
206        ad.log.info("Final Keyword Time Dict %s", keyword_time_dict)
207        for tel_state in text_search_mapping:
208            if tel_state not in blocked_for_calculate:
209                avg_time = self._get_list_average(keyword_time_dict[tel_state])
210                if avg_time < 12.0:
211                    ad.log.info("Average %s for %d iterations = %.2f seconds",
212                                tel_state, self.stress_test_number, avg_time)
213                else:
214                    ad.log.error("Average %s for %d iterations = %.2f seconds",
215                                 tel_state, self.stress_test_number, avg_time)
216                    fail_count[tel_state] += 1
217
218        ad.log.info("Bootup Time Dict: %s", keyword_time_dict)
219        ad.log.info("fail_count: %s", dict(fail_count))
220        for failure, count in fail_count.items():
221            if count:
222                ad.log.error("%s %s failures in %s iterations", count, failure,
223                             self.stress_test_number)
224                test_result = False
225        return test_result
226
227    def _cbrs_bootup_time_test(self):
228        """CBRS Bootup Perf Test
229
230        Expected Results:
231            Time
232
233        Returns:
234            True is pass, False if fail.
235        """
236        self.number_of_devices = 1
237        ad = self.dut
238        cbrs_subid, default_subid = get_cbrs_and_default_sub_id(ad)
239        toggle_airplane_mode(self.log, ad, False)
240
241        fail_count = collections.defaultdict(int)
242        test_result = True
243        keyword_time_dict = {}
244
245        text_search_mapping = {
246            'boot_complete': "ModemService: Received: android.intent.action.BOOT_COMPLETED",
247            'cbrs_active': "notifyPreferredDataSubIdChanged to %s" % cbrs_subid,
248        }
249
250        text_obj_mapping = {
251            "boot_complete": None,
252            "cbrs_active": None,
253        }
254        blocked_for_calculate = ["boot_complete"]
255        for i in range(1, self.stress_test_number + 1):
256            ad.log.info("CBRS Bootup Time Test %s Iteration: %d / %d",
257                        self.test_name, i, self.stress_test_number)
258            begin_time = get_current_epoch_time()
259            ad.log.debug("Begin Time is %s", begin_time)
260            ad.log.info("reboot!")
261            reboot_device(ad)
262            iteration_result = "pass"
263
264            time.sleep(WAIT_TIME_FOR_BOOT_COMPLETE)
265
266            dict_match = ad.search_logcat(
267                text_search_mapping['boot_complete'], begin_time=begin_time)
268            if len(dict_match) != 0:
269                text_obj_mapping['boot_complete'] = dict_match[0][
270                    'datetime_obj']
271                ad.log.debug("Datetime for boot_complete is %s",
272                             text_obj_mapping['boot_complete'])
273                bootup_time = dict_match[0]['datetime_obj'].strftime('%s')
274                bootup_time = int(bootup_time) * 1000
275                ad.log.info("Bootup Time is %d", bootup_time)
276            else:
277                ad.log.error("TERMINATE- boot_complete not seen in logcat")
278                return False
279
280            for tel_state in text_search_mapping:
281                if tel_state == "boot_complete":
282                    continue
283                dict_match = ad.search_logcat(
284                    text_search_mapping[tel_state], begin_time=bootup_time)
285                if len(dict_match) != 0:
286                    text_obj_mapping[tel_state] = dict_match[0]['datetime_obj']
287                    ad.log.debug("Datetime for %s is %s", tel_state,
288                                 text_obj_mapping[tel_state])
289                else:
290                    ad.log.error("Cannot Find Text %s in logcat",
291                                 text_search_mapping[tel_state])
292                    blocked_for_calculate.append(tel_state)
293                    ad.log.debug("New Blocked %s", blocked_for_calculate)
294
295            ad.log.info("List Blocked %s", blocked_for_calculate)
296            for tel_state in text_search_mapping:
297                if tel_state not in blocked_for_calculate:
298                    time_diff = text_obj_mapping[tel_state] - \
299                                text_obj_mapping['boot_complete']
300                    ad.log.info("Time Diff is %d for %s", time_diff.seconds,
301                                tel_state)
302                    if tel_state in keyword_time_dict:
303                        keyword_time_dict[tel_state].append(time_diff.seconds)
304                    else:
305                        keyword_time_dict[tel_state] = [
306                            time_diff.seconds,
307                        ]
308                    ad.log.debug("Keyword Time Dict %s", keyword_time_dict)
309
310            ad.log.info("CBRS Bootup Time Test %s Iteration: %d / %d %s",
311                        self.test_name, i, self.stress_test_number,
312                        iteration_result)
313        ad.log.info("Final Keyword Time Dict %s", keyword_time_dict)
314        for tel_state in text_search_mapping:
315            if tel_state not in blocked_for_calculate:
316                avg_time = self._get_list_average(keyword_time_dict[tel_state])
317                if avg_time < 12.0:
318                    ad.log.info("Average %s for %d iterations = %.2f seconds",
319                                tel_state, self.stress_test_number, avg_time)
320                else:
321                    ad.log.error("Average %s for %d iterations = %.2f seconds",
322                                 tel_state, self.stress_test_number, avg_time)
323                    fail_count[tel_state] += 1
324
325        ad.log.info("Bootup Time Dict: %s", keyword_time_dict)
326        ad.log.info("fail_count: %s", dict(fail_count))
327        for failure, count in fail_count.items():
328            if count:
329                ad.log.error("%s %s failures in %s iterations", count, failure,
330                             self.stress_test_number)
331                test_result = False
332        return test_result
333
334    """ Tests Begin """
335
336    @test_tracker_info(uuid="109d59ff-a488-4a68-87fd-2d8d0c035326")
337    @TelephonyBaseTest.tel_test_wrap
338    def test_bootup_optimized_stress(self):
339        """Bootup Optimized Reliability Test
340
341        Steps:
342            1. Reboot DUT.
343            2. Parse logcat for time taken by Voice, Data, VoLTE
344            3. Repeat Step 1~2 for N times. (before reboot)
345
346        Expected Results:
347            No crash happens in stress test.
348
349        Returns:
350            True is pass, False if fail.
351        """
352        return self._telephony_bootup_time_test()
353
354    @test_tracker_info(uuid="d29e6e62-3d54-4a58-b67f-2ba0de3d0a19")
355    @TelephonyBaseTest.tel_test_wrap
356    def test_bootup_cbrs_stress(self):
357        """Bootup Optimized Reliability Test
358
359        Steps:
360            1. Reboot DUT.
361            2. Parse logcat for time taken by CBRS data
362            3. Repeat Step 1~2 for N times. (before reboot)
363
364        Expected Results:
365            No crash happens in stress test.
366
367        Returns:
368            True is pass, False if fail.
369        """
370        return self._cbrs_bootup_time_test()
371
372    @test_tracker_info(uuid="67f50d11-a987-4e79-9a20-1569d365511b")
373    @TelephonyBaseTest.tel_test_wrap
374    def test_modem_power_anomaly_file_existence(self):
375        """Verify if the power anomaly file exists
376
377        1. Collect Bugreport
378        2. unzip bugreport
379        3. remane the .bin file to .tar
380        4. unzip dumpstate.tar
381        5. Verify if the file exists
382
383        """
384        ad = self.android_devices[0]
385        cmd = ("am broadcast -a "
386               "com.google.gservices.intent.action.GSERVICES_OVERRIDE "
387               "-e \"ce.cm.power_anomaly_data_enable\" \"true\"")
388        ad.adb.shell(cmd)
389        time.sleep(60)
390        begin_time = get_current_epoch_time()
391        for i in range(3):
392            try:
393                ad.take_bug_report(self.test_name, begin_time)
394                bugreport_path = ad.device_log_path
395                break
396            except Exception as e:
397                ad.log.error("bugreport attempt %s error: %s", i + 1, e)
398        ad.log.info("Bugreport Path is %s" % bugreport_path)
399        try:
400            list_of_files = os.listdir(bugreport_path)
401            ad.log.info(list_of_files)
402            for filename in list_of_files:
403                if ".zip" in filename:
404                    ad.log.info(filename)
405                    file_path = os.path.join(bugreport_path, filename)
406                    ad.log.info(file_path)
407                    unzip_maintain_permissions(file_path, bugreport_path)
408            dumpstate_path = os.path.join(bugreport_path,
409                                          "dumpstate_board.bin")
410            if os.path.isfile(dumpstate_path):
411                os.rename(dumpstate_path,
412                          bugreport_path + "/dumpstate_board.tar")
413                os.chmod(bugreport_path + "/dumpstate_board.tar", 0o777)
414                current_dir = os.getcwd()
415                os.chdir(bugreport_path)
416                exe_cmd("tar -xvf %s" %
417                        (bugreport_path + "/dumpstate_board.tar"))
418                os.chdir(current_dir)
419            else:
420                ad.log.info("The dumpstate_path file %s does not exist" % dumpstate_path)
421            if os.path.isfile(bugreport_path + "/power_anomaly_data.txt"):
422                ad.log.info("Modem Power Anomaly File Exists!!")
423                return True
424            ad.log.info("Modem Power Anomaly File DO NOT Exist!!")
425            return False
426        except Exception as e:
427            ad.log.error(e)
428            return False
429
430    @TelephonyBaseTest.tel_test_wrap
431    def test_lock_lte_band_4(self):
432        """Set LTE band lock 4"""
433        if not self.dut.is_apk_installed("com.google.mdstest"):
434            raise signals.TestSkip("mdstest is not installed")
435        return lock_lte_band_by_mds(self.dut, "4")
436
437    @TelephonyBaseTest.tel_test_wrap
438    def test_lock_lte_band_13(self):
439        """Set LTE band lock 4"""
440        if not self.dut.is_apk_installed("com.google.mdstest"):
441            raise signals.TestSkip("mdstest is not installed")
442        return lock_lte_band_by_mds(self.dut, "13")
443
444    @test_tracker_info(uuid="e2a8cb1e-7998-4912-9e16-d9e5f1daee5d")
445    @TelephonyBaseTest.tel_test_wrap
446    def test_modem_ssr_rampdump_generation(self):
447        """Trigger Modem SSR Crash and Verify if Ramdumps are generated
448
449        1. Empty the rampdump dir
450        2. Trigger ModemSSR
451        3. Verify if rampdumps are getting generated or not
452
453        """
454        if not self.dut.is_apk_installed("com.google.mdstest"):
455            raise signals.TestSkip("mdstest is not installed")
456        try:
457            ad = self.android_devices[0]
458            ad.adb.shell("rm -rf /data/vendor/ssrdump/*", ignore_status=True)
459            if not trigger_modem_crash_by_modem(ad):
460                ad.log.error("Failed to trigger Modem SSR, aborting...")
461                return False
462            out = ad.adb.shell("ls -l /data/vendor/ssrdump/ramdump_modem_*",
463                               ignore_status=True)
464            if "No such file" in out or not out:
465                ad.log.error("Ramdump Modem File not found post SSR\n %s", out)
466                return False
467            ad.log.info("Ramdump Modem File found post SSR\n %s", out)
468            return True
469        except Exception as e:
470            ad.log.error(e)
471            return False
472        finally:
473            ad.adb.shell("rm -rf /data/vendor/ssrdump/*", ignore_status=True)
474
475    @test_tracker_info(uuid="e12b2f00-7e18-47d6-b310-aabb96b165a3")
476    @TelephonyBaseTest.tel_test_wrap
477    def test_factory_modem_offline(self):
478        """Trigger Modem Factory Offline and verify if Modem Offline
479
480        1. Device in Fastboot
481        2. Wipe Userdata and set the fastboot command for factory
482        3. Device will bootup in adb, verify Modem Offline
483        4. Reboot again, and verify camping
484
485        """
486        try:
487            ad = self.android_devices[0]
488            skip_setup_wizard=True
489
490            # Pull sl4a apk from device
491            out = ad.adb.shell("pm path %s" % SL4A_APK_NAME)
492            result = re.search(r"package:(.*)", out)
493            if not result:
494                ad.log.error("Couldn't find sl4a apk")
495                return False
496            else:
497                sl4a_apk = result.group(1)
498                ad.log.info("Get sl4a apk from %s", sl4a_apk)
499                ad.pull_files([sl4a_apk], "/tmp/")
500            ad.stop_services()
501
502            # Fastboot Wipe
503            if ad.serial in list_adb_devices():
504                ad.log.info("Reboot to bootloader")
505                ad.adb.reboot("bootloader", ignore_status=True)
506                time.sleep(10)
507            if ad.serial in list_fastboot_devices():
508                ad.log.info("Wipe in fastboot")
509                ad.fastboot._w(timeout=300, ignore_status=True)
510                time.sleep(30)
511
512                # Factory Silent Mode Test
513                ad.log.info("Factory Offline in fastboot")
514                ad.fastboot.oem("continue-factory")
515                time.sleep(30)
516                ad.wait_for_boot_completion()
517                ad.root_adb()
518                ad.log.info("Re-install sl4a")
519                ad.adb.shell("settings put global verifier_verify_adb_installs"
520                             " 0")
521                ad.adb.install("-r /tmp/base.apk")
522                time.sleep(10)
523                try:
524                    ad.start_adb_logcat()
525                except:
526                    ad.log.error("Failed to start adb logcat!")
527                bring_up_sl4a(ad)
528                radio_state = ad.droid.telephonyIsRadioOn()
529                ad.log.info("Radio State is %s", radio_state)
530                if radio_state:
531                    ad.log.error("Radio state is ON in Factory Mode")
532                    return False
533                toggle_airplane_mode(self.log, ad, True)
534                time.sleep(5)
535                toggle_airplane_mode(self.log, ad, False)
536                radio_state = ad.droid.telephonyIsRadioOn()
537                ad.log.info("Radio State is %s", radio_state)
538                if ad.droid.telephonyIsRadioOn():
539                    ad.log.error("Radio state is ON after Airplane Toggle")
540                    return False
541                ad.log.info("Rebooting and verifying back in service")
542
543                # Bring it back to Online Mode
544                ad.stop_services()
545                ad.adb.reboot()
546                ad.wait_for_boot_completion()
547                ad.root_adb()
548                bring_up_sl4a(ad)
549                radio_state = ad.droid.telephonyIsRadioOn()
550                ad.log.info("Radio State is %s", radio_state)
551                if not radio_state:
552                    ad.log.error("Radio state is OFF in Online Mode")
553                    return False
554                return True
555        except Exception as e:
556            ad.log.error(e)
557            return False
558        finally:
559            ad.exit_setup_wizard()
560            bring_up_sl4a(ad)
561
562    @test_tracker_info(uuid="e681e6e2-a33c-4cbd-9ec4-8faa003cde6b")
563    @TelephonyBaseTest.tel_test_wrap
564    def test_carrier_config_version_after_fdr(self):
565        """Carrier Config Version Test after FDR
566
567        1. Disable Verity, remount, push carriersettings apk
568        2. WiFi is connected
569        3. Perform FDR, and re-connect WiFi
570        4. Wait for 45 mins and keep checking for version match
571
572        """
573        try:
574            cc_version_mapping = {
575                'vzw': VZW_CARRIER_CONFIG_VERSION,
576                'Verizon': VZW_CARRIER_CONFIG_VERSION,
577                'att': ATT_CARRIER_CONFIG_VERSION,
578            }
579            result_flag = False
580            time_var = 1
581            ad = self.android_devices[0]
582            skip_setup_wizard=True
583
584            # CarrierSettingsApk
585            carriersettingsapk = self.user_params["carriersettingsapk"]
586            if isinstance(carriersettingsapk, list):
587                carriersettingsapk = carriersettingsapk[0]
588            ad.log.info("Using file path %s", carriersettingsapk)
589
590            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
591                                         self.wifi_network_pass):
592                ad.log.error("connect WiFi failed")
593                return False
594
595            # Setup Steps
596            adb_disable_verity(ad)
597            install_carriersettings_apk(ad, carriersettingsapk)
598
599            # FDR
600            ad.log.info("Performing FDR")
601            fastboot_wipe(ad)
602            ad.log.info("FDR Complete")
603            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
604                                         self.wifi_network_pass):
605                ad.log.error("Connect WiFi failed")
606
607            # Wait for 45 mins for CC version upgrade
608            while(time_var < WAIT_TIME_FOR_CARRIERCONFIG_CHANGE):
609                current_version = get_carrier_config_version(ad)
610                if current_version == cc_version_mapping[self.dut_operator]:
611                    ad.log.info("Carrier Config Version Match %s in %s mins",
612                                current_version, time_var)
613                    result_flag = True
614                    break
615                else:
616                    ad.log.debug("Carrier Config Version Not Match")
617                time.sleep(60)
618                time_var += 1
619            if not result_flag:
620                ad.log.info("Carrier Config Failed to Update in %s mins",
621                             WAIT_TIME_FOR_CARRIERCONFIG_CHANGE)
622            return result_flag
623        except Exception as e:
624            ad.log.error(e)
625            return False
626
627
628    @test_tracker_info(uuid="41e6f2d3-76c9-4d3d-97b3-7075ad98bd41")
629    @TelephonyBaseTest.tel_test_wrap
630    def test_carrier_id_update_wifi_connected(self):
631        """Carrier Id Version Test after WiFi Connected
632
633        1. WiFi is connected
634        2. Perform setup steps to cleanup shared_prefs
635        3. Send P/H flag update to configUpdater
636        4. Wait for 5 mins and keep checking for version match
637
638        """
639        try:
640            result_flag = False
641            time_var = 1
642            ad = self.android_devices[0]
643            if ad.adb.getprop("ro.build.version.release") in ("9", "P", "10", "Q",
644                                "11", "R", "12", "S"):
645                CARRIER_ID_VERSION = CARRIER_ID_VERSION_P
646                CARRIER_ID_METADATA_URL = CARRIER_ID_METADATA_URL_P
647                CARRIER_ID_CONTENT_URL = CARRIER_ID_CONTENT_URL_P
648
649            ad.log.info("Before - CarrierId is %s", get_carrier_id_version(ad))
650            # Setup Steps
651            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
652                                         self.wifi_network_pass):
653                ad.log.error("connect WiFi failed")
654                return False
655            cleanup_configupdater(ad)
656            time.sleep(5)
657
658            # Trigger Config Update
659            ad.log.info("Triggering Config Update")
660            ad.log.info("%s", CARRIER_ID_METADATA_URL)
661            exe_cmd("adb -s %s shell %s" % (ad.serial,CARRIER_ID_METADATA_URL))
662            ad.log.info("%s", CARRIER_ID_CONTENT_URL)
663            exe_cmd("adb -s %s shell %s" % (ad.serial,CARRIER_ID_CONTENT_URL))
664
665            # Wait for 5 mins for Carrier Id version upgrade
666            while(time_var < WAIT_TIME_FOR_CARRIERID_CHANGE):
667                current_version = get_carrier_id_version(ad)
668                if current_version == CARRIER_ID_VERSION:
669                    ad.log.info("After CarrierId is %s in %s mins",
670                                current_version, time_var)
671                    result_flag = True
672                    break
673                else:
674                    ad.log.debug("Carrier Id Version Not Match")
675                time.sleep(60)
676                time_var += 1
677
678            if not result_flag:
679                ad.log.info("Carrier Id Failed to Update in %s mins",
680                             WAIT_TIME_FOR_CARRIERID_CHANGE)
681
682            # pb file check
683            out = ad.adb.shell("ls -l data/misc/carrierid/carrier_list.pb")
684            if "No such" in out:
685                ad.log.error("carrier_list.pb file is missing")
686                result_flag = False
687            else:
688                ad.log.info("carrier_list.pb file is present")
689            return result_flag
690        except Exception as e:
691            ad.log.error(e)
692            return False
693        finally:
694            carrier_id_path = os.path.join(self.log_path, self.test_name,
695                                           "CarrierId_%s" % ad.serial)
696            pull_carrier_id_files(ad, carrier_id_path)
697
698
699    @test_tracker_info(uuid="836d3963-f56d-438e-a35c-0706ac385153")
700    @TelephonyBaseTest.tel_test_wrap
701    def test_carrier_id_update_wifi_disconnected(self):
702        """Carrier Id Version Test with WiFi disconnected
703
704        1. WiFi is connected
705        2. Perform setup steps to cleanup shared_prefs
706        3. Send P/H flag update to configUpdater
707        4. Wait for 5 mins and keep checking for version match
708
709        """
710        try:
711            result_flag = False
712            time_var = 1
713            ad = self.android_devices[0]
714            ad.log.info("Before - CarrierId is %s", get_carrier_id_version(ad))
715
716            # Wifi Disconnect
717            cleanup_configupdater(ad)
718            wifi_toggle_state(ad.log, ad, False)
719
720            # Trigger Config Update
721            ad.log.info("Triggering Config Update")
722            ad.log.info("%s", CARRIER_ID_METADATA_URL)
723            exe_cmd("adb -s %s shell %s" % (ad.serial,CARRIER_ID_METADATA_URL))
724            ad.log.info("%s", CARRIER_ID_CONTENT_URL)
725            exe_cmd("adb -s %s shell %s" % (ad.serial,CARRIER_ID_CONTENT_URL))
726
727            # Wait for 5 mins for Carrier Id version upgrade
728            while(time_var < WAIT_TIME_FOR_CARRIERID_CHANGE):
729                current_version = get_carrier_id_version(ad)
730                if current_version == CARRIER_ID_VERSION:
731                    ad.log.info("After CarrierId is %s in %s mins",
732                                current_version, time_var)
733                    return False
734                else:
735                    ad.log.debug("Carrier Id Version Not Match")
736                time.sleep(60)
737                time_var += 1
738            time_var = 1
739            ad.log.info("Success - CarrierId not upgraded during WiFi OFF")
740
741            # WiFi Connect
742            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
743                                         self.wifi_network_pass):
744                ad.log.error("connect WiFi failed")
745                return False
746
747            # Wait for 5 mins for Carrier Id version upgrade
748            while(time_var < WAIT_TIME_FOR_CARRIERID_CHANGE):
749                current_version = get_carrier_id_version(ad)
750                if current_version == CARRIER_ID_VERSION:
751                    ad.log.info("After CarrierId is %s in %s mins",
752                                current_version, time_var)
753                    result_flag = True
754                    break
755                else:
756                    ad.log.debug("Carrier Id Version Not Match")
757                time.sleep(60)
758                time_var += 1
759
760            if not result_flag:
761                ad.log.info("Carrier Id Failed to Update in %s mins",
762                             WAIT_TIME_FOR_CARRIERID_CHANGE)
763            # pb file check
764            out = ad.adb.shell("ls -l data/misc/carrierid/carrier_list.pb")
765            if not out or "No such" in out:
766                ad.log.error("carrier_list.pb file is missing")
767                result_flag = False
768            else:
769                ad.log.info("carrier_list.pb file is present")
770            return result_flag
771        except Exception as e:
772            ad.log.error(e)
773            return False
774        finally:
775            carrier_id_path = os.path.join(self.log_path, self.test_name,
776                                           "CarrierId_%s" % ad.serial)
777            pull_carrier_id_files(ad, carrier_id_path)
778
779    @test_tracker_info(uuid="0edcafb1-b76d-45e1-9774-0638820b8b6e")
780    @TelephonyBaseTest.tel_test_wrap
781    def test_emergency_database_update_wifi_connected(self):
782        """Emergency DB Id Version Test after WiFi Connected
783
784        1. WiFi is connected
785        2. Login with whitelisted gmail credentials
786        3. Wait for 5 mins and keep checking for version match
787
788        """
789        try:
790            result_flag = False
791            time_var = 1
792            ad = self.android_devices[0]
793
794            # Get the Emergency database Id
795            ad.log.info("Before - Emergency DB Id is %s",
796                    get_er_db_id_version(ad))
797
798            # Connect to Wifi
799            if not ensure_wifi_connected(self.log, ad, self.wifi_network_ssid,
800                                         self.wifi_network_pass):
801                ad.log.error("connect WiFi failed")
802                return False
803            time.sleep(5)
804
805            #Login with whitelisted google account
806            if not install_googleaccountutil_apk(ad,self.path):
807                ad.log.error("Failed to install Google Util")
808                return False
809            if not add_whitelisted_account(ad,self.user_account,
810            self.user_password):
811                ad.log.error("Failed to Login with Google Account")
812                return False
813
814            # Wait for 5 mins for Emergency database Id version upgrade
815            while(time_var < WAIT_TIME_FOR_ER_DB_CHANGE):
816                current_version = get_er_db_id_version(ad)
817                if current_version == ER_DB_ID_VERSION:
818                    ad.log.info("ER DB version is %s in %s mins",
819                                current_version, time_var)
820                    result_flag = True
821                    break
822                else:
823                    ad.log.debug("ER Database Version Id Not Match")
824                time.sleep(60)
825                time_var += 1
826
827            if not result_flag:
828                ad.log.info("ER Database version Id Failed to Update in %s mins",
829                             WAIT_TIME_FOR_ER_DB_CHANGE)
830                return False
831            # Verify Emerency Database content
832            if not get_database_content(ad):
833                ad.log.error("Emergency Number does not match")
834                result_flag = False
835                return False
836            ad.log.info("Emergency Number is 54321")
837
838        except Exception as e:
839            ad.log.error(e)
840            return False
841        finally:
842            return result_flag
843""" Tests End """
844