blob: d8c4907589893735de5fbbb8f3cb004167d9cef4 [file] [log] [blame]
jasonkmlu4ba30a02020-04-09 14:16:49 +08001#!/usr/bin/env python3
jasonkmluff0d5b92019-03-21 11:24:45 +08002#
jasonkmludc430ec2020-03-27 10:40:39 +08003# Copyright 2020 - Google
jasonkmluff0d5b92019-03-21 11:24:45 +08004#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import time
18import re
19import os
jasonkmlu903ece82019-05-16 14:56:19 +080020import math
jasonkmlu903ece82019-05-16 14:56:19 +080021import shutil
jasonkmlu4fcdcad2019-07-10 14:35:12 +080022import fnmatch
23import posixpath
jasonkmlu5e7817c2020-05-08 14:06:43 +080024import tempfile
jasonkmlu8cc1c1e2020-01-06 17:18:27 +080025from collections import namedtuple
jasonkmluff0d5b92019-03-21 11:24:45 +080026
27from acts import utils
28from acts import signals
jasonkmlucb654ac2020-07-01 11:08:33 +080029from acts.libs.proc import job
jasonkmluff0d5b92019-03-21 11:24:45 +080030from acts.controllers.android_device import list_adb_devices
31from acts.controllers.android_device import list_fastboot_devices
32from acts.controllers.android_device import DEFAULT_QXDM_LOG_PATH
33from acts.controllers.android_device import SL4A_APK_NAME
Xianyuan Jia24299b72020-10-21 13:52:47 -070034from acts_contrib.test_utils.wifi import wifi_test_utils as wutils
35from acts_contrib.test_utils.tel import tel_test_utils as tutils
36from acts_contrib.test_utils.instrumentation.device.command.instrumentation_command_builder import InstrumentationCommandBuilder
37from acts_contrib.test_utils.instrumentation.device.command.instrumentation_command_builder import InstrumentationTestCommandBuilder
jasonkmluff0d5b92019-03-21 11:24:45 +080038from acts.utils import get_current_epoch_time
jasonkmlucb654ac2020-07-01 11:08:33 +080039from acts.utils import epoch_to_human_time
jasonkmluff0d5b92019-03-21 11:24:45 +080040
41WifiEnums = wutils.WifiEnums
42PULL_TIMEOUT = 300
jasonkmlu66fda532019-07-16 11:12:45 +080043GNSSSTATUS_LOG_PATH = (
44 "/storage/emulated/0/Android/data/com.android.gpstool/files/")
jasonkmlu214f0d62019-04-08 19:53:59 +080045QXDM_MASKS = ["GPS.cfg", "GPS-general.cfg", "default.cfg"]
jasonkmlucb654ac2020-07-01 11:08:33 +080046TTFF_REPORT = namedtuple(
47 "TTFF_REPORT", "utc_time ttff_loop ttff_sec ttff_pe ttff_ant_cn "
48 "ttff_base_cn")
jasonkmlu8cc1c1e2020-01-06 17:18:27 +080049TRACK_REPORT = namedtuple(
jasonkmlucb654ac2020-07-01 11:08:33 +080050 "TRACK_REPORT", "l5flag pe ant_top4cn ant_cn base_top4cn base_cn")
jasonkmlu6ea2a2b2020-11-02 13:29:41 +080051LOCAL_PROP_FILE_CONTENTS = """\
jasonkmlu38bd4d12019-10-04 16:38:48 +080052log.tag.LocationManagerService=VERBOSE
53log.tag.GnssLocationProvider=VERBOSE
54log.tag.GnssMeasurementsProvider=VERBOSE
55log.tag.GpsNetInitiatedHandler=VERBOSE
jasonkmlu6ea2a2b2020-11-02 13:29:41 +080056log.tag.GnssNetInitiatedHandler=VERBOSE
jasonkmlu38bd4d12019-10-04 16:38:48 +080057log.tag.GnssNetworkConnectivityHandler=VERBOSE
58log.tag.ConnectivityService=VERBOSE
59log.tag.ConnectivityManager=VERBOSE
jasonkmludc430ec2020-03-27 10:40:39 +080060log.tag.GnssVisibilityControl=VERBOSE
61log.tag.NtpTimeHelper=VERBOSE
jasonkmlu6ea2a2b2020-11-02 13:29:41 +080062log.tag.NtpTrustedTime=VERBOSE
63log.tag.GnssPsdsDownloader=VERBOSE
64log.tag.Gnss=VERBOSE
65log.tag.GnssConfiguration=VERBOSE"""
jasonkmlu4ba30a02020-04-09 14:16:49 +080066TEST_PACKAGE_NAME = "com.google.android.apps.maps"
jasonkmludc430ec2020-03-27 10:40:39 +080067LOCATION_PERMISSIONS = [
jasonkmlu4ba30a02020-04-09 14:16:49 +080068 "android.permission.ACCESS_FINE_LOCATION",
69 "android.permission.ACCESS_COARSE_LOCATION"
jasonkmludc430ec2020-03-27 10:40:39 +080070]
jasonkmlu4ba30a02020-04-09 14:16:49 +080071GNSSTOOL_PACKAGE_NAME = "com.android.gpstool"
72GNSSTOOL_PERMISSIONS = [
73 "android.permission.ACCESS_FINE_LOCATION",
74 "android.permission.READ_EXTERNAL_STORAGE",
75 "android.permission.ACCESS_COARSE_LOCATION",
76 "android.permission.CALL_PHONE",
77 "android.permission.WRITE_CONTACTS",
78 "android.permission.CAMERA",
79 "android.permission.WRITE_EXTERNAL_STORAGE",
80 "android.permission.READ_CONTACTS",
81 "android.permission.ACCESS_BACKGROUND_LOCATION"
82]
jasonkmluc0939182021-02-19 18:34:28 +080083DISABLE_LTO_FILE_CONTENTS = """\
84LONGTERM_PSDS_SERVER_1="http://"
85LONGTERM_PSDS_SERVER_2="http://"
86LONGTERM_PSDS_SERVER_3="http://"
87NORMAL_PSDS_SERVER="http://"
88REALTIME_PSDS_SERVER="http://"
89"""
jasonkmlu4ba30a02020-04-09 14:16:49 +080090
jasonkmluff0d5b92019-03-21 11:24:45 +080091
jasonkmluff0d5b92019-03-21 11:24:45 +080092class GnssTestUtilsError(Exception):
93 pass
94
jasonkmlu0f546de2019-12-13 20:58:41 +080095
jasonkmluff0d5b92019-03-21 11:24:45 +080096def remount_device(ad):
97 """Remount device file system to read and write.
98
99 Args:
100 ad: An AndroidDevice object.
101 """
jasonkmlu81b8b032019-06-21 15:18:27 +0800102 for retries in range(5):
jasonkmluff0d5b92019-03-21 11:24:45 +0800103 ad.root_adb()
Scott Hong7f3945f2020-02-20 18:04:56 +0800104 if ad.adb.getprop("ro.boot.veritymode") == "enforcing":
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800105 ad.adb.disable_verity()
Scott Hong7f3945f2020-02-20 18:04:56 +0800106 reboot(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800107 remount_result = ad.adb.remount()
108 ad.log.info("Attempt %d - %s" % (retries + 1, remount_result))
jasonkmlu81b8b032019-06-21 15:18:27 +0800109 if "remount succeeded" in remount_result:
jasonkmluff0d5b92019-03-21 11:24:45 +0800110 break
jasonkmlu214f0d62019-04-08 19:53:59 +0800111
jasonkmlu0f546de2019-12-13 20:58:41 +0800112
jasonkmlu214f0d62019-04-08 19:53:59 +0800113def reboot(ad):
114 """Reboot device and check if mobile data is available.
115
116 Args:
117 ad: An AndroidDevice object.
118 """
119 ad.log.info("Reboot device to make changes take effect.")
120 ad.reboot()
121 ad.unlock_screen(password=None)
122 if not int(ad.adb.shell("settings get global mobile_data")) == 1:
123 set_mobile_data(ad, True)
jasonkmlu49c32812019-04-12 18:11:10 +0800124 utils.sync_device_time(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800125
jasonkmlu0f546de2019-12-13 20:58:41 +0800126
jasonkmluff0d5b92019-03-21 11:24:45 +0800127def enable_gnss_verbose_logging(ad):
jasonkmlu81b8b032019-06-21 15:18:27 +0800128 """Enable GNSS VERBOSE Logging and persistent logcat.
jasonkmluff0d5b92019-03-21 11:24:45 +0800129
130 Args:
131 ad: An AndroidDevice object.
132 """
133 remount_device(ad)
jasonkmlu97ac56e2019-05-29 15:04:51 +0800134 ad.log.info("Enable GNSS VERBOSE Logging and persistent logcat.")
jasonkmluc0939182021-02-19 18:34:28 +0800135 if check_chipset_vendor_by_qualcomm(ad):
136 ad.adb.shell("echo -e '\nDEBUG_LEVEL = 5' >> /vendor/etc/gps.conf")
137 else:
138 ad.adb.shell("echo LogEnabled=true >> /data/vendor/gps/libgps.conf")
139 ad.adb.shell("chown gps.system /data/vendor/gps/libgps.conf")
jasonkmlu38bd4d12019-10-04 16:38:48 +0800140 ad.adb.shell("echo %r >> /data/local.prop" % LOCAL_PROP_FILE_CONTENTS)
jasonkmluff0d5b92019-03-21 11:24:45 +0800141 ad.adb.shell("chmod 644 /data/local.prop")
jasonkmluc1ec3052019-10-25 14:57:53 +0800142 ad.adb.shell("setprop persist.logd.logpersistd.size 20000")
jasonkmlu180a08c2019-04-23 17:24:55 +0800143 ad.adb.shell("setprop persist.logd.size 16777216")
jasonkmluff0d5b92019-03-21 11:24:45 +0800144 ad.adb.shell("setprop persist.vendor.radio.adb_log_on 1")
jasonkmlu81b8b032019-06-21 15:18:27 +0800145 ad.adb.shell("setprop persist.logd.logpersistd logcatd")
jasonkmluff0d5b92019-03-21 11:24:45 +0800146 ad.adb.shell("setprop log.tag.copresGcore VERBOSE")
147 ad.adb.shell("sync")
148
jasonkmlu0f546de2019-12-13 20:58:41 +0800149
jasonkmlu8cc1c1e2020-01-06 17:18:27 +0800150def get_am_flags(value):
151 """Returns the (value, type) flags for a given python value."""
152 if type(value) is bool:
153 return str(value).lower(), 'boolean'
154 elif type(value) is str:
155 return value, 'string'
156 raise ValueError("%s should be either 'boolean' or 'string'" % value)
157
158
jasonkmlu81b8b032019-06-21 15:18:27 +0800159def enable_compact_and_particle_fusion_log(ad):
jasonkmlu8cc1c1e2020-01-06 17:18:27 +0800160 """Enable CompactLog, FLP particle fusion log and disable gms
161 location-based quake monitoring.
jasonkmlu81b8b032019-06-21 15:18:27 +0800162
163 Args:
164 ad: An AndroidDevice object.
165 """
166 ad.root_adb()
jasonkmlu8cc1c1e2020-01-06 17:18:27 +0800167 ad.log.info("Enable FLP flags and Disable GMS location-based quake "
168 "monitoring.")
169 overrides = {
170 'compact_log_enabled': True,
171 'flp_use_particle_fusion': True,
172 'flp_particle_fusion_extended_bug_report': True,
173 'flp_event_log_size': '86400',
174 'proks_config': '28',
175 'flp_particle_fusion_bug_report_window_sec': '86400',
176 'flp_particle_fusion_bug_report_max_buffer_size': '86400',
177 'seismic_data_collection': False,
178 'Ealert__enable': False,
179 }
180 for flag, python_value in overrides.items():
181 value, type = get_am_flags(python_value)
182 cmd = ("am broadcast -a com.google.android.gms.phenotype.FLAG_OVERRIDE "
183 "--es package com.google.android.location --es user \* "
184 "--esa flags %s --esa values %s --esa types %s "
185 "com.google.android.gms" % (flag, value, type))
186 ad.adb.shell(cmd)
jasonkmlu81b8b032019-06-21 15:18:27 +0800187 ad.adb.shell("am force-stop com.google.android.gms")
188 ad.adb.shell("am broadcast -a com.google.android.gms.INITIALIZE")
jasonkmlu81b8b032019-06-21 15:18:27 +0800189
jasonkmlu0f546de2019-12-13 20:58:41 +0800190
jasonkmluff0d5b92019-03-21 11:24:45 +0800191def disable_xtra_throttle(ad):
192 """Disable XTRA throttle will have no limit to download XTRA data.
193
194 Args:
195 ad: An AndroidDevice object.
196 """
197 remount_device(ad)
198 ad.log.info("Disable XTRA Throttle.")
Scott Hongaccd8a12020-03-03 20:12:17 +0800199 ad.adb.shell("echo -e '\nXTRA_TEST_ENABLED=1' >> /vendor/etc/gps.conf")
200 ad.adb.shell("echo -e '\nXTRA_THROTTLE_ENABLED=0' >> /vendor/etc/gps.conf")
jasonkmluff0d5b92019-03-21 11:24:45 +0800201
jasonkmlu0f546de2019-12-13 20:58:41 +0800202
jasonkmluff0d5b92019-03-21 11:24:45 +0800203def enable_supl_mode(ad):
204 """Enable SUPL back on for next test item.
205
206 Args:
207 ad: An AndroidDevice object.
208 """
209 remount_device(ad)
210 ad.log.info("Enable SUPL mode.")
Scott Hongaccd8a12020-03-03 20:12:17 +0800211 ad.adb.shell("echo -e '\nSUPL_MODE=1' >> /etc/gps_debug.conf")
jasonkmluc0939182021-02-19 18:34:28 +0800212 if not check_chipset_vendor_by_qualcomm(ad):
213 lto_mode(ad, True)
214 else:
215 reboot(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800216
jasonkmlu0f546de2019-12-13 20:58:41 +0800217
jasonkmluff0d5b92019-03-21 11:24:45 +0800218def disable_supl_mode(ad):
jasonkmluc0939182021-02-19 18:34:28 +0800219 """Kill SUPL to test XTRA/LTO only test item.
jasonkmluff0d5b92019-03-21 11:24:45 +0800220
221 Args:
222 ad: An AndroidDevice object.
223 """
224 remount_device(ad)
225 ad.log.info("Disable SUPL mode.")
Scott Hongaccd8a12020-03-03 20:12:17 +0800226 ad.adb.shell("echo -e '\nSUPL_MODE=0' >> /etc/gps_debug.conf")
jasonkmluc0939182021-02-19 18:34:28 +0800227 if not check_chipset_vendor_by_qualcomm(ad):
228 lto_mode(ad, True)
229 else:
230 reboot(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800231
jasonkmlu0f546de2019-12-13 20:58:41 +0800232
jasonkmluff0d5b92019-03-21 11:24:45 +0800233def kill_xtra_daemon(ad):
234 """Kill XTRA daemon to test SUPL only test item.
235
236 Args:
237 ad: An AndroidDevice object.
238 """
239 ad.root_adb()
jasonkmluc0939182021-02-19 18:34:28 +0800240 if check_chipset_vendor_by_qualcomm(ad):
241 ad.log.info("Disable XTRA-daemon until next reboot.")
242 ad.adb.shell("killall xtra-daemon", ignore_status=True)
243 else:
244 lto_mode(ad, False)
jasonkmluff0d5b92019-03-21 11:24:45 +0800245
jasonkmlu0f546de2019-12-13 20:58:41 +0800246
jasonkmluff0d5b92019-03-21 11:24:45 +0800247def disable_private_dns_mode(ad):
248 """Due to b/118365122, it's better to disable private DNS mode while
249 testing. 8.8.8.8 private dns sever is unstable now, sometimes server
250 will not response dns query suddenly.
251
252 Args:
253 ad: An AndroidDevice object.
254 """
255 tutils.get_operator_name(ad.log, ad, subId=None)
256 if ad.adb.shell("settings get global private_dns_mode") != "off":
257 ad.log.info("Disable Private DNS mode.")
258 ad.adb.shell("settings put global private_dns_mode off")
259
jasonkmlu0f546de2019-12-13 20:58:41 +0800260
jasonkmluff0d5b92019-03-21 11:24:45 +0800261def _init_device(ad):
262 """Init GNSS test devices.
263
264 Args:
265 ad: An AndroidDevice object.
266 """
267 enable_gnss_verbose_logging(ad)
jasonkmlu81b8b032019-06-21 15:18:27 +0800268 enable_compact_and_particle_fusion_log(ad)
jasonkmluc0939182021-02-19 18:34:28 +0800269 if check_chipset_vendor_by_qualcomm(ad):
270 disable_xtra_throttle(ad)
271 set_gnss_qxdm_mask(ad, QXDM_MASKS)
jasonkmluff0d5b92019-03-21 11:24:45 +0800272 enable_supl_mode(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800273 ad.adb.shell("settings put system screen_off_timeout 1800000")
274 wutils.wifi_toggle_state(ad, False)
275 ad.log.info("Setting Bluetooth state to False")
276 ad.droid.bluetoothToggleState(False)
jasonkmluff0d5b92019-03-21 11:24:45 +0800277 check_location_service(ad)
278 set_wifi_and_bt_scanning(ad, True)
jasonkmlu214f0d62019-04-08 19:53:59 +0800279 disable_private_dns_mode(ad)
jasonkmlu180a08c2019-04-23 17:24:55 +0800280 reboot(ad)
jasonkmlu4ba30a02020-04-09 14:16:49 +0800281 init_gtw_gpstool(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800282
jasonkmlu0f546de2019-12-13 20:58:41 +0800283
jasonkmluff0d5b92019-03-21 11:24:45 +0800284def connect_to_wifi_network(ad, network):
285 """Connection logic for open and psk wifi networks.
286
287 Args:
288 ad: An AndroidDevice object.
289 network: Dictionary with network info.
290 """
291 SSID = network[WifiEnums.SSID_KEY]
jasonkmlub663d3e2019-12-30 15:11:07 +0800292 ad.ed.clear_all_events()
293 wutils.reset_wifi(ad)
294 wutils.start_wifi_connection_scan_and_ensure_network_found(ad, SSID)
jasonkmluff0d5b92019-03-21 11:24:45 +0800295 wutils.wifi_connect(ad, network, num_of_tries=5)
296
jasonkmlu0f546de2019-12-13 20:58:41 +0800297
jasonkmluff0d5b92019-03-21 11:24:45 +0800298def set_wifi_and_bt_scanning(ad, state=True):
299 """Set Wi-Fi and Bluetooth scanning on/off in Settings -> Location
300
301 Args:
302 ad: An AndroidDevice object.
jasonkmlu81b8b032019-06-21 15:18:27 +0800303 state: True to turn on "Wi-Fi and Bluetooth scanning".
304 False to turn off "Wi-Fi and Bluetooth scanning".
jasonkmluff0d5b92019-03-21 11:24:45 +0800305 """
306 ad.root_adb()
307 if state:
308 ad.adb.shell("settings put global wifi_scan_always_enabled 1")
309 ad.adb.shell("settings put global ble_scan_always_enabled 1")
310 ad.log.info("Wi-Fi and Bluetooth scanning are enabled")
311 else:
312 ad.adb.shell("settings put global wifi_scan_always_enabled 0")
313 ad.adb.shell("settings put global ble_scan_always_enabled 0")
314 ad.log.info("Wi-Fi and Bluetooth scanning are disabled")
315
jasonkmlu0f546de2019-12-13 20:58:41 +0800316
jasonkmluff0d5b92019-03-21 11:24:45 +0800317def check_location_service(ad):
318 """Set location service on.
319 Verify if location service is available.
320
321 Args:
322 ad: An AndroidDevice object.
jasonkmluff0d5b92019-03-21 11:24:45 +0800323 """
jasonkmlu81b8b032019-06-21 15:18:27 +0800324 remount_device(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800325 utils.set_location_service(ad, True)
jasonkmlu81b8b032019-06-21 15:18:27 +0800326 location_mode = int(ad.adb.shell("settings get secure location_mode"))
327 ad.log.info("Current Location Mode >> %d" % location_mode)
328 if location_mode != 3:
jasonkmlu78540632019-11-15 18:04:20 +0800329 raise signals.TestError("Failed to turn Location on")
jasonkmluff0d5b92019-03-21 11:24:45 +0800330
jasonkmlu0f546de2019-12-13 20:58:41 +0800331
jasonkmluff0d5b92019-03-21 11:24:45 +0800332def clear_logd_gnss_qxdm_log(ad):
333 """Clear /data/misc/logd,
334 /storage/emulated/0/Android/data/com.android.gpstool/files and
335 /data/vendor/radio/diag_logs/logs from previous test item then reboot.
336
337 Args:
338 ad: An AndroidDevice object.
339 """
340 remount_device(ad)
341 ad.log.info("Clear Logd, GNSS and QXDM Log from previous test item.")
342 ad.adb.shell("rm -rf /data/misc/logd", ignore_status=True)
Scott Hong0ccbc752020-10-12 14:18:49 +0800343 ad.adb.shell(
344 'find %s -name "*.txt" -type f -delete' % GNSSSTATUS_LOG_PATH,
345 ignore_status=True)
jasonkmluc0939182021-02-19 18:34:28 +0800346 if check_chipset_vendor_by_qualcomm(ad):
347 output_path = posixpath.join(DEFAULT_QXDM_LOG_PATH, "logs")
348 else:
349 output_path = ("/sdcard/Android/data/com.android.pixellogger/files"
350 "/logs/gps/")
jasonkmluff0d5b92019-03-21 11:24:45 +0800351 ad.adb.shell("rm -rf %s" % output_path, ignore_status=True)
jasonkmlu214f0d62019-04-08 19:53:59 +0800352 reboot(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800353
jasonkmlu0f546de2019-12-13 20:58:41 +0800354
jasonkmlu81b8b032019-06-21 15:18:27 +0800355def get_gnss_qxdm_log(ad, qdb_path):
jasonkmluff0d5b92019-03-21 11:24:45 +0800356 """Get /storage/emulated/0/Android/data/com.android.gpstool/files and
jasonkmlu81b8b032019-06-21 15:18:27 +0800357 /data/vendor/radio/diag_logs/logs for test item.
jasonkmluff0d5b92019-03-21 11:24:45 +0800358
359 Args:
360 ad: An AndroidDevice object.
jasonkmlu81b8b032019-06-21 15:18:27 +0800361 qdb_path: The path of qdsp6m.qdb on different projects.
jasonkmluff0d5b92019-03-21 11:24:45 +0800362 """
jasonkmlu903ece82019-05-16 14:56:19 +0800363 log_path = ad.device_log_path
Mark De Ruyter72f8df92020-02-12 13:44:49 -0800364 os.makedirs(log_path, exist_ok=True)
jasonkmlu903ece82019-05-16 14:56:19 +0800365 gnss_log_name = "gnssstatus_log_%s_%s" % (ad.model, ad.serial)
jasonkmlu670cfbc2019-11-27 18:58:21 +0800366 gnss_log_path = posixpath.join(log_path, gnss_log_name)
Mark De Ruyter72f8df92020-02-12 13:44:49 -0800367 os.makedirs(gnss_log_path, exist_ok=True)
jasonkmluff0d5b92019-03-21 11:24:45 +0800368 ad.log.info("Pull GnssStatus Log to %s" % gnss_log_path)
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800369 ad.adb.pull("%s %s" % (GNSSSTATUS_LOG_PATH+".", gnss_log_path),
jasonkmluff0d5b92019-03-21 11:24:45 +0800370 timeout=PULL_TIMEOUT, ignore_status=True)
jasonkmlu903ece82019-05-16 14:56:19 +0800371 shutil.make_archive(gnss_log_path, "zip", gnss_log_path)
372 shutil.rmtree(gnss_log_path)
jasonkmluc0939182021-02-19 18:34:28 +0800373 if check_chipset_vendor_by_qualcomm(ad):
374 output_path = posixpath.join(DEFAULT_QXDM_LOG_PATH, "logs/.")
375 file_count = ad.adb.shell(
376 "find %s -type f -iname *.qmdl | wc -l" % output_path)
377 else:
378 output_path = ("/sdcard/Android/data/com.android.pixellogger/files"
379 "/logs/gps/")
380 file_count = ad.adb.shell(
381 "find %s -type f -iname *.zip | wc -l" % output_path)
jasonkmluff0d5b92019-03-21 11:24:45 +0800382 if not int(file_count) == 0:
jasonkmlu903ece82019-05-16 14:56:19 +0800383 qxdm_log_name = "QXDM_%s_%s" % (ad.model, ad.serial)
jasonkmlu670cfbc2019-11-27 18:58:21 +0800384 qxdm_log_path = posixpath.join(log_path, qxdm_log_name)
Mark De Ruyter72f8df92020-02-12 13:44:49 -0800385 os.makedirs(qxdm_log_path, exist_ok=True)
jasonkmluff0d5b92019-03-21 11:24:45 +0800386 ad.log.info("Pull QXDM Log %s to %s" % (output_path, qxdm_log_path))
387 ad.adb.pull("%s %s" % (output_path, qxdm_log_path),
388 timeout=PULL_TIMEOUT, ignore_status=True)
jasonkmlu81b8b032019-06-21 15:18:27 +0800389 for path in qdb_path:
390 output = ad.adb.pull("%s %s" % (path, qxdm_log_path),
391 timeout=PULL_TIMEOUT, ignore_status=True)
392 if "No such file or directory" in output:
393 continue
394 break
jasonkmlu903ece82019-05-16 14:56:19 +0800395 shutil.make_archive(qxdm_log_path, "zip", qxdm_log_path)
396 shutil.rmtree(qxdm_log_path)
jasonkmluff0d5b92019-03-21 11:24:45 +0800397 else:
398 ad.log.error("QXDM file count is %d. There is no QXDM log on device."
399 % int(file_count))
400
jasonkmlu0f546de2019-12-13 20:58:41 +0800401
jasonkmluff0d5b92019-03-21 11:24:45 +0800402def set_mobile_data(ad, state):
403 """Set mobile data on or off and check mobile data state.
404
405 Args:
406 ad: An AndroidDevice object.
407 state: True to enable mobile data. False to disable mobile data.
408 """
409 ad.root_adb()
410 if state:
411 ad.log.info("Enable mobile data.")
412 ad.adb.shell("svc data enable")
413 else:
414 ad.log.info("Disable mobile data.")
415 ad.adb.shell("svc data disable")
416 time.sleep(5)
417 out = int(ad.adb.shell("settings get global mobile_data"))
418 if state and out == 1:
419 ad.log.info("Mobile data is enabled and set to %d" % out)
420 elif not state and out == 0:
421 ad.log.info("Mobile data is disabled and set to %d" % out)
422 else:
423 ad.log.error("Mobile data is at unknown state and set to %d" % out)
424
jasonkmlu0f546de2019-12-13 20:58:41 +0800425
jasonkmlu78540632019-11-15 18:04:20 +0800426def gnss_trigger_modem_ssr_by_adb(ad, dwelltime=60):
427 """Trigger modem SSR crash by adb and verify if modem crash and recover
jasonkmlu035eee12019-10-08 17:11:20 +0800428 successfully.
jasonkmluff0d5b92019-03-21 11:24:45 +0800429
430 Args:
431 ad: An AndroidDevice object.
jasonkmlu78540632019-11-15 18:04:20 +0800432 dwelltime: Waiting time for modem reset. Default is 60 seconds.
jasonkmluff0d5b92019-03-21 11:24:45 +0800433
434 Returns:
jasonkmlu81b8b032019-06-21 15:18:27 +0800435 True if success.
436 False if failed.
jasonkmluff0d5b92019-03-21 11:24:45 +0800437 """
jasonkmlu81b8b032019-06-21 15:18:27 +0800438 begin_time = get_current_epoch_time()
439 ad.root_adb()
440 cmds = ("echo restart > /sys/kernel/debug/msm_subsys/modem",
441 r"echo 'at+cfun=1,1\r' > /dev/at_mdm0")
442 for cmd in cmds:
443 ad.log.info("Triggering modem SSR crash by %s" % cmd)
444 output = ad.adb.shell(cmd, ignore_status=True)
445 if "No such file or directory" in output:
446 continue
447 break
448 time.sleep(dwelltime)
jasonkmluff0d5b92019-03-21 11:24:45 +0800449 ad.send_keycode("HOME")
jasonkmlu81b8b032019-06-21 15:18:27 +0800450 logcat_results = ad.search_logcat("SSRObserver", begin_time)
451 if logcat_results:
452 for ssr in logcat_results:
453 if "mSubsystem='modem', mCrashReason" in ssr["log_message"]:
454 ad.log.debug(ssr["log_message"])
455 ad.log.info("Triggering modem SSR crash successfully.")
456 return True
jasonkmlu78540632019-11-15 18:04:20 +0800457 raise signals.TestError("Failed to trigger modem SSR crash")
458 raise signals.TestError("No SSRObserver found in logcat")
459
jasonkmlu0f546de2019-12-13 20:58:41 +0800460
jasonkmlu78540632019-11-15 18:04:20 +0800461def gnss_trigger_modem_ssr_by_mds(ad, dwelltime=60):
462 """Trigger modem SSR crash by mds tool and verify if modem crash and recover
463 successfully.
464
465 Args:
466 ad: An AndroidDevice object.
467 dwelltime: Waiting time for modem reset. Default is 60 seconds.
468 """
469 mds_check = ad.adb.shell("pm path com.google.mdstest")
470 if not mds_check:
471 raise signals.TestError("MDS Tool is not properly installed.")
472 ad.root_adb()
473 cmd = ('am instrument -w -e request "4b 25 03 00" '
474 '"com.google.mdstest/com.google.mdstest.instrument'
475 '.ModemCommandInstrumentation"')
476 ad.log.info("Triggering modem SSR crash by MDS")
477 output = ad.adb.shell(cmd, ignore_status=True)
478 ad.log.debug(output)
479 time.sleep(dwelltime)
480 ad.send_keycode("HOME")
481 if "SUCCESS" in output:
482 ad.log.info("Triggering modem SSR crash by MDS successfully.")
483 else:
484 raise signals.TestError(
485 "Failed to trigger modem SSR crash by MDS. \n%s" % output)
486
jasonkmlu0f546de2019-12-13 20:58:41 +0800487
jasonkmluff0d5b92019-03-21 11:24:45 +0800488def check_xtra_download(ad, begin_time):
489 """Verify XTRA download success log message in logcat.
490
491 Args:
492 ad: An AndroidDevice object.
493 begin_time: test begin time
494
495 Returns:
496 True: xtra_download if XTRA downloaded and injected successfully
497 otherwise return False.
498 """
499 ad.send_keycode("HOME")
jasonkmluc0939182021-02-19 18:34:28 +0800500 if check_chipset_vendor_by_qualcomm(ad):
501 xtra_results = ad.search_logcat("XTRA download success. "
502 "inject data into modem", begin_time)
503 if xtra_results:
504 ad.log.debug("%s" % xtra_results[-1]["log_message"])
505 ad.log.info("XTRA downloaded and injected successfully.")
506 return True
507 ad.log.error("XTRA downloaded FAIL.")
508 else:
509 lto_results = ad.search_logcat("GnssPsdsAidl: injectPsdsData: "
510 "psdsType: 1", begin_time)
511 if lto_results:
512 ad.log.debug("%s" % lto_results[-1]["log_message"])
513 ad.log.info("LTO downloaded and injected successfully.")
514 return True
515 ad.log.error("LTO downloaded and inject FAIL.")
jasonkmluff0d5b92019-03-21 11:24:45 +0800516 return False
517
jasonkmlu0f546de2019-12-13 20:58:41 +0800518
jasonkmlu5e7817c2020-05-08 14:06:43 +0800519def pull_package_apk(ad, package_name):
520 """Pull apk of given package_name from device.
jasonkmluff0d5b92019-03-21 11:24:45 +0800521
522 Args:
523 ad: An AndroidDevice object.
jasonkmlu5e7817c2020-05-08 14:06:43 +0800524 package_name: Package name of apk to pull.
525
526 Returns:
527 The temp path of pulled apk.
jasonkmluff0d5b92019-03-21 11:24:45 +0800528 """
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800529 apk_path = None
jasonkmlu5e7817c2020-05-08 14:06:43 +0800530 out = ad.adb.shell("pm path %s" % package_name)
jasonkmluff0d5b92019-03-21 11:24:45 +0800531 result = re.search(r"package:(.*)", out)
532 if not result:
jasonkmlu5e7817c2020-05-08 14:06:43 +0800533 tutils.abort_all_tests(ad.log, "Couldn't find apk of %s" % package_name)
jasonkmluff0d5b92019-03-21 11:24:45 +0800534 else:
jasonkmlu5e7817c2020-05-08 14:06:43 +0800535 apk_source = result.group(1)
536 ad.log.info("Get apk of %s from %s" % (package_name, apk_source))
537 apk_path = tempfile.mkdtemp()
538 ad.pull_files([apk_source], apk_path)
539 return apk_path
jasonkmluff0d5b92019-03-21 11:24:45 +0800540
jasonkmlu0f546de2019-12-13 20:58:41 +0800541
jasonkmlu5e7817c2020-05-08 14:06:43 +0800542def reinstall_package_apk(ad, package_name, apk_path):
543 """Reinstall apk of given package_name.
jasonkmluff0d5b92019-03-21 11:24:45 +0800544
545 Args:
546 ad: An AndroidDevice object.
jasonkmlu5e7817c2020-05-08 14:06:43 +0800547 package_name: Package name of apk.
548 apk_path: The temp path of pulled apk.
jasonkmluff0d5b92019-03-21 11:24:45 +0800549 """
jasonkmlu5e7817c2020-05-08 14:06:43 +0800550 for path_key in os.listdir(apk_path):
551 if fnmatch.fnmatch(path_key, "*.apk"):
552 apk_path = os.path.join(apk_path, path_key)
553 break
554 else:
555 raise signals.TestError("No apk is found in %s" % apk_path)
556 ad.log.info("Re-install %s with path: %s" % (package_name, apk_path))
557 ad.adb.shell("settings put global verifier_verify_adb_installs 0")
558 ad.adb.install("-r -d -g --user 0 %s" % apk_path)
559 package_check = ad.adb.shell("pm path %s" % package_name)
560 if not package_check:
561 tutils.abort_all_tests(
562 ad.log, "%s is not properly re-installed." % package_name)
563 ad.log.info("%s is re-installed successfully." % package_name)
jasonkmluff0d5b92019-03-21 11:24:45 +0800564
jasonkmlu0f546de2019-12-13 20:58:41 +0800565
jasonkmlu180a08c2019-04-23 17:24:55 +0800566def init_gtw_gpstool(ad):
567 """Init GTW_GPSTool apk.
568
569 Args:
570 ad: An AndroidDevice object.
571 """
572 remount_device(ad)
jasonkmlu5e7817c2020-05-08 14:06:43 +0800573 gpstool_path = pull_package_apk(ad, "com.android.gpstool")
574 reinstall_package_apk(ad, "com.android.gpstool", gpstool_path)
jasonkmlu180a08c2019-04-23 17:24:55 +0800575
jasonkmlu0f546de2019-12-13 20:58:41 +0800576
jasonkmluff0d5b92019-03-21 11:24:45 +0800577def fastboot_factory_reset(ad):
578 """Factory reset the device in fastboot mode.
579 Pull sl4a apk from device. Terminate all sl4a sessions,
580 Reboot the device to bootloader,
581 factory reset the device by fastboot.
582 Reboot the device. wait for device to complete booting
583 Re-install and start an sl4a session.
584
585 Args:
586 ad: An AndroidDevice object.
587
588 Returns:
589 True if factory reset process complete.
590 """
591 status = True
592 skip_setup_wizard = True
jasonkmlu5e7817c2020-05-08 14:06:43 +0800593 sl4a_path = pull_package_apk(ad, SL4A_APK_NAME)
594 gpstool_path = pull_package_apk(ad, "com.android.gpstool")
595 mds_path = pull_package_apk(ad, "com.google.mdstest")
jasonkmluff0d5b92019-03-21 11:24:45 +0800596 tutils.stop_qxdm_logger(ad)
597 ad.stop_services()
598 attempts = 3
599 for i in range(1, attempts + 1):
600 try:
601 if ad.serial in list_adb_devices():
602 ad.log.info("Reboot to bootloader")
603 ad.adb.reboot("bootloader", ignore_status=True)
604 time.sleep(10)
605 if ad.serial in list_fastboot_devices():
606 ad.log.info("Factory reset in fastboot")
607 ad.fastboot._w(timeout=300, ignore_status=True)
608 time.sleep(30)
609 ad.log.info("Reboot in fastboot")
610 ad.fastboot.reboot()
611 ad.wait_for_boot_completion()
612 ad.root_adb()
613 if ad.skip_sl4a:
614 break
615 if ad.is_sl4a_installed():
616 break
jasonkmlu5e7817c2020-05-08 14:06:43 +0800617 reinstall_package_apk(ad, SL4A_APK_NAME, sl4a_path)
618 reinstall_package_apk(ad, "com.android.gpstool", gpstool_path)
619 reinstall_package_apk(ad, "com.google.mdstest", mds_path)
jasonkmluff0d5b92019-03-21 11:24:45 +0800620 time.sleep(10)
621 break
622 except Exception as e:
623 ad.log.error(e)
624 if i == attempts:
625 tutils.abort_all_tests(ad.log, str(e))
626 time.sleep(5)
627 try:
628 ad.start_adb_logcat()
629 except Exception as e:
630 ad.log.error(e)
631 if skip_setup_wizard:
632 ad.exit_setup_wizard()
633 if ad.skip_sl4a:
634 return status
635 tutils.bring_up_sl4a(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800636 return status
637
jasonkmlu0f546de2019-12-13 20:58:41 +0800638
jasonkmluff0d5b92019-03-21 11:24:45 +0800639def clear_aiding_data_by_gtw_gpstool(ad):
640 """Launch GTW GPSTool and Clear all GNSS aiding data.
641 Wait 5 seconds for GTW GPStool to clear all GNSS aiding
642 data properly.
643
644 Args:
645 ad: An AndroidDevice object.
646 """
jasonkmluc0939182021-02-19 18:34:28 +0800647 if not check_chipset_vendor_by_qualcomm(ad):
648 delete_lto_file(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800649 ad.log.info("Launch GTW GPSTool and Clear all GNSS aiding data")
650 ad.adb.shell("am start -S -n com.android.gpstool/.GPSTool --es mode clear")
651 time.sleep(10)
652
Jayakumar Munuswamybc6038c2019-10-30 14:46:38 -0700653
Scott Honga2e430b2020-08-27 15:14:57 +0800654def start_gnss_by_gtw_gpstool(ad,
655 state,
656 type="gnss",
657 bgdisplay=False,
658 freq=0,
659 lowpower=False,
660 meas=False):
jasonkmluff0d5b92019-03-21 11:24:45 +0800661 """Start or stop GNSS on GTW_GPSTool.
662
663 Args:
664 ad: An AndroidDevice object.
665 state: True to start GNSS. False to Stop GNSS.
jasonkmlu81b8b032019-06-21 15:18:27 +0800666 type: Different API for location fix. Use gnss/flp/nmea
Scott Honga2e430b2020-08-27 15:14:57 +0800667 bgdisplay: true to run GTW when Display off. false to not run GTW when
668 Display off.
669 freq: An integer to set location update frequency.
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800670 meas: A Boolean to set GNSS measurement registration.
Scott Honga2e430b2020-08-27 15:14:57 +0800671 lowpower: A boolean to set GNSS LowPowerMode.
jasonkmluff0d5b92019-03-21 11:24:45 +0800672 """
Scott Honga2e430b2020-08-27 15:14:57 +0800673 cmd = "am start -S -n com.android.gpstool/.GPSTool --es mode gps"
jasonkmluff0d5b92019-03-21 11:24:45 +0800674 if not state:
jasonkmlu81b8b032019-06-21 15:18:27 +0800675 ad.log.info("Stop %s on GTW_GPSTool." % type)
Scott Honga2e430b2020-08-27 15:14:57 +0800676 cmd = "am broadcast -a com.android.gpstool.stop_gps_action"
677 else:
678 options = ("--es type {} --ei freq {} --ez BG {} --ez meas {} --ez "
679 "lowpower {}").format(type, freq, bgdisplay, meas, lowpower)
680 cmd = cmd + " " + options
Scott Honga2e430b2020-08-27 15:14:57 +0800681 ad.adb.shell(cmd)
jasonkmluff0d5b92019-03-21 11:24:45 +0800682 time.sleep(3)
683
Jayakumar Munuswamybc6038c2019-10-30 14:46:38 -0700684
jasonkmlu8721ced2020-10-26 14:37:46 +0800685def process_gnss_by_gtw_gpstool(ad,
686 criteria,
687 type="gnss",
688 clear_data=True,
689 meas_flag=False):
jasonkmluff0d5b92019-03-21 11:24:45 +0800690 """Launch GTW GPSTool and Clear all GNSS aiding data
691 Start GNSS tracking on GTW_GPSTool.
692
693 Args:
694 ad: An AndroidDevice object.
695 criteria: Criteria for current test item.
jasonkmlu81b8b032019-06-21 15:18:27 +0800696 type: Different API for location fix. Use gnss/flp/nmea
jasonkmlu8721ced2020-10-26 14:37:46 +0800697 clear_data: True to clear GNSS aiding data. False is not to. Default
jasonkmlu5a385f22020-06-08 17:14:15 +0800698 set to True.
jasonkmlu8721ced2020-10-26 14:37:46 +0800699 meas_flag: True to enable GnssMeasurement. False is not to. Default
700 set to False.
jasonkmluff0d5b92019-03-21 11:24:45 +0800701
702 Returns:
703 True: First fix TTFF are within criteria.
704 False: First fix TTFF exceed criteria.
705 """
706 retries = 3
707 for i in range(retries):
jasonkmlud68fdf02020-07-23 16:18:11 +0800708 if not ad.is_adb_logcat_on:
709 ad.start_adb_logcat()
710 check_adblog_functionality(ad)
jasonkmlu4ba30a02020-04-09 14:16:49 +0800711 check_location_runtime_permissions(
712 ad, GNSSTOOL_PACKAGE_NAME, GNSSTOOL_PERMISSIONS)
jasonkmluff0d5b92019-03-21 11:24:45 +0800713 begin_time = get_current_epoch_time()
jasonkmlu5a385f22020-06-08 17:14:15 +0800714 if clear_data:
715 clear_aiding_data_by_gtw_gpstool(ad)
jasonkmlu035eee12019-10-08 17:11:20 +0800716 ad.log.info("Start %s on GTW_GPSTool - attempt %d" % (type.upper(),
717 i+1))
jasonkmlu8721ced2020-10-26 14:37:46 +0800718 start_gnss_by_gtw_gpstool(ad, state=True, type=type, meas=meas_flag)
jasonkmluff0d5b92019-03-21 11:24:45 +0800719 for _ in range(10 + criteria):
720 logcat_results = ad.search_logcat("First fixed", begin_time)
721 if logcat_results:
jasonkmlu81b8b032019-06-21 15:18:27 +0800722 ad.log.debug(logcat_results[-1]["log_message"])
jasonkmluff0d5b92019-03-21 11:24:45 +0800723 first_fixed = int(logcat_results[-1]["log_message"].split()[-1])
jasonkmlu81b8b032019-06-21 15:18:27 +0800724 ad.log.info("%s First fixed = %.3f seconds" %
725 (type.upper(), first_fixed/1000))
726 if (first_fixed/1000) <= criteria:
jasonkmluff0d5b92019-03-21 11:24:45 +0800727 return True
jasonkmlu8721ced2020-10-26 14:37:46 +0800728 start_gnss_by_gtw_gpstool(ad, state=False, type=type)
jasonkmlu035eee12019-10-08 17:11:20 +0800729 raise signals.TestFailure("Fail to get %s location fixed "
730 "within %d seconds criteria."
731 % (type.upper(), criteria))
jasonkmluff0d5b92019-03-21 11:24:45 +0800732 time.sleep(1)
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800733 check_current_focus_app(ad)
jasonkmlu8721ced2020-10-26 14:37:46 +0800734 start_gnss_by_gtw_gpstool(ad, state=False, type=type)
jasonkmlu035eee12019-10-08 17:11:20 +0800735 raise signals.TestFailure("Fail to get %s location fixed within %d "
736 "attempts." % (type.upper(), retries))
jasonkmluff0d5b92019-03-21 11:24:45 +0800737
Scott Hong72269692019-12-16 16:59:56 +0800738def start_ttff_by_gtw_gpstool(ad, ttff_mode, iteration, aid_data=False):
jasonkmluff0d5b92019-03-21 11:24:45 +0800739 """Identify which TTFF mode for different test items.
740
741 Args:
742 ad: An AndroidDevice object.
743 ttff_mode: TTFF Test mode for current test item.
744 iteration: Iteration of TTFF cycles.
Scott Hong72269692019-12-16 16:59:56 +0800745 aid_data: Boolean for identify aid_data existed or not
jasonkmluff0d5b92019-03-21 11:24:45 +0800746 """
jasonkmlu97ac56e2019-05-29 15:04:51 +0800747 begin_time = get_current_epoch_time()
Scott Hong72269692019-12-16 16:59:56 +0800748 if (ttff_mode == "hs" or ttff_mode == "ws") and not aid_data:
jasonkmlu81b8b032019-06-21 15:18:27 +0800749 ad.log.info("Wait 5 minutes to start TTFF %s..." % ttff_mode.upper())
jasonkmluff0d5b92019-03-21 11:24:45 +0800750 time.sleep(300)
751 if ttff_mode == "cs":
752 ad.log.info("Start TTFF Cold Start...")
753 time.sleep(3)
jasonkmlu97ac56e2019-05-29 15:04:51 +0800754 for i in range(1, 4):
755 ad.adb.shell("am broadcast -a com.android.gpstool.ttff_action "
756 "--es ttff %s --es cycle %d" % (ttff_mode, iteration))
jasonkmlu81b8b032019-06-21 15:18:27 +0800757 time.sleep(1)
jasonkmlu97ac56e2019-05-29 15:04:51 +0800758 if ad.search_logcat("act=com.android.gpstool.start_test_action",
759 begin_time):
760 ad.log.info("Send TTFF start_test_action successfully.")
761 break
jasonkmlu035eee12019-10-08 17:11:20 +0800762 else:
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800763 check_current_focus_app(ad)
jasonkmlu78540632019-11-15 18:04:20 +0800764 raise signals.TestError("Fail to send TTFF start_test_action.")
jasonkmluff0d5b92019-03-21 11:24:45 +0800765
jasonkmlu0f546de2019-12-13 20:58:41 +0800766
jasonkmlu8721ced2020-10-26 14:37:46 +0800767def gnss_tracking_via_gtw_gpstool(ad,
768 criteria,
769 type="gnss",
770 testtime=60,
771 meas_flag=False):
jasonkmlu66fda532019-07-16 11:12:45 +0800772 """Start GNSS/FLP tracking tests for input testtime on GTW_GPSTool.
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800773
774 Args:
775 ad: An AndroidDevice object.
776 criteria: Criteria for current TTFF.
777 type: Different API for location fix. Use gnss/flp/nmea
778 testtime: Tracking test time for minutes. Default set to 60 minutes.
jasonkmlu8721ced2020-10-26 14:37:46 +0800779 meas_flag: True to enable GnssMeasurement. False is not to. Default
780 set to False.
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800781 """
jasonkmlu3fcdc2b2021-03-22 19:35:48 +0800782 gnss_crash_list = [".*Fatal signal.*gnss",
783 ".*Fatal signal.*xtra",
784 ".*F DEBUG.*gnss"]
jasonkmlu8721ced2020-10-26 14:37:46 +0800785 process_gnss_by_gtw_gpstool(
786 ad, criteria=criteria, type=type, meas_flag=meas_flag)
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800787 ad.log.info("Start %s tracking test for %d minutes" % (type.upper(),
788 testtime))
789 begin_time = get_current_epoch_time()
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800790 while get_current_epoch_time() - begin_time < testtime * 60 * 1000:
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800791 if not ad.is_adb_logcat_on:
792 ad.start_adb_logcat()
jasonkmlu3fcdc2b2021-03-22 19:35:48 +0800793 for attr in gnss_crash_list:
794 gnss_crash_result = ad.adb.shell(
795 "logcat -d | grep -E -i '%s'" % attr)
796 if gnss_crash_result:
797 start_gnss_by_gtw_gpstool(ad, state=False, type=type)
798 raise signals.TestFailure(
799 "Test failed due to GNSS HAL crashed. \n%s" %
800 gnss_crash_result)
801 gpstool_crash_result = ad.search_logcat("Force finishing activity "
802 "com.android.gpstool/.GPSTool",
803 begin_time)
804 if gpstool_crash_result:
jasonkmlu78540632019-11-15 18:04:20 +0800805 raise signals.TestError("GPSTool crashed. Abort test.")
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800806 ad.log.info("Successfully tested for %d minutes" % testtime)
jasonkmlu8721ced2020-10-26 14:37:46 +0800807 start_gnss_by_gtw_gpstool(ad, state=False, type=type)
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800808
jasonkmlu0f546de2019-12-13 20:58:41 +0800809
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800810def parse_gtw_gpstool_log(ad, true_position, type="gnss"):
811 """Process GNSS/FLP API logs from GTW GPSTool and output track_data to
812 test_run_info for ACTS plugin to parse and display on MobileHarness as
813 Property.
814
815 Args:
816 ad: An AndroidDevice object.
817 true_position: Coordinate as [latitude, longitude] to calculate
818 position error.
819 type: Different API for location fix. Use gnss/flp/nmea
820 """
821 test_logfile = {}
822 track_data = {}
jasonkmlucb654ac2020-07-01 11:08:33 +0800823 ant_top4_cn = 0
824 ant_cn = 0
825 base_top4_cn = 0
826 base_cn = 0
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800827 track_lat = 0
828 track_long = 0
jasonkmlu035eee12019-10-08 17:11:20 +0800829 l5flag = "false"
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800830 file_count = int(ad.adb.shell("find %s -type f -iname *.txt | wc -l"
831 % GNSSSTATUS_LOG_PATH))
832 if file_count != 1:
833 ad.log.error("%d API logs exist." % file_count)
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800834 dir_file = ad.adb.shell("ls %s" % GNSSSTATUS_LOG_PATH).split()
835 for path_key in dir_file:
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800836 if fnmatch.fnmatch(path_key, "*.txt"):
837 logpath = posixpath.join(GNSSSTATUS_LOG_PATH, path_key)
838 out = ad.adb.shell("wc -c %s" % logpath)
839 file_size = int(out.split(" ")[0])
840 if file_size < 2000:
841 ad.log.info("Skip log %s due to log size %d bytes" %
842 (path_key, file_size))
843 continue
844 test_logfile = logpath
845 if not test_logfile:
jasonkmlu78540632019-11-15 18:04:20 +0800846 raise signals.TestError("Failed to get test log file in device.")
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800847 lines = ad.adb.shell("cat %s" % test_logfile).split("\n")
848 for line in lines:
jasonkmlucb654ac2020-07-01 11:08:33 +0800849 if "Antenna_History Avg Top4" in line:
850 ant_top4_cn = float(line.split(":")[-1].strip())
851 elif "Antenna_History Avg" in line:
852 ant_cn = float(line.split(":")[-1].strip())
853 elif "Baseband_History Avg Top4" in line:
854 base_top4_cn = float(line.split(":")[-1].strip())
855 elif "Baseband_History Avg" in line:
856 base_cn = float(line.split(":")[-1].strip())
857 elif "L5 used in fix" in line:
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800858 l5flag = line.split(":")[-1].strip()
jasonkmlucb654ac2020-07-01 11:08:33 +0800859 elif "Latitude" in line:
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800860 track_lat = float(line.split(":")[-1].strip())
jasonkmlucb654ac2020-07-01 11:08:33 +0800861 elif "Longitude" in line:
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800862 track_long = float(line.split(":")[-1].strip())
jasonkmlucb654ac2020-07-01 11:08:33 +0800863 elif "Time" in line:
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800864 track_utc = line.split("Time:")[-1].strip()
865 if track_utc in track_data.keys():
866 continue
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800867 pe = calculate_position_error(track_lat, track_long, true_position)
jasonkmlucb654ac2020-07-01 11:08:33 +0800868 track_data[track_utc] = TRACK_REPORT(l5flag=l5flag,
869 pe=pe,
870 ant_top4cn=ant_top4_cn,
871 ant_cn=ant_cn,
872 base_top4cn=base_top4_cn,
873 base_cn=base_cn)
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800874 ad.log.debug(track_data)
875 prop_basename = "TestResult %s_tracking_" % type.upper()
876 time_list = sorted(track_data.keys())
jasonkmlucb654ac2020-07-01 11:08:33 +0800877 l5flag_list = [track_data[key].l5flag for key in time_list]
878 pe_list = [float(track_data[key].pe) for key in time_list]
879 ant_top4cn_list = [float(track_data[key].ant_top4cn) for key in time_list]
880 ant_cn_list = [float(track_data[key].ant_cn) for key in time_list]
881 base_top4cn_list = [float(track_data[key].base_top4cn) for key in time_list]
882 base_cn_list = [float(track_data[key].base_cn) for key in time_list]
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800883 ad.log.info(prop_basename+"StartTime %s" % time_list[0].replace(" ", "-"))
884 ad.log.info(prop_basename+"EndTime %s" % time_list[-1].replace(" ", "-"))
885 ad.log.info(prop_basename+"TotalFixPoints %d" % len(time_list))
886 ad.log.info(prop_basename+"L5FixRate "+'{percent:.2%}'.format(
887 percent=l5flag_list.count("true")/len(l5flag_list)))
888 ad.log.info(prop_basename+"AvgDis %.1f" % (sum(pe_list)/len(pe_list)))
889 ad.log.info(prop_basename+"MaxDis %.1f" % max(pe_list))
jasonkmlucb654ac2020-07-01 11:08:33 +0800890 ad.log.info(prop_basename+"Ant_AvgTop4Signal %.1f" % ant_top4cn_list[-1])
891 ad.log.info(prop_basename+"Ant_AvgSignal %.1f" % ant_cn_list[-1])
892 ad.log.info(prop_basename+"Base_AvgTop4Signal %.1f" % base_top4cn_list[-1])
893 ad.log.info(prop_basename+"Base_AvgSignal %.1f" % base_cn_list[-1])
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800894
jasonkmlu0f546de2019-12-13 20:58:41 +0800895
jasonkmlu81b8b032019-06-21 15:18:27 +0800896def process_ttff_by_gtw_gpstool(ad, begin_time, true_position, type="gnss"):
897 """Process TTFF and record results in ttff_data.
jasonkmluff0d5b92019-03-21 11:24:45 +0800898
899 Args:
900 ad: An AndroidDevice object.
jasonkmlu903ece82019-05-16 14:56:19 +0800901 begin_time: test begin time.
jasonkmlu733738f2019-09-02 18:59:42 +0800902 true_position: Coordinate as [latitude, longitude] to calculate
903 position error.
jasonkmlu81b8b032019-06-21 15:18:27 +0800904 type: Different API for location fix. Use gnss/flp/nmea
jasonkmluff0d5b92019-03-21 11:24:45 +0800905
906 Returns:
jasonkmlu81b8b032019-06-21 15:18:27 +0800907 ttff_data: A dict of all TTFF data.
jasonkmluff0d5b92019-03-21 11:24:45 +0800908 """
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800909 ttff_lat = 0
910 ttff_lon = 0
911 utc_time = epoch_to_human_time(get_current_epoch_time())
jasonkmlu903ece82019-05-16 14:56:19 +0800912 ttff_data = {}
jasonkmlu733738f2019-09-02 18:59:42 +0800913 ttff_loop_time = get_current_epoch_time()
jasonkmlu97ac56e2019-05-29 15:04:51 +0800914 while True:
jasonkmlu733738f2019-09-02 18:59:42 +0800915 if get_current_epoch_time() - ttff_loop_time >= 120000:
jasonkmlu78540632019-11-15 18:04:20 +0800916 raise signals.TestError("Fail to search specific GPSService "
917 "message in logcat. Abort test.")
jasonkmlu97ac56e2019-05-29 15:04:51 +0800918 if not ad.is_adb_logcat_on:
919 ad.start_adb_logcat()
jasonkmlu61b686f2020-07-20 20:07:04 +0800920 logcat_results = ad.search_logcat("write TTFF log", ttff_loop_time)
jasonkmlu97ac56e2019-05-29 15:04:51 +0800921 if logcat_results:
jasonkmlu61b686f2020-07-20 20:07:04 +0800922 ttff_loop_time = get_current_epoch_time()
jasonkmlu97ac56e2019-05-29 15:04:51 +0800923 ttff_log = logcat_results[-1]["log_message"].split()
924 ttff_loop = int(ttff_log[8].split(":")[-1])
jasonkmlu81b8b032019-06-21 15:18:27 +0800925 ttff_sec = float(ttff_log[11])
926 if ttff_sec != 0.0:
jasonkmlucb654ac2020-07-01 11:08:33 +0800927 ttff_ant_cn = float(ttff_log[18].strip("]"))
928 ttff_base_cn = float(ttff_log[25].strip("]"))
jasonkmlu81b8b032019-06-21 15:18:27 +0800929 if type == "gnss":
jasonkmlu733738f2019-09-02 18:59:42 +0800930 gnss_results = ad.search_logcat("GPSService: Check item",
931 begin_time)
jasonkmlu81b8b032019-06-21 15:18:27 +0800932 if gnss_results:
933 ad.log.debug(gnss_results[-1]["log_message"])
jasonkmlu733738f2019-09-02 18:59:42 +0800934 gnss_location_log = \
935 gnss_results[-1]["log_message"].split()
936 ttff_lat = float(
937 gnss_location_log[8].split("=")[-1].strip(","))
938 ttff_lon = float(
939 gnss_location_log[9].split("=")[-1].strip(","))
jasonkmlucb654ac2020-07-01 11:08:33 +0800940 loc_time = int(
941 gnss_location_log[10].split("=")[-1].strip(","))
942 utc_time = epoch_to_human_time(loc_time)
jasonkmlu81b8b032019-06-21 15:18:27 +0800943 elif type == "flp":
jasonkmlu733738f2019-09-02 18:59:42 +0800944 flp_results = ad.search_logcat("GPSService: FLP Location",
945 begin_time)
jasonkmlu81b8b032019-06-21 15:18:27 +0800946 if flp_results:
947 ad.log.debug(flp_results[-1]["log_message"])
jasonkmlucb654ac2020-07-01 11:08:33 +0800948 flp_location_log = flp_results[-1][
949 "log_message"].split()
jasonkmlu81b8b032019-06-21 15:18:27 +0800950 ttff_lat = float(flp_location_log[8].split(",")[0])
951 ttff_lon = float(flp_location_log[8].split(",")[1])
jasonkmlucb654ac2020-07-01 11:08:33 +0800952 utc_time = epoch_to_human_time(get_current_epoch_time())
jasonkmlu81b8b032019-06-21 15:18:27 +0800953 else:
jasonkmlucb654ac2020-07-01 11:08:33 +0800954 ttff_ant_cn = float(ttff_log[19].strip("]"))
955 ttff_base_cn = float(ttff_log[26].strip("]"))
956 ttff_lat = 0
957 ttff_lon = 0
958 utc_time = epoch_to_human_time(get_current_epoch_time())
jasonkmlu2565d892019-11-12 15:31:26 +0800959 ad.log.debug("TTFF Loop %d - (Lat, Lon) = (%s, %s)" % (ttff_loop,
960 ttff_lat,
961 ttff_lon))
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800962 ttff_pe = calculate_position_error(
963 ttff_lat, ttff_lon, true_position)
jasonkmlucb654ac2020-07-01 11:08:33 +0800964 ttff_data[ttff_loop] = TTFF_REPORT(utc_time=utc_time,
965 ttff_loop=ttff_loop,
jasonkmlu97ac56e2019-05-29 15:04:51 +0800966 ttff_sec=ttff_sec,
967 ttff_pe=ttff_pe,
jasonkmlucb654ac2020-07-01 11:08:33 +0800968 ttff_ant_cn=ttff_ant_cn,
969 ttff_base_cn=ttff_base_cn)
970 ad.log.info("UTC Time = %s, Loop %d = %.1f seconds, "
jasonkmlu97ac56e2019-05-29 15:04:51 +0800971 "Position Error = %.1f meters, "
jasonkmlucb654ac2020-07-01 11:08:33 +0800972 "Antenna Average Signal = %.1f dbHz, "
973 "Baseband Average Signal = %.1f dbHz" % (utc_time,
974 ttff_loop,
975 ttff_sec,
976 ttff_pe,
977 ttff_ant_cn,
978 ttff_base_cn))
979 stop_gps_results = ad.search_logcat("stop gps test", begin_time)
980 if stop_gps_results:
981 ad.send_keycode("HOME")
982 break
983 crash_result = ad.search_logcat("Force finishing activity "
984 "com.android.gpstool/.GPSTool",
985 begin_time)
986 if crash_result:
987 raise signals.TestError("GPSTool crashed. Abort test.")
jasonkmlu08cb9292020-07-29 11:49:08 +0800988 # wait 10 seconds to avoid logs not writing into logcat yet
989 time.sleep(10)
jasonkmlu97ac56e2019-05-29 15:04:51 +0800990 return ttff_data
jasonkmluff0d5b92019-03-21 11:24:45 +0800991
jasonkmlu0f546de2019-12-13 20:58:41 +0800992
jasonkmlu903ece82019-05-16 14:56:19 +0800993def check_ttff_data(ad, ttff_data, ttff_mode, criteria):
jasonkmlu81b8b032019-06-21 15:18:27 +0800994 """Verify all TTFF results from ttff_data.
jasonkmluff0d5b92019-03-21 11:24:45 +0800995
996 Args:
997 ad: An AndroidDevice object.
jasonkmlu903ece82019-05-16 14:56:19 +0800998 ttff_data: TTFF data of secs, position error and signal strength.
jasonkmluff0d5b92019-03-21 11:24:45 +0800999 ttff_mode: TTFF Test mode for current test item.
1000 criteria: Criteria for current test item.
1001
1002 Returns:
1003 True: All TTFF results are within criteria.
1004 False: One or more TTFF results exceed criteria or Timeout.
1005 """
1006 ad.log.info("%d iterations of TTFF %s tests finished."
jasonkmlu903ece82019-05-16 14:56:19 +08001007 % (len(ttff_data.keys()), ttff_mode))
jasonkmluff0d5b92019-03-21 11:24:45 +08001008 ad.log.info("%s PASS criteria is %d seconds" % (ttff_mode, criteria))
jasonkmlu81b8b032019-06-21 15:18:27 +08001009 ad.log.debug("%s TTFF data: %s" % (ttff_mode, ttff_data))
jasonkmlu4fcdcad2019-07-10 14:35:12 +08001010 ttff_property_key_and_value(ad, ttff_data, ttff_mode)
jasonkmlu903ece82019-05-16 14:56:19 +08001011 if len(ttff_data.keys()) == 0:
jasonkmluff0d5b92019-03-21 11:24:45 +08001012 ad.log.error("GTW_GPSTool didn't process TTFF properly.")
1013 return False
jasonkmlu903ece82019-05-16 14:56:19 +08001014 elif any(float(ttff_data[key].ttff_sec) == 0.0 for key in ttff_data.keys()):
jasonkmluff0d5b92019-03-21 11:24:45 +08001015 ad.log.error("One or more TTFF %s Timeout" % ttff_mode)
1016 return False
jasonkmlu035eee12019-10-08 17:11:20 +08001017 elif any(float(ttff_data[key].ttff_sec) >= criteria for key in
1018 ttff_data.keys()):
jasonkmluff0d5b92019-03-21 11:24:45 +08001019 ad.log.error("One or more TTFF %s are over test criteria %d seconds"
1020 % (ttff_mode, criteria))
1021 return False
1022 ad.log.info("All TTFF %s are within test criteria %d seconds."
1023 % (ttff_mode, criteria))
1024 return True
1025
jasonkmlu0f546de2019-12-13 20:58:41 +08001026
jasonkmlu4fcdcad2019-07-10 14:35:12 +08001027def ttff_property_key_and_value(ad, ttff_data, ttff_mode):
jasonkmlu81b8b032019-06-21 15:18:27 +08001028 """Output ttff_data to test_run_info for ACTS plugin to parse and display
1029 on MobileHarness as Property.
1030
1031 Args:
1032 ad: An AndroidDevice object.
1033 ttff_data: TTFF data of secs, position error and signal strength.
1034 ttff_mode: TTFF Test mode for current test item.
1035 """
1036 prop_basename = "TestResult "+ttff_mode.replace(" ", "_")+"_TTFF_"
1037 sec_list = [float(ttff_data[key].ttff_sec) for key in ttff_data.keys()]
1038 pe_list = [float(ttff_data[key].ttff_pe) for key in ttff_data.keys()]
jasonkmlucb654ac2020-07-01 11:08:33 +08001039 ant_cn_list = [float(ttff_data[key].ttff_ant_cn) for key in
1040 ttff_data.keys()]
1041 base_cn_list = [float(ttff_data[key].ttff_base_cn) for key in
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001042 ttff_data.keys()]
jasonkmlu81b8b032019-06-21 15:18:27 +08001043 timeoutcount = sec_list.count(0.0)
jasonkmluc1ec3052019-10-25 14:57:53 +08001044 if len(sec_list) == timeoutcount:
1045 avgttff = 9527
1046 else:
1047 avgttff = sum(sec_list)/(len(sec_list) - timeoutcount)
jasonkmlu81b8b032019-06-21 15:18:27 +08001048 if timeoutcount != 0:
jasonkmlu4fcdcad2019-07-10 14:35:12 +08001049 maxttff = 9527
jasonkmlu81b8b032019-06-21 15:18:27 +08001050 else:
1051 maxttff = max(sec_list)
1052 avgdis = sum(pe_list)/len(pe_list)
1053 maxdis = max(pe_list)
jasonkmlucb654ac2020-07-01 11:08:33 +08001054 ant_avgcn = sum(ant_cn_list)/len(ant_cn_list)
1055 base_avgcn = sum(base_cn_list)/len(base_cn_list)
jasonkmlu81b8b032019-06-21 15:18:27 +08001056 ad.log.info(prop_basename+"AvgTime %.1f" % avgttff)
1057 ad.log.info(prop_basename+"MaxTime %.1f" % maxttff)
1058 ad.log.info(prop_basename+"TimeoutCount %d" % timeoutcount)
1059 ad.log.info(prop_basename+"AvgDis %.1f" % avgdis)
1060 ad.log.info(prop_basename+"MaxDis %.1f" % maxdis)
jasonkmlucb654ac2020-07-01 11:08:33 +08001061 ad.log.info(prop_basename+"Ant_AvgSignal %.1f" % ant_avgcn)
1062 ad.log.info(prop_basename+"Base_AvgSignal %.1f" % base_avgcn)
jasonkmlu81b8b032019-06-21 15:18:27 +08001063
jasonkmlu0f546de2019-12-13 20:58:41 +08001064
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001065def calculate_position_error(latitude, longitude, true_position):
jasonkmlu903ece82019-05-16 14:56:19 +08001066 """Use haversine formula to calculate position error base on true location
1067 coordinate.
1068
1069 Args:
jasonkmlu903ece82019-05-16 14:56:19 +08001070 latitude: latitude of location fixed in the present.
1071 longitude: longitude of location fixed in the present.
1072 true_position: [latitude, longitude] of true location coordinate.
1073
1074 Returns:
1075 position_error of location fixed in the present.
1076 """
1077 radius = 6371009
1078 dlat = math.radians(latitude - true_position[0])
1079 dlon = math.radians(longitude - true_position[1])
1080 a = math.sin(dlat/2) * math.sin(dlat/2) + \
1081 math.cos(math.radians(true_position[0])) * \
1082 math.cos(math.radians(latitude)) * math.sin(dlon/2) * math.sin(dlon/2)
1083 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
1084 return radius * c
1085
jasonkmlu0f546de2019-12-13 20:58:41 +08001086
jasonkmluff0d5b92019-03-21 11:24:45 +08001087def launch_google_map(ad):
1088 """Launch Google Map via intent.
1089
1090 Args:
1091 ad: An AndroidDevice object.
1092 """
1093 ad.log.info("Launch Google Map.")
1094 try:
1095 ad.adb.shell("am start -S -n com.google.android.apps.maps/"
1096 "com.google.android.maps.MapsActivity")
1097 ad.send_keycode("BACK")
1098 ad.force_stop_apk("com.google.android.apps.maps")
1099 ad.adb.shell("am start -S -n com.google.android.apps.maps/"
1100 "com.google.android.maps.MapsActivity")
1101 except Exception as e:
1102 ad.log.error(e)
jasonkmlu78540632019-11-15 18:04:20 +08001103 raise signals.TestError("Failed to launch google map.")
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001104 check_current_focus_app(ad)
jasonkmlu49c32812019-04-12 18:11:10 +08001105
jasonkmlu0f546de2019-12-13 20:58:41 +08001106
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001107def check_current_focus_app(ad):
jasonkmlu903ece82019-05-16 14:56:19 +08001108 """Check to see current focused window and app.
jasonkmlu49c32812019-04-12 18:11:10 +08001109
1110 Args:
1111 ad: An AndroidDevice object.
jasonkmlu49c32812019-04-12 18:11:10 +08001112 """
jasonkmlu903ece82019-05-16 14:56:19 +08001113 time.sleep(1)
jasonkmlu035eee12019-10-08 17:11:20 +08001114 current = ad.adb.shell(
1115 "dumpsys window | grep -E 'mCurrentFocus|mFocusedApp'")
jasonkmlu81b8b032019-06-21 15:18:27 +08001116 ad.log.debug("\n"+current)
jasonkmluff0d5b92019-03-21 11:24:45 +08001117
jasonkmlu0f546de2019-12-13 20:58:41 +08001118
jasonkmluff0d5b92019-03-21 11:24:45 +08001119def check_location_api(ad, retries):
1120 """Verify if GnssLocationProvider API reports location.
1121
1122 Args:
1123 ad: An AndroidDevice object.
1124 retries: Retry time.
1125
1126 Returns:
1127 True: GnssLocationProvider API reports location.
1128 otherwise return False.
1129 """
1130 for i in range(retries):
1131 begin_time = get_current_epoch_time()
1132 ad.log.info("Try to get location report from GnssLocationProvider API "
1133 "- attempt %d" % (i+1))
1134 while get_current_epoch_time() - begin_time <= 30000:
1135 logcat_results = ad.search_logcat("REPORT_LOCATION", begin_time)
1136 if logcat_results:
1137 ad.log.info("%s" % logcat_results[-1]["log_message"])
jasonkmlu035eee12019-10-08 17:11:20 +08001138 ad.log.info("GnssLocationProvider reports location "
1139 "successfully.")
jasonkmluff0d5b92019-03-21 11:24:45 +08001140 return True
1141 if not ad.is_adb_logcat_on:
1142 ad.start_adb_logcat()
1143 ad.log.error("GnssLocationProvider is unable to report location.")
1144 return False
1145
Scott Hong72269692019-12-16 16:59:56 +08001146def check_network_location(ad, retries, location_type, criteria=30):
jasonkmluff0d5b92019-03-21 11:24:45 +08001147 """Verify if NLP reports location after requesting via GPSTool.
1148
1149 Args:
1150 ad: An AndroidDevice object.
1151 retries: Retry time.
Scott Hongaccd8a12020-03-03 20:12:17 +08001152 location_type: cell or wifi.
Scott Hong72269692019-12-16 16:59:56 +08001153 criteria: expected nlp return time, default 30 seconds
jasonkmluff0d5b92019-03-21 11:24:45 +08001154
1155 Returns:
1156 True: NLP reports location.
1157 otherwise return False.
1158 """
Scott Hong72269692019-12-16 16:59:56 +08001159 criteria = criteria * 1000
Scott Hongaccd8a12020-03-03 20:12:17 +08001160 search_pattern = ("GPSTool : networkLocationType = %s" % location_type)
jasonkmluff0d5b92019-03-21 11:24:45 +08001161 for i in range(retries):
jasonkmluff0d5b92019-03-21 11:24:45 +08001162 begin_time = get_current_epoch_time()
1163 ad.log.info("Try to get NLP status - attempt %d" % (i+1))
jasonkmlu035eee12019-10-08 17:11:20 +08001164 ad.adb.shell(
1165 "am start -S -n com.android.gpstool/.GPSTool --es mode nlp")
Scott Hong72269692019-12-16 16:59:56 +08001166 while get_current_epoch_time() - begin_time <= criteria:
Scott Hongaccd8a12020-03-03 20:12:17 +08001167 # Search pattern in 1 second interval
1168 time.sleep(1)
1169 result = ad.search_logcat(search_pattern, begin_time)
1170 if result:
1171 ad.log.info("Pattern Found: %s." % result[-1]["log_message"])
1172 ad.send_keycode("BACK")
1173 return True
jasonkmluff0d5b92019-03-21 11:24:45 +08001174 if not ad.is_adb_logcat_on:
1175 ad.start_adb_logcat()
1176 ad.send_keycode("BACK")
1177 ad.log.error("Unable to report network location \"%s\"." % location_type)
1178 return False
1179
jasonkmlu0f546de2019-12-13 20:58:41 +08001180
jasonkmlu8d6bbfc2019-03-29 15:57:43 +08001181def set_attenuator_gnss_signal(ad, attenuator, atten_value):
jasonkmluff0d5b92019-03-21 11:24:45 +08001182 """Set attenuation value for different GNSS signal.
1183
1184 Args:
1185 ad: An AndroidDevice object.
jasonkmlu8d6bbfc2019-03-29 15:57:43 +08001186 attenuator: The attenuator object.
jasonkmluff0d5b92019-03-21 11:24:45 +08001187 atten_value: attenuation value
1188 """
jasonkmluff0d5b92019-03-21 11:24:45 +08001189 try:
jasonkmlu035eee12019-10-08 17:11:20 +08001190 ad.log.info(
1191 "Set attenuation value to \"%d\" for GNSS signal." % atten_value)
jasonkmlu8d6bbfc2019-03-29 15:57:43 +08001192 attenuator[0].set_atten(atten_value)
jasonkmlu81b8b032019-06-21 15:18:27 +08001193 except Exception as e:
jasonkmlu4fcdcad2019-07-10 14:35:12 +08001194 ad.log.error(e)
jasonkmluff0d5b92019-03-21 11:24:45 +08001195
jasonkmlu0f546de2019-12-13 20:58:41 +08001196
jasonkmluff0d5b92019-03-21 11:24:45 +08001197def set_battery_saver_mode(ad, state):
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001198 """Enable or disable battery saver mode via adb.
jasonkmluff0d5b92019-03-21 11:24:45 +08001199
1200 Args:
1201 ad: An AndroidDevice object.
1202 state: True is enable Battery Saver mode. False is disable.
1203 """
1204 ad.root_adb()
1205 if state:
1206 ad.log.info("Enable Battery Saver mode.")
1207 ad.adb.shell("cmd battery unplug")
1208 ad.adb.shell("settings put global low_power 1")
1209 else:
1210 ad.log.info("Disable Battery Saver mode.")
1211 ad.adb.shell("settings put global low_power 0")
1212 ad.adb.shell("cmd battery reset")
1213
jasonkmlu0f546de2019-12-13 20:58:41 +08001214
jasonkmluff0d5b92019-03-21 11:24:45 +08001215def set_gnss_qxdm_mask(ad, masks):
1216 """Find defined gnss qxdm mask and set as default logging mask.
1217
1218 Args:
1219 ad: An AndroidDevice object.
1220 masks: Defined gnss qxdm mask.
1221 """
1222 try:
1223 for mask in masks:
1224 if not tutils.find_qxdm_log_mask(ad, mask):
1225 continue
1226 tutils.set_qxdm_logger_command(ad, mask)
1227 break
1228 except Exception as e:
1229 ad.log.error(e)
jasonkmlu78540632019-11-15 18:04:20 +08001230 raise signals.TestError("Failed to set any QXDM masks.")
jasonkmlu903ece82019-05-16 14:56:19 +08001231
jasonkmlu0f546de2019-12-13 20:58:41 +08001232
jasonkmlu903ece82019-05-16 14:56:19 +08001233def start_youtube_video(ad, url=None, retries=0):
1234 """Start youtube video and verify if audio is in music state.
jasonkmlu81b8b032019-06-21 15:18:27 +08001235
jasonkmlu903ece82019-05-16 14:56:19 +08001236 Args:
1237 ad: An AndroidDevice object.
1238 url: Youtube video url.
1239 retries: Retry times if audio is not in music state.
jasonkmlu81b8b032019-06-21 15:18:27 +08001240
jasonkmlu903ece82019-05-16 14:56:19 +08001241 Returns:
1242 True if youtube video is playing normally.
1243 False if youtube video is not playing properly.
1244 """
1245 for i in range(retries):
1246 ad.log.info("Open an youtube video - attempt %d" % (i+1))
jasonkmluc0939182021-02-19 18:34:28 +08001247 cmd = ("am start -n com.google.android.youtube/"
1248 "com.google.android.youtube.UrlActivity -d \"%s\"" % url)
1249 ad.adb.shell(cmd)
jasonkmlu903ece82019-05-16 14:56:19 +08001250 time.sleep(2)
jasonkmlu035eee12019-10-08 17:11:20 +08001251 out = ad.adb.shell(
1252 "dumpsys activity | grep NewVersionAvailableActivity")
jasonkmlu903ece82019-05-16 14:56:19 +08001253 if out:
1254 ad.log.info("Skip Youtube New Version Update.")
1255 ad.send_keycode("BACK")
1256 if tutils.wait_for_state(ad.droid.audioIsMusicActive, True, 15, 1):
1257 ad.log.info("Started a video in youtube, audio is in MUSIC state")
1258 return True
1259 ad.log.info("Force-Stop youtube and reopen youtube again.")
1260 ad.force_stop_apk("com.google.android.youtube")
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001261 check_current_focus_app(ad)
jasonkmlu78540632019-11-15 18:04:20 +08001262 raise signals.TestError("Started a video in youtube, "
1263 "but audio is not in MUSIC state")
jasonkmlu81b8b032019-06-21 15:18:27 +08001264
jasonkmlu0f546de2019-12-13 20:58:41 +08001265
jasonkmlu81b8b032019-06-21 15:18:27 +08001266def get_baseband_and_gms_version(ad, extra_msg=""):
1267 """Get current radio baseband and GMSCore version of AndroidDevice object.
1268
1269 Args:
1270 ad: An AndroidDevice object.
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001271 extra_msg: Extra message before or after the change.
jasonkmlu81b8b032019-06-21 15:18:27 +08001272 """
1273 try:
jasonkmlud93060f2019-11-05 15:12:55 +08001274 build_version = ad.adb.getprop("ro.build.id")
jasonkmlu81b8b032019-06-21 15:18:27 +08001275 baseband_version = ad.adb.getprop("gsm.version.baseband")
jasonkmlu035eee12019-10-08 17:11:20 +08001276 gms_version = ad.adb.shell(
1277 "dumpsys package com.google.android.gms | grep versionName"
1278 ).split("\n")[0].split("=")[1]
1279 mpss_version = ad.adb.shell("cat /sys/devices/soc0/images | grep MPSS "
1280 "| cut -d ':' -f 3")
jasonkmlu81b8b032019-06-21 15:18:27 +08001281 if not extra_msg:
jasonkmlud93060f2019-11-05 15:12:55 +08001282 ad.log.info("TestResult Build_Version %s" % build_version)
jasonkmlu81b8b032019-06-21 15:18:27 +08001283 ad.log.info("TestResult Baseband_Version %s" % baseband_version)
jasonkmlu035eee12019-10-08 17:11:20 +08001284 ad.log.info(
1285 "TestResult GMS_Version %s" % gms_version.replace(" ", ""))
1286 ad.log.info("TestResult MPSS_Version %s" % mpss_version)
jasonkmlu81b8b032019-06-21 15:18:27 +08001287 else:
jasonkmlu035eee12019-10-08 17:11:20 +08001288 ad.log.info(
1289 "%s, Baseband_Version = %s" % (extra_msg, baseband_version))
jasonkmlu81b8b032019-06-21 15:18:27 +08001290 except Exception as e:
jasonkmlu035eee12019-10-08 17:11:20 +08001291 ad.log.error(e)
1292
jasonkmlu0f546de2019-12-13 20:58:41 +08001293
jasonkmlu035eee12019-10-08 17:11:20 +08001294def start_toggle_gnss_by_gtw_gpstool(ad, iteration):
1295 """Send toggle gnss off/on start_test_action
1296
1297 Args:
1298 ad: An AndroidDevice object.
1299 iteration: Iteration of toggle gnss off/on cycles.
1300 """
1301 msg_list = []
1302 begin_time = get_current_epoch_time()
1303 try:
1304 for i in range(1, 4):
1305 ad.adb.shell("am start -S -n com.android.gpstool/.GPSTool "
1306 "--es mode toggle --es cycle %d" % iteration)
1307 time.sleep(1)
1308 if ad.search_logcat("cmp=com.android.gpstool/.ToggleGPS",
1309 begin_time):
1310 ad.log.info("Send ToggleGPS start_test_action successfully.")
1311 break
1312 else:
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001313 check_current_focus_app(ad)
jasonkmlu78540632019-11-15 18:04:20 +08001314 raise signals.TestError("Fail to send ToggleGPS "
1315 "start_test_action within 3 attempts.")
jasonkmlu035eee12019-10-08 17:11:20 +08001316 time.sleep(2)
1317 test_start = ad.search_logcat("GPSTool_ToggleGPS: startService",
1318 begin_time)
1319 if test_start:
1320 ad.log.info(test_start[-1]["log_message"].split(":")[-1].strip())
1321 else:
jasonkmlu78540632019-11-15 18:04:20 +08001322 raise signals.TestError("Fail to start toggle GPS off/on test.")
jasonkmlu035eee12019-10-08 17:11:20 +08001323 # Every iteration is expected to finish within 4 minutes.
1324 while get_current_epoch_time() - begin_time <= iteration * 240000:
1325 crash_end = ad.search_logcat("Force finishing activity "
1326 "com.android.gpstool/.GPSTool",
1327 begin_time)
1328 if crash_end:
jasonkmlu78540632019-11-15 18:04:20 +08001329 raise signals.TestError("GPSTool crashed. Abort test.")
jasonkmlu035eee12019-10-08 17:11:20 +08001330 toggle_results = ad.search_logcat("GPSTool : msg", begin_time)
1331 if toggle_results:
1332 for toggle_result in toggle_results:
1333 msg = toggle_result["log_message"]
1334 if not msg in msg_list:
1335 ad.log.info(msg.split(":")[-1].strip())
1336 msg_list.append(msg)
1337 if "timeout" in msg:
1338 raise signals.TestFailure("Fail to get location fixed "
1339 "within 60 seconds.")
1340 if "Test end" in msg:
1341 raise signals.TestPass("Completed quick toggle GNSS "
1342 "off/on test.")
1343 raise signals.TestFailure("Fail to finish toggle GPS off/on test "
1344 "within %d minutes" % (iteration * 4))
1345 finally:
1346 ad.send_keycode("HOME")
jasonkmludc430ec2020-03-27 10:40:39 +08001347
jasonkmlu4ba30a02020-04-09 14:16:49 +08001348
jasonkmludc430ec2020-03-27 10:40:39 +08001349def grant_location_permission(ad, option):
1350 """Grant or revoke location related permission.
1351
1352 Args:
1353 ad: An AndroidDevice object.
1354 option: Boolean to grant or revoke location related permissions.
1355 """
jasonkmlu4ba30a02020-04-09 14:16:49 +08001356 action = "grant" if option else "revoke"
jasonkmludc430ec2020-03-27 10:40:39 +08001357 for permission in LOCATION_PERMISSIONS:
1358 ad.log.info(
jasonkmlu4ba30a02020-04-09 14:16:49 +08001359 "%s permission:%s on %s" % (action, permission, TEST_PACKAGE_NAME))
1360 ad.adb.shell("pm %s %s %s" % (action, TEST_PACKAGE_NAME, permission))
1361
1362
1363def check_location_runtime_permissions(ad, package, permissions):
1364 """Check if runtime permissions are granted on selected package.
1365
1366 Args:
1367 ad: An AndroidDevice object.
1368 package: Apk package name to check.
1369 permissions: A list of permissions to be granted.
1370 """
1371 for _ in range(3):
1372 location_runtime_permission = ad.adb.shell(
1373 "dumpsys package %s | grep ACCESS_FINE_LOCATION" % package)
1374 if "true" not in location_runtime_permission:
1375 ad.log.info("ACCESS_FINE_LOCATION is NOT granted on %s" % package)
1376 for permission in permissions:
1377 ad.log.debug("Grant %s on %s" % (permission, package))
1378 ad.adb.shell("pm grant %s %s" % (package, permission))
1379 else:
1380 ad.log.info("ACCESS_FINE_LOCATION is granted on %s" % package)
1381 break
1382 else:
1383 raise signals.TestError(
1384 "Fail to grant ACCESS_FINE_LOCATION on %s" % package)
jasonkmlucb654ac2020-07-01 11:08:33 +08001385
1386
1387def install_mdstest_app(ad, mdsapp):
1388 """
1389 Install MDS test app in DUT
1390
1391 Args:
1392 ad: An Android Device Object
1393 mdsapp: Installation path of MDSTest app
1394 """
1395 if not ad.is_apk_installed("com.google.mdstest"):
1396 ad.adb.install("-r %s" % mdsapp, timeout=300, ignore_status=True)
1397
1398
1399def write_modemconfig(ad, mdsapp, nvitem_dict, modemparfile):
1400 """
1401 Modify the NV items using modem_tool.par
1402 Note: modem_tool.par
1403
1404 Args:
1405 ad: An Android Device Object
1406 mdsapp: Installation path of MDSTest app
1407 nvitem_dict: dictionary of NV items and values.
1408 modemparfile: modem_tool.par path.
1409 """
1410 ad.log.info("Verify MDSTest app installed in DUT")
1411 install_mdstest_app(ad, mdsapp)
1412 os.system("chmod 777 %s" % modemparfile)
1413 for key, value in nvitem_dict.items():
1414 if key.isdigit():
1415 op_name = "WriteEFS"
1416 else:
1417 op_name = "WriteNV"
1418 ad.log.info("Modifying the NV{!r} using {}".format(key, op_name))
1419 job.run("{} --op {} --item {} --data '{}'".
1420 format(modemparfile, op_name, key, value))
1421 time.sleep(2)
1422
1423
1424def verify_modemconfig(ad, nvitem_dict, modemparfile):
1425 """
1426 Verify the NV items using modem_tool.par
1427 Note: modem_tool.par
1428
1429 Args:
1430 ad: An Android Device Object
1431 nvitem_dict: dictionary of NV items and values
1432 modemparfile: modem_tool.par path.
1433 """
1434 os.system("chmod 777 %s" % modemparfile)
1435 for key, value in nvitem_dict.items():
1436 if key.isdigit():
1437 op_name = "ReadEFS"
1438 else:
1439 op_name = "ReadNV"
1440 # Sleeptime to avoid Modem communication error
1441 time.sleep(5)
1442 result = job.run(
1443 "{} --op {} --item {}".format(modemparfile, op_name, key))
1444 output = str(result.stdout)
1445 ad.log.info("Actual Value for NV{!r} is {!r}".format(key, output))
1446 if not value.casefold() in output:
1447 ad.log.error("NV Value is wrong {!r} in {!r}".format(value, result))
1448 raise ValueError(
1449 "could not find {!r} in {!r}".format(value, result))
Jayakumar Munuswamy7efa25b2020-07-07 15:30:08 -07001450
1451
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001452def check_ttff_pe(ad, ttff_data, ttff_mode, pe_criteria):
Jayakumar Munuswamy7efa25b2020-07-07 15:30:08 -07001453 """Verify all TTFF results from ttff_data.
1454
1455 Args:
1456 ad: An AndroidDevice object.
1457 ttff_data: TTFF data of secs, position error and signal strength.
1458 ttff_mode: TTFF Test mode for current test item.
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001459 pe_criteria: Criteria for current test item.
Jayakumar Munuswamy7efa25b2020-07-07 15:30:08 -07001460
1461 """
1462 ad.log.info("%d iterations of TTFF %s tests finished.",
1463 (len(ttff_data.keys()), ttff_mode))
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001464 ad.log.info("%s PASS criteria is %f meters", (ttff_mode, pe_criteria))
Jayakumar Munuswamy7efa25b2020-07-07 15:30:08 -07001465 ad.log.debug("%s TTFF data: %s", (ttff_mode, ttff_data))
1466
1467 if len(ttff_data.keys()) == 0:
1468 ad.log.error("GTW_GPSTool didn't process TTFF properly.")
1469 raise signals.TestFailure("GTW_GPSTool didn't process TTFF properly.")
1470
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001471 elif any(float(ttff_data[key].ttff_pe) >= pe_criteria for key in
Jayakumar Munuswamy7efa25b2020-07-07 15:30:08 -07001472 ttff_data.keys()):
1473 ad.log.error("One or more TTFF %s are over test criteria %f meters",
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001474 (ttff_mode, pe_criteria))
Jayakumar Munuswamy7efa25b2020-07-07 15:30:08 -07001475 raise signals.TestFailure("GTW_GPSTool didn't process TTFF properly.")
1476 ad.log.info("All TTFF %s are within test criteria %f meters.",
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001477 (ttff_mode, pe_criteria))
jasonkmlud68fdf02020-07-23 16:18:11 +08001478
1479
1480def check_adblog_functionality(ad):
1481 """Restart adb logcat if system can't write logs into file after checking
1482 adblog file size.
1483
1484 Args:
1485 ad: An AndroidDevice object.
1486 """
1487 logcat_path = os.path.join(ad.device_log_path, "adblog_%s_debug.txt" %
1488 ad.serial)
1489 if not os.path.exists(logcat_path):
1490 raise signals.TestError("Logcat file %s does not exist." % logcat_path)
1491 original_log_size = os.path.getsize(logcat_path)
1492 ad.log.debug("Original adblog size is %d" % original_log_size)
1493 time.sleep(.5)
1494 current_log_size = os.path.getsize(logcat_path)
1495 ad.log.debug("Current adblog size is %d" % current_log_size)
1496 if current_log_size == original_log_size:
1497 ad.log.warn("System can't write logs into file. Restart adb "
1498 "logcat process now.")
1499 ad.stop_adb_logcat()
1500 ad.start_adb_logcat()
Scott Hong0f5dfc42020-08-22 00:47:53 +08001501
jasonkmluc0939182021-02-19 18:34:28 +08001502
Scott Hong0f5dfc42020-08-22 00:47:53 +08001503def build_instrumentation_call(package,
1504 runner,
1505 test_methods=None,
1506 options=None):
1507 """Build an instrumentation call for the tests
1508
1509 Args:
1510 package: A string to identify test package.
1511 runner: A string to identify test runner.
1512 test_methods: A dictionary contains {class_name, test_method}.
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001513 options: A dictionary constant {key, value} param for test.
Scott Hong0f5dfc42020-08-22 00:47:53 +08001514
1515 Returns:
1516 An instrumentation call command.
1517 """
1518 if test_methods is None:
1519 test_methods = {}
1520 cmd_builder = InstrumentationCommandBuilder()
1521 else:
1522 cmd_builder = InstrumentationTestCommandBuilder()
Scott Hong0f5dfc42020-08-22 00:47:53 +08001523 if options is None:
1524 options = {}
Scott Hong0f5dfc42020-08-22 00:47:53 +08001525 cmd_builder.set_manifest_package(package)
1526 cmd_builder.set_runner(runner)
Scott Honga2e430b2020-08-27 15:14:57 +08001527 cmd_builder.add_flag("-w")
Scott Hong0f5dfc42020-08-22 00:47:53 +08001528 for class_name, test_method in test_methods.items():
1529 cmd_builder.add_test_method(class_name, test_method)
Scott Hong0f5dfc42020-08-22 00:47:53 +08001530 for option_key, option_value in options.items():
1531 cmd_builder.add_key_value_param(option_key, option_value)
Scott Hong0f5dfc42020-08-22 00:47:53 +08001532 return cmd_builder.build()
jasonkmluc0939182021-02-19 18:34:28 +08001533
1534
1535def check_chipset_vendor_by_qualcomm(ad):
1536 """Check if cipset vendor is by Qualcomm.
1537
1538 Args:
1539 ad: An AndroidDevice object.
1540
1541 Returns:
1542 True if it's by Qualcomm. False irf not.
1543 """
1544 ad.root_adb()
1545 soc = str(ad.adb.shell("getprop gsm.version.ril-impl"))
1546 ad.log.debug("SOC = %s" % soc)
1547 return "Qualcomm" in soc
1548
1549
1550def delete_lto_file(ad):
1551 """Delete downloaded LTO files.
1552
1553 Args:
1554 ad: An AndroidDevice object.
1555 """
1556 remount_device(ad)
1557 status = ad.adb.shell("rm -rf /data/vendor/gps/lto*")
1558 ad.log.info("Delete downloaded LTO files.\n%s" % status)
1559
1560
1561def lto_mode(ad, state):
1562 """Enable or Disable LTO mode.
1563
1564 Args:
1565 ad: An AndroidDevice object.
1566 state: True to enable. False to disable.
1567 """
1568 server_list = ["LONGTERM_PSDS_SERVER_1",
1569 "LONGTERM_PSDS_SERVER_2",
1570 "LONGTERM_PSDS_SERVER_3",
1571 "NORMAL_PSDS_SERVER",
1572 "REALTIME_PSDS_SERVER"]
1573 delete_lto_file(ad)
1574 tmp_path = tempfile.mkdtemp()
1575 ad.pull_files("/etc/gps_debug.conf", tmp_path)
1576 gps_conf_path = os.path.join(tmp_path, "gps_debug.conf")
1577 gps_conf_file = open(gps_conf_path, "r")
1578 lines = gps_conf_file.readlines()
1579 gps_conf_file.close()
1580 fout = open(gps_conf_path, "w")
1581 if state:
1582 for line in lines:
1583 for server in server_list:
1584 if server in line:
1585 line = line.replace(line, "")
1586 fout.write(line)
1587 fout.close()
1588 ad.push_system_file(gps_conf_path, "/etc/gps_debug.conf")
1589 ad.log.info("Push back modified gps_debug.conf")
1590 ad.log.info("LTO/RTO/RTI enabled")
1591 else:
1592 ad.adb.shell("echo %r >> /etc/gps_debug.conf" %
1593 DISABLE_LTO_FILE_CONTENTS)
1594 ad.log.info("LTO/RTO/RTI disabled")
1595 reboot(ad)
1596
1597
1598def start_pixel_logger(ad):
1599 """adb to start pixel logger for GNSS logging.
1600
1601 Args:
1602 ad: An AndroidDevice object.
1603 """
1604 start_timeout_sec = 60
1605 start_cmd = ("am startservice -a com.android.pixellogger."
1606 "service.logging.LoggingService.ACTION_START_LOGGING "
1607 "-e intent_logger brcm_gps")
1608 begin_time = get_current_epoch_time()
1609 ad.log.info("Start Pixel Logger.")
1610 ad.adb.shell(start_cmd)
1611 while get_current_epoch_time() - begin_time <= start_timeout_sec * 1000:
1612 start_result = ad.search_logcat("startRecording", begin_time)
1613 if start_result:
1614 ad.log.info("Pixel Logger starts recording successfully.")
1615 break
1616 else:
1617 ad.log.warn("Pixel Logger fails to start recording.")
1618
1619
1620def stop_pixel_logger(ad):
1621 """adb to stop pixel logger for GNSS logging.
1622
1623 Args:
1624 ad: An AndroidDevice object.
1625 """
1626 stop_timeout_sec = 300
1627 stop_cmd = ("am startservice -a com.android.pixellogger."
1628 "service.logging.LoggingService.ACTION_STOP_LOGGING "
1629 "-e intent_logger brcm_gps")
1630 begin_time = get_current_epoch_time()
1631 ad.log.info("Stop Pixel Logger.")
1632 ad.adb.shell(stop_cmd)
1633 while get_current_epoch_time() - begin_time <= stop_timeout_sec * 1000:
1634 stop_result = ad.search_logcat("LoggingService: Stopping service",
1635 begin_time)
1636 if stop_result:
1637 ad.log.info("Pixel Logger stops successfully.")
1638 break
1639 else:
1640 ad.log.warn(
1641 "Pixel Logger fails to stop in %d seconds." % stop_timeout_sec)