• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
17from multiprocessing import Process
18
19from acts import utils
20from acts.base_test import BaseTestClass
21from acts.test_decorators import test_tracker_info
22from acts.test_utils.wifi import wifi_test_utils as wutils
23from acts.test_utils.tel import tel_test_utils as tutils
24from acts.test_utils.gnss import gnss_test_utils as gutils
25from acts.utils import get_current_epoch_time
26
27
28class GNSSSanityTest(BaseTestClass):
29    """ GNSS Function Sanity Tests"""
30    def __init__(self, controllers):
31        BaseTestClass.__init__(self, controllers)
32        self.ad = self.android_devices[0]
33        req_params = ["pixel_lab_network",
34                      "standalone_cs_criteria", "supl_cs_criteria",
35                      "xtra_ws_criteria", "xtra_cs_criteria",
36                      "weak_signal_supl_cs_criteria",
37                      "weak_signal_xtra_ws_criteria",
38                      "weak_signal_xtra_cs_criteria",
39                      "default_gnss_signal_attenuation",
40                      "weak_gnss_signal_attenuation",
41                      "no_gnss_signal_attenuation"]
42        self.unpack_userparams(req_param_names=req_params)
43        # create hashmap for SSID
44        self.ssid_map = {}
45        for network in self.pixel_lab_network:
46            SSID = network['SSID']
47            self.ssid_map[SSID] = network
48
49    def setup_class(self):
50        self.ad.droid.wakeLockAcquireBright()
51        self.ad.droid.wakeUpNow()
52        tutils.print_radio_info(self.ad)
53        gutils.set_attenuator_gnss_signal(self.ad, self.attenuators,
54                                          self.default_gnss_signal_attenuation)
55        gutils._init_device(self.ad)
56        if not tutils.verify_internet_connection(self.ad.log,
57                                                 self.ad,
58                                                 retries=3,
59                                                 expected_state=True):
60            tutils.abort_all_tests(self.ad.log,
61                                   "Fail to connect to LTE network")
62        if not gutils.check_location_service(self.ad):
63            tutils.abort_all_tests(self.ad.log, "Fail to switch Location on")
64
65    def setup_test(self):
66        gutils.clear_logd_gnss_qxdm_log(self.ad)
67
68    def teardown_test(self):
69        tutils.stop_qxdm_logger(self.ad)
70        if tutils.check_call_state_connected_by_adb(self.ad):
71            tutils.hangup_call(self.ad.log, self.ad)
72        if not int(self.ad.adb.shell("settings get global airplane_mode_on")) == 0:
73            self.ad.log.info("Force airplane mode off")
74            utils.force_airplane_mode(self.ad, False)
75        if self.ad.droid.wifiCheckState():
76            wutils.wifi_toggle_state(self.ad, False)
77        if not int(self.ad.adb.shell("settings get global mobile_data")) == 1:
78            gutils.set_mobile_data(self.ad, True)
79        if not int(self.ad.adb.shell(
80            "settings get global wifi_scan_always_enabled")) == 1:
81            gutils.set_wifi_and_bt_scanning(self.ad, True)
82        if not int(self.attenuators[0].get_atten()) == self.default_gnss_signal_attenuation:
83            gutils.set_attenuator_gnss_signal(self.ad, self.attenuators,
84                                              self.default_gnss_signal_attenuation)
85
86    def on_fail(self, test_name, begin_time):
87        gutils.get_gnss_qxdm_log(self.ad, test_name)
88        self.ad.take_bug_report(test_name, begin_time)
89
90    """ Test Cases """
91
92    @test_tracker_info(uuid="ff318483-411c-411a-8b1a-422bd54f4a3f")
93    def test_supl_capabilities(self):
94        """Verify SUPL capabilities.
95
96        Steps:
97            1. Root DUT.
98            2. Check SUPL capabilities.
99
100        Expected Results:
101            CAPABILITIES=0x37 which supports MSA + MSB.
102
103        Return:
104            True if PASS, False if FAIL.
105        """
106        capabilities_state = str(self.ad.adb.shell("cat vendor/etc/gps.conf | "
107                                                   "grep CAPABILITIES"))
108        self.ad.log.info("SUPL capabilities - %s" % capabilities_state)
109        if "CAPABILITIES=0x37" in capabilities_state:
110            return True
111        return False
112
113    @test_tracker_info(uuid="dcae6979-ddb4-4cad-9d14-fbdd9439cf42")
114    def test_sap_valid_modes(self):
115        """Verify SAP Valid Modes.
116
117        Steps:
118            1. Root DUT.
119            2. Check SAP Valid Modes.
120
121        Expected Results:
122            SAP=PREMIUM
123
124        Return:
125            True if PASS, False if FAIL.
126        """
127        sap_state = str(self.ad.adb.shell("cat vendor/etc/izat.conf | grep "
128                                          "SAP="))
129        self.ad.log.info("SAP Valid Modes - %s" % sap_state)
130        if "SAP=PREMIUM" in sap_state:
131            return True
132        return False
133
134    @test_tracker_info(uuid="14daaaba-35b4-42d9-8d2c-2a803dd746a6")
135    def test_network_location_provider_cell(self):
136        """Verify LocationManagerService API reports cell Network Location.
137
138        Steps:
139            1. WiFi scanning and Bluetooth scanning in Location Setting are OFF.
140            2. Launch GTW_GPSTool.
141            3. Verify whether test devices could report cell Network Location.
142            4. Repeat Step 2. to Step 3. for 5 times.
143
144        Expected Results:
145            Test devices could report cell Network Location.
146
147        Return:
148            True if PASS, False if FAIL.
149        """
150        test_result_all = []
151        tutils.start_qxdm_logger(self.ad, get_current_epoch_time())
152        gutils.set_wifi_and_bt_scanning(self.ad, False)
153        for i in range(1, 6):
154            test_result = gutils.check_network_location(
155                self.ad, retries=3, location_type = "networkLocationType=cell")
156            test_result_all.append(test_result)
157            self.ad.log.info("Iteraion %d => %s" % (i, test_result))
158        gutils.set_wifi_and_bt_scanning(self.ad, True)
159        return all(test_result_all)
160
161    @test_tracker_info(uuid="a45bdc7d-29fa-4a1d-ba34-6340b90e308d")
162    def test_network_location_provider_wifi(self):
163        """Verify LocationManagerService API reports wifi Network Location.
164
165        Steps:
166            1. WiFi scanning and Bluetooth scanning in Location Setting are ON.
167            2. Launch GTW_GPSTool.
168            3. Verify whether test devices could report wifi Network Location.
169            4. Repeat Step 2. to Step 3. for 5 times.
170
171        Expected Results:
172            Test devices could report wifi Network Location.
173
174        Return:
175            True if PASS, False if FAIL.
176        """
177        test_result_all = []
178        tutils.start_qxdm_logger(self.ad, get_current_epoch_time())
179        gutils.set_wifi_and_bt_scanning(self.ad, True)
180        for i in range(1, 6):
181            test_result = gutils.check_network_location(
182                self.ad, retries=3, location_type = "networkLocationType=wifi")
183            test_result_all.append(test_result)
184            self.ad.log.info("Iteraion %d => %s" % (i, test_result))
185        return all(test_result_all)
186
187    @test_tracker_info(uuid="0919d375-baf2-4fe7-b66b-3f72d386f791")
188    def test_gmap_location_report_gps_network(self):
189        """Verify GnssLocationProvider API reports location to Google Map
190           when GPS and Location Accuracy are on.
191
192        Steps:
193            1. GPS and NLP are on.
194            2. Launch Google Map.
195            3. Verify whether test devices could report location.
196            4. Repeat Step 2. to Step 3. for 5 times.
197
198        Expected Results:
199            Test devices could report location to Google Map.
200
201        Return:
202            True if PASS, False if FAIL.
203        """
204        test_result_all = []
205        tutils.start_qxdm_logger(self.ad, get_current_epoch_time())
206        for i in range(1, 6):
207            gutils.launch_google_map(self.ad)
208            test_result = gutils.check_location_api(self.ad, retries=3)
209            self.ad.send_keycode("HOME")
210            test_result_all.append(test_result)
211            self.ad.log.info("Iteraion %d => %s" % (i, test_result))
212        return all(test_result_all)
213
214    @test_tracker_info(uuid="513361d2-7d72-41b0-a944-fb259c606b81")
215    def test_gmap_location_report_gps(self):
216        """Verify GnssLocationProvider API reports location to Google Map
217           when GPS is on and Location Accuracy is off.
218
219        Steps:
220            1. GPS is on.
221            2. Location Accuracy is off.
222            3. Launch Google Map.
223            4. Verify whether test devices could report location.
224            5. Repeat Step 3. to Step 4. for 5 times.
225
226        Expected Results:
227            Test devices could report location to Google Map.
228
229        Return:
230            True if PASS, False if FAIL.
231        """
232        test_result_all = []
233        tutils.start_qxdm_logger(self.ad, get_current_epoch_time())
234        self.ad.adb.shell("settings put secure location_providers_allowed "
235                          "-network")
236        out = self.ad.adb.shell("settings get secure location_providers_allowed")
237        self.ad.log.info("Modify current Location Provider to %s" % out)
238        for i in range(1, 6):
239            gutils.launch_google_map(self.ad)
240            test_result = gutils.check_location_api(self.ad, retries=3)
241            self.ad.send_keycode("HOME")
242            test_result_all.append(test_result)
243            self.ad.log.info("Iteraion %d => %s" % (i, test_result))
244        self.ad.adb.shell("settings put secure location_providers_allowed "
245                          "+network")
246        out = self.ad.adb.shell("settings get secure location_providers_allowed")
247        self.ad.log.info("Modify current Location Provider to %s" % out)
248        return all(test_result_all)
249
250    @test_tracker_info(uuid="91a65121-b87d-450d-bd0f-387ade450ab7")
251    def test_gmap_location_report_battery_saver(self):
252        """Verify GnssLocationProvider API reports location to Google Map
253           when Battery Saver is enabled.
254
255        Steps:
256            1. GPS and NLP are on.
257            2. Enable Battery Saver.
258            3. Launch Google Map.
259            4. Verify whether test devices could report location.
260            5. Repeat Step 3. to Step 4. for 5 times.
261            6. Disable Battery Saver.
262
263        Expected Results:
264            Test devices could report location to Google Map.
265
266        Return:
267            True if PASS, False if FAIL.
268        """
269        test_result_all = []
270        tutils.start_qxdm_logger(self.ad, get_current_epoch_time())
271        gutils.set_battery_saver_mode(self.ad, True)
272        for i in range(1, 6):
273            gutils.launch_google_map(self.ad)
274            test_result = gutils.check_location_api(self.ad, retries=3)
275            self.ad.send_keycode("HOME")
276            test_result_all.append(test_result)
277            self.ad.log.info("Iteraion %d => %s" % (i, test_result))
278        gutils.set_battery_saver_mode(self.ad, False)
279        return all(test_result_all)
280
281    @test_tracker_info(uuid="60c0aeec-0c8f-4a96-bc6c-05cba1260e73")
282    def test_supl_ongoing_call(self):
283        """Verify SUPL functionality during phone call.
284
285        Steps:
286            1. Kill XTRA daemon to support SUPL only case.
287            2. Initiate call on DUT.
288            3. SUPL TTFF Cold Start for 10 iteration.
289            4. DUT hang up call.
290
291        Expected Results:
292            All SUPL TTFF Cold Start results should be less than
293            supl_cs_criteria.
294
295        Return:
296            True if PASS, False if FAIL.
297        """
298        begin_time = get_current_epoch_time()
299        tutils.start_qxdm_logger(self.ad, begin_time)
300        gutils.kill_xtra_daemon(self.ad)
301        self.ad.droid.setVoiceCallVolume(25)
302        tutils.initiate_call(self.ad.log, self.ad, "99117")
303        time.sleep(5)
304        if tutils.check_call_state_idle_by_adb(self.ad):
305            self.ad.log.error("Call is not connected.")
306            return False
307        if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.supl_cs_criteria):
308            return False
309        gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
310        ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
311        return gutils.check_ttff_result(self.ad, ttff_result,
312                                        ttff_mode="Cold Start",
313                                        criteria=self.supl_cs_criteria)
314
315    @test_tracker_info(uuid="df605509-328f-43e8-b6d8-00635bf701ef")
316    def test_supl_downloading_files(self):
317        """Verify SUPL functionality when downloading files.
318
319        Steps:
320            1. Kill XTRA daemon to support SUPL only case.
321            2. DUT start downloading files by sl4a.
322            3. SUPL TTFF Cold Start for 10 iteration.
323            4. DUT cancel downloading files.
324
325        Expected Results:
326            All SUPL TTFF Cold Start results should be within supl_cs_criteria.
327
328        Return:
329            True if PASS, False if FAIL.
330        """
331        begin_time = get_current_epoch_time()
332        tutils.start_qxdm_logger(self.ad, begin_time)
333        gutils.kill_xtra_daemon(self.ad)
334        download = Process(target=tutils.http_file_download_by_sl4a,
335                           args=(self.ad, "https://speed.hetzner.de/10GB.bin",
336                                 None, None, True, 3600))
337        download.start()
338        time.sleep(10)
339        if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.supl_cs_criteria):
340            download.terminate()
341            time.sleep(3)
342            return False
343        gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
344        ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
345        download.terminate()
346        time.sleep(3)
347        return gutils.check_ttff_result(self.ad, ttff_result,
348                                        ttff_mode="Cold Start",
349                                        criteria=self.supl_cs_criteria)
350
351    @test_tracker_info(uuid="66b9f9d4-1397-4da7-9e55-8b89b1732017")
352    def test_supl_watching_youtube(self):
353        """Verify SUPL functionality when watching video on youtube.
354
355        Steps:
356            1. Kill XTRA daemon to support SUPL only case.
357            2. DUT start watching video on youtube.
358            3. SUPL TTFF Cold Start for 10 iteration at the background.
359            4. DUT stop watching video on youtube.
360
361        Expected Results:
362            All SUPL TTFF Cold Start results should be within supl_cs_criteria.
363
364        Return:
365            True if PASS, False if FAIL.
366        """
367        begin_time = get_current_epoch_time()
368        tutils.start_qxdm_logger(self.ad, begin_time)
369        gutils.kill_xtra_daemon(self.ad)
370        if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.supl_cs_criteria):
371            return False
372        gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
373        if not gutils.start_youtube_video(
374            self.ad, "https://www.youtube.com/watch?v=AbdVsi1VjQY", retries=3):
375            return False
376        ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
377        return gutils.check_ttff_result(self.ad, ttff_result,
378                                        ttff_mode="Cold Start",
379                                        criteria=self.supl_cs_criteria)
380
381    @test_tracker_info(uuid="a748af8b-e1eb-4ec6-bde3-74bcefa1c680")
382    def test_supl_modem_ssr(self):
383        """Verify SUPL functionality after modem silent reboot.
384
385        Steps:
386            1. Trigger modem crash by adb.
387            2. Wait 1 minute for modem to recover.
388            3. SUPL TTFF Cold Start for 3 iteration.
389            4. Repeat Step 1. to Step 3. for 5 times.
390
391        Expected Results:
392            All SUPL TTFF Cold Start results should be within supl_cs_criteria.
393
394        Return:
395            True if PASS, False if FAIL.
396        """
397        supl_ssr_test_result_all = []
398        tutils.start_qxdm_logger(self.ad, get_current_epoch_time())
399        gutils.kill_xtra_daemon(self.ad)
400        for times in range(1, 6):
401            begin_time = get_current_epoch_time()
402            before_modem_ssr = gutils.get_modem_ssr_crash_count(self.ad)
403            tutils.trigger_modem_crash(self.ad, timeout=60)
404            after_modem_ssr = gutils.get_modem_ssr_crash_count(self.ad)
405            if not int(after_modem_ssr) == int(before_modem_ssr) + 1:
406                self.ad.log.error("Simulated Modem SSR Failed.")
407                return False
408            if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.supl_cs_criteria):
409                return False
410            gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=3)
411            ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
412            supl_ssr_test_result = gutils.check_ttff_result(
413                self.ad, ttff_result, "Cold Start", self.supl_cs_criteria)
414            self.ad.log.info("SUPL after Modem SSR test %d times -> %s"
415                             % (times, supl_ssr_test_result))
416            supl_ssr_test_result_all.append(supl_ssr_test_result)
417        return all(supl_ssr_test_result_all)
418
419    @test_tracker_info(uuid="01602e65-8ded-4459-8df1-7df70a1bfe8a")
420    def test_gnss_airplane_mode_on(self):
421        """Verify Standalone GNSS functionality while airplane mode is on.
422
423        Steps:
424            1. Turn on airplane mode.
425            2. TTFF Cold Start for 10 iteration.
426            3. Turn off airplane mode.
427
428        Expected Results:
429            All Standalone TTFF Cold Start results should be within
430            standalone_cs_criteria.
431
432        Return:
433            True if PASS, False if FAIL.
434        """
435        begin_time = get_current_epoch_time()
436        tutils.start_qxdm_logger(self.ad, begin_time)
437        self.ad.log.info("Turn airplane mode on")
438        utils.force_airplane_mode(self.ad, True)
439        if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria):
440            return False
441        gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
442        ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
443        return gutils.check_ttff_result(self.ad, ttff_result,
444                                        ttff_mode="Cold Start",
445                                        criteria=self.standalone_cs_criteria)
446
447    @test_tracker_info(uuid="23731b0d-cb80-4c79-a877-cfe7c2faa447")
448    def test_gnss_mobile_data_off(self):
449        """Verify Standalone GNSS functionality while mobile radio is off.
450
451        Steps:
452            1. Disable mobile data.
453            2. TTFF Cold Start for 10 iteration.
454            3. Enable mobile data.
455
456        Expected Results:
457            All Standalone TTFF Cold Start results should be within
458            standalone_cs_criteria.
459
460        Return:
461            True if PASS, False if FAIL.
462        """
463        begin_time = get_current_epoch_time()
464        tutils.start_qxdm_logger(self.ad, begin_time)
465        gutils.kill_xtra_daemon(self.ad)
466        gutils.set_mobile_data(self.ad, False)
467        if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.standalone_cs_criteria):
468            return False
469        gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
470        ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
471        return gutils.check_ttff_result(self.ad, ttff_result,
472                                        ttff_mode="Cold Start",
473                                        criteria=self.standalone_cs_criteria)
474
475    @test_tracker_info(uuid="085b86a9-0212-4c0f-8ca1-2e467a0a2e6e")
476    def test_supl_without_gnss_signal(self):
477        """Verify SUPL functionality after no GNSS signal for awhile.
478
479        Steps:
480            1. Get location fixed.
481            2  Let device do GNSS tracking for 1 minute.
482            3. Set attenuation value to 60 to block GNSS signal.
483            4. Let DUT stay in no GNSS signal for 5 minutes.
484            5. Set attenuation value to 23 to regain GNSS signal.
485            6. Try to get location reported again.
486            7. Repeat Step 1. to Step 6. for 5 times.
487
488        Expected Results:
489            After setting attenuation value to 10 (GPS signal regain),
490            DUT could get location fixed again.
491
492        Return:
493            True if PASS, False if FAIL.
494        """
495        supl_no_gnss_signal_all = []
496        tutils.start_qxdm_logger(self.ad, get_current_epoch_time())
497        for times in range(1, 6):
498            if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.supl_cs_criteria):
499                return False
500            self.ad.log.info("Let device do GNSS tracking for 1 minute.")
501            time.sleep(60)
502            gutils.set_attenuator_gnss_signal(self.ad, self.attenuators,
503                                              self.no_gnss_signal_attenuation)
504            self.ad.log.info("Let device stay in no GNSS signal for 5 minutes.")
505            time.sleep(300)
506            gutils.set_attenuator_gnss_signal(self.ad, self.attenuators,
507                                              self.default_gnss_signal_attenuation)
508            supl_no_gnss_signal = gutils.check_location_api(self.ad, retries=3)
509            gutils.start_gnss_by_gtw_gpstool(self.ad, False)
510            self.ad.log.info("SUPL without GNSS signal test %d times -> %s"
511                             % (times, supl_no_gnss_signal))
512            supl_no_gnss_signal_all.append(supl_no_gnss_signal)
513        return all(supl_no_gnss_signal_all)
514
515    @test_tracker_info(uuid="3ff2f2fa-42d8-47fa-91de-060816cca9df")
516    def test_supl_weak_gnss_signal(self):
517        """Verify SUPL TTFF functionality under weak GNSS signal.
518
519        Steps:
520            1. Set attenuation value to 40 to set weak GNSS signal.
521            2. Kill XTRA daemon to support SUPL only case.
522            3. SUPL TTFF Cold Start for 10 iteration.
523            4. Set attenuation value to 23 to set default GNSS signal.
524
525        Expected Results:
526            All SUPL TTFF Cold Start results should be less than
527            weak_signal_supl_cs_criteria.
528
529        Return:
530            True if PASS, False if FAIL.
531        """
532        gutils.set_attenuator_gnss_signal(self.ad, self.attenuators,
533                                          self.weak_gnss_signal_attenuation)
534        begin_time = get_current_epoch_time()
535        tutils.start_qxdm_logger(self.ad, begin_time)
536        gutils.kill_xtra_daemon(self.ad)
537        if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.weak_signal_supl_cs_criteria):
538            return False
539        gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
540        ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
541        return gutils.check_ttff_result(self.ad, ttff_result, "Cold Start",
542                                        self.weak_signal_supl_cs_criteria)
543
544    @test_tracker_info(uuid="4ad4a371-949a-42e1-b1f4-628c79fa8ddc")
545    def test_supl_factory_reset(self):
546        """Verify SUPL functionality after factory reset.
547
548        Steps:
549            1. Factory reset device.
550            2. Kill XTRA daemon to support SUPL only case.
551            3. SUPL TTFF Cold Start for 10 iteration.
552            4. Repeat Step 1. to Step 3. for 3 times.
553
554        Expected Results:
555            All SUPL TTFF Cold Start results should be within supl_cs_criteria.
556
557        Return:
558            True if PASS, False if FAIL.
559        """
560        for times in range(1, 4):
561            gutils.fastboot_factory_reset(self.ad)
562            self.ad.unlock_screen(password=None)
563            gutils._init_device(self.ad)
564            if not gutils.check_location_service(self.ad):
565                return False
566            begin_time = get_current_epoch_time()
567            tutils.start_qxdm_logger(self.ad, begin_time)
568            gutils.kill_xtra_daemon(self.ad)
569            if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.supl_cs_criteria):
570                return False
571            gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
572            ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
573            if not gutils.check_ttff_result(self.ad, ttff_result,
574                                            ttff_mode="Cold Start",
575                                            criteria=self.supl_cs_criteria):
576                self.ad.log.error("SUPL after Factory Reset test %d times "
577                                  "-> FAIL" % times)
578                return False
579            self.ad.log.info("SUPL after Factory Reset test %d times -> "
580                             "PASS" % times)
581        return True
582
583    @test_tracker_info(uuid="ea3096cf-4f72-4e91-bfb3-0bcbfe865ab4")
584    def test_xtra_ttff_mobile_data(self):
585        """Verify XTRA TTFF functionality with mobile data.
586
587        Steps:
588            1. Disable SUPL mode.
589            2. TTFF Warm Start for 10 iteration.
590            3. TTFF Cold Start for 10 iteration.
591
592        Expected Results:
593            XTRA TTFF Warm Start results should be within xtra_ws_criteria.
594            XTRA TTFF Cold Start results should be within xtra_cs_criteria.
595
596        Return:
597            True if PASS, False if FAIL.
598        """
599        gutils.disable_supl_mode(self.ad)
600        begin_time = get_current_epoch_time()
601        tutils.start_qxdm_logger(self.ad, begin_time)
602        if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.xtra_cs_criteria):
603            return False
604        gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="ws", iteration=10)
605        ws_ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
606        if not gutils.check_ttff_result(self.ad, ws_ttff_result, "Warm Start",
607                                        self.xtra_ws_criteria):
608            return False
609        begin_time = get_current_epoch_time()
610        if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.xtra_cs_criteria):
611            return False
612        gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
613        cs_ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
614        return gutils.check_ttff_result(self.ad, cs_ttff_result, "Cold Start",
615                                        self.xtra_cs_criteria)
616
617    @test_tracker_info(uuid="c91ba740-220e-41de-81e5-43af31f63907")
618    def test_xtra_ttff_weak_gnss_signal(self):
619        """Verify XTRA TTFF functionality under weak GNSS signal.
620
621        Steps:
622            1. Set attenuation value to 40 to set weak GNSS signal.
623            2. TTFF Warm Start for 10 iteration.
624            3. TTFF Cold Start for 10 iteration.
625            4. Set attenuation value to 23 to set default GNSS signal.
626
627        Expected Results:
628            XTRA TTFF Warm Start results should be within
629            weak_signal_xtra_ws_criteria.
630            XTRA TTFF Cold Start results should be within
631            weak_signal_xtra_cs_criteria.
632
633        Return:
634            True if PASS, False if FAIL.
635        """
636        gutils.disable_supl_mode(self.ad)
637        gutils.set_attenuator_gnss_signal(self.ad, self.attenuators,
638                                          self.weak_gnss_signal_attenuation)
639        begin_time = get_current_epoch_time()
640        tutils.start_qxdm_logger(self.ad, begin_time)
641        if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.weak_signal_xtra_cs_criteria):
642            return False
643        gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="ws", iteration=10)
644        ws_ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
645        if not gutils.check_ttff_result(self.ad, ws_ttff_result, "Warm Start",
646                                        self.weak_signal_xtra_ws_criteria):
647            return False
648        begin_time = get_current_epoch_time()
649        if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.weak_signal_xtra_cs_criteria):
650            return False
651        gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
652        cs_ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
653        return gutils.check_ttff_result(self.ad, cs_ttff_result, "Cold Start",
654                                        self.weak_signal_xtra_cs_criteria)
655
656    @test_tracker_info(uuid="beeb3454-bcb2-451e-83fb-26289e89b515")
657    def test_xtra_ttff_wifi(self):
658        """Verify XTRA TTFF functionality with WiFi.
659
660        Steps:
661            1. Disable SUPL mode and turn airplane mode on.
662            2. Connect to WiFi.
663            3. TTFF Warm Start for 10 iteration.
664            4. TTFF Cold Start for 10 iteration.
665
666        Expected Results:
667            XTRA TTFF Warm Start results should be within xtra_ws_criteria.
668            XTRA TTFF Cold Start results should be within xtra_cs_criteria.
669
670        Return:
671            True if PASS, False if FAIL.
672        """
673        gutils.disable_supl_mode(self.ad)
674        begin_time = get_current_epoch_time()
675        tutils.start_qxdm_logger(self.ad, begin_time)
676        self.ad.log.info("Turn airplane mode on")
677        utils.force_airplane_mode(self.ad, True)
678        wutils.wifi_toggle_state(self.ad, True)
679        gutils.connect_to_wifi_network(
680            self.ad, self.ssid_map[self.pixel_lab_network[0]["SSID"]])
681        if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.xtra_cs_criteria):
682            return False
683        gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="ws", iteration=10)
684        ws_ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
685        if not gutils.check_ttff_result(self.ad, ws_ttff_result, "Warm Start",
686                                        self.xtra_ws_criteria):
687            return False
688        begin_time = get_current_epoch_time()
689        if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.xtra_cs_criteria):
690            return False
691        gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=10)
692        cs_ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
693        return gutils.check_ttff_result(self.ad, cs_ttff_result, "Cold Start",
694                                        self.xtra_cs_criteria)
695
696    @test_tracker_info(uuid="1745b8a4-5925-4aa0-809a-1b17e848dc9c")
697    def test_xtra_modem_ssr(self):
698        """Verify XTRA functionality after modem silent reboot.
699
700        Steps:
701            1. Trigger modem crash by adb.
702            2. Wait 1 minute for modem to recover.
703            3. XTRA TTFF Cold Start for 3 iteration.
704            4. Repeat Step1. to Step 3. for 5 times.
705
706        Expected Results:
707            All XTRA TTFF Cold Start results should be within xtra_cs_criteria.
708
709        Return:
710            True if PASS, False if FAIL.
711        """
712        gutils.disable_supl_mode(self.ad)
713        xtra_ssr_test_result_all = []
714        tutils.start_qxdm_logger(self.ad, get_current_epoch_time())
715        for times in range(1, 6):
716            begin_time = get_current_epoch_time()
717            before_modem_ssr = gutils.get_modem_ssr_crash_count(self.ad)
718            tutils.trigger_modem_crash(self.ad, timeout=60)
719            after_modem_ssr = gutils.get_modem_ssr_crash_count(self.ad)
720            if not int(after_modem_ssr) == int(before_modem_ssr) + 1:
721                self.ad.log.error("Simulated Modem SSR Failed.")
722                return False
723            if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.xtra_cs_criteria):
724                return False
725            gutils.start_ttff_by_gtw_gpstool(self.ad, ttff_mode="cs", iteration=3)
726            ttff_result = gutils.process_ttff_by_gtw_gpstool(self.ad, begin_time)
727            xtra_ssr_test_result = gutils.check_ttff_result(self.ad,
728                                                            ttff_result,
729                                                            "Cold Start",
730                                                            self.xtra_cs_criteria)
731            self.ad.log.info("XTRA after Modem SSR test %d times -> %s"
732                             % (times, xtra_ssr_test_result))
733            xtra_ssr_test_result_all.append(xtra_ssr_test_result)
734        return all(xtra_ssr_test_result_all)
735
736    @test_tracker_info(uuid="4d6e81e1-3abb-4e03-b732-7b6b497a2258")
737    def test_xtra_download_mobile_data(self):
738        """Verify XTRA data could be downloaded via mobile data.
739
740        Steps:
741            1. Delete all GNSS aiding data.
742            2. Get location fixed.
743            3. Verify whether XTRA is downloaded and injected.
744            4. Repeat Step 1. to Step 3. for 5 times.
745
746        Expected Results:
747            XTRA data is properly downloaded and injected via mobile data.
748
749        Return:
750            True if PASS, False if FAIL.
751        """
752        mobile_xtra_result_all = []
753        gutils.disable_supl_mode(self.ad)
754        tutils.start_qxdm_logger(self.ad, get_current_epoch_time())
755        for i in range(1, 6):
756            begin_time = get_current_epoch_time()
757            if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.xtra_cs_criteria):
758                return False
759            time.sleep(5)
760            gutils.start_gnss_by_gtw_gpstool(self.ad, False)
761            mobile_xtra_result = gutils.check_xtra_download(self.ad, begin_time)
762            self.ad.log.info("Iteration %d => %s" % (i, mobile_xtra_result))
763            mobile_xtra_result_all.append(mobile_xtra_result)
764        return all(mobile_xtra_result_all)
765
766    @test_tracker_info(uuid="625ac665-1446-4406-a722-e6a19645222c")
767    def test_xtra_download_wifi(self):
768        """Verify XTRA data could be downloaded via WiFi.
769
770        Steps:
771            1. Connect to WiFi.
772            2. Delete all GNSS aiding data.
773            3. Get location fixed.
774            4. Verify whether XTRA is downloaded and injected.
775            5. Repeat Step 2. to Step 4. for 5 times.
776
777        Expected Results:
778            XTRA data is properly downloaded and injected via WiFi.
779
780        Return:
781            True if PASS, False if FAIL.
782        """
783        wifi_xtra_result_all = []
784        gutils.disable_supl_mode(self.ad)
785        tutils.start_qxdm_logger(self.ad, get_current_epoch_time())
786        self.ad.log.info("Turn airplane mode on")
787        utils.force_airplane_mode(self.ad, True)
788        wutils.wifi_toggle_state(self.ad, True)
789        gutils.connect_to_wifi_network(
790            self.ad, self.ssid_map[self.pixel_lab_network[0]["SSID"]])
791        for i in range(1, 6):
792            begin_time = get_current_epoch_time()
793            if not gutils.process_gnss_by_gtw_gpstool(self.ad, self.xtra_cs_criteria):
794                return False
795            time.sleep(5)
796            gutils.start_gnss_by_gtw_gpstool(self.ad, False)
797            wifi_xtra_result = gutils.check_xtra_download(self.ad, begin_time)
798            wifi_xtra_result_all.append(wifi_xtra_result)
799            self.ad.log.info("Iteraion %d => %s" % (i, wifi_xtra_result))
800        return all(wifi_xtra_result_all)
801