blob: 7d728eeddec16757fec11a5525d43d7654c11349 [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)
jasonkmluff0d5b92019-03-21 11:24:45 +0800271 enable_supl_mode(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800272 ad.adb.shell("settings put system screen_off_timeout 1800000")
273 wutils.wifi_toggle_state(ad, False)
274 ad.log.info("Setting Bluetooth state to False")
275 ad.droid.bluetoothToggleState(False)
jasonkmluff0d5b92019-03-21 11:24:45 +0800276 check_location_service(ad)
277 set_wifi_and_bt_scanning(ad, True)
jasonkmlu214f0d62019-04-08 19:53:59 +0800278 disable_private_dns_mode(ad)
jasonkmlu180a08c2019-04-23 17:24:55 +0800279 reboot(ad)
jasonkmlu4ba30a02020-04-09 14:16:49 +0800280 init_gtw_gpstool(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800281
jasonkmlu0f546de2019-12-13 20:58:41 +0800282
jasonkmluff0d5b92019-03-21 11:24:45 +0800283def connect_to_wifi_network(ad, network):
284 """Connection logic for open and psk wifi networks.
285
286 Args:
287 ad: An AndroidDevice object.
288 network: Dictionary with network info.
289 """
290 SSID = network[WifiEnums.SSID_KEY]
jasonkmlub663d3e2019-12-30 15:11:07 +0800291 ad.ed.clear_all_events()
292 wutils.reset_wifi(ad)
293 wutils.start_wifi_connection_scan_and_ensure_network_found(ad, SSID)
jasonkmluff0d5b92019-03-21 11:24:45 +0800294 wutils.wifi_connect(ad, network, num_of_tries=5)
295
jasonkmlu0f546de2019-12-13 20:58:41 +0800296
jasonkmluff0d5b92019-03-21 11:24:45 +0800297def set_wifi_and_bt_scanning(ad, state=True):
298 """Set Wi-Fi and Bluetooth scanning on/off in Settings -> Location
299
300 Args:
301 ad: An AndroidDevice object.
jasonkmlu81b8b032019-06-21 15:18:27 +0800302 state: True to turn on "Wi-Fi and Bluetooth scanning".
303 False to turn off "Wi-Fi and Bluetooth scanning".
jasonkmluff0d5b92019-03-21 11:24:45 +0800304 """
305 ad.root_adb()
306 if state:
307 ad.adb.shell("settings put global wifi_scan_always_enabled 1")
308 ad.adb.shell("settings put global ble_scan_always_enabled 1")
309 ad.log.info("Wi-Fi and Bluetooth scanning are enabled")
310 else:
311 ad.adb.shell("settings put global wifi_scan_always_enabled 0")
312 ad.adb.shell("settings put global ble_scan_always_enabled 0")
313 ad.log.info("Wi-Fi and Bluetooth scanning are disabled")
314
jasonkmlu0f546de2019-12-13 20:58:41 +0800315
jasonkmluff0d5b92019-03-21 11:24:45 +0800316def check_location_service(ad):
317 """Set location service on.
318 Verify if location service is available.
319
320 Args:
321 ad: An AndroidDevice object.
jasonkmluff0d5b92019-03-21 11:24:45 +0800322 """
jasonkmlu81b8b032019-06-21 15:18:27 +0800323 remount_device(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800324 utils.set_location_service(ad, True)
jasonkmlu81b8b032019-06-21 15:18:27 +0800325 location_mode = int(ad.adb.shell("settings get secure location_mode"))
326 ad.log.info("Current Location Mode >> %d" % location_mode)
327 if location_mode != 3:
jasonkmlu78540632019-11-15 18:04:20 +0800328 raise signals.TestError("Failed to turn Location on")
jasonkmluff0d5b92019-03-21 11:24:45 +0800329
jasonkmlu0f546de2019-12-13 20:58:41 +0800330
jasonkmluff0d5b92019-03-21 11:24:45 +0800331def clear_logd_gnss_qxdm_log(ad):
332 """Clear /data/misc/logd,
333 /storage/emulated/0/Android/data/com.android.gpstool/files and
334 /data/vendor/radio/diag_logs/logs from previous test item then reboot.
335
336 Args:
337 ad: An AndroidDevice object.
338 """
339 remount_device(ad)
340 ad.log.info("Clear Logd, GNSS and QXDM Log from previous test item.")
341 ad.adb.shell("rm -rf /data/misc/logd", ignore_status=True)
Scott Hong0ccbc752020-10-12 14:18:49 +0800342 ad.adb.shell(
343 'find %s -name "*.txt" -type f -delete' % GNSSSTATUS_LOG_PATH,
344 ignore_status=True)
jasonkmluc0939182021-02-19 18:34:28 +0800345 if check_chipset_vendor_by_qualcomm(ad):
jasonkmlu9b278f92021-04-20 01:06:50 +0800346 diag_logs = (
347 "/sdcard/Android/data/com.android.pixellogger/files/logs/diag_logs")
348 ad.adb.shell("rm -rf %s" % diag_logs, ignore_status=True)
jasonkmluc0939182021-02-19 18:34:28 +0800349 output_path = posixpath.join(DEFAULT_QXDM_LOG_PATH, "logs")
350 else:
351 output_path = ("/sdcard/Android/data/com.android.pixellogger/files"
352 "/logs/gps/")
jasonkmluff0d5b92019-03-21 11:24:45 +0800353 ad.adb.shell("rm -rf %s" % output_path, ignore_status=True)
jasonkmlu214f0d62019-04-08 19:53:59 +0800354 reboot(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800355
jasonkmlu0f546de2019-12-13 20:58:41 +0800356
jasonkmlu81b8b032019-06-21 15:18:27 +0800357def get_gnss_qxdm_log(ad, qdb_path):
jasonkmluff0d5b92019-03-21 11:24:45 +0800358 """Get /storage/emulated/0/Android/data/com.android.gpstool/files and
jasonkmlu81b8b032019-06-21 15:18:27 +0800359 /data/vendor/radio/diag_logs/logs for test item.
jasonkmluff0d5b92019-03-21 11:24:45 +0800360
361 Args:
362 ad: An AndroidDevice object.
jasonkmlu81b8b032019-06-21 15:18:27 +0800363 qdb_path: The path of qdsp6m.qdb on different projects.
jasonkmluff0d5b92019-03-21 11:24:45 +0800364 """
jasonkmlu903ece82019-05-16 14:56:19 +0800365 log_path = ad.device_log_path
Mark De Ruyter72f8df92020-02-12 13:44:49 -0800366 os.makedirs(log_path, exist_ok=True)
jasonkmlu903ece82019-05-16 14:56:19 +0800367 gnss_log_name = "gnssstatus_log_%s_%s" % (ad.model, ad.serial)
jasonkmlu670cfbc2019-11-27 18:58:21 +0800368 gnss_log_path = posixpath.join(log_path, gnss_log_name)
Mark De Ruyter72f8df92020-02-12 13:44:49 -0800369 os.makedirs(gnss_log_path, exist_ok=True)
jasonkmluff0d5b92019-03-21 11:24:45 +0800370 ad.log.info("Pull GnssStatus Log to %s" % gnss_log_path)
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800371 ad.adb.pull("%s %s" % (GNSSSTATUS_LOG_PATH+".", gnss_log_path),
jasonkmluff0d5b92019-03-21 11:24:45 +0800372 timeout=PULL_TIMEOUT, ignore_status=True)
jasonkmlu903ece82019-05-16 14:56:19 +0800373 shutil.make_archive(gnss_log_path, "zip", gnss_log_path)
374 shutil.rmtree(gnss_log_path)
jasonkmluc0939182021-02-19 18:34:28 +0800375 if check_chipset_vendor_by_qualcomm(ad):
jasonkmlu9b278f92021-04-20 01:06:50 +0800376 output_path = (
377 "/sdcard/Android/data/com.android.pixellogger/files/logs/diag_logs")
jasonkmluc0939182021-02-19 18:34:28 +0800378 else:
jasonkmlu9b278f92021-04-20 01:06:50 +0800379 output_path = (
380 "/sdcard/Android/data/com.android.pixellogger/files/logs/gps/")
381 file_count = ad.adb.shell(
382 "find %s -type f -iname *.zip | wc -l" % output_path)
jasonkmluff0d5b92019-03-21 11:24:45 +0800383 if not int(file_count) == 0:
jasonkmlu903ece82019-05-16 14:56:19 +0800384 qxdm_log_name = "QXDM_%s_%s" % (ad.model, ad.serial)
jasonkmlu670cfbc2019-11-27 18:58:21 +0800385 qxdm_log_path = posixpath.join(log_path, qxdm_log_name)
Mark De Ruyter72f8df92020-02-12 13:44:49 -0800386 os.makedirs(qxdm_log_path, exist_ok=True)
jasonkmluff0d5b92019-03-21 11:24:45 +0800387 ad.log.info("Pull QXDM Log %s to %s" % (output_path, qxdm_log_path))
388 ad.adb.pull("%s %s" % (output_path, qxdm_log_path),
389 timeout=PULL_TIMEOUT, ignore_status=True)
jasonkmlu81b8b032019-06-21 15:18:27 +0800390 for path in qdb_path:
391 output = ad.adb.pull("%s %s" % (path, qxdm_log_path),
392 timeout=PULL_TIMEOUT, ignore_status=True)
393 if "No such file or directory" in output:
394 continue
395 break
jasonkmlu903ece82019-05-16 14:56:19 +0800396 shutil.make_archive(qxdm_log_path, "zip", qxdm_log_path)
397 shutil.rmtree(qxdm_log_path)
jasonkmluff0d5b92019-03-21 11:24:45 +0800398 else:
399 ad.log.error("QXDM file count is %d. There is no QXDM log on device."
400 % int(file_count))
401
jasonkmlu0f546de2019-12-13 20:58:41 +0800402
jasonkmluff0d5b92019-03-21 11:24:45 +0800403def set_mobile_data(ad, state):
404 """Set mobile data on or off and check mobile data state.
405
406 Args:
407 ad: An AndroidDevice object.
408 state: True to enable mobile data. False to disable mobile data.
409 """
410 ad.root_adb()
411 if state:
412 ad.log.info("Enable mobile data.")
413 ad.adb.shell("svc data enable")
414 else:
415 ad.log.info("Disable mobile data.")
416 ad.adb.shell("svc data disable")
417 time.sleep(5)
418 out = int(ad.adb.shell("settings get global mobile_data"))
419 if state and out == 1:
420 ad.log.info("Mobile data is enabled and set to %d" % out)
421 elif not state and out == 0:
422 ad.log.info("Mobile data is disabled and set to %d" % out)
423 else:
424 ad.log.error("Mobile data is at unknown state and set to %d" % out)
425
jasonkmlu0f546de2019-12-13 20:58:41 +0800426
jasonkmlu78540632019-11-15 18:04:20 +0800427def gnss_trigger_modem_ssr_by_adb(ad, dwelltime=60):
428 """Trigger modem SSR crash by adb and verify if modem crash and recover
jasonkmlu035eee12019-10-08 17:11:20 +0800429 successfully.
jasonkmluff0d5b92019-03-21 11:24:45 +0800430
431 Args:
432 ad: An AndroidDevice object.
jasonkmlu78540632019-11-15 18:04:20 +0800433 dwelltime: Waiting time for modem reset. Default is 60 seconds.
jasonkmluff0d5b92019-03-21 11:24:45 +0800434
435 Returns:
jasonkmlu81b8b032019-06-21 15:18:27 +0800436 True if success.
437 False if failed.
jasonkmluff0d5b92019-03-21 11:24:45 +0800438 """
jasonkmlu81b8b032019-06-21 15:18:27 +0800439 begin_time = get_current_epoch_time()
440 ad.root_adb()
441 cmds = ("echo restart > /sys/kernel/debug/msm_subsys/modem",
442 r"echo 'at+cfun=1,1\r' > /dev/at_mdm0")
443 for cmd in cmds:
444 ad.log.info("Triggering modem SSR crash by %s" % cmd)
445 output = ad.adb.shell(cmd, ignore_status=True)
446 if "No such file or directory" in output:
447 continue
448 break
449 time.sleep(dwelltime)
jasonkmluff0d5b92019-03-21 11:24:45 +0800450 ad.send_keycode("HOME")
jasonkmlu81b8b032019-06-21 15:18:27 +0800451 logcat_results = ad.search_logcat("SSRObserver", begin_time)
452 if logcat_results:
453 for ssr in logcat_results:
454 if "mSubsystem='modem', mCrashReason" in ssr["log_message"]:
455 ad.log.debug(ssr["log_message"])
456 ad.log.info("Triggering modem SSR crash successfully.")
457 return True
jasonkmlu78540632019-11-15 18:04:20 +0800458 raise signals.TestError("Failed to trigger modem SSR crash")
459 raise signals.TestError("No SSRObserver found in logcat")
460
jasonkmlu0f546de2019-12-13 20:58:41 +0800461
jasonkmlu78540632019-11-15 18:04:20 +0800462def gnss_trigger_modem_ssr_by_mds(ad, dwelltime=60):
463 """Trigger modem SSR crash by mds tool and verify if modem crash and recover
464 successfully.
465
466 Args:
467 ad: An AndroidDevice object.
468 dwelltime: Waiting time for modem reset. Default is 60 seconds.
469 """
470 mds_check = ad.adb.shell("pm path com.google.mdstest")
471 if not mds_check:
472 raise signals.TestError("MDS Tool is not properly installed.")
473 ad.root_adb()
474 cmd = ('am instrument -w -e request "4b 25 03 00" '
475 '"com.google.mdstest/com.google.mdstest.instrument'
476 '.ModemCommandInstrumentation"')
477 ad.log.info("Triggering modem SSR crash by MDS")
478 output = ad.adb.shell(cmd, ignore_status=True)
479 ad.log.debug(output)
480 time.sleep(dwelltime)
481 ad.send_keycode("HOME")
482 if "SUCCESS" in output:
483 ad.log.info("Triggering modem SSR crash by MDS successfully.")
484 else:
485 raise signals.TestError(
486 "Failed to trigger modem SSR crash by MDS. \n%s" % output)
487
jasonkmlu0f546de2019-12-13 20:58:41 +0800488
jasonkmluff0d5b92019-03-21 11:24:45 +0800489def check_xtra_download(ad, begin_time):
490 """Verify XTRA download success log message in logcat.
491
492 Args:
493 ad: An AndroidDevice object.
494 begin_time: test begin time
495
496 Returns:
497 True: xtra_download if XTRA downloaded and injected successfully
498 otherwise return False.
499 """
500 ad.send_keycode("HOME")
jasonkmluc0939182021-02-19 18:34:28 +0800501 if check_chipset_vendor_by_qualcomm(ad):
502 xtra_results = ad.search_logcat("XTRA download success. "
503 "inject data into modem", begin_time)
504 if xtra_results:
505 ad.log.debug("%s" % xtra_results[-1]["log_message"])
506 ad.log.info("XTRA downloaded and injected successfully.")
507 return True
508 ad.log.error("XTRA downloaded FAIL.")
509 else:
510 lto_results = ad.search_logcat("GnssPsdsAidl: injectPsdsData: "
511 "psdsType: 1", begin_time)
512 if lto_results:
513 ad.log.debug("%s" % lto_results[-1]["log_message"])
514 ad.log.info("LTO downloaded and injected successfully.")
515 return True
516 ad.log.error("LTO downloaded and inject FAIL.")
jasonkmluff0d5b92019-03-21 11:24:45 +0800517 return False
518
jasonkmlu0f546de2019-12-13 20:58:41 +0800519
jasonkmlu5e7817c2020-05-08 14:06:43 +0800520def pull_package_apk(ad, package_name):
521 """Pull apk of given package_name from device.
jasonkmluff0d5b92019-03-21 11:24:45 +0800522
523 Args:
524 ad: An AndroidDevice object.
jasonkmlu5e7817c2020-05-08 14:06:43 +0800525 package_name: Package name of apk to pull.
526
527 Returns:
528 The temp path of pulled apk.
jasonkmluff0d5b92019-03-21 11:24:45 +0800529 """
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800530 apk_path = None
jasonkmlu5e7817c2020-05-08 14:06:43 +0800531 out = ad.adb.shell("pm path %s" % package_name)
jasonkmluff0d5b92019-03-21 11:24:45 +0800532 result = re.search(r"package:(.*)", out)
533 if not result:
jasonkmlu5e7817c2020-05-08 14:06:43 +0800534 tutils.abort_all_tests(ad.log, "Couldn't find apk of %s" % package_name)
jasonkmluff0d5b92019-03-21 11:24:45 +0800535 else:
jasonkmlu5e7817c2020-05-08 14:06:43 +0800536 apk_source = result.group(1)
537 ad.log.info("Get apk of %s from %s" % (package_name, apk_source))
538 apk_path = tempfile.mkdtemp()
539 ad.pull_files([apk_source], apk_path)
540 return apk_path
jasonkmluff0d5b92019-03-21 11:24:45 +0800541
jasonkmlu0f546de2019-12-13 20:58:41 +0800542
jasonkmlu5e7817c2020-05-08 14:06:43 +0800543def reinstall_package_apk(ad, package_name, apk_path):
544 """Reinstall apk of given package_name.
jasonkmluff0d5b92019-03-21 11:24:45 +0800545
546 Args:
547 ad: An AndroidDevice object.
jasonkmlu5e7817c2020-05-08 14:06:43 +0800548 package_name: Package name of apk.
549 apk_path: The temp path of pulled apk.
jasonkmluff0d5b92019-03-21 11:24:45 +0800550 """
jasonkmlu5e7817c2020-05-08 14:06:43 +0800551 for path_key in os.listdir(apk_path):
552 if fnmatch.fnmatch(path_key, "*.apk"):
553 apk_path = os.path.join(apk_path, path_key)
554 break
555 else:
556 raise signals.TestError("No apk is found in %s" % apk_path)
557 ad.log.info("Re-install %s with path: %s" % (package_name, apk_path))
558 ad.adb.shell("settings put global verifier_verify_adb_installs 0")
559 ad.adb.install("-r -d -g --user 0 %s" % apk_path)
560 package_check = ad.adb.shell("pm path %s" % package_name)
561 if not package_check:
562 tutils.abort_all_tests(
563 ad.log, "%s is not properly re-installed." % package_name)
564 ad.log.info("%s is re-installed successfully." % package_name)
jasonkmluff0d5b92019-03-21 11:24:45 +0800565
jasonkmlu0f546de2019-12-13 20:58:41 +0800566
jasonkmlu180a08c2019-04-23 17:24:55 +0800567def init_gtw_gpstool(ad):
568 """Init GTW_GPSTool apk.
569
570 Args:
571 ad: An AndroidDevice object.
572 """
573 remount_device(ad)
jasonkmlu5e7817c2020-05-08 14:06:43 +0800574 gpstool_path = pull_package_apk(ad, "com.android.gpstool")
575 reinstall_package_apk(ad, "com.android.gpstool", gpstool_path)
jasonkmlu180a08c2019-04-23 17:24:55 +0800576
jasonkmlu0f546de2019-12-13 20:58:41 +0800577
jasonkmluff0d5b92019-03-21 11:24:45 +0800578def fastboot_factory_reset(ad):
579 """Factory reset the device in fastboot mode.
580 Pull sl4a apk from device. Terminate all sl4a sessions,
581 Reboot the device to bootloader,
582 factory reset the device by fastboot.
583 Reboot the device. wait for device to complete booting
584 Re-install and start an sl4a session.
585
586 Args:
587 ad: An AndroidDevice object.
588
589 Returns:
590 True if factory reset process complete.
591 """
592 status = True
593 skip_setup_wizard = True
jasonkmlu5e7817c2020-05-08 14:06:43 +0800594 sl4a_path = pull_package_apk(ad, SL4A_APK_NAME)
595 gpstool_path = pull_package_apk(ad, "com.android.gpstool")
596 mds_path = pull_package_apk(ad, "com.google.mdstest")
jasonkmluff0d5b92019-03-21 11:24:45 +0800597 tutils.stop_qxdm_logger(ad)
598 ad.stop_services()
599 attempts = 3
600 for i in range(1, attempts + 1):
601 try:
602 if ad.serial in list_adb_devices():
603 ad.log.info("Reboot to bootloader")
604 ad.adb.reboot("bootloader", ignore_status=True)
605 time.sleep(10)
606 if ad.serial in list_fastboot_devices():
607 ad.log.info("Factory reset in fastboot")
608 ad.fastboot._w(timeout=300, ignore_status=True)
609 time.sleep(30)
610 ad.log.info("Reboot in fastboot")
611 ad.fastboot.reboot()
612 ad.wait_for_boot_completion()
613 ad.root_adb()
614 if ad.skip_sl4a:
615 break
616 if ad.is_sl4a_installed():
617 break
jasonkmlu5e7817c2020-05-08 14:06:43 +0800618 reinstall_package_apk(ad, SL4A_APK_NAME, sl4a_path)
619 reinstall_package_apk(ad, "com.android.gpstool", gpstool_path)
620 reinstall_package_apk(ad, "com.google.mdstest", mds_path)
jasonkmluff0d5b92019-03-21 11:24:45 +0800621 time.sleep(10)
622 break
623 except Exception as e:
624 ad.log.error(e)
625 if i == attempts:
626 tutils.abort_all_tests(ad.log, str(e))
627 time.sleep(5)
628 try:
629 ad.start_adb_logcat()
630 except Exception as e:
631 ad.log.error(e)
632 if skip_setup_wizard:
633 ad.exit_setup_wizard()
634 if ad.skip_sl4a:
635 return status
636 tutils.bring_up_sl4a(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800637 return status
638
jasonkmlu0f546de2019-12-13 20:58:41 +0800639
jasonkmluff0d5b92019-03-21 11:24:45 +0800640def clear_aiding_data_by_gtw_gpstool(ad):
641 """Launch GTW GPSTool and Clear all GNSS aiding data.
642 Wait 5 seconds for GTW GPStool to clear all GNSS aiding
643 data properly.
644
645 Args:
646 ad: An AndroidDevice object.
647 """
jasonkmluc0939182021-02-19 18:34:28 +0800648 if not check_chipset_vendor_by_qualcomm(ad):
649 delete_lto_file(ad)
jasonkmluff0d5b92019-03-21 11:24:45 +0800650 ad.log.info("Launch GTW GPSTool and Clear all GNSS aiding data")
651 ad.adb.shell("am start -S -n com.android.gpstool/.GPSTool --es mode clear")
652 time.sleep(10)
653
Jayakumar Munuswamybc6038c2019-10-30 14:46:38 -0700654
Scott Honga2e430b2020-08-27 15:14:57 +0800655def start_gnss_by_gtw_gpstool(ad,
656 state,
657 type="gnss",
658 bgdisplay=False,
659 freq=0,
660 lowpower=False,
661 meas=False):
jasonkmluff0d5b92019-03-21 11:24:45 +0800662 """Start or stop GNSS on GTW_GPSTool.
663
664 Args:
665 ad: An AndroidDevice object.
666 state: True to start GNSS. False to Stop GNSS.
jasonkmlu81b8b032019-06-21 15:18:27 +0800667 type: Different API for location fix. Use gnss/flp/nmea
Scott Honga2e430b2020-08-27 15:14:57 +0800668 bgdisplay: true to run GTW when Display off. false to not run GTW when
669 Display off.
670 freq: An integer to set location update frequency.
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800671 meas: A Boolean to set GNSS measurement registration.
Scott Honga2e430b2020-08-27 15:14:57 +0800672 lowpower: A boolean to set GNSS LowPowerMode.
jasonkmluff0d5b92019-03-21 11:24:45 +0800673 """
Scott Honga2e430b2020-08-27 15:14:57 +0800674 cmd = "am start -S -n com.android.gpstool/.GPSTool --es mode gps"
jasonkmluff0d5b92019-03-21 11:24:45 +0800675 if not state:
jasonkmlu81b8b032019-06-21 15:18:27 +0800676 ad.log.info("Stop %s on GTW_GPSTool." % type)
Scott Honga2e430b2020-08-27 15:14:57 +0800677 cmd = "am broadcast -a com.android.gpstool.stop_gps_action"
678 else:
679 options = ("--es type {} --ei freq {} --ez BG {} --ez meas {} --ez "
680 "lowpower {}").format(type, freq, bgdisplay, meas, lowpower)
681 cmd = cmd + " " + options
Scott Honga2e430b2020-08-27 15:14:57 +0800682 ad.adb.shell(cmd)
jasonkmluff0d5b92019-03-21 11:24:45 +0800683 time.sleep(3)
684
Jayakumar Munuswamybc6038c2019-10-30 14:46:38 -0700685
jasonkmlu8721ced2020-10-26 14:37:46 +0800686def process_gnss_by_gtw_gpstool(ad,
687 criteria,
688 type="gnss",
689 clear_data=True,
690 meas_flag=False):
jasonkmluff0d5b92019-03-21 11:24:45 +0800691 """Launch GTW GPSTool and Clear all GNSS aiding data
692 Start GNSS tracking on GTW_GPSTool.
693
694 Args:
695 ad: An AndroidDevice object.
696 criteria: Criteria for current test item.
jasonkmlu81b8b032019-06-21 15:18:27 +0800697 type: Different API for location fix. Use gnss/flp/nmea
jasonkmlu8721ced2020-10-26 14:37:46 +0800698 clear_data: True to clear GNSS aiding data. False is not to. Default
jasonkmlu5a385f22020-06-08 17:14:15 +0800699 set to True.
jasonkmlu8721ced2020-10-26 14:37:46 +0800700 meas_flag: True to enable GnssMeasurement. False is not to. Default
701 set to False.
jasonkmluff0d5b92019-03-21 11:24:45 +0800702
703 Returns:
704 True: First fix TTFF are within criteria.
705 False: First fix TTFF exceed criteria.
706 """
707 retries = 3
708 for i in range(retries):
jasonkmlud68fdf02020-07-23 16:18:11 +0800709 if not ad.is_adb_logcat_on:
710 ad.start_adb_logcat()
711 check_adblog_functionality(ad)
jasonkmlu4ba30a02020-04-09 14:16:49 +0800712 check_location_runtime_permissions(
713 ad, GNSSTOOL_PACKAGE_NAME, GNSSTOOL_PERMISSIONS)
jasonkmluff0d5b92019-03-21 11:24:45 +0800714 begin_time = get_current_epoch_time()
jasonkmlu5a385f22020-06-08 17:14:15 +0800715 if clear_data:
716 clear_aiding_data_by_gtw_gpstool(ad)
jasonkmlu035eee12019-10-08 17:11:20 +0800717 ad.log.info("Start %s on GTW_GPSTool - attempt %d" % (type.upper(),
718 i+1))
jasonkmlu8721ced2020-10-26 14:37:46 +0800719 start_gnss_by_gtw_gpstool(ad, state=True, type=type, meas=meas_flag)
jasonkmluff0d5b92019-03-21 11:24:45 +0800720 for _ in range(10 + criteria):
721 logcat_results = ad.search_logcat("First fixed", begin_time)
722 if logcat_results:
jasonkmlu81b8b032019-06-21 15:18:27 +0800723 ad.log.debug(logcat_results[-1]["log_message"])
jasonkmluff0d5b92019-03-21 11:24:45 +0800724 first_fixed = int(logcat_results[-1]["log_message"].split()[-1])
jasonkmlu81b8b032019-06-21 15:18:27 +0800725 ad.log.info("%s First fixed = %.3f seconds" %
726 (type.upper(), first_fixed/1000))
727 if (first_fixed/1000) <= criteria:
jasonkmluff0d5b92019-03-21 11:24:45 +0800728 return True
jasonkmlu8721ced2020-10-26 14:37:46 +0800729 start_gnss_by_gtw_gpstool(ad, state=False, type=type)
jasonkmlu035eee12019-10-08 17:11:20 +0800730 raise signals.TestFailure("Fail to get %s location fixed "
731 "within %d seconds criteria."
732 % (type.upper(), criteria))
jasonkmluff0d5b92019-03-21 11:24:45 +0800733 time.sleep(1)
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800734 check_current_focus_app(ad)
jasonkmlu8721ced2020-10-26 14:37:46 +0800735 start_gnss_by_gtw_gpstool(ad, state=False, type=type)
jasonkmlu035eee12019-10-08 17:11:20 +0800736 raise signals.TestFailure("Fail to get %s location fixed within %d "
737 "attempts." % (type.upper(), retries))
jasonkmluff0d5b92019-03-21 11:24:45 +0800738
Scott Hong72269692019-12-16 16:59:56 +0800739def start_ttff_by_gtw_gpstool(ad, ttff_mode, iteration, aid_data=False):
jasonkmluff0d5b92019-03-21 11:24:45 +0800740 """Identify which TTFF mode for different test items.
741
742 Args:
743 ad: An AndroidDevice object.
744 ttff_mode: TTFF Test mode for current test item.
745 iteration: Iteration of TTFF cycles.
Scott Hong72269692019-12-16 16:59:56 +0800746 aid_data: Boolean for identify aid_data existed or not
jasonkmluff0d5b92019-03-21 11:24:45 +0800747 """
jasonkmlu97ac56e2019-05-29 15:04:51 +0800748 begin_time = get_current_epoch_time()
Scott Hong72269692019-12-16 16:59:56 +0800749 if (ttff_mode == "hs" or ttff_mode == "ws") and not aid_data:
jasonkmlu81b8b032019-06-21 15:18:27 +0800750 ad.log.info("Wait 5 minutes to start TTFF %s..." % ttff_mode.upper())
jasonkmluff0d5b92019-03-21 11:24:45 +0800751 time.sleep(300)
752 if ttff_mode == "cs":
753 ad.log.info("Start TTFF Cold Start...")
754 time.sleep(3)
jasonkmlu97ac56e2019-05-29 15:04:51 +0800755 for i in range(1, 4):
756 ad.adb.shell("am broadcast -a com.android.gpstool.ttff_action "
757 "--es ttff %s --es cycle %d" % (ttff_mode, iteration))
jasonkmlu81b8b032019-06-21 15:18:27 +0800758 time.sleep(1)
jasonkmlu97ac56e2019-05-29 15:04:51 +0800759 if ad.search_logcat("act=com.android.gpstool.start_test_action",
760 begin_time):
761 ad.log.info("Send TTFF start_test_action successfully.")
762 break
jasonkmlu035eee12019-10-08 17:11:20 +0800763 else:
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800764 check_current_focus_app(ad)
jasonkmlu78540632019-11-15 18:04:20 +0800765 raise signals.TestError("Fail to send TTFF start_test_action.")
jasonkmluff0d5b92019-03-21 11:24:45 +0800766
jasonkmlu0f546de2019-12-13 20:58:41 +0800767
jasonkmlu8721ced2020-10-26 14:37:46 +0800768def gnss_tracking_via_gtw_gpstool(ad,
769 criteria,
770 type="gnss",
771 testtime=60,
772 meas_flag=False):
jasonkmlu66fda532019-07-16 11:12:45 +0800773 """Start GNSS/FLP tracking tests for input testtime on GTW_GPSTool.
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800774
775 Args:
776 ad: An AndroidDevice object.
777 criteria: Criteria for current TTFF.
778 type: Different API for location fix. Use gnss/flp/nmea
779 testtime: Tracking test time for minutes. Default set to 60 minutes.
jasonkmlu8721ced2020-10-26 14:37:46 +0800780 meas_flag: True to enable GnssMeasurement. False is not to. Default
781 set to False.
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800782 """
jasonkmlu3fcdc2b2021-03-22 19:35:48 +0800783 gnss_crash_list = [".*Fatal signal.*gnss",
784 ".*Fatal signal.*xtra",
785 ".*F DEBUG.*gnss"]
jasonkmlu8721ced2020-10-26 14:37:46 +0800786 process_gnss_by_gtw_gpstool(
787 ad, criteria=criteria, type=type, meas_flag=meas_flag)
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800788 ad.log.info("Start %s tracking test for %d minutes" % (type.upper(),
789 testtime))
790 begin_time = get_current_epoch_time()
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800791 while get_current_epoch_time() - begin_time < testtime * 60 * 1000:
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800792 if not ad.is_adb_logcat_on:
793 ad.start_adb_logcat()
jasonkmlu3fcdc2b2021-03-22 19:35:48 +0800794 for attr in gnss_crash_list:
795 gnss_crash_result = ad.adb.shell(
796 "logcat -d | grep -E -i '%s'" % attr)
797 if gnss_crash_result:
798 start_gnss_by_gtw_gpstool(ad, state=False, type=type)
799 raise signals.TestFailure(
800 "Test failed due to GNSS HAL crashed. \n%s" %
801 gnss_crash_result)
802 gpstool_crash_result = ad.search_logcat("Force finishing activity "
803 "com.android.gpstool/.GPSTool",
804 begin_time)
805 if gpstool_crash_result:
jasonkmlu78540632019-11-15 18:04:20 +0800806 raise signals.TestError("GPSTool crashed. Abort test.")
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800807 ad.log.info("Successfully tested for %d minutes" % testtime)
jasonkmlu8721ced2020-10-26 14:37:46 +0800808 start_gnss_by_gtw_gpstool(ad, state=False, type=type)
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800809
jasonkmlu0f546de2019-12-13 20:58:41 +0800810
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800811def parse_gtw_gpstool_log(ad, true_position, type="gnss"):
812 """Process GNSS/FLP API logs from GTW GPSTool and output track_data to
813 test_run_info for ACTS plugin to parse and display on MobileHarness as
814 Property.
815
816 Args:
817 ad: An AndroidDevice object.
818 true_position: Coordinate as [latitude, longitude] to calculate
819 position error.
820 type: Different API for location fix. Use gnss/flp/nmea
821 """
822 test_logfile = {}
823 track_data = {}
jasonkmlucb654ac2020-07-01 11:08:33 +0800824 ant_top4_cn = 0
825 ant_cn = 0
826 base_top4_cn = 0
827 base_cn = 0
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800828 track_lat = 0
829 track_long = 0
jasonkmlu035eee12019-10-08 17:11:20 +0800830 l5flag = "false"
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800831 file_count = int(ad.adb.shell("find %s -type f -iname *.txt | wc -l"
832 % GNSSSTATUS_LOG_PATH))
833 if file_count != 1:
834 ad.log.error("%d API logs exist." % file_count)
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800835 dir_file = ad.adb.shell("ls %s" % GNSSSTATUS_LOG_PATH).split()
836 for path_key in dir_file:
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800837 if fnmatch.fnmatch(path_key, "*.txt"):
838 logpath = posixpath.join(GNSSSTATUS_LOG_PATH, path_key)
839 out = ad.adb.shell("wc -c %s" % logpath)
840 file_size = int(out.split(" ")[0])
841 if file_size < 2000:
842 ad.log.info("Skip log %s due to log size %d bytes" %
843 (path_key, file_size))
844 continue
845 test_logfile = logpath
846 if not test_logfile:
jasonkmlu78540632019-11-15 18:04:20 +0800847 raise signals.TestError("Failed to get test log file in device.")
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800848 lines = ad.adb.shell("cat %s" % test_logfile).split("\n")
849 for line in lines:
jasonkmlucb654ac2020-07-01 11:08:33 +0800850 if "Antenna_History Avg Top4" in line:
851 ant_top4_cn = float(line.split(":")[-1].strip())
852 elif "Antenna_History Avg" in line:
853 ant_cn = float(line.split(":")[-1].strip())
854 elif "Baseband_History Avg Top4" in line:
855 base_top4_cn = float(line.split(":")[-1].strip())
856 elif "Baseband_History Avg" in line:
857 base_cn = float(line.split(":")[-1].strip())
858 elif "L5 used in fix" in line:
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800859 l5flag = line.split(":")[-1].strip()
jasonkmlucb654ac2020-07-01 11:08:33 +0800860 elif "Latitude" in line:
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800861 track_lat = float(line.split(":")[-1].strip())
jasonkmlucb654ac2020-07-01 11:08:33 +0800862 elif "Longitude" in line:
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800863 track_long = float(line.split(":")[-1].strip())
jasonkmlucb654ac2020-07-01 11:08:33 +0800864 elif "Time" in line:
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800865 track_utc = line.split("Time:")[-1].strip()
866 if track_utc in track_data.keys():
867 continue
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800868 pe = calculate_position_error(track_lat, track_long, true_position)
jasonkmlucb654ac2020-07-01 11:08:33 +0800869 track_data[track_utc] = TRACK_REPORT(l5flag=l5flag,
870 pe=pe,
871 ant_top4cn=ant_top4_cn,
872 ant_cn=ant_cn,
873 base_top4cn=base_top4_cn,
874 base_cn=base_cn)
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800875 ad.log.debug(track_data)
876 prop_basename = "TestResult %s_tracking_" % type.upper()
877 time_list = sorted(track_data.keys())
jasonkmlucb654ac2020-07-01 11:08:33 +0800878 l5flag_list = [track_data[key].l5flag for key in time_list]
879 pe_list = [float(track_data[key].pe) for key in time_list]
880 ant_top4cn_list = [float(track_data[key].ant_top4cn) for key in time_list]
881 ant_cn_list = [float(track_data[key].ant_cn) for key in time_list]
882 base_top4cn_list = [float(track_data[key].base_top4cn) for key in time_list]
883 base_cn_list = [float(track_data[key].base_cn) for key in time_list]
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800884 ad.log.info(prop_basename+"StartTime %s" % time_list[0].replace(" ", "-"))
885 ad.log.info(prop_basename+"EndTime %s" % time_list[-1].replace(" ", "-"))
886 ad.log.info(prop_basename+"TotalFixPoints %d" % len(time_list))
887 ad.log.info(prop_basename+"L5FixRate "+'{percent:.2%}'.format(
888 percent=l5flag_list.count("true")/len(l5flag_list)))
889 ad.log.info(prop_basename+"AvgDis %.1f" % (sum(pe_list)/len(pe_list)))
890 ad.log.info(prop_basename+"MaxDis %.1f" % max(pe_list))
jasonkmlucb654ac2020-07-01 11:08:33 +0800891 ad.log.info(prop_basename+"Ant_AvgTop4Signal %.1f" % ant_top4cn_list[-1])
892 ad.log.info(prop_basename+"Ant_AvgSignal %.1f" % ant_cn_list[-1])
893 ad.log.info(prop_basename+"Base_AvgTop4Signal %.1f" % base_top4cn_list[-1])
894 ad.log.info(prop_basename+"Base_AvgSignal %.1f" % base_cn_list[-1])
jasonkmlu4fcdcad2019-07-10 14:35:12 +0800895
jasonkmlu0f546de2019-12-13 20:58:41 +0800896
jasonkmlu81b8b032019-06-21 15:18:27 +0800897def process_ttff_by_gtw_gpstool(ad, begin_time, true_position, type="gnss"):
898 """Process TTFF and record results in ttff_data.
jasonkmluff0d5b92019-03-21 11:24:45 +0800899
900 Args:
901 ad: An AndroidDevice object.
jasonkmlu903ece82019-05-16 14:56:19 +0800902 begin_time: test begin time.
jasonkmlu733738f2019-09-02 18:59:42 +0800903 true_position: Coordinate as [latitude, longitude] to calculate
904 position error.
jasonkmlu81b8b032019-06-21 15:18:27 +0800905 type: Different API for location fix. Use gnss/flp/nmea
jasonkmluff0d5b92019-03-21 11:24:45 +0800906
907 Returns:
jasonkmlu81b8b032019-06-21 15:18:27 +0800908 ttff_data: A dict of all TTFF data.
jasonkmluff0d5b92019-03-21 11:24:45 +0800909 """
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800910 ttff_lat = 0
911 ttff_lon = 0
912 utc_time = epoch_to_human_time(get_current_epoch_time())
jasonkmlu903ece82019-05-16 14:56:19 +0800913 ttff_data = {}
jasonkmlu733738f2019-09-02 18:59:42 +0800914 ttff_loop_time = get_current_epoch_time()
jasonkmlu97ac56e2019-05-29 15:04:51 +0800915 while True:
jasonkmlu733738f2019-09-02 18:59:42 +0800916 if get_current_epoch_time() - ttff_loop_time >= 120000:
jasonkmlu78540632019-11-15 18:04:20 +0800917 raise signals.TestError("Fail to search specific GPSService "
918 "message in logcat. Abort test.")
jasonkmlu97ac56e2019-05-29 15:04:51 +0800919 if not ad.is_adb_logcat_on:
920 ad.start_adb_logcat()
jasonkmlu61b686f2020-07-20 20:07:04 +0800921 logcat_results = ad.search_logcat("write TTFF log", ttff_loop_time)
jasonkmlu97ac56e2019-05-29 15:04:51 +0800922 if logcat_results:
jasonkmlu61b686f2020-07-20 20:07:04 +0800923 ttff_loop_time = get_current_epoch_time()
jasonkmlu97ac56e2019-05-29 15:04:51 +0800924 ttff_log = logcat_results[-1]["log_message"].split()
925 ttff_loop = int(ttff_log[8].split(":")[-1])
jasonkmlu81b8b032019-06-21 15:18:27 +0800926 ttff_sec = float(ttff_log[11])
927 if ttff_sec != 0.0:
jasonkmlucb654ac2020-07-01 11:08:33 +0800928 ttff_ant_cn = float(ttff_log[18].strip("]"))
929 ttff_base_cn = float(ttff_log[25].strip("]"))
jasonkmlu81b8b032019-06-21 15:18:27 +0800930 if type == "gnss":
jasonkmlu733738f2019-09-02 18:59:42 +0800931 gnss_results = ad.search_logcat("GPSService: Check item",
932 begin_time)
jasonkmlu81b8b032019-06-21 15:18:27 +0800933 if gnss_results:
934 ad.log.debug(gnss_results[-1]["log_message"])
jasonkmlu733738f2019-09-02 18:59:42 +0800935 gnss_location_log = \
936 gnss_results[-1]["log_message"].split()
937 ttff_lat = float(
938 gnss_location_log[8].split("=")[-1].strip(","))
939 ttff_lon = float(
940 gnss_location_log[9].split("=")[-1].strip(","))
jasonkmlucb654ac2020-07-01 11:08:33 +0800941 loc_time = int(
942 gnss_location_log[10].split("=")[-1].strip(","))
943 utc_time = epoch_to_human_time(loc_time)
jasonkmlu81b8b032019-06-21 15:18:27 +0800944 elif type == "flp":
jasonkmlu733738f2019-09-02 18:59:42 +0800945 flp_results = ad.search_logcat("GPSService: FLP Location",
946 begin_time)
jasonkmlu81b8b032019-06-21 15:18:27 +0800947 if flp_results:
948 ad.log.debug(flp_results[-1]["log_message"])
jasonkmlucb654ac2020-07-01 11:08:33 +0800949 flp_location_log = flp_results[-1][
950 "log_message"].split()
jasonkmlu81b8b032019-06-21 15:18:27 +0800951 ttff_lat = float(flp_location_log[8].split(",")[0])
952 ttff_lon = float(flp_location_log[8].split(",")[1])
jasonkmlucb654ac2020-07-01 11:08:33 +0800953 utc_time = epoch_to_human_time(get_current_epoch_time())
jasonkmlu81b8b032019-06-21 15:18:27 +0800954 else:
jasonkmlucb654ac2020-07-01 11:08:33 +0800955 ttff_ant_cn = float(ttff_log[19].strip("]"))
956 ttff_base_cn = float(ttff_log[26].strip("]"))
957 ttff_lat = 0
958 ttff_lon = 0
959 utc_time = epoch_to_human_time(get_current_epoch_time())
jasonkmlu2565d892019-11-12 15:31:26 +0800960 ad.log.debug("TTFF Loop %d - (Lat, Lon) = (%s, %s)" % (ttff_loop,
961 ttff_lat,
962 ttff_lon))
jasonkmlu6ea2a2b2020-11-02 13:29:41 +0800963 ttff_pe = calculate_position_error(
964 ttff_lat, ttff_lon, true_position)
jasonkmlucb654ac2020-07-01 11:08:33 +0800965 ttff_data[ttff_loop] = TTFF_REPORT(utc_time=utc_time,
966 ttff_loop=ttff_loop,
jasonkmlu97ac56e2019-05-29 15:04:51 +0800967 ttff_sec=ttff_sec,
968 ttff_pe=ttff_pe,
jasonkmlucb654ac2020-07-01 11:08:33 +0800969 ttff_ant_cn=ttff_ant_cn,
970 ttff_base_cn=ttff_base_cn)
971 ad.log.info("UTC Time = %s, Loop %d = %.1f seconds, "
jasonkmlu97ac56e2019-05-29 15:04:51 +0800972 "Position Error = %.1f meters, "
jasonkmlucb654ac2020-07-01 11:08:33 +0800973 "Antenna Average Signal = %.1f dbHz, "
974 "Baseband Average Signal = %.1f dbHz" % (utc_time,
975 ttff_loop,
976 ttff_sec,
977 ttff_pe,
978 ttff_ant_cn,
979 ttff_base_cn))
980 stop_gps_results = ad.search_logcat("stop gps test", begin_time)
981 if stop_gps_results:
982 ad.send_keycode("HOME")
983 break
984 crash_result = ad.search_logcat("Force finishing activity "
985 "com.android.gpstool/.GPSTool",
986 begin_time)
987 if crash_result:
988 raise signals.TestError("GPSTool crashed. Abort test.")
jasonkmlu9b278f92021-04-20 01:06:50 +0800989 # wait 5 seconds to avoid logs not writing into logcat yet
990 time.sleep(5)
jasonkmlu97ac56e2019-05-29 15:04:51 +0800991 return ttff_data
jasonkmluff0d5b92019-03-21 11:24:45 +0800992
jasonkmlu0f546de2019-12-13 20:58:41 +0800993
jasonkmlu903ece82019-05-16 14:56:19 +0800994def check_ttff_data(ad, ttff_data, ttff_mode, criteria):
jasonkmlu81b8b032019-06-21 15:18:27 +0800995 """Verify all TTFF results from ttff_data.
jasonkmluff0d5b92019-03-21 11:24:45 +0800996
997 Args:
998 ad: An AndroidDevice object.
jasonkmlu903ece82019-05-16 14:56:19 +0800999 ttff_data: TTFF data of secs, position error and signal strength.
jasonkmluff0d5b92019-03-21 11:24:45 +08001000 ttff_mode: TTFF Test mode for current test item.
1001 criteria: Criteria for current test item.
1002
1003 Returns:
1004 True: All TTFF results are within criteria.
1005 False: One or more TTFF results exceed criteria or Timeout.
1006 """
1007 ad.log.info("%d iterations of TTFF %s tests finished."
jasonkmlu903ece82019-05-16 14:56:19 +08001008 % (len(ttff_data.keys()), ttff_mode))
jasonkmluff0d5b92019-03-21 11:24:45 +08001009 ad.log.info("%s PASS criteria is %d seconds" % (ttff_mode, criteria))
jasonkmlu81b8b032019-06-21 15:18:27 +08001010 ad.log.debug("%s TTFF data: %s" % (ttff_mode, ttff_data))
jasonkmlu4fcdcad2019-07-10 14:35:12 +08001011 ttff_property_key_and_value(ad, ttff_data, ttff_mode)
jasonkmlu903ece82019-05-16 14:56:19 +08001012 if len(ttff_data.keys()) == 0:
jasonkmluff0d5b92019-03-21 11:24:45 +08001013 ad.log.error("GTW_GPSTool didn't process TTFF properly.")
1014 return False
jasonkmlu903ece82019-05-16 14:56:19 +08001015 elif any(float(ttff_data[key].ttff_sec) == 0.0 for key in ttff_data.keys()):
jasonkmluff0d5b92019-03-21 11:24:45 +08001016 ad.log.error("One or more TTFF %s Timeout" % ttff_mode)
1017 return False
jasonkmlu035eee12019-10-08 17:11:20 +08001018 elif any(float(ttff_data[key].ttff_sec) >= criteria for key in
1019 ttff_data.keys()):
jasonkmluff0d5b92019-03-21 11:24:45 +08001020 ad.log.error("One or more TTFF %s are over test criteria %d seconds"
1021 % (ttff_mode, criteria))
1022 return False
1023 ad.log.info("All TTFF %s are within test criteria %d seconds."
1024 % (ttff_mode, criteria))
1025 return True
1026
jasonkmlu0f546de2019-12-13 20:58:41 +08001027
jasonkmlu4fcdcad2019-07-10 14:35:12 +08001028def ttff_property_key_and_value(ad, ttff_data, ttff_mode):
jasonkmlu81b8b032019-06-21 15:18:27 +08001029 """Output ttff_data to test_run_info for ACTS plugin to parse and display
1030 on MobileHarness as Property.
1031
1032 Args:
1033 ad: An AndroidDevice object.
1034 ttff_data: TTFF data of secs, position error and signal strength.
1035 ttff_mode: TTFF Test mode for current test item.
1036 """
1037 prop_basename = "TestResult "+ttff_mode.replace(" ", "_")+"_TTFF_"
1038 sec_list = [float(ttff_data[key].ttff_sec) for key in ttff_data.keys()]
1039 pe_list = [float(ttff_data[key].ttff_pe) for key in ttff_data.keys()]
jasonkmlucb654ac2020-07-01 11:08:33 +08001040 ant_cn_list = [float(ttff_data[key].ttff_ant_cn) for key in
1041 ttff_data.keys()]
1042 base_cn_list = [float(ttff_data[key].ttff_base_cn) for key in
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001043 ttff_data.keys()]
jasonkmlu81b8b032019-06-21 15:18:27 +08001044 timeoutcount = sec_list.count(0.0)
jasonkmluc1ec3052019-10-25 14:57:53 +08001045 if len(sec_list) == timeoutcount:
1046 avgttff = 9527
1047 else:
1048 avgttff = sum(sec_list)/(len(sec_list) - timeoutcount)
jasonkmlu81b8b032019-06-21 15:18:27 +08001049 if timeoutcount != 0:
jasonkmlu4fcdcad2019-07-10 14:35:12 +08001050 maxttff = 9527
jasonkmlu81b8b032019-06-21 15:18:27 +08001051 else:
1052 maxttff = max(sec_list)
1053 avgdis = sum(pe_list)/len(pe_list)
1054 maxdis = max(pe_list)
jasonkmlucb654ac2020-07-01 11:08:33 +08001055 ant_avgcn = sum(ant_cn_list)/len(ant_cn_list)
1056 base_avgcn = sum(base_cn_list)/len(base_cn_list)
jasonkmlu81b8b032019-06-21 15:18:27 +08001057 ad.log.info(prop_basename+"AvgTime %.1f" % avgttff)
1058 ad.log.info(prop_basename+"MaxTime %.1f" % maxttff)
1059 ad.log.info(prop_basename+"TimeoutCount %d" % timeoutcount)
1060 ad.log.info(prop_basename+"AvgDis %.1f" % avgdis)
1061 ad.log.info(prop_basename+"MaxDis %.1f" % maxdis)
jasonkmlucb654ac2020-07-01 11:08:33 +08001062 ad.log.info(prop_basename+"Ant_AvgSignal %.1f" % ant_avgcn)
1063 ad.log.info(prop_basename+"Base_AvgSignal %.1f" % base_avgcn)
jasonkmlu81b8b032019-06-21 15:18:27 +08001064
jasonkmlu0f546de2019-12-13 20:58:41 +08001065
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001066def calculate_position_error(latitude, longitude, true_position):
jasonkmlu903ece82019-05-16 14:56:19 +08001067 """Use haversine formula to calculate position error base on true location
1068 coordinate.
1069
1070 Args:
jasonkmlu903ece82019-05-16 14:56:19 +08001071 latitude: latitude of location fixed in the present.
1072 longitude: longitude of location fixed in the present.
1073 true_position: [latitude, longitude] of true location coordinate.
1074
1075 Returns:
1076 position_error of location fixed in the present.
1077 """
1078 radius = 6371009
1079 dlat = math.radians(latitude - true_position[0])
1080 dlon = math.radians(longitude - true_position[1])
1081 a = math.sin(dlat/2) * math.sin(dlat/2) + \
1082 math.cos(math.radians(true_position[0])) * \
1083 math.cos(math.radians(latitude)) * math.sin(dlon/2) * math.sin(dlon/2)
1084 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
1085 return radius * c
1086
jasonkmlu0f546de2019-12-13 20:58:41 +08001087
jasonkmluff0d5b92019-03-21 11:24:45 +08001088def launch_google_map(ad):
1089 """Launch Google Map via intent.
1090
1091 Args:
1092 ad: An AndroidDevice object.
1093 """
1094 ad.log.info("Launch Google Map.")
1095 try:
1096 ad.adb.shell("am start -S -n com.google.android.apps.maps/"
1097 "com.google.android.maps.MapsActivity")
1098 ad.send_keycode("BACK")
1099 ad.force_stop_apk("com.google.android.apps.maps")
1100 ad.adb.shell("am start -S -n com.google.android.apps.maps/"
1101 "com.google.android.maps.MapsActivity")
1102 except Exception as e:
1103 ad.log.error(e)
jasonkmlu78540632019-11-15 18:04:20 +08001104 raise signals.TestError("Failed to launch google map.")
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001105 check_current_focus_app(ad)
jasonkmlu49c32812019-04-12 18:11:10 +08001106
jasonkmlu0f546de2019-12-13 20:58:41 +08001107
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001108def check_current_focus_app(ad):
jasonkmlu903ece82019-05-16 14:56:19 +08001109 """Check to see current focused window and app.
jasonkmlu49c32812019-04-12 18:11:10 +08001110
1111 Args:
1112 ad: An AndroidDevice object.
jasonkmlu49c32812019-04-12 18:11:10 +08001113 """
jasonkmlu903ece82019-05-16 14:56:19 +08001114 time.sleep(1)
jasonkmlu035eee12019-10-08 17:11:20 +08001115 current = ad.adb.shell(
1116 "dumpsys window | grep -E 'mCurrentFocus|mFocusedApp'")
jasonkmlu81b8b032019-06-21 15:18:27 +08001117 ad.log.debug("\n"+current)
jasonkmluff0d5b92019-03-21 11:24:45 +08001118
jasonkmlu0f546de2019-12-13 20:58:41 +08001119
jasonkmluff0d5b92019-03-21 11:24:45 +08001120def check_location_api(ad, retries):
1121 """Verify if GnssLocationProvider API reports location.
1122
1123 Args:
1124 ad: An AndroidDevice object.
1125 retries: Retry time.
1126
1127 Returns:
1128 True: GnssLocationProvider API reports location.
1129 otherwise return False.
1130 """
1131 for i in range(retries):
1132 begin_time = get_current_epoch_time()
1133 ad.log.info("Try to get location report from GnssLocationProvider API "
1134 "- attempt %d" % (i+1))
1135 while get_current_epoch_time() - begin_time <= 30000:
1136 logcat_results = ad.search_logcat("REPORT_LOCATION", begin_time)
1137 if logcat_results:
1138 ad.log.info("%s" % logcat_results[-1]["log_message"])
jasonkmlu035eee12019-10-08 17:11:20 +08001139 ad.log.info("GnssLocationProvider reports location "
1140 "successfully.")
jasonkmluff0d5b92019-03-21 11:24:45 +08001141 return True
1142 if not ad.is_adb_logcat_on:
1143 ad.start_adb_logcat()
1144 ad.log.error("GnssLocationProvider is unable to report location.")
1145 return False
1146
Scott Hong72269692019-12-16 16:59:56 +08001147def check_network_location(ad, retries, location_type, criteria=30):
jasonkmluff0d5b92019-03-21 11:24:45 +08001148 """Verify if NLP reports location after requesting via GPSTool.
1149
1150 Args:
1151 ad: An AndroidDevice object.
1152 retries: Retry time.
Scott Hongaccd8a12020-03-03 20:12:17 +08001153 location_type: cell or wifi.
Scott Hong72269692019-12-16 16:59:56 +08001154 criteria: expected nlp return time, default 30 seconds
jasonkmluff0d5b92019-03-21 11:24:45 +08001155
1156 Returns:
1157 True: NLP reports location.
1158 otherwise return False.
1159 """
Scott Hong72269692019-12-16 16:59:56 +08001160 criteria = criteria * 1000
Scott Hongaccd8a12020-03-03 20:12:17 +08001161 search_pattern = ("GPSTool : networkLocationType = %s" % location_type)
jasonkmluff0d5b92019-03-21 11:24:45 +08001162 for i in range(retries):
jasonkmluff0d5b92019-03-21 11:24:45 +08001163 begin_time = get_current_epoch_time()
1164 ad.log.info("Try to get NLP status - attempt %d" % (i+1))
jasonkmlu035eee12019-10-08 17:11:20 +08001165 ad.adb.shell(
1166 "am start -S -n com.android.gpstool/.GPSTool --es mode nlp")
Scott Hong72269692019-12-16 16:59:56 +08001167 while get_current_epoch_time() - begin_time <= criteria:
Scott Hongaccd8a12020-03-03 20:12:17 +08001168 # Search pattern in 1 second interval
1169 time.sleep(1)
1170 result = ad.search_logcat(search_pattern, begin_time)
1171 if result:
1172 ad.log.info("Pattern Found: %s." % result[-1]["log_message"])
1173 ad.send_keycode("BACK")
1174 return True
jasonkmluff0d5b92019-03-21 11:24:45 +08001175 if not ad.is_adb_logcat_on:
1176 ad.start_adb_logcat()
1177 ad.send_keycode("BACK")
1178 ad.log.error("Unable to report network location \"%s\"." % location_type)
1179 return False
1180
jasonkmlu0f546de2019-12-13 20:58:41 +08001181
jasonkmlu8d6bbfc2019-03-29 15:57:43 +08001182def set_attenuator_gnss_signal(ad, attenuator, atten_value):
jasonkmluff0d5b92019-03-21 11:24:45 +08001183 """Set attenuation value for different GNSS signal.
1184
1185 Args:
1186 ad: An AndroidDevice object.
jasonkmlu8d6bbfc2019-03-29 15:57:43 +08001187 attenuator: The attenuator object.
jasonkmluff0d5b92019-03-21 11:24:45 +08001188 atten_value: attenuation value
1189 """
jasonkmluff0d5b92019-03-21 11:24:45 +08001190 try:
jasonkmlu035eee12019-10-08 17:11:20 +08001191 ad.log.info(
1192 "Set attenuation value to \"%d\" for GNSS signal." % atten_value)
jasonkmlu8d6bbfc2019-03-29 15:57:43 +08001193 attenuator[0].set_atten(atten_value)
jasonkmlu81b8b032019-06-21 15:18:27 +08001194 except Exception as e:
jasonkmlu4fcdcad2019-07-10 14:35:12 +08001195 ad.log.error(e)
jasonkmluff0d5b92019-03-21 11:24:45 +08001196
jasonkmlu0f546de2019-12-13 20:58:41 +08001197
jasonkmluff0d5b92019-03-21 11:24:45 +08001198def set_battery_saver_mode(ad, state):
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001199 """Enable or disable battery saver mode via adb.
jasonkmluff0d5b92019-03-21 11:24:45 +08001200
1201 Args:
1202 ad: An AndroidDevice object.
1203 state: True is enable Battery Saver mode. False is disable.
1204 """
1205 ad.root_adb()
1206 if state:
1207 ad.log.info("Enable Battery Saver mode.")
1208 ad.adb.shell("cmd battery unplug")
1209 ad.adb.shell("settings put global low_power 1")
1210 else:
1211 ad.log.info("Disable Battery Saver mode.")
1212 ad.adb.shell("settings put global low_power 0")
1213 ad.adb.shell("cmd battery reset")
1214
jasonkmlu0f546de2019-12-13 20:58:41 +08001215
jasonkmluff0d5b92019-03-21 11:24:45 +08001216def set_gnss_qxdm_mask(ad, masks):
1217 """Find defined gnss qxdm mask and set as default logging mask.
1218
1219 Args:
1220 ad: An AndroidDevice object.
1221 masks: Defined gnss qxdm mask.
1222 """
1223 try:
1224 for mask in masks:
1225 if not tutils.find_qxdm_log_mask(ad, mask):
1226 continue
1227 tutils.set_qxdm_logger_command(ad, mask)
1228 break
1229 except Exception as e:
1230 ad.log.error(e)
jasonkmlu78540632019-11-15 18:04:20 +08001231 raise signals.TestError("Failed to set any QXDM masks.")
jasonkmlu903ece82019-05-16 14:56:19 +08001232
jasonkmlu0f546de2019-12-13 20:58:41 +08001233
jasonkmlu903ece82019-05-16 14:56:19 +08001234def start_youtube_video(ad, url=None, retries=0):
1235 """Start youtube video and verify if audio is in music state.
jasonkmlu81b8b032019-06-21 15:18:27 +08001236
jasonkmlu903ece82019-05-16 14:56:19 +08001237 Args:
1238 ad: An AndroidDevice object.
1239 url: Youtube video url.
1240 retries: Retry times if audio is not in music state.
jasonkmlu81b8b032019-06-21 15:18:27 +08001241
jasonkmlu903ece82019-05-16 14:56:19 +08001242 Returns:
1243 True if youtube video is playing normally.
1244 False if youtube video is not playing properly.
1245 """
1246 for i in range(retries):
1247 ad.log.info("Open an youtube video - attempt %d" % (i+1))
jasonkmluc0939182021-02-19 18:34:28 +08001248 cmd = ("am start -n com.google.android.youtube/"
1249 "com.google.android.youtube.UrlActivity -d \"%s\"" % url)
1250 ad.adb.shell(cmd)
jasonkmlu903ece82019-05-16 14:56:19 +08001251 time.sleep(2)
jasonkmlu035eee12019-10-08 17:11:20 +08001252 out = ad.adb.shell(
1253 "dumpsys activity | grep NewVersionAvailableActivity")
jasonkmlu903ece82019-05-16 14:56:19 +08001254 if out:
1255 ad.log.info("Skip Youtube New Version Update.")
1256 ad.send_keycode("BACK")
1257 if tutils.wait_for_state(ad.droid.audioIsMusicActive, True, 15, 1):
1258 ad.log.info("Started a video in youtube, audio is in MUSIC state")
1259 return True
1260 ad.log.info("Force-Stop youtube and reopen youtube again.")
1261 ad.force_stop_apk("com.google.android.youtube")
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001262 check_current_focus_app(ad)
jasonkmlu78540632019-11-15 18:04:20 +08001263 raise signals.TestError("Started a video in youtube, "
1264 "but audio is not in MUSIC state")
jasonkmlu81b8b032019-06-21 15:18:27 +08001265
jasonkmlu0f546de2019-12-13 20:58:41 +08001266
jasonkmlu81b8b032019-06-21 15:18:27 +08001267def get_baseband_and_gms_version(ad, extra_msg=""):
1268 """Get current radio baseband and GMSCore version of AndroidDevice object.
1269
1270 Args:
1271 ad: An AndroidDevice object.
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001272 extra_msg: Extra message before or after the change.
jasonkmlu81b8b032019-06-21 15:18:27 +08001273 """
1274 try:
jasonkmlud93060f2019-11-05 15:12:55 +08001275 build_version = ad.adb.getprop("ro.build.id")
jasonkmlu81b8b032019-06-21 15:18:27 +08001276 baseband_version = ad.adb.getprop("gsm.version.baseband")
jasonkmlu035eee12019-10-08 17:11:20 +08001277 gms_version = ad.adb.shell(
1278 "dumpsys package com.google.android.gms | grep versionName"
1279 ).split("\n")[0].split("=")[1]
1280 mpss_version = ad.adb.shell("cat /sys/devices/soc0/images | grep MPSS "
1281 "| cut -d ':' -f 3")
jasonkmlu81b8b032019-06-21 15:18:27 +08001282 if not extra_msg:
jasonkmlud93060f2019-11-05 15:12:55 +08001283 ad.log.info("TestResult Build_Version %s" % build_version)
jasonkmlu81b8b032019-06-21 15:18:27 +08001284 ad.log.info("TestResult Baseband_Version %s" % baseband_version)
jasonkmlu035eee12019-10-08 17:11:20 +08001285 ad.log.info(
1286 "TestResult GMS_Version %s" % gms_version.replace(" ", ""))
1287 ad.log.info("TestResult MPSS_Version %s" % mpss_version)
jasonkmlu81b8b032019-06-21 15:18:27 +08001288 else:
jasonkmlu035eee12019-10-08 17:11:20 +08001289 ad.log.info(
1290 "%s, Baseband_Version = %s" % (extra_msg, baseband_version))
jasonkmlu81b8b032019-06-21 15:18:27 +08001291 except Exception as e:
jasonkmlu035eee12019-10-08 17:11:20 +08001292 ad.log.error(e)
1293
jasonkmlu0f546de2019-12-13 20:58:41 +08001294
jasonkmlu035eee12019-10-08 17:11:20 +08001295def start_toggle_gnss_by_gtw_gpstool(ad, iteration):
1296 """Send toggle gnss off/on start_test_action
1297
1298 Args:
1299 ad: An AndroidDevice object.
1300 iteration: Iteration of toggle gnss off/on cycles.
1301 """
1302 msg_list = []
1303 begin_time = get_current_epoch_time()
1304 try:
1305 for i in range(1, 4):
1306 ad.adb.shell("am start -S -n com.android.gpstool/.GPSTool "
1307 "--es mode toggle --es cycle %d" % iteration)
1308 time.sleep(1)
1309 if ad.search_logcat("cmp=com.android.gpstool/.ToggleGPS",
1310 begin_time):
1311 ad.log.info("Send ToggleGPS start_test_action successfully.")
1312 break
1313 else:
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001314 check_current_focus_app(ad)
jasonkmlu78540632019-11-15 18:04:20 +08001315 raise signals.TestError("Fail to send ToggleGPS "
1316 "start_test_action within 3 attempts.")
jasonkmlu035eee12019-10-08 17:11:20 +08001317 time.sleep(2)
1318 test_start = ad.search_logcat("GPSTool_ToggleGPS: startService",
1319 begin_time)
1320 if test_start:
1321 ad.log.info(test_start[-1]["log_message"].split(":")[-1].strip())
1322 else:
jasonkmlu78540632019-11-15 18:04:20 +08001323 raise signals.TestError("Fail to start toggle GPS off/on test.")
jasonkmlu035eee12019-10-08 17:11:20 +08001324 # Every iteration is expected to finish within 4 minutes.
1325 while get_current_epoch_time() - begin_time <= iteration * 240000:
1326 crash_end = ad.search_logcat("Force finishing activity "
1327 "com.android.gpstool/.GPSTool",
1328 begin_time)
1329 if crash_end:
jasonkmlu78540632019-11-15 18:04:20 +08001330 raise signals.TestError("GPSTool crashed. Abort test.")
jasonkmlu035eee12019-10-08 17:11:20 +08001331 toggle_results = ad.search_logcat("GPSTool : msg", begin_time)
1332 if toggle_results:
1333 for toggle_result in toggle_results:
1334 msg = toggle_result["log_message"]
1335 if not msg in msg_list:
1336 ad.log.info(msg.split(":")[-1].strip())
1337 msg_list.append(msg)
1338 if "timeout" in msg:
1339 raise signals.TestFailure("Fail to get location fixed "
1340 "within 60 seconds.")
1341 if "Test end" in msg:
1342 raise signals.TestPass("Completed quick toggle GNSS "
1343 "off/on test.")
1344 raise signals.TestFailure("Fail to finish toggle GPS off/on test "
1345 "within %d minutes" % (iteration * 4))
1346 finally:
1347 ad.send_keycode("HOME")
jasonkmludc430ec2020-03-27 10:40:39 +08001348
jasonkmlu4ba30a02020-04-09 14:16:49 +08001349
jasonkmludc430ec2020-03-27 10:40:39 +08001350def grant_location_permission(ad, option):
1351 """Grant or revoke location related permission.
1352
1353 Args:
1354 ad: An AndroidDevice object.
1355 option: Boolean to grant or revoke location related permissions.
1356 """
jasonkmlu4ba30a02020-04-09 14:16:49 +08001357 action = "grant" if option else "revoke"
jasonkmludc430ec2020-03-27 10:40:39 +08001358 for permission in LOCATION_PERMISSIONS:
1359 ad.log.info(
jasonkmlu4ba30a02020-04-09 14:16:49 +08001360 "%s permission:%s on %s" % (action, permission, TEST_PACKAGE_NAME))
1361 ad.adb.shell("pm %s %s %s" % (action, TEST_PACKAGE_NAME, permission))
1362
1363
1364def check_location_runtime_permissions(ad, package, permissions):
1365 """Check if runtime permissions are granted on selected package.
1366
1367 Args:
1368 ad: An AndroidDevice object.
1369 package: Apk package name to check.
1370 permissions: A list of permissions to be granted.
1371 """
1372 for _ in range(3):
1373 location_runtime_permission = ad.adb.shell(
1374 "dumpsys package %s | grep ACCESS_FINE_LOCATION" % package)
1375 if "true" not in location_runtime_permission:
1376 ad.log.info("ACCESS_FINE_LOCATION is NOT granted on %s" % package)
1377 for permission in permissions:
1378 ad.log.debug("Grant %s on %s" % (permission, package))
1379 ad.adb.shell("pm grant %s %s" % (package, permission))
1380 else:
1381 ad.log.info("ACCESS_FINE_LOCATION is granted on %s" % package)
1382 break
1383 else:
1384 raise signals.TestError(
1385 "Fail to grant ACCESS_FINE_LOCATION on %s" % package)
jasonkmlucb654ac2020-07-01 11:08:33 +08001386
1387
1388def install_mdstest_app(ad, mdsapp):
1389 """
1390 Install MDS test app in DUT
1391
1392 Args:
1393 ad: An Android Device Object
1394 mdsapp: Installation path of MDSTest app
1395 """
1396 if not ad.is_apk_installed("com.google.mdstest"):
1397 ad.adb.install("-r %s" % mdsapp, timeout=300, ignore_status=True)
1398
1399
1400def write_modemconfig(ad, mdsapp, nvitem_dict, modemparfile):
1401 """
1402 Modify the NV items using modem_tool.par
1403 Note: modem_tool.par
1404
1405 Args:
1406 ad: An Android Device Object
1407 mdsapp: Installation path of MDSTest app
1408 nvitem_dict: dictionary of NV items and values.
1409 modemparfile: modem_tool.par path.
1410 """
1411 ad.log.info("Verify MDSTest app installed in DUT")
1412 install_mdstest_app(ad, mdsapp)
1413 os.system("chmod 777 %s" % modemparfile)
1414 for key, value in nvitem_dict.items():
1415 if key.isdigit():
1416 op_name = "WriteEFS"
1417 else:
1418 op_name = "WriteNV"
1419 ad.log.info("Modifying the NV{!r} using {}".format(key, op_name))
1420 job.run("{} --op {} --item {} --data '{}'".
1421 format(modemparfile, op_name, key, value))
1422 time.sleep(2)
1423
1424
1425def verify_modemconfig(ad, nvitem_dict, modemparfile):
1426 """
1427 Verify the NV items using modem_tool.par
1428 Note: modem_tool.par
1429
1430 Args:
1431 ad: An Android Device Object
1432 nvitem_dict: dictionary of NV items and values
1433 modemparfile: modem_tool.par path.
1434 """
1435 os.system("chmod 777 %s" % modemparfile)
1436 for key, value in nvitem_dict.items():
1437 if key.isdigit():
1438 op_name = "ReadEFS"
1439 else:
1440 op_name = "ReadNV"
1441 # Sleeptime to avoid Modem communication error
1442 time.sleep(5)
1443 result = job.run(
1444 "{} --op {} --item {}".format(modemparfile, op_name, key))
1445 output = str(result.stdout)
1446 ad.log.info("Actual Value for NV{!r} is {!r}".format(key, output))
1447 if not value.casefold() in output:
1448 ad.log.error("NV Value is wrong {!r} in {!r}".format(value, result))
1449 raise ValueError(
1450 "could not find {!r} in {!r}".format(value, result))
Jayakumar Munuswamy7efa25b2020-07-07 15:30:08 -07001451
1452
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001453def check_ttff_pe(ad, ttff_data, ttff_mode, pe_criteria):
Jayakumar Munuswamy7efa25b2020-07-07 15:30:08 -07001454 """Verify all TTFF results from ttff_data.
1455
1456 Args:
1457 ad: An AndroidDevice object.
1458 ttff_data: TTFF data of secs, position error and signal strength.
1459 ttff_mode: TTFF Test mode for current test item.
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001460 pe_criteria: Criteria for current test item.
Jayakumar Munuswamy7efa25b2020-07-07 15:30:08 -07001461
1462 """
1463 ad.log.info("%d iterations of TTFF %s tests finished.",
1464 (len(ttff_data.keys()), ttff_mode))
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001465 ad.log.info("%s PASS criteria is %f meters", (ttff_mode, pe_criteria))
Jayakumar Munuswamy7efa25b2020-07-07 15:30:08 -07001466 ad.log.debug("%s TTFF data: %s", (ttff_mode, ttff_data))
1467
1468 if len(ttff_data.keys()) == 0:
1469 ad.log.error("GTW_GPSTool didn't process TTFF properly.")
1470 raise signals.TestFailure("GTW_GPSTool didn't process TTFF properly.")
1471
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001472 elif any(float(ttff_data[key].ttff_pe) >= pe_criteria for key in
Jayakumar Munuswamy7efa25b2020-07-07 15:30:08 -07001473 ttff_data.keys()):
1474 ad.log.error("One or more TTFF %s are over test criteria %f meters",
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001475 (ttff_mode, pe_criteria))
Jayakumar Munuswamy7efa25b2020-07-07 15:30:08 -07001476 raise signals.TestFailure("GTW_GPSTool didn't process TTFF properly.")
1477 ad.log.info("All TTFF %s are within test criteria %f meters.",
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001478 (ttff_mode, pe_criteria))
jasonkmlud68fdf02020-07-23 16:18:11 +08001479
1480
1481def check_adblog_functionality(ad):
1482 """Restart adb logcat if system can't write logs into file after checking
1483 adblog file size.
1484
1485 Args:
1486 ad: An AndroidDevice object.
1487 """
1488 logcat_path = os.path.join(ad.device_log_path, "adblog_%s_debug.txt" %
1489 ad.serial)
1490 if not os.path.exists(logcat_path):
1491 raise signals.TestError("Logcat file %s does not exist." % logcat_path)
1492 original_log_size = os.path.getsize(logcat_path)
1493 ad.log.debug("Original adblog size is %d" % original_log_size)
1494 time.sleep(.5)
1495 current_log_size = os.path.getsize(logcat_path)
1496 ad.log.debug("Current adblog size is %d" % current_log_size)
1497 if current_log_size == original_log_size:
1498 ad.log.warn("System can't write logs into file. Restart adb "
1499 "logcat process now.")
1500 ad.stop_adb_logcat()
1501 ad.start_adb_logcat()
Scott Hong0f5dfc42020-08-22 00:47:53 +08001502
jasonkmluc0939182021-02-19 18:34:28 +08001503
Scott Hong0f5dfc42020-08-22 00:47:53 +08001504def build_instrumentation_call(package,
1505 runner,
1506 test_methods=None,
1507 options=None):
1508 """Build an instrumentation call for the tests
1509
1510 Args:
1511 package: A string to identify test package.
1512 runner: A string to identify test runner.
1513 test_methods: A dictionary contains {class_name, test_method}.
jasonkmlu6ea2a2b2020-11-02 13:29:41 +08001514 options: A dictionary constant {key, value} param for test.
Scott Hong0f5dfc42020-08-22 00:47:53 +08001515
1516 Returns:
1517 An instrumentation call command.
1518 """
1519 if test_methods is None:
1520 test_methods = {}
1521 cmd_builder = InstrumentationCommandBuilder()
1522 else:
1523 cmd_builder = InstrumentationTestCommandBuilder()
Scott Hong0f5dfc42020-08-22 00:47:53 +08001524 if options is None:
1525 options = {}
Scott Hong0f5dfc42020-08-22 00:47:53 +08001526 cmd_builder.set_manifest_package(package)
1527 cmd_builder.set_runner(runner)
Scott Honga2e430b2020-08-27 15:14:57 +08001528 cmd_builder.add_flag("-w")
Scott Hong0f5dfc42020-08-22 00:47:53 +08001529 for class_name, test_method in test_methods.items():
1530 cmd_builder.add_test_method(class_name, test_method)
Scott Hong0f5dfc42020-08-22 00:47:53 +08001531 for option_key, option_value in options.items():
1532 cmd_builder.add_key_value_param(option_key, option_value)
Scott Hong0f5dfc42020-08-22 00:47:53 +08001533 return cmd_builder.build()
jasonkmluc0939182021-02-19 18:34:28 +08001534
1535
1536def check_chipset_vendor_by_qualcomm(ad):
1537 """Check if cipset vendor is by Qualcomm.
1538
1539 Args:
1540 ad: An AndroidDevice object.
1541
1542 Returns:
1543 True if it's by Qualcomm. False irf not.
1544 """
1545 ad.root_adb()
1546 soc = str(ad.adb.shell("getprop gsm.version.ril-impl"))
1547 ad.log.debug("SOC = %s" % soc)
1548 return "Qualcomm" in soc
1549
1550
1551def delete_lto_file(ad):
1552 """Delete downloaded LTO files.
1553
1554 Args:
1555 ad: An AndroidDevice object.
1556 """
1557 remount_device(ad)
1558 status = ad.adb.shell("rm -rf /data/vendor/gps/lto*")
1559 ad.log.info("Delete downloaded LTO files.\n%s" % status)
1560
1561
1562def lto_mode(ad, state):
1563 """Enable or Disable LTO mode.
1564
1565 Args:
1566 ad: An AndroidDevice object.
1567 state: True to enable. False to disable.
1568 """
1569 server_list = ["LONGTERM_PSDS_SERVER_1",
1570 "LONGTERM_PSDS_SERVER_2",
1571 "LONGTERM_PSDS_SERVER_3",
1572 "NORMAL_PSDS_SERVER",
1573 "REALTIME_PSDS_SERVER"]
1574 delete_lto_file(ad)
1575 tmp_path = tempfile.mkdtemp()
1576 ad.pull_files("/etc/gps_debug.conf", tmp_path)
1577 gps_conf_path = os.path.join(tmp_path, "gps_debug.conf")
1578 gps_conf_file = open(gps_conf_path, "r")
1579 lines = gps_conf_file.readlines()
1580 gps_conf_file.close()
1581 fout = open(gps_conf_path, "w")
1582 if state:
1583 for line in lines:
1584 for server in server_list:
1585 if server in line:
1586 line = line.replace(line, "")
1587 fout.write(line)
1588 fout.close()
1589 ad.push_system_file(gps_conf_path, "/etc/gps_debug.conf")
1590 ad.log.info("Push back modified gps_debug.conf")
1591 ad.log.info("LTO/RTO/RTI enabled")
1592 else:
1593 ad.adb.shell("echo %r >> /etc/gps_debug.conf" %
1594 DISABLE_LTO_FILE_CONTENTS)
1595 ad.log.info("LTO/RTO/RTI disabled")
1596 reboot(ad)
1597
1598
jasonkmlu9b278f92021-04-20 01:06:50 +08001599def start_pixel_logger(ad, max_log_size_mb=100, max_number_of_files=500):
jasonkmluc0939182021-02-19 18:34:28 +08001600 """adb to start pixel logger for GNSS logging.
1601
1602 Args:
1603 ad: An AndroidDevice object.
jasonkmlu9b278f92021-04-20 01:06:50 +08001604 max_log_size_mb: Determines when to create a new log file if current
1605 one reaches the size limit.
1606 max_number_of_files: Determines how many log files can be saved on DUT.
jasonkmluc0939182021-02-19 18:34:28 +08001607 """
1608 start_timeout_sec = 60
jasonkmlu9b278f92021-04-20 01:06:50 +08001609 default_gnss_cfg = "/vendor/etc/mdlog/DEFAULT+SECURITY+FULLDPL+GPS.cfg"
1610 if check_chipset_vendor_by_qualcomm(ad):
1611 start_cmd = ("am start-foreground-service -a com.android.pixellogger"
1612 ".service.logging.LoggingService.ACTION_START_LOGGING "
1613 "-e intent_key_cfg_path '%s' "
1614 "--ei intent_key_max_log_size_mb %d "
1615 "--ei intent_key_max_number_of_files %d" % (
1616 default_gnss_cfg, max_log_size_mb, max_number_of_files))
1617 else:
1618 start_cmd = ("am startservice -a com.android.pixellogger."
1619 "service.logging.LoggingService.ACTION_START_LOGGING "
1620 "-e intent_logger brcm_gps")
jasonkmluc0939182021-02-19 18:34:28 +08001621 begin_time = get_current_epoch_time()
1622 ad.log.info("Start Pixel Logger.")
1623 ad.adb.shell(start_cmd)
1624 while get_current_epoch_time() - begin_time <= start_timeout_sec * 1000:
jasonkmlu9b278f92021-04-20 01:06:50 +08001625 if not ad.is_adb_logcat_on:
1626 ad.start_adb_logcat()
1627 if check_chipset_vendor_by_qualcomm(ad):
1628 start_result = ad.search_logcat("Start logging", begin_time)
1629 else:
1630 start_result = ad.search_logcat("startRecording", begin_time)
jasonkmluc0939182021-02-19 18:34:28 +08001631 if start_result:
1632 ad.log.info("Pixel Logger starts recording successfully.")
1633 break
1634 else:
1635 ad.log.warn("Pixel Logger fails to start recording.")
1636
1637
1638def stop_pixel_logger(ad):
1639 """adb to stop pixel logger for GNSS logging.
1640
1641 Args:
1642 ad: An AndroidDevice object.
1643 """
1644 stop_timeout_sec = 300
jasonkmlu9b278f92021-04-20 01:06:50 +08001645 if check_chipset_vendor_by_qualcomm(ad):
1646 stop_cmd = ("am start-foreground-service -a com.android.pixellogger"
1647 ".service.logging.LoggingService.ACTION_STOP_LOGGING")
1648 else:
1649 stop_cmd = ("am startservice -a com.android.pixellogger."
1650 "service.logging.LoggingService.ACTION_STOP_LOGGING "
1651 "-e intent_logger brcm_gps")
jasonkmluc0939182021-02-19 18:34:28 +08001652 begin_time = get_current_epoch_time()
1653 ad.log.info("Stop Pixel Logger.")
1654 ad.adb.shell(stop_cmd)
1655 while get_current_epoch_time() - begin_time <= stop_timeout_sec * 1000:
jasonkmlu9b278f92021-04-20 01:06:50 +08001656 if not ad.is_adb_logcat_on:
1657 ad.start_adb_logcat()
1658 stop_result = ad.search_logcat(
1659 "LoggingService: Stopping service", begin_time)
jasonkmluc0939182021-02-19 18:34:28 +08001660 if stop_result:
1661 ad.log.info("Pixel Logger stops successfully.")
1662 break
1663 else:
1664 ad.log.warn(
1665 "Pixel Logger fails to stop in %d seconds." % stop_timeout_sec)