1#!/usr/bin/env python3.5
2#
3#   Copyright 2019 - 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.test_utils.wifi import wifi_test_utils as wutils
28from acts.test_utils.tel import tel_test_utils as tutils
29from acts.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.test_utils.wifi.wifi_test_utils import wifi_toggle_state
34from acts.test_utils.tel.tel_test_utils import flash_radio
35from acts.test_utils.tel.tel_test_utils import verify_internet_connection
36from acts.test_utils.tel.tel_test_utils import abort_all_tests
37from acts.test_utils.tel.tel_test_utils import stop_qxdm_logger
38from acts.test_utils.tel.tel_test_utils import check_call_state_connected_by_adb
39from acts.test_utils.tel.tel_test_utils import initiate_call
40from acts.test_utils.tel.tel_test_utils import hangup_call
41from acts.test_utils.tel.tel_test_utils import http_file_download_by_sl4a
42from acts.test_utils.tel.tel_test_utils import start_qxdm_logger
43from acts.test_utils.tel.tel_test_utils import trigger_modem_crash
44from acts.test_utils.gnss.gnss_test_utils import get_baseband_and_gms_version
45from acts.test_utils.gnss.gnss_test_utils import set_attenuator_gnss_signal
46from acts.test_utils.gnss.gnss_test_utils import _init_device
47from acts.test_utils.gnss.gnss_test_utils import check_location_service
48from acts.test_utils.gnss.gnss_test_utils import clear_logd_gnss_qxdm_log
49from acts.test_utils.gnss.gnss_test_utils import set_mobile_data
50from acts.test_utils.gnss.gnss_test_utils import set_wifi_and_bt_scanning
51from acts.test_utils.gnss.gnss_test_utils import get_gnss_qxdm_log
52from acts.test_utils.gnss.gnss_test_utils import remount_device
53from acts.test_utils.gnss.gnss_test_utils import reboot
54from acts.test_utils.gnss.gnss_test_utils import check_network_location
55from acts.test_utils.gnss.gnss_test_utils import launch_google_map
56from acts.test_utils.gnss.gnss_test_utils import check_location_api
57from acts.test_utils.gnss.gnss_test_utils import set_battery_saver_mode
58from acts.test_utils.gnss.gnss_test_utils import kill_xtra_daemon
59from acts.test_utils.gnss.gnss_test_utils import start_gnss_by_gtw_gpstool
60from acts.test_utils.gnss.gnss_test_utils import process_gnss_by_gtw_gpstool
61from acts.test_utils.gnss.gnss_test_utils import start_ttff_by_gtw_gpstool
62from acts.test_utils.gnss.gnss_test_utils import process_ttff_by_gtw_gpstool
63from acts.test_utils.gnss.gnss_test_utils import check_ttff_data
64from acts.test_utils.gnss.gnss_test_utils import start_youtube_video
65from acts.test_utils.gnss.gnss_test_utils import fastboot_factory_reset
66from acts.test_utils.gnss.gnss_test_utils import gnss_trigger_modem_ssr_by_adb
67from acts.test_utils.gnss.gnss_test_utils import gnss_trigger_modem_ssr_by_mds
68from acts.test_utils.gnss.gnss_test_utils import disable_supl_mode
69from acts.test_utils.gnss.gnss_test_utils import connect_to_wifi_network
70from acts.test_utils.gnss.gnss_test_utils import check_xtra_download
71from acts.test_utils.gnss.gnss_test_utils import gnss_tracking_via_gtw_gpstool
72from acts.test_utils.gnss.gnss_test_utils import parse_gtw_gpstool_log
73from acts.test_utils.gnss.gnss_test_utils import enable_supl_mode
74from acts.test_utils.gnss.gnss_test_utils import start_toggle_gnss_by_gtw_gpstool
75from acts.test_utils.tel.tel_test_utils import start_adb_tcpdump
76from acts.test_utils.tel.tel_test_utils import stop_adb_tcpdump
77from acts.test_utils.tel.tel_test_utils import get_tcpdump_log
78
79
80class GnssSanityTest(BaseTestClass):
81    """ GNSS Function Sanity Tests"""
82    def setup_class(self):
83        super().setup_class()
84        self.ad = self.android_devices[0]
85        req_params = ["pixel_lab_network", "standalone_cs_criteria",
86                      "supl_cs_criteria", "xtra_ws_criteria",
87                      "xtra_cs_criteria", "weak_signal_supl_cs_criteria",
88                      "weak_signal_xtra_ws_criteria",
89                      "weak_signal_xtra_cs_criteria",
90                      "default_gnss_signal_attenuation",
91                      "weak_gnss_signal_attenuation",
92                      "no_gnss_signal_attenuation", "gnss_init_error_list",
93                      "gnss_init_error_whitelist", "pixel_lab_location",
94                      "legacy_wifi_xtra_cs_criteria", "legacy_projects",
95                      "qdsp6m_path", "supl_capabilities"]
96        self.unpack_userparams(req_param_names=req_params)
97        # create hashmap for SSID
98        self.ssid_map = {}
99        for network in self.pixel_lab_network:
100            SSID = network['SSID']
101            self.ssid_map[SSID] = network
102        if self.ad.model in self.legacy_projects:
103            self.wifi_xtra_cs_criteria = self.legacy_wifi_xtra_cs_criteria
104        else:
105            self.wifi_xtra_cs_criteria = self.xtra_cs_criteria
106        self.flash_new_radio_or_mbn()
107        set_attenuator_gnss_signal(self.ad, self.attenuators,
108                                   self.default_gnss_signal_attenuation)
109        _init_device(self.ad)
110
111    def setup_test(self):
112        get_baseband_and_gms_version(self.ad)
113        clear_logd_gnss_qxdm_log(self.ad)
114        set_attenuator_gnss_signal(self.ad, self.attenuators,
115                                   self.default_gnss_signal_attenuation)
116        if not verify_internet_connection(self.ad.log, self.ad, retries=3,
117                                          expected_state=True):
118            raise signals.TestFailure("Fail to connect to LTE network.")
119
120    def teardown_test(self):
121        stop_qxdm_logger(self.ad)
122        stop_adb_tcpdump(self.ad)
123        if check_call_state_connected_by_adb(self.ad):
124            hangup_call(self.ad.log, self.ad)
125        if int(self.ad.adb.shell("settings get global airplane_mode_on")) != 0:
126            self.ad.log.info("Force airplane mode off")
127            force_airplane_mode(self.ad, False)
128        if self.ad.droid.wifiCheckState():
129            wifi_toggle_state(self.ad, False)
130        if int(self.ad.adb.shell("settings get global mobile_data")) != 1:
131            set_mobile_data(self.ad, True)
132        if int(self.ad.adb.shell(
133            "settings get global wifi_scan_always_enabled")) != 1:
134            set_wifi_and_bt_scanning(self.ad, True)
135        set_attenuator_gnss_signal(self.ad, self.attenuators,
136                                   self.default_gnss_signal_attenuation)
137
138    def on_pass(self, test_name, begin_time):
139        self.ad.take_bug_report(test_name, begin_time)
140        get_gnss_qxdm_log(self.ad, self.qdsp6m_path)
141        get_tcpdump_log(self.ad, test_name, begin_time)
142
143    def on_fail(self, test_name, begin_time):
144        self.ad.take_bug_report(test_name, begin_time)
145        get_gnss_qxdm_log(self.ad, self.qdsp6m_path)
146        get_tcpdump_log(self.ad, test_name, begin_time)
147
148    def flash_new_radio_or_mbn(self):
149        paths = {}
150        path = self.user_params.get("radio_image")
151        if isinstance(path, list):
152            path = path[0]
153        if "dev/null" in path:
154            self.ad.log.info("Radio image path is not defined in Test flag.")
155            return False
156        for path_key in os.listdir(path):
157            if fnmatch.fnmatch(path_key, "*.img"):
158                paths["radio_image"] = os.path.join(path, path_key)
159                os.system("chmod -R 777 %s" % paths["radio_image"])
160                self.ad.log.info("radio_image = %s" % paths["radio_image"])
161            if fnmatch.fnmatch(path_key, "*.zip"):
162                zip_path = os.path.join(path, path_key)
163                self.ad.log.info("Unzip %s", zip_path)
164                dest_path = os.path.join(path, "mbn")
165                unzip_maintain_permissions(zip_path, dest_path)
166                paths["mbn_path"] = dest_path
167                os.system("chmod -R 777 %s" % paths["mbn_path"])
168                self.ad.log.info("mbn_path = %s" % paths["mbn_path"])
169                self.ad.log.info(os.listdir(paths["mbn_path"]))
170        if not paths.get("radio_image"):
171            self.ad.log.info("No radio image is provided on X20. "
172                             "Skip flashing radio step.")
173            return False
174        else:
175            get_baseband_and_gms_version(self.ad, "Before flash radio")
176            flash_radio(self.ad, paths["radio_image"])
177            get_baseband_and_gms_version(self.ad, "After flash radio")
178        if not paths.get("mbn_path"):
179            self.ad.log.info("No need to push mbn files")
180            return False
181        else:
182            try:
183                mcfg_ver = self.ad.adb.shell(
184                    "cat /vendor/rfs/msm/mpss/readonly/vendor/mbn/mcfg.version")
185                if mcfg_ver:
186                    self.ad.log.info("Before push mcfg, mcfg.version = %s",
187                                     mcfg_ver)
188                else:
189                    self.ad.log.info("There is no mcfg.version before push, "
190                                     "unmatching device")
191                    return False
192            except:
193                self.ad.log.info("There is no mcfg.version before push, "
194                                 "unmatching device")
195                return False
196            get_baseband_and_gms_version(self.ad, "Before push mcfg")
197            try:
198                remount_device(self.ad)
199                cmd = "%s %s" % (paths["mbn_path"]+"/.",
200                                 "/vendor/rfs/msm/mpss/readonly/vendor/mbn/")
201                out = self.ad.adb.push(cmd)
202                self.ad.log.info(out)
203                reboot(self.ad)
204            except Exception as e:
205                self.ad.log.error("Push mbn files error %s", e)
206                return False
207            get_baseband_and_gms_version(self.ad, "After push mcfg")
208            try:
209                new_mcfg_ver = self.ad.adb.shell(
210                    "cat /vendor/rfs/msm/mpss/readonly/vendor/mbn/mcfg.version")
211                if new_mcfg_ver:
212                    self.ad.log.info("New mcfg.version = %s", new_mcfg_ver)
213                    if new_mcfg_ver == mcfg_ver:
214                        self.ad.log.error("mcfg.version is the same before and "
215                                          "after push")
216                        return True
217                else:
218                    self.ad.log.error("Unable to get new mcfg.version")
219                    return False
220            except Exception as e:
221                self.ad.log.error("cat mcfg.version with error %s", e)
222                return False
223
224    """ Test Cases """
225
226    @test_tracker_info(uuid="ab859f2a-2c95-4d15-bb7f-bd0e3278340f")
227    def test_gnss_one_hour_tracking(self):
228        """Verify GNSS tracking performance of signal strength and position
229        error.
230
231        Steps:
232            1. Launch GTW_GPSTool.
233            2. GNSS tracking for 60 minutes.
234
235        Expected Results:
236            DUT could finish 60 minutes test and output track data.
237        """
238        start_qxdm_logger(self.ad, get_current_epoch_time())
239        start_adb_tcpdump(self.ad)
240        gnss_tracking_via_gtw_gpstool(self.ad, self.standalone_cs_criteria,
241                                      type="gnss", testtime=60)
242        parse_gtw_gpstool_log(self.ad, self.pixel_lab_location, type="gnss")
243
244    @test_tracker_info(uuid="499d2091-640a-4735-9c58-de67370e4421")
245    def test_gnss_init_error(self):
246        """Check if there is any GNSS initialization error after reboot.
247
248        Steps:
249            1. Reboot DUT.
250            2. Check logcat if the following error pattern shows up.
251              "E LocSvc.*", ".*avc.*denied.*u:r:location:s0",
252              ".*avc.*denied.*u:r:hal_gnss_qti:s0"
253
254        Expected Results:
255            There should be no GNSS initialization error after reboot.
256        """
257        error_mismatch = True
258        for attr in self.gnss_init_error_list:
259            error = self.ad.adb.shell("logcat -d | grep -E '%s'" % attr)
260            if error:
261                for whitelist in self.gnss_init_error_whitelist:
262                    if whitelist in error:
263                        error = re.sub(".*"+whitelist+".*\n?", "", error)
264                        self.ad.log.info("\"%s\" is white-listed and removed "
265                                         "from error." % whitelist)
266                if error:
267                    error_mismatch = False
268                    self.ad.log.error("\n%s" % error)
269            else:
270                self.ad.log.info("NO \"%s\" initialization error found." % attr)
271        asserts.assert_true(error_mismatch, "Error message found after GNSS "
272                                            "init")
273
274    @test_tracker_info(uuid="ff318483-411c-411a-8b1a-422bd54f4a3f")
275    def test_supl_capabilities(self):
276        """Verify SUPL capabilities.
277
278        Steps:
279            1. Root DUT.
280            2. Check SUPL capabilities.
281
282        Expected Results:
283            CAPABILITIES=0x37 which supports MSA + MSB.
284            CAPABILITIES=0x17 = ON_DEMAND_TIME | MSA | MSB | SCHEDULING
285        """
286        capabilities_state = str(
287            self.ad.adb.shell(
288                "cat vendor/etc/gps.conf | grep CAPABILITIES")).split("=")[-1]
289        self.ad.log.info("SUPL capabilities - %s" % capabilities_state)
290        asserts.assert_true(capabilities_state in self.supl_capabilities,
291                            "Wrong default SUPL capabilities is set. Found %s, "
292                            "expected any of %r" % (capabilities_state,
293                                                    self.supl_capabilities))
294
295    @test_tracker_info(uuid="dcae6979-ddb4-4cad-9d14-fbdd9439cf42")
296    def test_sap_valid_modes(self):
297        """Verify SAP Valid Modes.
298
299        Steps:
300            1. Root DUT.
301            2. Check SAP Valid Modes.
302
303        Expected Results:
304            SAP=PREMIUM
305        """
306        sap_state = str(self.ad.adb.shell("cat vendor/etc/izat.conf | grep "
307                                          "SAP="))
308        self.ad.log.info("SAP Valid Modes - %s" % sap_state)
309        asserts.assert_true(sap_state == "SAP=PREMIUM",
310                            "Wrong SAP Valid Modes is set")
311
312    @test_tracker_info(uuid="14daaaba-35b4-42d9-8d2c-2a803dd746a6")
313    def test_network_location_provider_cell(self):
314        """Verify LocationManagerService API reports cell Network Location.
315
316        Steps:
317            1. WiFi scanning and Bluetooth scanning in Location Setting are OFF.
318            2. Launch GTW_GPSTool.
319            3. Verify whether test devices could report cell Network Location.
320            4. Repeat Step 2. to Step 3. for 5 times.
321
322        Expected Results:
323            Test devices could report cell Network Location.
324        """
325        test_result_all = []
326        start_qxdm_logger(self.ad, get_current_epoch_time())
327        start_adb_tcpdump(self.ad)
328        set_wifi_and_bt_scanning(self.ad, False)
329        for i in range(1, 6):
330            test_result = check_network_location(
331                self.ad, retries=3, location_type="networkLocationType=cell")
332            test_result_all.append(test_result)
333            self.ad.log.info("Iteraion %d => %s" % (i, test_result))
334        set_wifi_and_bt_scanning(self.ad, True)
335        asserts.assert_true(all(test_result_all),
336                            "Fail to get networkLocationType=cell")
337
338    @test_tracker_info(uuid="a45bdc7d-29fa-4a1d-ba34-6340b90e308d")
339    def test_network_location_provider_wifi(self):
340        """Verify LocationManagerService API reports wifi Network Location.
341
342        Steps:
343            1. WiFi scanning and Bluetooth scanning in Location Setting are ON.
344            2. Launch GTW_GPSTool.
345            3. Verify whether test devices could report wifi Network Location.
346            4. Repeat Step 2. to Step 3. for 5 times.
347
348        Expected Results:
349            Test devices could report wifi Network Location.
350        """
351        test_result_all = []
352        start_qxdm_logger(self.ad, get_current_epoch_time())
353        start_adb_tcpdump(self.ad)
354        set_wifi_and_bt_scanning(self.ad, True)
355        for i in range(1, 6):
356            test_result = check_network_location(
357                self.ad, retries=3, location_type="networkLocationType=wifi")
358            test_result_all.append(test_result)
359            self.ad.log.info("Iteraion %d => %s" % (i, test_result))
360        asserts.assert_true(all(test_result_all),
361                            "Fail to get networkLocationType=wifi")
362
363    @test_tracker_info(uuid="0919d375-baf2-4fe7-b66b-3f72d386f791")
364    def test_gmap_location_report_gps_network(self):
365        """Verify GnssLocationProvider API reports location to Google Map
366           when GPS and Location Accuracy are on.
367
368        Steps:
369            1. GPS and NLP are on.
370            2. Launch Google Map.
371            3. Verify whether test devices could report location.
372            4. Repeat Step 2. to Step 3. for 5 times.
373
374        Expected Results:
375            Test devices could report location to Google Map.
376        """
377        test_result_all = []
378        start_qxdm_logger(self.ad, get_current_epoch_time())
379        start_adb_tcpdump(self.ad)
380        for i in range(1, 6):
381            launch_google_map(self.ad)
382            test_result = check_location_api(self.ad, retries=3)
383            self.ad.send_keycode("HOME")
384            test_result_all.append(test_result)
385            self.ad.log.info("Iteraion %d => %s" % (i, test_result))
386        asserts.assert_true(all(test_result_all), "Fail to get location update")
387
388    @test_tracker_info(uuid="513361d2-7d72-41b0-a944-fb259c606b81")
389    def test_gmap_location_report_gps(self):
390        """Verify GnssLocationProvider API reports location to Google Map
391           when GPS is on and Location Accuracy is off.
392
393        Steps:
394            1. GPS is on.
395            2. Location Accuracy is off.
396            3. Launch Google Map.
397            4. Verify whether test devices could report location.
398            5. Repeat Step 3. to Step 4. for 5 times.
399
400        Expected Results:
401            Test devices could report location to Google Map.
402        """
403        test_result_all = []
404        start_qxdm_logger(self.ad, get_current_epoch_time())
405        start_adb_tcpdump(self.ad)
406        self.ad.adb.shell("settings put secure location_mode 1")
407        out = int(self.ad.adb.shell("settings get secure location_mode"))
408        self.ad.log.info("Modify current Location Mode to %d" % out)
409        for i in range(1, 6):
410            launch_google_map(self.ad)
411            test_result = check_location_api(self.ad, retries=3)
412            self.ad.send_keycode("HOME")
413            test_result_all.append(test_result)
414            self.ad.log.info("Iteraion %d => %s" % (i, test_result))
415        check_location_service(self.ad)
416        asserts.assert_true(all(test_result_all), "Fail to get location update")
417
418    @test_tracker_info(uuid="91a65121-b87d-450d-bd0f-387ade450ab7")
419    def test_gmap_location_report_battery_saver(self):
420        """Verify GnssLocationProvider API reports location to Google Map
421           when Battery Saver is enabled.
422
423        Steps:
424            1. GPS and NLP are on.
425            2. Enable Battery Saver.
426            3. Launch Google Map.
427            4. Verify whether test devices could report location.
428            5. Repeat Step 3. to Step 4. for 5 times.
429            6. Disable Battery Saver.
430
431        Expected Results:
432            Test devices could report location to Google Map.
433        """
434        test_result_all = []
435        start_qxdm_logger(self.ad, get_current_epoch_time())
436        start_adb_tcpdump(self.ad)
437        set_battery_saver_mode(self.ad, True)
438        for i in range(1, 6):
439            launch_google_map(self.ad)
440            test_result = check_location_api(self.ad, retries=3)
441            self.ad.send_keycode("HOME")
442            test_result_all.append(test_result)
443            self.ad.log.info("Iteraion %d => %s" % (i, test_result))
444        set_battery_saver_mode(self.ad, False)
445        asserts.assert_true(all(test_result_all), "Fail to get location update")
446
447    @test_tracker_info(uuid="60c0aeec-0c8f-4a96-bc6c-05cba1260e73")
448    def test_supl_ongoing_call(self):
449        """Verify SUPL functionality during phone call.
450
451        Steps:
452            1. Kill XTRA daemon to support SUPL only case.
453            2. Initiate call on DUT.
454            3. SUPL TTFF Cold Start for 10 iteration.
455            4. DUT hang up call.
456
457        Expected Results:
458            All SUPL TTFF Cold Start results should be less than
459            supl_cs_criteria.
460        """
461        begin_time = get_current_epoch_time()
462        start_qxdm_logger(self.ad, begin_time)
463        start_adb_tcpdump(self.ad)
464        kill_xtra_daemon(self.ad)
465        self.ad.droid.setVoiceCallVolume(25)
466        initiate_call(self.ad.log, self.ad, "99117")
467        time.sleep(5)
468        if not check_call_state_connected_by_adb(self.ad):
469            raise signals.TestFailure("Call is not connected.")
470        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
471        start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
472        ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
473                                                self.pixel_lab_location)
474        result = check_ttff_data(self.ad, ttff_data, ttff_mode="Cold Start",
475                                 criteria=self.supl_cs_criteria)
476        asserts.assert_true(result, "TTFF fails to reach designated criteria")
477
478    @test_tracker_info(uuid="df605509-328f-43e8-b6d8-00635bf701ef")
479    def test_supl_downloading_files(self):
480        """Verify SUPL functionality when downloading files.
481
482        Steps:
483            1. Kill XTRA daemon to support SUPL only case.
484            2. DUT start downloading files by sl4a.
485            3. SUPL TTFF Cold Start for 10 iteration.
486            4. DUT cancel downloading files.
487
488        Expected Results:
489            All SUPL TTFF Cold Start results should be within supl_cs_criteria.
490        """
491        begin_time = get_current_epoch_time()
492        start_qxdm_logger(self.ad, begin_time)
493        start_adb_tcpdump(self.ad)
494        kill_xtra_daemon(self.ad)
495        download = Process(target=http_file_download_by_sl4a,
496                           args=(self.ad, "https://speed.hetzner.de/10GB.bin",
497                                 None, None, True, 3600))
498        download.start()
499        time.sleep(10)
500        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
501        start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
502        ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
503                                                self.pixel_lab_location)
504        download.terminate()
505        time.sleep(3)
506        result = check_ttff_data(self.ad, ttff_data, ttff_mode="Cold Start",
507                                 criteria=self.supl_cs_criteria)
508        asserts.assert_true(result, "TTFF fails to reach designated criteria")
509
510    @test_tracker_info(uuid="66b9f9d4-1397-4da7-9e55-8b89b1732017")
511    def test_supl_watching_youtube(self):
512        """Verify SUPL functionality when watching video on youtube.
513
514        Steps:
515            1. Kill XTRA daemon to support SUPL only case.
516            2. DUT start watching video on youtube.
517            3. SUPL TTFF Cold Start for 10 iteration at the background.
518            4. DUT stop watching video on youtube.
519
520        Expected Results:
521            All SUPL TTFF Cold Start results should be within supl_cs_criteria.
522        """
523        begin_time = get_current_epoch_time()
524        start_qxdm_logger(self.ad, begin_time)
525        start_adb_tcpdump(self.ad)
526        kill_xtra_daemon(self.ad)
527        self.ad.droid.setMediaVolume(25)
528        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
529        start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
530        start_youtube_video(self.ad,
531                            url="https://www.youtube.com/watch?v=AbdVsi1VjQY",
532                            retries=3)
533        ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
534                                                self.pixel_lab_location)
535        result = check_ttff_data(self.ad, ttff_data, ttff_mode="Cold Start",
536                                 criteria=self.supl_cs_criteria)
537        asserts.assert_true(result, "TTFF fails to reach designated criteria")
538
539    @test_tracker_info(uuid="a748af8b-e1eb-4ec6-bde3-74bcefa1c680")
540    def test_supl_modem_ssr(self):
541        """Verify SUPL functionality after modem silent reboot.
542
543        Steps:
544            1. Trigger modem crash by adb.
545            2. Wait 1 minute for modem to recover.
546            3. SUPL TTFF Cold Start for 3 iteration.
547            4. Repeat Step 1. to Step 3. for 5 times.
548
549        Expected Results:
550            All SUPL TTFF Cold Start results should be within supl_cs_criteria.
551        """
552        supl_ssr_test_result_all = []
553        start_qxdm_logger(self.ad, get_current_epoch_time())
554        start_adb_tcpdump(self.ad)
555        kill_xtra_daemon(self.ad)
556        for times in range(1, 6):
557            begin_time = get_current_epoch_time()
558            gnss_trigger_modem_ssr_by_mds(self.ad)
559            if not verify_internet_connection(self.ad.log, self.ad, retries=3,
560                                              expected_state=True):
561                raise signals.TestFailure("Fail to connect to LTE network.")
562            process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
563            start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=3)
564            ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
565                                                    self.pixel_lab_location)
566            supl_ssr_test_result = check_ttff_data(
567                self.ad, ttff_data, ttff_mode="Cold Start",
568                criteria=self.supl_cs_criteria)
569            self.ad.log.info("SUPL after Modem SSR test %d times -> %s"
570                             % (times, supl_ssr_test_result))
571            supl_ssr_test_result_all.append(supl_ssr_test_result)
572        asserts.assert_true(all(supl_ssr_test_result_all),
573                            "TTFF fails to reach designated criteria")
574
575    @test_tracker_info(uuid="01602e65-8ded-4459-8df1-7df70a1bfe8a")
576    def test_gnss_airplane_mode_on(self):
577        """Verify Standalone GNSS functionality while airplane mode is on.
578
579        Steps:
580            1. Turn on airplane mode.
581            2. TTFF Cold Start for 10 iteration.
582            3. Turn off airplane mode.
583
584        Expected Results:
585            All Standalone TTFF Cold Start results should be within
586            standalone_cs_criteria.
587        """
588        begin_time = get_current_epoch_time()
589        start_qxdm_logger(self.ad, begin_time)
590        start_adb_tcpdump(self.ad)
591        self.ad.log.info("Turn airplane mode on")
592        force_airplane_mode(self.ad, True)
593        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
594        start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
595        ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
596                                                self.pixel_lab_location)
597        result = check_ttff_data(self.ad, ttff_data, ttff_mode="Cold Start",
598                                 criteria=self.standalone_cs_criteria)
599        asserts.assert_true(result, "TTFF fails to reach designated criteria")
600
601    @test_tracker_info(uuid="23731b0d-cb80-4c79-a877-cfe7c2faa447")
602    def test_gnss_mobile_data_off(self):
603        """Verify Standalone GNSS functionality while mobile radio is off.
604
605        Steps:
606            1. Disable mobile data.
607            2. TTFF Cold Start for 10 iteration.
608            3. Enable mobile data.
609
610        Expected Results:
611            All Standalone TTFF Cold Start results should be within
612            standalone_cs_criteria.
613        """
614        begin_time = get_current_epoch_time()
615        start_qxdm_logger(self.ad, begin_time)
616        start_adb_tcpdump(self.ad)
617        kill_xtra_daemon(self.ad)
618        set_mobile_data(self.ad, False)
619        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
620        start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
621        ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
622                                                self.pixel_lab_location)
623        result = check_ttff_data(self.ad, ttff_data, ttff_mode="Cold Start",
624                                 criteria=self.standalone_cs_criteria)
625        asserts.assert_true(result, "TTFF fails to reach designated criteria")
626
627    @test_tracker_info(uuid="085b86a9-0212-4c0f-8ca1-2e467a0a2e6e")
628    def test_supl_without_gnss_signal(self):
629        """Verify SUPL functionality after no GNSS signal for awhile.
630
631        Steps:
632            1. Get location fixed.
633            2  Let device do GNSS tracking for 1 minute.
634            3. Set attenuation value to block GNSS signal.
635            4. Let DUT stay in no GNSS signal for 5 minutes.
636            5. Set attenuation value to regain GNSS signal.
637            6. Try to get location reported again.
638            7. Repeat Step 1. to Step 6. for 5 times.
639
640        Expected Results:
641            After setting attenuation value to 10 (GPS signal regain),
642            DUT could get location fixed again.
643        """
644        supl_no_gnss_signal_all = []
645        start_qxdm_logger(self.ad, get_current_epoch_time())
646        start_adb_tcpdump(self.ad)
647        for times in range(1, 6):
648            process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
649            self.ad.log.info("Let device do GNSS tracking for 1 minute.")
650            time.sleep(60)
651            set_attenuator_gnss_signal(self.ad, self.attenuators,
652                                       self.no_gnss_signal_attenuation)
653            self.ad.log.info("Let device stay in no GNSS signal for 5 minutes.")
654            time.sleep(300)
655            set_attenuator_gnss_signal(self.ad, self.attenuators,
656                                       self.default_gnss_signal_attenuation)
657            supl_no_gnss_signal = check_location_api(self.ad, retries=3)
658            start_gnss_by_gtw_gpstool(self.ad, False)
659            self.ad.log.info("SUPL without GNSS signal test %d times -> %s"
660                             % (times, supl_no_gnss_signal))
661            supl_no_gnss_signal_all.append(supl_no_gnss_signal)
662        asserts.assert_true(all(supl_no_gnss_signal_all),
663                            "Fail to get location update")
664
665    @test_tracker_info(uuid="3ff2f2fa-42d8-47fa-91de-060816cca9df")
666    def test_supl_weak_gnss_signal(self):
667        """Verify SUPL TTFF functionality under weak GNSS signal.
668
669        Steps:
670            1. Set attenuation value to weak GNSS signal.
671            2. Kill XTRA daemon to support SUPL only case.
672            3. SUPL TTFF Cold Start for 10 iteration.
673
674        Expected Results:
675            All SUPL TTFF Cold Start results should be less than
676            weak_signal_supl_cs_criteria.
677        """
678        set_attenuator_gnss_signal(self.ad, self.attenuators,
679                                   self.weak_gnss_signal_attenuation)
680        begin_time = get_current_epoch_time()
681        start_qxdm_logger(self.ad, begin_time)
682        start_adb_tcpdump(self.ad)
683        kill_xtra_daemon(self.ad)
684        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
685        start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
686        ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
687                                                self.pixel_lab_location)
688        result = check_ttff_data(self.ad, ttff_data, ttff_mode="Cold Start",
689                                 criteria=self.weak_signal_supl_cs_criteria)
690        asserts.assert_true(result, "TTFF fails to reach designated criteria")
691
692    @test_tracker_info(uuid="4ad4a371-949a-42e1-b1f4-628c79fa8ddc")
693    def test_supl_factory_reset(self):
694        """Verify SUPL functionality after factory reset.
695
696        Steps:
697            1. Factory reset device.
698            2. Kill XTRA daemon to support SUPL only case.
699            3. SUPL TTFF Cold Start for 10 iteration.
700            4. Repeat Step 1. to Step 3. for 3 times.
701
702        Expected Results:
703            All SUPL TTFF Cold Start results should be within supl_cs_criteria.
704        """
705        for times in range(1, 4):
706            fastboot_factory_reset(self.ad)
707            self.ad.unlock_screen(password=None)
708            _init_device(self.ad)
709            begin_time = get_current_epoch_time()
710            start_qxdm_logger(self.ad, begin_time)
711            start_adb_tcpdump(self.ad)
712            kill_xtra_daemon(self.ad)
713            process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
714            start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
715            ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
716                                                    self.pixel_lab_location)
717            if not check_ttff_data(self.ad, ttff_data, ttff_mode="Cold Start",
718                                   criteria=self.supl_cs_criteria):
719                raise signals.TestFailure("SUPL after Factory Reset test %d "
720                                          "times -> FAIL" % times)
721            self.ad.log.info("SUPL after Factory Reset test %d times -> "
722                             "PASS" % times)
723
724    @test_tracker_info(uuid="ea3096cf-4f72-4e91-bfb3-0bcbfe865ab4")
725    def test_xtra_ttff_mobile_data(self):
726        """Verify XTRA TTFF functionality with mobile data.
727
728        Steps:
729            1. Disable SUPL mode.
730            2. TTFF Warm Start for 10 iteration.
731            3. TTFF Cold Start for 10 iteration.
732
733        Expected Results:
734            XTRA TTFF Warm Start results should be within xtra_ws_criteria.
735            XTRA TTFF Cold Start results should be within xtra_cs_criteria.
736        """
737        xtra_result = []
738        disable_supl_mode(self.ad)
739        begin_time = get_current_epoch_time()
740        start_qxdm_logger(self.ad, begin_time)
741        start_adb_tcpdump(self.ad)
742        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
743        start_ttff_by_gtw_gpstool(self.ad, ttff_mode="ws", iteration=10)
744        ws_ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
745                                                   self.pixel_lab_location)
746        ws_result = check_ttff_data(self.ad,
747                                    ws_ttff_data,
748                                    ttff_mode="Warm Start",
749                                    criteria=self.xtra_ws_criteria)
750        xtra_result.append(ws_result)
751        begin_time = get_current_epoch_time()
752        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
753        start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
754        cs_ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
755                                                   self.pixel_lab_location)
756        cs_result = check_ttff_data(self.ad,
757                                    cs_ttff_data,
758                                    ttff_mode="Cold Start",
759                                    criteria=self.xtra_cs_criteria)
760        xtra_result.append(cs_result)
761        asserts.assert_true(all(xtra_result),
762                            "TTFF fails to reach designated criteria")
763
764    @test_tracker_info(uuid="c91ba740-220e-41de-81e5-43af31f63907")
765    def test_xtra_ttff_weak_gnss_signal(self):
766        """Verify XTRA TTFF functionality under weak GNSS signal.
767
768        Steps:
769            1. Set attenuation value to weak GNSS signal.
770            2. TTFF Warm Start for 10 iteration.
771            3. TTFF Cold Start for 10 iteration.
772
773        Expected Results:
774            XTRA TTFF Warm Start results should be within
775            weak_signal_xtra_ws_criteria.
776            XTRA TTFF Cold Start results should be within
777            weak_signal_xtra_cs_criteria.
778        """
779        xtra_result = []
780        disable_supl_mode(self.ad)
781        set_attenuator_gnss_signal(self.ad, self.attenuators,
782                                   self.weak_gnss_signal_attenuation)
783        begin_time = get_current_epoch_time()
784        start_qxdm_logger(self.ad, begin_time)
785        start_adb_tcpdump(self.ad)
786        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
787        start_ttff_by_gtw_gpstool(self.ad, ttff_mode="ws", iteration=10)
788        ws_ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
789                                                   self.pixel_lab_location)
790        ws_result = check_ttff_data(self.ad,
791                                    ws_ttff_data,
792                                    ttff_mode="Warm Start",
793                                    criteria=self.weak_signal_xtra_ws_criteria)
794        xtra_result.append(ws_result)
795        begin_time = get_current_epoch_time()
796        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
797        start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
798        cs_ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
799                                                   self.pixel_lab_location)
800        cs_result = check_ttff_data(self.ad,
801                                    cs_ttff_data,
802                                    ttff_mode="Cold Start",
803                                    criteria=self.weak_signal_xtra_cs_criteria)
804        xtra_result.append(cs_result)
805        asserts.assert_true(all(xtra_result),
806                            "TTFF fails to reach designated criteria")
807
808    @test_tracker_info(uuid="beeb3454-bcb2-451e-83fb-26289e89b515")
809    def test_xtra_ttff_wifi(self):
810        """Verify XTRA TTFF functionality with WiFi.
811
812        Steps:
813            1. Disable SUPL mode and turn airplane mode on.
814            2. Connect to WiFi.
815            3. TTFF Warm Start for 10 iteration.
816            4. TTFF Cold Start for 10 iteration.
817
818        Expected Results:
819            XTRA TTFF Warm Start results should be within xtra_ws_criteria.
820            XTRA TTFF Cold Start results should be within xtra_cs_criteria.
821        """
822        xtra_result = []
823        disable_supl_mode(self.ad)
824        begin_time = get_current_epoch_time()
825        start_qxdm_logger(self.ad, begin_time)
826        start_adb_tcpdump(self.ad)
827        self.ad.log.info("Turn airplane mode on")
828        force_airplane_mode(self.ad, True)
829        wifi_toggle_state(self.ad, True)
830        connect_to_wifi_network(
831            self.ad, self.ssid_map[self.pixel_lab_network[0]["SSID"]])
832        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
833        start_ttff_by_gtw_gpstool(self.ad, ttff_mode="ws", iteration=10)
834        ws_ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
835                                                   self.pixel_lab_location)
836        ws_result = check_ttff_data(self.ad,
837                                    ws_ttff_data,
838                                    ttff_mode="Warm Start",
839                                    criteria=self.xtra_ws_criteria)
840        xtra_result.append(ws_result)
841        begin_time = get_current_epoch_time()
842        process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
843        start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
844        cs_ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
845                                                   self.pixel_lab_location)
846        cs_result = check_ttff_data(self.ad,
847                                    cs_ttff_data,
848                                    ttff_mode="Cold Start",
849                                    criteria=self.wifi_xtra_cs_criteria)
850        xtra_result.append(cs_result)
851        asserts.assert_true(all(xtra_result),
852                            "TTFF fails to reach designated criteria")
853
854    @test_tracker_info(uuid="1745b8a4-5925-4aa0-809a-1b17e848dc9c")
855    def test_xtra_modem_ssr(self):
856        """Verify XTRA functionality after modem silent reboot.
857
858        Steps:
859            1. Trigger modem crash by adb.
860            2. Wait 1 minute for modem to recover.
861            3. XTRA TTFF Cold Start for 3 iteration.
862            4. Repeat Step1. to Step 3. for 5 times.
863
864        Expected Results:
865            All XTRA TTFF Cold Start results should be within xtra_cs_criteria.
866        """
867        disable_supl_mode(self.ad)
868        xtra_ssr_test_result_all = []
869        start_qxdm_logger(self.ad, get_current_epoch_time())
870        start_adb_tcpdump(self.ad)
871        for times in range(1, 6):
872            begin_time = get_current_epoch_time()
873            gnss_trigger_modem_ssr_by_mds(self.ad)
874            if not verify_internet_connection(self.ad.log, self.ad, retries=3,
875                                              expected_state=True):
876                raise signals.TestFailure("Fail to connect to LTE network.")
877            process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
878            start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=3)
879            ttff_data = process_ttff_by_gtw_gpstool(self.ad, begin_time,
880                                                    self.pixel_lab_location)
881            xtra_ssr_test_result = check_ttff_data(
882                self.ad, ttff_data, ttff_mode="Cold Start",
883                criteria=self.xtra_cs_criteria)
884            self.ad.log.info("XTRA after Modem SSR test %d times -> %s"
885                             % (times, xtra_ssr_test_result))
886            xtra_ssr_test_result_all.append(xtra_ssr_test_result)
887        asserts.assert_true(all(xtra_ssr_test_result_all),
888                            "TTFF fails to reach designated criteria")
889
890    @test_tracker_info(uuid="4d6e81e1-3abb-4e03-b732-7b6b497a2258")
891    def test_xtra_download_mobile_data(self):
892        """Verify XTRA data could be downloaded via mobile data.
893
894        Steps:
895            1. Delete all GNSS aiding data.
896            2. Get location fixed.
897            3. Verify whether XTRA is downloaded and injected.
898            4. Repeat Step 1. to Step 3. for 5 times.
899
900        Expected Results:
901            XTRA data is properly downloaded and injected via mobile data.
902        """
903        mobile_xtra_result_all = []
904        disable_supl_mode(self.ad)
905        start_qxdm_logger(self.ad, get_current_epoch_time())
906        start_adb_tcpdump(self.ad)
907        for i in range(1, 6):
908            begin_time = get_current_epoch_time()
909            process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
910            time.sleep(5)
911            start_gnss_by_gtw_gpstool(self.ad, False)
912            mobile_xtra_result = check_xtra_download(self.ad, begin_time)
913            self.ad.log.info("Iteration %d => %s" % (i, mobile_xtra_result))
914            mobile_xtra_result_all.append(mobile_xtra_result)
915        asserts.assert_true(all(mobile_xtra_result_all),
916                            "Fail to Download XTRA file")
917
918    @test_tracker_info(uuid="625ac665-1446-4406-a722-e6a19645222c")
919    def test_xtra_download_wifi(self):
920        """Verify XTRA data could be downloaded via WiFi.
921
922        Steps:
923            1. Connect to WiFi.
924            2. Delete all GNSS aiding data.
925            3. Get location fixed.
926            4. Verify whether XTRA is downloaded and injected.
927            5. Repeat Step 2. to Step 4. for 5 times.
928
929        Expected Results:
930            XTRA data is properly downloaded and injected via WiFi.
931        """
932        wifi_xtra_result_all = []
933        disable_supl_mode(self.ad)
934        start_qxdm_logger(self.ad, get_current_epoch_time())
935        start_adb_tcpdump(self.ad)
936        self.ad.log.info("Turn airplane mode on")
937        force_airplane_mode(self.ad, True)
938        wifi_toggle_state(self.ad, True)
939        connect_to_wifi_network(
940            self.ad, self.ssid_map[self.pixel_lab_network[0]["SSID"]])
941        for i in range(1, 6):
942            begin_time = get_current_epoch_time()
943            process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria)
944            time.sleep(5)
945            start_gnss_by_gtw_gpstool(self.ad, False)
946            wifi_xtra_result = check_xtra_download(self.ad, begin_time)
947            wifi_xtra_result_all.append(wifi_xtra_result)
948            self.ad.log.info("Iteraion %d => %s" % (i, wifi_xtra_result))
949        asserts.assert_true(all(wifi_xtra_result_all),
950                            "Fail to Download XTRA file")
951
952    @test_tracker_info(uuid="2a9f2890-3c0a-48b8-821d-bf97e36355e9")
953    def test_quick_toggle_gnss_state(self):
954        """Verify GNSS can still work properly after quick toggle GNSS off
955        to on.
956
957        Steps:
958            1. Launch GTW_GPSTool.
959            2. Go to "Advance setting"
960            3. Set Cycle = 10 & Time-out = 60
961            4. Go to "Toggle GPS" tab
962            5. Execute "Start"
963
964        Expected Results:
965            No single Timeout is seen in 10 iterations.
966        """
967        enable_supl_mode(self.ad)
968        reboot(self.ad)
969        start_qxdm_logger(self.ad, get_current_epoch_time())
970        start_adb_tcpdump(self.ad)
971        start_toggle_gnss_by_gtw_gpstool(self.ad, iteration=10)
972