1#!/usr/bin/env python3
2#
3#   Copyright 2020 - The Android Open Source Project
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.
16import time
17import os
18import re
19import fnmatch
20from multiprocessing import Process
21
22from acts import utils
23from acts import asserts
24from acts import signals
25from acts.base_test import BaseTestClass
26from acts.test_decorators import test_tracker_info
27from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
28from acts_contrib.test_utils.tel import tel_test_utils as tutils
29from acts_contrib.test_utils.gnss import gnss_test_utils as gutils
30from acts.utils import get_current_epoch_time
31from acts.utils import unzip_maintain_permissions
32from acts.utils import force_airplane_mode
33from acts_contrib.test_utils.wifi.wifi_test_utils import wifi_toggle_state
34from acts_contrib.test_utils.tel.tel_test_utils import flash_radio
35from acts_contrib.test_utils.tel.tel_test_utils import verify_internet_connection
36from acts_contrib.test_utils.tel.tel_test_utils import abort_all_tests
37from acts_contrib.test_utils.tel.tel_test_utils import stop_qxdm_logger
38from acts_contrib.test_utils.tel.tel_test_utils import check_call_state_connected_by_adb
39from acts_contrib.test_utils.tel.tel_test_utils import initiate_call
40from acts_contrib.test_utils.tel.tel_test_utils import hangup_call
41from acts_contrib.test_utils.tel.tel_test_utils import http_file_download_by_sl4a
42from acts_contrib.test_utils.tel.tel_test_utils import start_qxdm_logger
43from acts_contrib.test_utils.tel.tel_test_utils import trigger_modem_crash
44from acts_contrib.test_utils.gnss.gnss_test_utils import get_baseband_and_gms_version
45from acts_contrib.test_utils.gnss.gnss_test_utils import set_attenuator_gnss_signal
46from acts_contrib.test_utils.gnss.gnss_test_utils import _init_device
47from acts_contrib.test_utils.gnss.gnss_test_utils import check_location_service
48from acts_contrib.test_utils.gnss.gnss_test_utils import clear_logd_gnss_qxdm_log
49from acts_contrib.test_utils.gnss.gnss_test_utils import set_mobile_data
50from acts_contrib.test_utils.gnss.gnss_test_utils import set_wifi_and_bt_scanning
51from acts_contrib.test_utils.gnss.gnss_test_utils import get_gnss_qxdm_log
52from acts_contrib.test_utils.gnss.gnss_test_utils import remount_device
53from acts_contrib.test_utils.gnss.gnss_test_utils import reboot
54from acts_contrib.test_utils.gnss.gnss_test_utils import check_network_location
55from acts_contrib.test_utils.gnss.gnss_test_utils import launch_google_map
56from acts_contrib.test_utils.gnss.gnss_test_utils import check_location_api
57from acts_contrib.test_utils.gnss.gnss_test_utils import set_battery_saver_mode
58from acts_contrib.test_utils.gnss.gnss_test_utils import kill_xtra_daemon
59from acts_contrib.test_utils.gnss.gnss_test_utils import start_gnss_by_gtw_gpstool
60from acts_contrib.test_utils.gnss.gnss_test_utils import process_gnss_by_gtw_gpstool
61from acts_contrib.test_utils.gnss.gnss_test_utils import start_ttff_by_gtw_gpstool
62from acts_contrib.test_utils.gnss.gnss_test_utils import process_ttff_by_gtw_gpstool
63from acts_contrib.test_utils.gnss.gnss_test_utils import check_ttff_data
64from acts_contrib.test_utils.gnss.gnss_test_utils import start_youtube_video
65from acts_contrib.test_utils.gnss.gnss_test_utils import fastboot_factory_reset
66from acts_contrib.test_utils.gnss.gnss_test_utils import gnss_trigger_modem_ssr_by_adb
67from acts_contrib.test_utils.gnss.gnss_test_utils import gnss_trigger_modem_ssr_by_mds
68from acts_contrib.test_utils.gnss.gnss_test_utils import disable_supl_mode
69from acts_contrib.test_utils.gnss.gnss_test_utils import connect_to_wifi_network
70from acts_contrib.test_utils.gnss.gnss_test_utils import check_xtra_download
71from acts_contrib.test_utils.gnss.gnss_test_utils import gnss_tracking_via_gtw_gpstool
72from acts_contrib.test_utils.gnss.gnss_test_utils import parse_gtw_gpstool_log
73from acts_contrib.test_utils.gnss.gnss_test_utils import enable_supl_mode
74from acts_contrib.test_utils.gnss.gnss_test_utils import start_toggle_gnss_by_gtw_gpstool
75from acts_contrib.test_utils.gnss.gnss_test_utils import grant_location_permission
76from acts_contrib.test_utils.tel.tel_test_utils import start_adb_tcpdump
77from acts_contrib.test_utils.tel.tel_test_utils import stop_adb_tcpdump
78from acts_contrib.test_utils.tel.tel_test_utils import get_tcpdump_log
79
80
81class GnssFunctionTest(BaseTestClass):
82    """ GNSS Function Tests"""
83    def setup_class(self):
84        super().setup_class()
85        self.ad = self.android_devices[0]
86        req_params = ["pixel_lab_network", "standalone_cs_criteria",
87                      "standalone_ws_criteria", "standalone_hs_criteria",
88                      "supl_cs_criteria", "supl_ws_criteria",
89                      "supl_hs_criteria", "xtra_cs_criteria",
90                      "xtra_ws_criteria", "xtra_hs_criteria",
91                      "weak_signal_supl_cs_criteria",
92                      "weak_signal_supl_ws_criteria",
93                      "weak_signal_supl_hs_criteria",
94                      "weak_signal_xtra_cs_criteria",
95                      "weak_signal_xtra_ws_criteria",
96                      "weak_signal_xtra_hs_criteria",
97                      "default_gnss_signal_attenuation",
98                      "weak_gnss_signal_attenuation",
99                      "no_gnss_signal_attenuation", "gnss_init_error_list",
100                      "gnss_init_error_allowlist", "pixel_lab_location",
101                      "legacy_wifi_xtra_cs_criteria", "legacy_projects",
102                      "qdsp6m_path", "supl_capabilities", "ttff_test_cycle",
103                      "collect_logs", "dpo_threshold"]
104        self.unpack_userparams(req_param_names=req_params)
105        # create hashmap for SSID
106        self.ssid_map = {}
107        for network in self.pixel_lab_network:
108            SSID = network["SSID"]
109            self.ssid_map[SSID] = network
110        self.ttff_mode = {"cs": "Cold Start",
111                          "ws": "Warm Start",
112                          "hs": "Hot Start"}
113        if self.ad.model in self.legacy_projects:
114            self.wifi_xtra_cs_criteria = self.legacy_wifi_xtra_cs_criteria
115        else:
116            self.wifi_xtra_cs_criteria = self.xtra_cs_criteria
117        if self.collect_logs and \
118            gutils.check_chipset_vendor_by_qualcomm(self.ad):
119            self.flash_new_radio_or_mbn()
120            self.push_gnss_cfg()
121        _init_device(self.ad)
122
123    def setup_test(self):
124        get_baseband_and_gms_version(self.ad)
125        if self.collect_logs:
126            clear_logd_gnss_qxdm_log(self.ad)
127            set_attenuator_gnss_signal(self.ad, self.attenuators,
128                                       self.default_gnss_signal_attenuation)
129        if not verify_internet_connection(self.ad.log, self.ad, retries=3,
130                                          expected_state=True):
131            raise signals.TestFailure("Fail to connect to LTE network.")
132
133    def teardown_test(self):
134        if self.collect_logs:
135            gutils.stop_pixel_logger(self.ad)
136            stop_adb_tcpdump(self.ad)
137            set_attenuator_gnss_signal(self.ad, self.attenuators,
138                                       self.default_gnss_signal_attenuation)
139        if check_call_state_connected_by_adb(self.ad):
140            hangup_call(self.ad.log, self.ad)
141        if int(self.ad.adb.shell("settings get global airplane_mode_on")) != 0:
142            self.ad.log.info("Force airplane mode off")
143            force_airplane_mode(self.ad, False)
144        if self.ad.droid.wifiCheckState():
145            wifi_toggle_state(self.ad, False)
146        if int(self.ad.adb.shell("settings get global mobile_data")) != 1:
147            set_mobile_data(self.ad, True)
148        if int(self.ad.adb.shell(
149            "settings get global wifi_scan_always_enabled")) != 1:
150            set_wifi_and_bt_scanning(self.ad, True)
151
152    def on_fail(self, test_name, begin_time):
153        if self.collect_logs:
154            self.ad.take_bug_report(test_name, begin_time)
155            get_gnss_qxdm_log(self.ad, self.qdsp6m_path)
156            get_tcpdump_log(self.ad, test_name, begin_time)
157
158    def push_gnss_cfg(self):
159        """Push required GNSS cfg file to DUT for PixelLogger to use as
160        default GNSS logging mask."""
161        gnss_cfg_path = "/vendor/etc/mdlog"
162        gnss_cfg_file = self.user_params.get("gnss_cfg")
163        if isinstance(gnss_cfg_file, list):
164            gnss_cfg_file = gnss_cfg_file[0]
165        os.system("chmod -R 777 %s" % gnss_cfg_file)
166        self.ad.log.info("GNSS Required CFG = %s" % gnss_cfg_file)
167        self.ad.log.info("Push %s to %s" % (gnss_cfg_file, gnss_cfg_path))
168        self.ad.push_system_file(gnss_cfg_file, gnss_cfg_path)
169
170    def flash_new_radio_or_mbn(self):
171        paths = {}
172        path = self.user_params.get("radio_image")
173        if isinstance(path, list):
174            path = path[0]
175        if "dev/null" in path:
176            self.ad.log.info("Radio image path is not defined in Test flag.")
177            return False
178        for path_key in os.listdir(path):
179            if fnmatch.fnmatch(path_key, "*.img"):
180                paths["radio_image"] = os.path.join(path, path_key)
181                os.system("chmod -R 777 %s" % paths["radio_image"])
182                self.ad.log.info("radio_image = %s" % paths["radio_image"])
183            if fnmatch.fnmatch(path_key, "*.zip"):
184                zip_path = os.path.join(path, path_key)
185                self.ad.log.info("Unzip %s", zip_path)
186                dest_path = os.path.join(path, "mbn")
187                unzip_maintain_permissions(zip_path, dest_path)
188                paths["mbn_path"] = dest_path
189                os.system("chmod -R 777 %s" % paths["mbn_path"])
190                self.ad.log.info("mbn_path = %s" % paths["mbn_path"])
191                self.ad.log.info(os.listdir(paths["mbn_path"]))
192        if not paths.get("radio_image"):
193            self.ad.log.info("No radio image is provided on X20. "
194                             "Skip flashing radio step.")
195            return False
196        else:
197            get_baseband_and_gms_version(self.ad, "Before flash radio")
198            flash_radio(self.ad, paths["radio_image"])
199            get_baseband_and_gms_version(self.ad, "After flash radio")
200        if not paths.get("mbn_path"):
201            self.ad.log.info("No need to push mbn files")
202            return False
203        else:
204            try:
205                mcfg_ver = self.ad.adb.shell(
206                    "cat /vendor/rfs/msm/mpss/readonly/vendor/mbn/mcfg.version")
207                if mcfg_ver:
208                    self.ad.log.info("Before push mcfg, mcfg.version = %s",
209                                     mcfg_ver)
210                else:
211                    self.ad.log.info("There is no mcfg.version before push, "
212                                     "unmatching device")
213                    return False
214            except Exception as e:
215                self.ad.log.info("There is no mcfg.version before push, "
216                                 "unmatching device %s" % e)
217                return False
218            get_baseband_and_gms_version(self.ad, "Before push mcfg")
219            try:
220                remount_device(self.ad)
221                cmd = "%s %s" % (paths["mbn_path"]+"/.",
222                                 "/vendor/rfs/msm/mpss/readonly/vendor/mbn/")
223                out = self.ad.adb.push(cmd)
224                self.ad.log.info(out)
225                reboot(self.ad)
226            except Exception as e:
227                self.ad.log.error("Push mbn files error %s", e)
228                return False
229            get_baseband_and_gms_version(self.ad, "After push mcfg")
230            try:
231                new_mcfg_ver = self.ad.adb.shell(
232                    "cat /vendor/rfs/msm/mpss/readonly/vendor/mbn/mcfg.version")
233                if new_mcfg_ver:
234                    self.ad.log.info("New mcfg.version = %s", new_mcfg_ver)
235                    if new_mcfg_ver == mcfg_ver:
236                        self.ad.log.error("mcfg.version is the same before and "
237                                          "after push")
238                        return True
239                else:
240                    self.ad.log.error("Unable to get new mcfg.version")
241                    return False
242            except Exception as e:
243                self.ad.log.error("cat mcfg.version with error %s", e)
244                return False
245
246    def run_ttff_via_gtw_gpstool(self, mode, criteria):
247        """Run GNSS TTFF test with selected mode and parse the results.
248
249        Args:
250            mode: "cs", "ws" or "hs"
251            criteria: Criteria for the TTFF.
252        """
253        begin_time = get_current_epoch_time()
254        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
255        start_ttff_by_gtw_gpstool(self.ad, mode, self.ttff_test_cycle)
256        ttff_data = process_ttff_by_gtw_gpstool(
257            self.ad, begin_time, self.pixel_lab_location)
258        result = check_ttff_data(
259            self.ad, ttff_data, self.ttff_mode.get(mode), criteria)
260        asserts.assert_true(
261            result, "TTFF %s fails to reach designated criteria of %d "
262                    "seconds." % (self.ttff_mode.get(mode), criteria))
263
264    def start_qxdm_and_tcpdump_log(self):
265        """Start QXDM and adb tcpdump if collect_logs is True."""
266        if self.collect_logs:
267            gutils.start_pixel_logger(self.ad)
268            start_adb_tcpdump(self.ad)
269
270    def supl_ttff_with_sim(self, mode, criteria):
271        """Verify SUPL TTFF functionality.
272
273        Args:
274            mode: "cs", "ws" or "hs"
275            criteria: Criteria for the test.
276        """
277        kill_xtra_daemon(self.ad)
278        self.start_qxdm_and_tcpdump_log()
279        self.run_ttff_via_gtw_gpstool(mode, criteria)
280
281    def standalone_ttff_airplane_mode_on(self, mode, criteria):
282        """Verify Standalone GNSS TTFF functionality while airplane mode is on.
283
284        Args:
285            mode: "cs", "ws" or "hs"
286            criteria: Criteria for the test.
287        """
288        self.start_qxdm_and_tcpdump_log()
289        self.ad.log.info("Turn airplane mode on")
290        force_airplane_mode(self.ad, True)
291        self.run_ttff_via_gtw_gpstool(mode, criteria)
292
293    def supl_ttff_weak_gnss_signal(self, mode, criteria):
294        """Verify SUPL TTFF functionality under weak GNSS signal.
295
296        Args:
297            mode: "cs", "ws" or "hs"
298            criteria: Criteria for the test.
299        """
300        set_attenuator_gnss_signal(self.ad, self.attenuators,
301                                   self.weak_gnss_signal_attenuation)
302        kill_xtra_daemon(self.ad)
303        self.start_qxdm_and_tcpdump_log()
304        self.run_ttff_via_gtw_gpstool(mode, criteria)
305
306    def xtra_ttff_mobile_data(self, mode, criteria):
307        """Verify XTRA\LTO TTFF functionality with mobile data.
308
309        Args:
310            mode: "cs", "ws" or "hs"
311            criteria: Criteria for the test.
312        """
313        disable_supl_mode(self.ad)
314        self.start_qxdm_and_tcpdump_log()
315        self.run_ttff_via_gtw_gpstool(mode, criteria)
316
317    def xtra_ttff_weak_gnss_signal(self, mode, criteria):
318        """Verify XTRA\LTO TTFF functionality under weak GNSS signal.
319
320        Args:
321            mode: "cs", "ws" or "hs"
322            criteria: Criteria for the test.
323        """
324        set_attenuator_gnss_signal(self.ad, self.attenuators,
325                                   self.weak_gnss_signal_attenuation)
326        disable_supl_mode(self.ad)
327        self.start_qxdm_and_tcpdump_log()
328        self.run_ttff_via_gtw_gpstool(mode, criteria)
329
330    def xtra_ttff_wifi(self, mode, criteria):
331        """Verify XTRA\LTO TTFF functionality with WiFi.
332
333        Args:
334            mode: "cs", "ws" or "hs"
335            criteria: Criteria for the test.
336        """
337        disable_supl_mode(self.ad)
338        self.start_qxdm_and_tcpdump_log()
339        self.ad.log.info("Turn airplane mode on")
340        force_airplane_mode(self.ad, True)
341        wifi_toggle_state(self.ad, True)
342        connect_to_wifi_network(
343            self.ad, self.ssid_map[self.pixel_lab_network[0]["SSID"]])
344        self.run_ttff_via_gtw_gpstool(mode, criteria)
345
346    """ Test Cases """
347
348    @test_tracker_info(uuid="ab859f2a-2c95-4d15-bb7f-bd0e3278340f")
349    def test_gnss_one_hour_tracking(self):
350        """Verify GNSS tracking performance of signal strength and position
351        error.
352
353        Steps:
354            1. Launch GTW_GPSTool.
355            2. GNSS tracking for 60 minutes.
356
357        Expected Results:
358            DUT could finish 60 minutes test and output track data.
359        """
360        self.start_qxdm_and_tcpdump_log()
361        gnss_tracking_via_gtw_gpstool(self.ad, self.standalone_cs_criteria,
362                                      type="gnss", testtime=60)
363        parse_gtw_gpstool_log(self.ad, self.pixel_lab_location, type="gnss")
364
365    @test_tracker_info(uuid="623628ab-fdab-449d-9025-ebf4e9a404c2")
366    def test_dpo_function(self):
367        """Verify DPO Functionality.
368
369        Steps:
370            1. Launch GTW_GPSTool.
371            2. Enable GnssMeasurement.
372            3. GNSS tracking for 5 minutes.
373            4. Calculate the count diff of "HardwareClockDiscontinuityCount"
374
375        Expected Results:
376            DPO should be engaged in 5 minutes GNSS tracking.
377        """
378        tracking_minutes = 5
379        self.start_qxdm_and_tcpdump_log()
380        dpo_begin_time = get_current_epoch_time()
381        gnss_tracking_via_gtw_gpstool(self.ad,
382                                      self.standalone_cs_criteria,
383                                      type="gnss",
384                                      testtime=tracking_minutes,
385                                      meas_flag=True)
386        dpo_results = self.ad.search_logcat("HardwareClockDiscontinuityCount",
387                                            dpo_begin_time)
388        if not dpo_results:
389            raise signals.TestError(
390                "No \"HardwareClockDiscontinuityCount\" is found in logs.")
391        self.ad.log.info(dpo_results[0]["log_message"])
392        self.ad.log.info(dpo_results[-1]["log_message"])
393        first_dpo_count = int(dpo_results[0]["log_message"].split()[-1])
394        final_dpo_count = int(dpo_results[-1]["log_message"].split()[-1])
395        dpo_rate = ((final_dpo_count - first_dpo_count)/(tracking_minutes * 60))
396        dpo_engage_rate = "{percent:.2%}".format(percent=dpo_rate)
397        self.ad.log.info("DPO is ON for %d seconds during %d minutes test." % (
398            final_dpo_count - first_dpo_count, tracking_minutes))
399        self.ad.log.info("TestResult DPO_Engage_Rate " + dpo_engage_rate)
400        threshold = "{percent:.0%}".format(percent=self.dpo_threshold / 100)
401        asserts.assert_true(dpo_rate * 100 > self.dpo_threshold,
402                            "DPO only engaged %s in %d minutes test with "
403                            "threshold %s." % (dpo_engage_rate,
404                                               tracking_minutes,
405                                               threshold))
406
407    @test_tracker_info(uuid="499d2091-640a-4735-9c58-de67370e4421")
408    def test_gnss_init_error(self):
409        """Check if there is any GNSS initialization error after reboot.
410
411        Steps:
412            1. Reboot DUT.
413            2. Check logcat if the following error pattern shows up.
414              "E LocSvc.*", ".*avc.*denied.*u:r:location:s0",
415              ".*avc.*denied.*u:r:hal_gnss_qti:s0"
416
417        Expected Results:
418            There should be no GNSS initialization error after reboot.
419        """
420        error_mismatch = True
421        for attr in self.gnss_init_error_list:
422            error = self.ad.adb.shell("logcat -d | grep -E '%s'" % attr)
423            if error:
424                for allowlist in self.gnss_init_error_allowlist:
425                    if allowlist in error:
426                        error = re.sub(".*"+allowlist+".*\n?", "", error)
427                        self.ad.log.info("\"%s\" is in allow-list and removed "
428                                         "from error." % allowlist)
429                if error:
430                    error_mismatch = False
431                    self.ad.log.error("\n%s" % error)
432            else:
433                self.ad.log.info("NO \"%s\" initialization error found." % attr)
434        asserts.assert_true(error_mismatch, "Error message found after GNSS "
435                                            "init")
436
437    @test_tracker_info(uuid="ff318483-411c-411a-8b1a-422bd54f4a3f")
438    def test_supl_capabilities(self):
439        """Verify SUPL capabilities.
440
441        Steps:
442            1. Root DUT.
443            2. Check SUPL capabilities.
444
445        Expected Results:
446            CAPABILITIES=0x37 which supports MSA + MSB.
447            CAPABILITIES=0x17 = ON_DEMAND_TIME | MSA | MSB | SCHEDULING
448        """
449        if not gutils.check_chipset_vendor_by_qualcomm(self.ad):
450            raise signals.TestSkip("Not Qualcomm chipset. Skip the test.")
451        capabilities_state = str(
452            self.ad.adb.shell(
453                "cat vendor/etc/gps.conf | grep CAPABILITIES")).split("=")[-1]
454        self.ad.log.info("SUPL capabilities - %s" % capabilities_state)
455        asserts.assert_true(capabilities_state in self.supl_capabilities,
456                            "Wrong default SUPL capabilities is set. Found %s, "
457                            "expected any of %r" % (capabilities_state,
458                                                    self.supl_capabilities))
459
460    @test_tracker_info(uuid="dcae6979-ddb4-4cad-9d14-fbdd9439cf42")
461    def test_sap_valid_modes(self):
462        """Verify SAP Valid Modes.
463
464        Steps:
465            1. Root DUT.
466            2. Check SAP Valid Modes.
467
468        Expected Results:
469            SAP=PREMIUM
470        """
471        if not gutils.check_chipset_vendor_by_qualcomm(self.ad):
472            raise signals.TestSkip("Not Qualcomm chipset. Skip the test.")
473        sap_state = str(self.ad.adb.shell("cat vendor/etc/izat.conf | grep "
474                                          "SAP="))
475        self.ad.log.info("SAP Valid Modes - %s" % sap_state)
476        asserts.assert_true("SAP=PREMIUM" in sap_state,
477                            "Wrong SAP Valid Modes is set")
478
479    @test_tracker_info(uuid="14daaaba-35b4-42d9-8d2c-2a803dd746a6")
480    def test_network_location_provider_cell(self):
481        """Verify LocationManagerService API reports cell Network Location.
482
483        Steps:
484            1. WiFi scanning and Bluetooth scanning in Location Setting are OFF.
485            2. Launch GTW_GPSTool.
486            3. Verify whether test devices could report cell Network Location.
487            4. Repeat Step 2. to Step 3. for 5 times.
488
489        Expected Results:
490            Test devices could report cell Network Location.
491        """
492        test_result_all = []
493        self.start_qxdm_and_tcpdump_log()
494        set_wifi_and_bt_scanning(self.ad, False)
495        for i in range(1, 6):
496            test_result = check_network_location(
497                self.ad, retries=3, location_type="cell")
498            test_result_all.append(test_result)
499            self.ad.log.info("Iteration %d => %s" % (i, test_result))
500        set_wifi_and_bt_scanning(self.ad, True)
501        asserts.assert_true(all(test_result_all),
502                            "Fail to get networkLocationType=cell")
503
504    @test_tracker_info(uuid="a45bdc7d-29fa-4a1d-ba34-6340b90e308d")
505    def test_network_location_provider_wifi(self):
506        """Verify LocationManagerService API reports wifi Network Location.
507
508        Steps:
509            1. WiFi scanning and Bluetooth scanning in Location Setting are ON.
510            2. Launch GTW_GPSTool.
511            3. Verify whether test devices could report wifi Network Location.
512            4. Repeat Step 2. to Step 3. for 5 times.
513
514        Expected Results:
515            Test devices could report wifi Network Location.
516        """
517        test_result_all = []
518        self.start_qxdm_and_tcpdump_log()
519        set_wifi_and_bt_scanning(self.ad, True)
520        for i in range(1, 6):
521            test_result = check_network_location(
522                self.ad, retries=3, location_type="wifi")
523            test_result_all.append(test_result)
524            self.ad.log.info("Iteration %d => %s" % (i, test_result))
525        asserts.assert_true(all(test_result_all),
526                            "Fail to get networkLocationType=wifi")
527
528    @test_tracker_info(uuid="0919d375-baf2-4fe7-b66b-3f72d386f791")
529    def test_gmap_location_report_gps_network(self):
530        """Verify GnssLocationProvider API reports location to Google Map
531           when GPS and Location Accuracy are on.
532
533        Steps:
534            1. GPS and NLP are on.
535            2. Launch Google Map.
536            3. Verify whether test devices could report location.
537            4. Repeat Step 2. to Step 3. for 5 times.
538
539        Expected Results:
540            Test devices could report location to Google Map.
541        """
542        test_result_all = []
543        self.start_qxdm_and_tcpdump_log()
544        for i in range(1, 6):
545            grant_location_permission(self.ad, True)
546            launch_google_map(self.ad)
547            test_result = check_location_api(self.ad, retries=3)
548            self.ad.send_keycode("HOME")
549            test_result_all.append(test_result)
550            self.ad.log.info("Iteration %d => %s" % (i, test_result))
551        asserts.assert_true(all(test_result_all), "Fail to get location update")
552
553    @test_tracker_info(uuid="513361d2-7d72-41b0-a944-fb259c606b81")
554    def test_gmap_location_report_gps(self):
555        """Verify GnssLocationProvider API reports location to Google Map
556           when GPS is on and Location Accuracy is off.
557
558        Steps:
559            1. GPS is on.
560            2. Location Accuracy is off.
561            3. Launch Google Map.
562            4. Verify whether test devices could report location.
563            5. Repeat Step 3. to Step 4. for 5 times.
564
565        Expected Results:
566            Test devices could report location to Google Map.
567        """
568        test_result_all = []
569        self.start_qxdm_and_tcpdump_log()
570        self.ad.adb.shell("settings put secure location_mode 1")
571        out = int(self.ad.adb.shell("settings get secure location_mode"))
572        self.ad.log.info("Modify current Location Mode to %d" % out)
573        for i in range(1, 6):
574            grant_location_permission(self.ad, True)
575            launch_google_map(self.ad)
576            test_result = check_location_api(self.ad, retries=3)
577            self.ad.send_keycode("HOME")
578            test_result_all.append(test_result)
579            self.ad.log.info("Iteration %d => %s" % (i, test_result))
580        check_location_service(self.ad)
581        asserts.assert_true(all(test_result_all), "Fail to get location update")
582
583    @test_tracker_info(uuid="91a65121-b87d-450d-bd0f-387ade450ab7")
584    def test_gmap_location_report_battery_saver(self):
585        """Verify GnssLocationProvider API reports location to Google Map
586           when Battery Saver is enabled.
587
588        Steps:
589            1. GPS and NLP are on.
590            2. Enable Battery Saver.
591            3. Launch Google Map.
592            4. Verify whether test devices could report location.
593            5. Repeat Step 3. to Step 4. for 5 times.
594            6. Disable Battery Saver.
595
596        Expected Results:
597            Test devices could report location to Google Map.
598        """
599        test_result_all = []
600        self.start_qxdm_and_tcpdump_log()
601        set_battery_saver_mode(self.ad, True)
602        for i in range(1, 6):
603            grant_location_permission(self.ad, True)
604            launch_google_map(self.ad)
605            test_result = check_location_api(self.ad, retries=3)
606            self.ad.send_keycode("HOME")
607            test_result_all.append(test_result)
608            self.ad.log.info("Iteration %d => %s" % (i, test_result))
609        set_battery_saver_mode(self.ad, False)
610        asserts.assert_true(all(test_result_all), "Fail to get location update")
611
612    @test_tracker_info(uuid="a59c72af-5d56-4d88-9746-ae2749cac671")
613    def test_supl_ttff_cs(self):
614        """Verify SUPL functionality of TTFF Cold Start.
615
616        Steps:
617            1. Kill XTRA/LTO daemon to support SUPL only case.
618            2. SUPL TTFF Cold Start for 10 iteration.
619
620        Expected Results:
621            All SUPL TTFF Cold Start results should be less than
622            supl_cs_criteria.
623        """
624        self.supl_ttff_with_sim("cs", self.supl_cs_criteria)
625
626    @test_tracker_info(uuid="9a91c8ad-1978-414a-a9ac-8ebc782f77ff")
627    def test_supl_ttff_ws(self):
628        """Verify SUPL functionality of TTFF Warm Start.
629
630        Steps:
631            1. Kill XTRA/LTO daemon to support SUPL only case.
632            2. SUPL TTFF Warm Start for 10 iteration.
633
634        Expected Results:
635            All SUPL TTFF Warm Start results should be less than
636            supl_ws_criteria.
637        """
638        self.supl_ttff_with_sim("ws", self.supl_ws_criteria)
639
640    @test_tracker_info(uuid="bbd5aad4-3309-4579-a3b2-a06bfb674dfa")
641    def test_supl_ttff_hs(self):
642        """Verify SUPL functionality of TTFF Hot Start.
643
644        Steps:
645            1. Kill XTRA/LTO daemon to support SUPL only case.
646            2. SUPL TTFF Hot Start for 10 iteration.
647
648        Expected Results:
649            All SUPL TTFF Hot Start results should be less than
650            supl_hs_criteria.
651        """
652        self.supl_ttff_with_sim("hs", self.supl_hs_criteria)
653
654    @test_tracker_info(uuid="60c0aeec-0c8f-4a96-bc6c-05cba1260e73")
655    def test_supl_ongoing_call(self):
656        """Verify SUPL functionality during phone call.
657
658        Steps:
659            1. Kill XTRA/LTO daemon to support SUPL only case.
660            2. Initiate call on DUT.
661            3. SUPL TTFF Cold Start for 10 iteration.
662            4. DUT hang up call.
663
664        Expected Results:
665            All SUPL TTFF Cold Start results should be less than
666            supl_cs_criteria.
667        """
668        kill_xtra_daemon(self.ad)
669        self.start_qxdm_and_tcpdump_log()
670        self.ad.droid.setVoiceCallVolume(25)
671        initiate_call(self.ad.log, self.ad, "99117")
672        time.sleep(5)
673        if not check_call_state_connected_by_adb(self.ad):
674            raise signals.TestFailure("Call is not connected.")
675        self.run_ttff_via_gtw_gpstool("cs", self.supl_cs_criteria)
676
677    @test_tracker_info(uuid="df605509-328f-43e8-b6d8-00635bf701ef")
678    def test_supl_downloading_files(self):
679        """Verify SUPL functionality when downloading files.
680
681        Steps:
682            1. Kill XTRA/LTO daemon to support SUPL only case.
683            2. DUT start downloading files by sl4a.
684            3. SUPL TTFF Cold Start for 10 iteration.
685            4. DUT cancel downloading files.
686
687        Expected Results:
688            All SUPL TTFF Cold Start results should be within supl_cs_criteria.
689        """
690        begin_time = get_current_epoch_time()
691        kill_xtra_daemon(self.ad)
692        self.start_qxdm_and_tcpdump_log()
693        download = Process(target=http_file_download_by_sl4a,
694                           args=(self.ad, "https://speed.hetzner.de/10GB.bin",
695                                 None, None, True, 3600))
696        download.start()
697        time.sleep(10)
698        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
699        start_ttff_by_gtw_gpstool(
700            self.ad, ttff_mode="cs", iteration=self.ttff_test_cycle)
701        ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
702                                                self.pixel_lab_location)
703        download.terminate()
704        time.sleep(3)
705        result = check_ttff_data(self.ad, ttff_data, ttff_mode="Cold Start",
706                                 criteria=self.supl_cs_criteria)
707        asserts.assert_true(result, "TTFF fails to reach designated criteria")
708
709    @test_tracker_info(uuid="66b9f9d4-1397-4da7-9e55-8b89b1732017")
710    def test_supl_watching_youtube(self):
711        """Verify SUPL functionality when watching video on youtube.
712
713        Steps:
714            1. Kill XTRA/LTO daemon to support SUPL only case.
715            2. DUT start watching video on youtube.
716            3. SUPL TTFF Cold Start for 10 iteration at the background.
717            4. DUT stop watching video on youtube.
718
719        Expected Results:
720            All SUPL TTFF Cold Start results should be within supl_cs_criteria.
721        """
722        begin_time = get_current_epoch_time()
723        kill_xtra_daemon(self.ad)
724        self.start_qxdm_and_tcpdump_log()
725        self.ad.droid.setMediaVolume(25)
726        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
727        start_ttff_by_gtw_gpstool(
728            self.ad, ttff_mode="cs", iteration=self.ttff_test_cycle)
729        start_youtube_video(self.ad,
730                            url="https://www.youtube.com/watch?v=AbdVsi1VjQY",
731                            retries=3)
732        ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
733                                                self.pixel_lab_location)
734        result = check_ttff_data(self.ad, ttff_data, ttff_mode="Cold Start",
735                                 criteria=self.supl_cs_criteria)
736        asserts.assert_true(result, "TTFF fails to reach designated criteria")
737
738    @test_tracker_info(uuid="a748af8b-e1eb-4ec6-bde3-74bcefa1c680")
739    def test_supl_modem_ssr(self):
740        """Verify SUPL functionality after modem silent reboot /
741        GPS daemons restart.
742
743        Steps:
744            1. Trigger modem crash by adb/Restart GPS daemons by killing PID.
745            2. Wait 1 minute for modem to recover.
746            3. SUPL TTFF Cold Start for 3 iteration.
747            4. Repeat Step 1. to Step 3. for 5 times.
748
749        Expected Results:
750            All SUPL TTFF Cold Start results should be within supl_cs_criteria.
751        """
752        supl_ssr_test_result_all = []
753        kill_xtra_daemon(self.ad)
754        self.start_qxdm_and_tcpdump_log()
755        for times in range(1, 6):
756            begin_time = get_current_epoch_time()
757            if gutils.check_chipset_vendor_by_qualcomm(self.ad):
758                test_info = "Modem SSR"
759                gnss_trigger_modem_ssr_by_mds(self.ad)
760            else:
761                test_info = "restarting GPS daemons"
762                gutils.restart_gps_daemons(self.ad)
763            if not verify_internet_connection(self.ad.log, self.ad, retries=3,
764                                              expected_state=True):
765                raise signals.TestFailure("Fail to connect to LTE network.")
766            process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
767            start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=3)
768            ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
769                                                    self.pixel_lab_location)
770            supl_ssr_test_result = check_ttff_data(
771                self.ad, ttff_data, ttff_mode="Cold Start",
772                criteria=self.supl_cs_criteria)
773            self.ad.log.info("SUPL after %s test %d times -> %s" % (
774                test_info, times, supl_ssr_test_result))
775            supl_ssr_test_result_all.append(supl_ssr_test_result)
776        asserts.assert_true(all(supl_ssr_test_result_all),
777                            "TTFF fails to reach designated criteria")
778
779    @test_tracker_info(uuid="01602e65-8ded-4459-8df1-7df70a1bfe8a")
780    def test_gnss_ttff_cs_airplane_mode_on(self):
781        """Verify Standalone GNSS functionality of TTFF Cold Start while
782        airplane mode is on.
783
784        Steps:
785            1. Turn on airplane mode.
786            2. TTFF Cold Start for 10 iteration.
787
788        Expected Results:
789            All Standalone TTFF Cold Start results should be within
790            standalone_cs_criteria.
791        """
792        self.standalone_ttff_airplane_mode_on("cs", self.standalone_cs_criteria)
793
794    @test_tracker_info(uuid="30b9e7c2-0048-4ccd-b3ae-f385eb5f4e46")
795    def test_gnss_ttff_ws_airplane_mode_on(self):
796        """Verify Standalone GNSS functionality of TTFF Warm Start while
797        airplane mode is on.
798
799        Steps:
800            1. Turn on airplane mode.
801            2. TTFF Warm Start for 10 iteration.
802
803        Expected Results:
804            All Standalone TTFF Warm Start results should be within
805            standalone_ws_criteria.
806        """
807        self.standalone_ttff_airplane_mode_on("ws", self.standalone_ws_criteria)
808
809    @test_tracker_info(uuid="8f3c323a-c625-4339-ab7a-6a41d34cba8f")
810    def test_gnss_ttff_hs_airplane_mode_on(self):
811        """Verify Standalone GNSS functionality of TTFF Hot Start while
812        airplane mode is on.
813
814        Steps:
815            1. Turn on airplane mode.
816            2. TTFF Hot Start for 10 iteration.
817
818        Expected Results:
819            All Standalone TTFF Hot Start results should be within
820            standalone_hs_criteria.
821        """
822        self.standalone_ttff_airplane_mode_on("hs", self.standalone_hs_criteria)
823
824    @test_tracker_info(uuid="23731b0d-cb80-4c79-a877-cfe7c2faa447")
825    def test_gnss_mobile_data_off(self):
826        """Verify Standalone GNSS functionality while mobile radio is off.
827
828        Steps:
829            1. Disable mobile data.
830            2. TTFF Cold Start for 10 iteration.
831            3. Enable mobile data.
832
833        Expected Results:
834            All Standalone TTFF Cold Start results should be within
835            standalone_cs_criteria.
836        """
837        kill_xtra_daemon(self.ad)
838        self.start_qxdm_and_tcpdump_log()
839        set_mobile_data(self.ad, False)
840        self.run_ttff_via_gtw_gpstool("cs", self.standalone_cs_criteria)
841
842    @test_tracker_info(uuid="085b86a9-0212-4c0f-8ca1-2e467a0a2e6e")
843    def test_supl_after_regain_gnss_signal(self):
844        """Verify SUPL functionality after regain GNSS signal.
845
846        Steps:
847            1. Get location fixed.
848            2  Let device do GNSS tracking for 1 minute.
849            3. Set attenuation value to block GNSS signal.
850            4. Let DUT stay in no GNSS signal for 5 minutes.
851            5. Set attenuation value to regain GNSS signal.
852            6. Try to get location reported again.
853            7. Repeat Step 1. to Step 6. for 5 times.
854
855        Expected Results:
856            After setting attenuation value to 10 (GPS signal regain),
857            DUT could get location fixed again.
858        """
859        supl_no_gnss_signal_all = []
860        enable_supl_mode(self.ad)
861        self.start_qxdm_and_tcpdump_log()
862        for times in range(1, 6):
863            process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
864            self.ad.log.info("Let device do GNSS tracking for 1 minute.")
865            time.sleep(60)
866            set_attenuator_gnss_signal(self.ad, self.attenuators,
867                                       self.no_gnss_signal_attenuation)
868            self.ad.log.info("Let device stay in no GNSS signal for 5 minutes.")
869            time.sleep(300)
870            set_attenuator_gnss_signal(self.ad, self.attenuators,
871                                       self.default_gnss_signal_attenuation)
872            supl_no_gnss_signal = check_location_api(self.ad, retries=3)
873            start_gnss_by_gtw_gpstool(self.ad, False)
874            self.ad.log.info("SUPL without GNSS signal test %d times -> %s"
875                             % (times, supl_no_gnss_signal))
876            supl_no_gnss_signal_all.append(supl_no_gnss_signal)
877        asserts.assert_true(all(supl_no_gnss_signal_all),
878                            "Fail to get location update")
879
880    @test_tracker_info(uuid="3ff2f2fa-42d8-47fa-91de-060816cca9df")
881    def test_supl_ttff_cs_weak_gnss_signal(self):
882        """Verify SUPL functionality of TTFF Cold Start under weak GNSS signal.
883
884        Steps:
885            1. Set attenuation value to weak GNSS signal.
886            2. Kill XTRA/LTO daemon to support SUPL only case.
887            3. SUPL TTFF Cold Start for 10 iteration.
888
889        Expected Results:
890            All SUPL TTFF Cold Start results should be less than
891            weak_signal_supl_cs_criteria.
892        """
893        self.supl_ttff_weak_gnss_signal("cs", self.weak_signal_supl_cs_criteria)
894
895    @test_tracker_info(uuid="d72364d4-dad8-4d46-8190-87183def9822")
896    def test_supl_ttff_ws_weak_gnss_signal(self):
897        """Verify SUPL functionality of TTFF Warm Start under weak GNSS signal.
898
899        Steps:
900            1. Set attenuation value to weak GNSS signal.
901            2. Kill XTRA/LTO daemon to support SUPL only case.
902            3. SUPL TTFF Warm Start for 10 iteration.
903
904        Expected Results:
905            All SUPL TTFF Warm Start results should be less than
906            weak_signal_supl_ws_criteria.
907        """
908        self.supl_ttff_weak_gnss_signal("ws", self.weak_signal_supl_ws_criteria)
909
910    @test_tracker_info(uuid="aeb95733-9829-470d-bfc7-e3b059bf881f")
911    def test_supl_ttff_hs_weak_gnss_signal(self):
912        """Verify SUPL functionality of TTFF Hot Start under weak GNSS signal.
913
914        Steps:
915            1. Set attenuation value to weak GNSS signal.
916            2. Kill XTRA/LTO daemon to support SUPL only case.
917            3. SUPL TTFF Hot Start for 10 iteration.
918
919        Expected Results:
920            All SUPL TTFF Hot Start results should be less than
921            weak_signal_supl_hs_criteria.
922        """
923        self.supl_ttff_weak_gnss_signal("hs", self.weak_signal_supl_hs_criteria)
924
925    @test_tracker_info(uuid="4ad4a371-949a-42e1-b1f4-628c79fa8ddc")
926    def test_supl_factory_reset(self):
927        """Verify SUPL functionality after factory reset.
928
929        Steps:
930            1. Factory reset device.
931            2. Kill XTRA/LTO daemon to support SUPL only case.
932            3. SUPL TTFF Cold Start for 10 iteration.
933            4. Repeat Step 1. to Step 3. for 3 times.
934
935        Expected Results:
936            All SUPL TTFF Cold Start results should be within supl_cs_criteria.
937        """
938        for times in range(1, 4):
939            fastboot_factory_reset(self.ad)
940            self.ad.unlock_screen(password=None)
941            _init_device(self.ad)
942            begin_time = get_current_epoch_time()
943            kill_xtra_daemon(self.ad)
944            self.start_qxdm_and_tcpdump_log()
945            process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
946            start_ttff_by_gtw_gpstool(
947                self.ad, ttff_mode="cs", iteration=self.ttff_test_cycle)
948            ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
949                                                    self.pixel_lab_location)
950            if not check_ttff_data(self.ad, ttff_data, ttff_mode="Cold Start",
951                                   criteria=self.supl_cs_criteria):
952                raise signals.TestFailure("SUPL after Factory Reset test %d "
953                                          "times -> FAIL" % times)
954            self.ad.log.info("SUPL after Factory Reset test %d times -> "
955                             "PASS" % times)
956
957    @test_tracker_info(uuid="ea3096cf-4f72-4e91-bfb3-0bcbfe865ab4")
958    def test_xtra_ttff_cs_mobile_data(self):
959        """Verify XTRA/LTO functionality of TTFF Cold Start with mobile data.
960
961        Steps:
962            1. Disable SUPL mode.
963            2. TTFF Cold Start for 10 iteration.
964
965        Expected Results:
966            XTRA/LTO TTFF Cold Start results should be within xtra_cs_criteria.
967        """
968        self.xtra_ttff_mobile_data("cs", self.xtra_cs_criteria)
969
970    @test_tracker_info(uuid="c9b22894-deb3-4dc2-af14-4dcbb8ebad66")
971    def test_xtra_ttff_ws_mobile_data(self):
972        """Verify XTRA/LTO functionality of TTFF Warm Start with mobile data.
973
974        Steps:
975            1. Disable SUPL mode.
976            2. TTFF Warm Start for 10 iteration.
977
978        Expected Results:
979            XTRA/LTO TTFF Warm Start results should be within xtra_ws_criteria.
980        """
981        self.xtra_ttff_mobile_data("ws", self.xtra_ws_criteria)
982
983    @test_tracker_info(uuid="273741e2-0815-4817-96df-9c13401119dd")
984    def test_xtra_ttff_hs_mobile_data(self):
985        """Verify XTRA/LTO functionality of TTFF Hot Start with mobile data.
986
987        Steps:
988            1. Disable SUPL mode.
989            2. TTFF Hot Start for 10 iteration.
990
991        Expected Results:
992            XTRA/LTO TTFF Hot Start results should be within xtra_hs_criteria.
993        """
994        self.xtra_ttff_mobile_data("hs", self.xtra_hs_criteria)
995
996    @test_tracker_info(uuid="c91ba740-220e-41de-81e5-43af31f63907")
997    def test_xtra_ttff_cs_weak_gnss_signal(self):
998        """Verify XTRA/LTO functionality of TTFF Cold Start under weak GNSS
999        signal.
1000
1001        Steps:
1002            1. Disable SUPL mode.
1003            2. Set attenuation value to weak GNSS signal.
1004            3. TTFF Cold Start for 10 iteration.
1005
1006        Expected Results:
1007            XTRA/LTO TTFF Cold Start results should be within
1008            weak_signal_xtra_cs_criteria.
1009        """
1010        self.xtra_ttff_weak_gnss_signal("cs", self.weak_signal_xtra_cs_criteria)
1011
1012    @test_tracker_info(uuid="2a285be7-3571-49fb-8825-01efa2e65f10")
1013    def test_xtra_ttff_ws_weak_gnss_signal(self):
1014        """Verify XTRA/LTO functionality of TTFF Warm Start under weak GNSS
1015        signal.
1016
1017        Steps:
1018            1. Disable SUPL mode.
1019            2. Set attenuation value to weak GNSS signal.
1020            3. TTFF Warm Start for 10 iteration.
1021
1022        Expected Results:
1023            XTRA/LTO TTFF Warm Start results should be within
1024            weak_signal_xtra_ws_criteria.
1025        """
1026        self.xtra_ttff_weak_gnss_signal("ws", self.weak_signal_xtra_ws_criteria)
1027
1028    @test_tracker_info(uuid="249bf484-8b04-4cd9-a372-aa718e5f4ec6")
1029    def test_xtra_ttff_hs_weak_gnss_signal(self):
1030        """Verify XTRA/LTO functionality of TTFF Hot Start under weak GNSS
1031        signal.
1032
1033        Steps:
1034            1. Disable SUPL mode.
1035            2. Set attenuation value to weak GNSS signal.
1036            3. TTFF Hot Start for 10 iteration.
1037
1038        Expected Results:
1039            XTRA/LTO TTFF Hot Start results should be within
1040            weak_signal_xtra_hs_criteria.
1041        """
1042        self.xtra_ttff_weak_gnss_signal("hs", self.weak_signal_xtra_hs_criteria)
1043
1044    @test_tracker_info(uuid="beeb3454-bcb2-451e-83fb-26289e89b515")
1045    def test_xtra_ttff_cs_wifi(self):
1046        """Verify XTRA/LTO functionality of TTFF Cold Start with WiFi.
1047
1048        Steps:
1049            1. Disable SUPL mode and turn airplane mode on.
1050            2. Connect to WiFi.
1051            3. TTFF Cold Start for 10 iteration.
1052
1053        Expected Results:
1054            XTRA/LTO TTFF Cold Start results should be within
1055            wifi_xtra_cs_criteria.
1056        """
1057        self.xtra_ttff_wifi("cs", self.wifi_xtra_cs_criteria)
1058
1059    @test_tracker_info(uuid="f6e79b31-99d5-49ca-974f-4543957ea449")
1060    def test_xtra_ttff_ws_wifi(self):
1061        """Verify XTRA/LTO functionality of TTFF Warm Start with WiFi.
1062
1063        Steps:
1064            1. Disable SUPL mode and turn airplane mode on.
1065            2. Connect to WiFi.
1066            3. TTFF Warm Start for 10 iteration.
1067
1068        Expected Results:
1069            XTRA/LTO TTFF Warm Start results should be within xtra_ws_criteria.
1070        """
1071        self.xtra_ttff_wifi("ws", self.xtra_ws_criteria)
1072
1073    @test_tracker_info(uuid="8981363c-f64f-4c37-9674-46733c40473b")
1074    def test_xtra_ttff_hs_wifi(self):
1075        """Verify XTRA/LTO functionality of TTFF Hot Start with WiFi.
1076
1077        Steps:
1078            1. Disable SUPL mode and turn airplane mode on.
1079            2. Connect to WiFi.
1080            3. TTFF Hot Start for 10 iteration.
1081
1082        Expected Results:
1083            XTRA/LTO TTFF Hot Start results should be within xtra_hs_criteria.
1084        """
1085        self.xtra_ttff_wifi("hs", self.xtra_hs_criteria)
1086
1087    @test_tracker_info(uuid="1745b8a4-5925-4aa0-809a-1b17e848dc9c")
1088    def test_xtra_modem_ssr(self):
1089        """Verify XTRA/LTO functionality after modem silent reboot /
1090        GPS daemons restart.
1091
1092        Steps:
1093            1. Trigger modem crash by adb/Restart GPS daemons by killing PID.
1094            2. Wait 1 minute for modem to recover.
1095            3. XTRA/LTO TTFF Cold Start for 3 iteration.
1096            4. Repeat Step1. to Step 3. for 5 times.
1097
1098        Expected Results:
1099            All XTRA/LTO TTFF Cold Start results should be within
1100            xtra_cs_criteria.
1101        """
1102        xtra_ssr_test_result_all = []
1103        disable_supl_mode(self.ad)
1104        self.start_qxdm_and_tcpdump_log()
1105        for times in range(1, 6):
1106            begin_time = get_current_epoch_time()
1107            if gutils.check_chipset_vendor_by_qualcomm(self.ad):
1108                test_info = "XTRA after Modem SSR"
1109                gnss_trigger_modem_ssr_by_mds(self.ad)
1110            else:
1111                test_info = "LTO after restarting GPS daemons"
1112                gutils.restart_gps_daemons(self.ad)
1113            if not verify_internet_connection(self.ad.log, self.ad, retries=3,
1114                                              expected_state=True):
1115                raise signals.TestFailure("Fail to connect to LTE network.")
1116            process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
1117            start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=3)
1118            ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
1119                                                    self.pixel_lab_location)
1120            xtra_ssr_test_result = check_ttff_data(
1121                self.ad, ttff_data, ttff_mode="Cold Start",
1122                criteria=self.xtra_cs_criteria)
1123            self.ad.log.info("%s test %d times -> %s" % (
1124                test_info, times, xtra_ssr_test_result))
1125            xtra_ssr_test_result_all.append(xtra_ssr_test_result)
1126        asserts.assert_true(all(xtra_ssr_test_result_all),
1127                            "TTFF fails to reach designated criteria")
1128
1129    @test_tracker_info(uuid="4d6e81e1-3abb-4e03-b732-7b6b497a2258")
1130    def test_xtra_download_mobile_data(self):
1131        """Verify XTRA/LTO data could be downloaded via mobile data.
1132
1133        Steps:
1134            1. Delete all GNSS aiding data.
1135            2. Get location fixed.
1136            3. Verify whether XTRA/LTO is downloaded and injected.
1137            4. Repeat Step 1. to Step 3. for 5 times.
1138
1139        Expected Results:
1140            XTRA/LTO data is properly downloaded and injected via mobile data.
1141        """
1142        mobile_xtra_result_all = []
1143        disable_supl_mode(self.ad)
1144        self.start_qxdm_and_tcpdump_log()
1145        for i in range(1, 6):
1146            begin_time = get_current_epoch_time()
1147            process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
1148            time.sleep(5)
1149            start_gnss_by_gtw_gpstool(self.ad, False)
1150            mobile_xtra_result = check_xtra_download(self.ad, begin_time)
1151            self.ad.log.info("Iteration %d => %s" % (i, mobile_xtra_result))
1152            mobile_xtra_result_all.append(mobile_xtra_result)
1153        asserts.assert_true(all(mobile_xtra_result_all),
1154                            "Fail to Download and Inject XTRA/LTO File.")
1155
1156    @test_tracker_info(uuid="625ac665-1446-4406-a722-e6a19645222c")
1157    def test_xtra_download_wifi(self):
1158        """Verify XTRA/LTO data could be downloaded via WiFi.
1159
1160        Steps:
1161            1. Connect to WiFi.
1162            2. Delete all GNSS aiding data.
1163            3. Get location fixed.
1164            4. Verify whether XTRA/LTO is downloaded and injected.
1165            5. Repeat Step 2. to Step 4. for 5 times.
1166
1167        Expected Results:
1168            XTRA data is properly downloaded and injected via WiFi.
1169        """
1170        wifi_xtra_result_all = []
1171        disable_supl_mode(self.ad)
1172        self.start_qxdm_and_tcpdump_log()
1173        self.ad.log.info("Turn airplane mode on")
1174        force_airplane_mode(self.ad, True)
1175        wifi_toggle_state(self.ad, True)
1176        connect_to_wifi_network(
1177            self.ad, self.ssid_map[self.pixel_lab_network[0]["SSID"]])
1178        for i in range(1, 6):
1179            begin_time = get_current_epoch_time()
1180            process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
1181            time.sleep(5)
1182            start_gnss_by_gtw_gpstool(self.ad, False)
1183            wifi_xtra_result = check_xtra_download(self.ad, begin_time)
1184            wifi_xtra_result_all.append(wifi_xtra_result)
1185            self.ad.log.info("Iteration %d => %s" % (i, wifi_xtra_result))
1186        asserts.assert_true(all(wifi_xtra_result_all),
1187                            "Fail to Download and Inject XTRA/LTO File.")
1188
1189    @test_tracker_info(uuid="2a9f2890-3c0a-48b8-821d-bf97e36355e9")
1190    def test_quick_toggle_gnss_state(self):
1191        """Verify GNSS can still work properly after quick toggle GNSS off
1192        to on.
1193
1194        Steps:
1195            1. Launch GTW_GPSTool.
1196            2. Go to "Advance setting"
1197            3. Set Cycle = 10 & Time-out = 60
1198            4. Go to "Toggle GPS" tab
1199            5. Execute "Start"
1200
1201        Expected Results:
1202            No single Timeout is seen in 10 iterations.
1203        """
1204        enable_supl_mode(self.ad)
1205        self.start_qxdm_and_tcpdump_log()
1206        start_toggle_gnss_by_gtw_gpstool(
1207            self.ad, iteration=self.ttff_test_cycle)
1208
1209    @test_tracker_info(uuid="9f565b32-9938-42c0-a29d-f4d28b5f4d75")
1210    def test_supl_system_server_restart(self):
1211        """Verify SUPL functionality after system server restart.
1212
1213        Steps:
1214            1. Kill XTRA/LTO daemon to support SUPL only case.
1215            2. Get location fixed within supl_cs_criteria.
1216            3. Restarts android runtime.
1217            4. Get location fixed within supl_cs_criteria.
1218
1219        Expected Results:
1220            Location fixed within supl_cs_criteria.
1221        """
1222        overall_test_result = []
1223        kill_xtra_daemon(self.ad)
1224        self.start_qxdm_and_tcpdump_log()
1225        for test_loop in range(1, 6):
1226            process_gnss_by_gtw_gpstool(self.ad, self.supl_cs_criteria)
1227            start_gnss_by_gtw_gpstool(self.ad, False)
1228            self.ad.restart_runtime()
1229            self.ad.unlock_screen(password=None)
1230            test_result = process_gnss_by_gtw_gpstool(self.ad,
1231                                                      self.supl_cs_criteria)
1232            start_gnss_by_gtw_gpstool(self.ad, False)
1233            self.ad.log.info("Iteration %d => %s" % (test_loop, test_result))
1234            overall_test_result.append(test_result)
1235        asserts.assert_true(all(overall_test_result),
1236                            "SUPL fail after system server restart.")
1237
1238    @test_tracker_info(uuid="a9a64900-9016-46d0-ad7e-cab30e8152cd")
1239    def test_xtra_system_server_restart(self):
1240        """Verify XTRA/LTO functionality after system server restart.
1241
1242        Steps:
1243            1. Disable SUPL mode.
1244            2. Get location fixed within xtra_cs_criteria.
1245            3. Restarts android runtime.
1246            4. Get location fixed within xtra_cs_criteria.
1247
1248        Expected Results:
1249            Location fixed within xtra_cs_criteria.
1250        """
1251        overall_test_result = []
1252        disable_supl_mode(self.ad)
1253        self.start_qxdm_and_tcpdump_log()
1254        for test_loop in range(1, 6):
1255            process_gnss_by_gtw_gpstool(self.ad, self.xtra_cs_criteria)
1256            start_gnss_by_gtw_gpstool(self.ad, False)
1257            self.ad.restart_runtime()
1258            self.ad.unlock_screen(password=None)
1259            test_result = process_gnss_by_gtw_gpstool(self.ad,
1260                                                      self.xtra_cs_criteria)
1261            start_gnss_by_gtw_gpstool(self.ad, False)
1262            self.ad.log.info("Iteration %d => %s" % (test_loop, test_result))
1263            overall_test_result.append(test_result)
1264        asserts.assert_true(all(overall_test_result),
1265                            "XTRA/LTO fail after system server restart.")
1266
1267    @test_tracker_info(uuid="ab5ef9f7-0b28-48ed-a693-7f1d902ca3e1")
1268    def test_gnss_init_after_reboot(self):
1269        """Verify SUPL and XTRA/LTO functionality after reboot.
1270
1271        Steps:
1272            1. Get location fixed within supl_cs_criteria.
1273            2. Reboot DUT.
1274            3. Get location fixed within supl_hs_criteria.
1275            4. Repeat Step 2. to Step 3. for 10 times.
1276
1277        Expected Results:
1278            Location fixed within supl_hs_criteria.
1279        """
1280        overall_test_result = []
1281        enable_supl_mode(self.ad)
1282        process_gnss_by_gtw_gpstool(self.ad, self.supl_cs_criteria)
1283        start_gnss_by_gtw_gpstool(self.ad, False)
1284        for test_loop in range(1, 11):
1285            reboot(self.ad)
1286            test_result = process_gnss_by_gtw_gpstool(
1287                self.ad, self.supl_hs_criteria, clear_data=False)
1288            start_gnss_by_gtw_gpstool(self.ad, False)
1289            self.ad.log.info("Iteration %d => %s" % (test_loop, test_result))
1290            overall_test_result.append(test_result)
1291        pass_rate = overall_test_result.count(True)/len(overall_test_result)
1292        self.ad.log.info("TestResult Pass_rate %s" % format(pass_rate, ".0%"))
1293        asserts.assert_true(all(overall_test_result),
1294                            "GNSS init fail after reboot.")
1295