• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1from multiprocessing import Process
2import time
3
4from acts import asserts
5from acts import signals
6from acts.base_test import BaseTestClass
7from acts_contrib.test_utils.gnss import gnss_test_utils as gutils
8from acts_contrib.test_utils.gnss import supl
9from acts_contrib.test_utils.gnss import gnss_defines
10from acts_contrib.test_utils.gnss.testtracker_util import log_testtracker_uuid
11from acts_contrib.test_utils.tel.tel_data_utils import http_file_download_by_sl4a
12from acts_contrib.test_utils.tel.tel_logging_utils import get_tcpdump_log
13from acts_contrib.test_utils.tel.tel_logging_utils import stop_adb_tcpdump
14from acts_contrib.test_utils.tel.tel_logging_utils import get_tcpdump_log
15from acts_contrib.test_utils.tel.tel_test_utils import check_call_state_connected_by_adb
16from acts_contrib.test_utils.tel.tel_test_utils import verify_internet_connection
17from acts_contrib.test_utils.tel.tel_test_utils import toggle_airplane_mode
18from acts_contrib.test_utils.tel.tel_voice_utils import initiate_call
19from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
20from acts.utils import get_current_epoch_time
21
22
23class GnssSuplTest(BaseTestClass):
24    def setup_class(self):
25        super().setup_class()
26        self.ad = self.android_devices[0]
27        req_params = [
28            "pixel_lab_network", "standalone_cs_criteria", "supl_cs_criteria", "supl_ws_criteria",
29            "supl_hs_criteria", "default_gnss_signal_attenuation", "pixel_lab_location",
30            "qdsp6m_path", "collect_logs", "ttff_test_cycle",
31            "supl_capabilities", "no_gnss_signal_attenuation", "set_attenuator"
32        ]
33        self.unpack_userparams(req_param_names=req_params)
34        # create hashmap for SSID
35        self.ssid_map = {}
36        for network in self.pixel_lab_network:
37            SSID = network["SSID"]
38            self.ssid_map[SSID] = network
39        self.init_device()
40
41    def only_brcm_device_runs_wifi_case(self):
42        """SUPL over wifi is only supported by BRCM devices, for QUAL device, skip the test.
43        """
44        if gutils.check_chipset_vendor_by_qualcomm(self.ad):
45            raise signals.TestSkip("Qualcomm device doesn't support SUPL over wifi")
46
47    def wearable_btwifi_should_skip_mobile_data_case(self):
48        if gutils.is_wearable_btwifi(self.ad):
49            raise signals.TestSkip("Skip mobile data case for BtWiFi sku")
50
51    def init_device(self):
52        """Init GNSS test devices for SUPL suite."""
53        gutils._init_device(self.ad)
54        gutils.disable_vendor_orbit_assistance_data(self.ad)
55        gutils.enable_supl_mode(self.ad)
56        self.enable_supl_over_wifi()
57        gutils.reboot(self.ad)
58
59    def enable_supl_over_wifi(self):
60        if not gutils.check_chipset_vendor_by_qualcomm(self.ad):
61            supl.set_supl_over_wifi_state(self.ad, turn_on=True)
62
63    def setup_test(self):
64        gutils.log_current_epoch_time(self.ad, "test_start_time")
65        log_testtracker_uuid(self.ad, self.current_test_name)
66        gutils.clear_logd_gnss_qxdm_log(self.ad)
67        gutils.get_baseband_and_gms_version(self.ad)
68        toggle_airplane_mode(self.ad.log, self.ad, new_state=False)
69        if gutils.is_wearable_btwifi(self.ad):
70            wutils.wifi_toggle_state(self.ad, True)
71            gutils.connect_to_wifi_network(self.ad,
72                                           self.ssid_map[self.pixel_lab_network[0]["SSID"]])
73        else:
74            wutils.wifi_toggle_state(self.ad, False)
75            gutils.set_mobile_data(self.ad, state=True)
76        if not verify_internet_connection(self.ad.log, self.ad, retries=3,
77                                          expected_state=True):
78            raise signals.TestFailure("Fail to connect to LTE network.")
79        # Once the device is rebooted, the xtra service will be alive again
80        # In order not to affect the supl case, disable it in setup_test.
81        if gutils.check_chipset_vendor_by_qualcomm(self.ad):
82            gutils.disable_qualcomm_orbit_assistance_data(self.ad)
83
84    def teardown_test(self):
85        if self.collect_logs:
86            gutils.stop_pixel_logger(self.ad)
87            stop_adb_tcpdump(self.ad)
88        if self.set_attenuator:
89            gutils.set_attenuator_gnss_signal(self.ad, self.attenuators,
90                                              self.default_gnss_signal_attenuation)
91        gutils.log_current_epoch_time(self.ad, "test_end_time")
92
93    def on_fail(self, test_name, begin_time):
94        if self.collect_logs:
95            self.ad.take_bug_report(test_name, begin_time)
96            gutils.get_gnss_qxdm_log(self.ad, self.qdsp6m_path)
97            self.get_brcm_gps_xml_to_sponge()
98            get_tcpdump_log(self.ad, test_name, begin_time)
99
100    def get_brcm_gps_xml_to_sponge(self):
101        # request from b/250506003 - to check the SUPL setting
102        if not gutils.check_chipset_vendor_by_qualcomm(self.ad):
103            self.ad.pull_files(gnss_defines.BCM_GPS_XML_PATH, self.ad.device_log_path)
104
105    def run_ttff(self, mode, criteria):
106        """Triggers TTFF.
107
108        Args:
109            mode: "cs", "ws" or "hs"
110            criteria: Criteria for the test.
111        """
112        return gutils.run_ttff(self.ad, mode, criteria, self.ttff_test_cycle,
113                               self.pixel_lab_location, self.collect_logs)
114
115    def supl_ttff_weak_gnss_signal(self, mode, criteria):
116        """Verify SUPL TTFF functionality under weak GNSS signal.
117
118        Args:
119            mode: "cs", "ws" or "hs"
120            criteria: Criteria for the test.
121        """
122        gutils.set_attenuator_gnss_signal(self.ad, self.attenuators,
123                                          self.weak_gnss_signal_attenuation)
124        self.run_ttff(mode, criteria)
125
126    def connect_to_wifi_with_mobile_data_off(self):
127        gutils.set_mobile_data(self.ad, False)
128        wutils.wifi_toggle_state(self.ad, True)
129        gutils.connect_to_wifi_network(self.ad, self.ssid_map[self.pixel_lab_network[0]["SSID"]])
130
131    def connect_to_wifi_with_airplane_mode_on(self):
132        toggle_airplane_mode(self.ad.log, self.ad, new_state=True)
133        wutils.wifi_toggle_state(self.ad, True)
134        gutils.connect_to_wifi_network(self.ad, self.ssid_map[self.pixel_lab_network[0]["SSID"]])
135
136    def check_position_mode(self, begin_time: int, mode: str):
137        logcat_results = self.ad.search_logcat(
138            matching_string="setting position_mode to", begin_time=begin_time)
139        return all([result["log_message"].split(" ")[-1] == mode for result in logcat_results])
140
141    def test_supl_capabilities(self):
142        """Verify SUPL capabilities.
143
144        Steps:
145            1. Root DUT.
146            2. Check SUPL capabilities.
147
148        Expected Results:
149            CAPABILITIES=0x37 which supports MSA + MSB.
150            CAPABILITIES=0x17 = ON_DEMAND_TIME | MSA | MSB | SCHEDULING
151        """
152        if not gutils.check_chipset_vendor_by_qualcomm(self.ad):
153            raise signals.TestSkip("Not Qualcomm chipset. Skip the test.")
154        capabilities_state = str(
155            self.ad.adb.shell(
156                "cat vendor/etc/gps.conf | grep CAPABILITIES")).split("=")[-1]
157        self.ad.log.info("SUPL capabilities - %s" % capabilities_state)
158
159        asserts.assert_true(capabilities_state in self.supl_capabilities,
160                            "Wrong default SUPL capabilities is set. Found %s, "
161                            "expected any of %r" % (capabilities_state,
162                                                    self.supl_capabilities))
163
164
165    def test_supl_ttff_cs(self):
166        """Verify SUPL functionality of TTFF Cold Start.
167
168        Steps:
169            1. Kill XTRA/LTO daemon to support SUPL only case.
170            2. SUPL TTFF Cold Start for 10 iteration.
171
172        Expected Results:
173            All SUPL TTFF Cold Start results should be less than
174            supl_cs_criteria.
175        """
176        self.run_ttff("cs", self.supl_cs_criteria)
177
178    def test_supl_ttff_ws(self):
179        """Verify SUPL functionality of TTFF Warm Start.
180
181        Steps:
182            1. Kill XTRA/LTO daemon to support SUPL only case.
183            2. SUPL TTFF Warm Start for 10 iteration.
184
185        Expected Results:
186            All SUPL TTFF Warm Start results should be less than
187            supl_ws_criteria.
188        """
189        self.run_ttff("ws", self.supl_ws_criteria)
190
191    def test_supl_ttff_hs(self):
192        """Verify SUPL functionality of TTFF Hot Start.
193
194        Steps:
195            1. Kill XTRA/LTO daemon to support SUPL only case.
196            2. SUPL TTFF Hot Start for 10 iteration.
197
198        Expected Results:
199            All SUPL TTFF Hot Start results should be less than
200            supl_hs_criteria.
201        """
202        self.run_ttff("hs", self.supl_hs_criteria)
203
204    def test_cs_ttff_supl_over_wifi_with_airplane_mode_on(self):
205        """ Test supl can works through wifi with airplane mode on
206
207        Test steps are executed in the following sequence.
208        - Turn on airplane mode
209        - Connect to wifi
210        - Run SUPL CS TTFF
211        """
212        self.only_brcm_device_runs_wifi_case()
213
214        self.connect_to_wifi_with_airplane_mode_on()
215
216        self.run_ttff(mode="cs", criteria=self.supl_cs_criteria)
217
218    def test_ws_ttff_supl_over_wifi_with_airplane_mode_on(self):
219        """ Test supl can works through wifi with airplane mode on
220
221        Test steps are executed in the following sequence.
222        - Turn on airplane mode
223        - Connect to wifi
224        - Run SUPL WS TTFF
225        """
226        self.only_brcm_device_runs_wifi_case()
227
228        self.connect_to_wifi_with_airplane_mode_on()
229
230        self.run_ttff("ws", self.supl_ws_criteria)
231
232    def test_hs_ttff_supl_over_wifi_with_airplane_mode_on(self):
233        """ Test supl can works through wifi with airplane mode on
234
235        Test steps are executed in the following sequence.
236        - Turn on airplane mode
237        - Connect to wifi
238        - Run SUPL WS TTFF
239        """
240        self.only_brcm_device_runs_wifi_case()
241
242        self.connect_to_wifi_with_airplane_mode_on()
243
244        self.run_ttff("hs", self.supl_ws_criteria)
245
246    def test_ttff_gla_on(self):
247        """ Test the turn on "Google Location Accuracy" in settings work or not.
248
249        Test steps are executed in the following sequence.
250        - Turn off airplane mode
251        - Connect to Cellular
252        - Turn off LTO/RTO
253        - Turn on SUPL
254        - Turn on GLA
255        - Run CS TTFF
256
257        Expected Results:
258        - The position mode must be "MS_BASED"
259        - The TTFF time should be less than 10 seconds
260        """
261        begin_time = get_current_epoch_time()
262        gutils.gla_mode(self.ad, True)
263
264        self.run_ttff("cs", self.supl_cs_criteria)
265        asserts.assert_true(self.check_position_mode(begin_time, "MS_BASED"),
266                                msg=f"Fail to enter the MS_BASED mode")
267
268    def test_ttff_gla_off(self):
269        """ Test the turn off "Google Location Accuracy" in settings work or not.
270
271        Test steps are executed in the following sequence.
272        - Turn off airplane mode
273        - Connect to Cellular
274        - Turn off LTO/RTO
275        - Turn on SUPL
276        - Turn off GLA
277        - Run CS TTFF
278
279        Expected Results:
280        - The position mode must be "standalone"
281        - The TTFF time must be between slower than supl_ws and faster than standalone_cs.
282        """
283        begin_time = get_current_epoch_time()
284        gutils.gla_mode(self.ad, False)
285
286        ttff_data = self.run_ttff("cs", self.standalone_cs_criteria)
287
288        asserts.assert_true(any(float(ttff_data[key].ttff_sec) > self.supl_ws_criteria
289                                for key in ttff_data.keys()),
290                            msg=f"One or more TTFF Cold Start are faster than \
291                            test criteria {self.supl_ws_criteria} seconds")
292
293        asserts.assert_true(self.check_position_mode(begin_time, "standalone"),
294                                msg=f"Fail to enter the standalone mode")
295