jasonkmlu | 4ba30a0 | 2020-04-09 14:16:49 +0800 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 2 | # |
jasonkmlu | dc430ec | 2020-03-27 10:40:39 +0800 | [diff] [blame] | 3 | # Copyright 2020 - Google |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | import time |
| 18 | import re |
| 19 | import os |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 20 | import math |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 21 | import shutil |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 22 | import fnmatch |
| 23 | import posixpath |
jasonkmlu | 5e7817c | 2020-05-08 14:06:43 +0800 | [diff] [blame] | 24 | import tempfile |
jasonkmlu | 8cc1c1e | 2020-01-06 17:18:27 +0800 | [diff] [blame] | 25 | from collections import namedtuple |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 26 | |
| 27 | from acts import utils |
| 28 | from acts import signals |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 29 | from acts.libs.proc import job |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 30 | from acts.controllers.android_device import list_adb_devices |
| 31 | from acts.controllers.android_device import list_fastboot_devices |
| 32 | from acts.controllers.android_device import DEFAULT_QXDM_LOG_PATH |
| 33 | from acts.controllers.android_device import SL4A_APK_NAME |
Xianyuan Jia | 24299b7 | 2020-10-21 13:52:47 -0700 | [diff] [blame] | 34 | from acts_contrib.test_utils.wifi import wifi_test_utils as wutils |
| 35 | from acts_contrib.test_utils.tel import tel_test_utils as tutils |
| 36 | from acts_contrib.test_utils.instrumentation.device.command.instrumentation_command_builder import InstrumentationCommandBuilder |
| 37 | from acts_contrib.test_utils.instrumentation.device.command.instrumentation_command_builder import InstrumentationTestCommandBuilder |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 38 | from acts.utils import get_current_epoch_time |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 39 | from acts.utils import epoch_to_human_time |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 40 | |
| 41 | WifiEnums = wutils.WifiEnums |
| 42 | PULL_TIMEOUT = 300 |
jasonkmlu | 66fda53 | 2019-07-16 11:12:45 +0800 | [diff] [blame] | 43 | GNSSSTATUS_LOG_PATH = ( |
| 44 | "/storage/emulated/0/Android/data/com.android.gpstool/files/") |
jasonkmlu | 214f0d6 | 2019-04-08 19:53:59 +0800 | [diff] [blame] | 45 | QXDM_MASKS = ["GPS.cfg", "GPS-general.cfg", "default.cfg"] |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 46 | TTFF_REPORT = namedtuple( |
| 47 | "TTFF_REPORT", "utc_time ttff_loop ttff_sec ttff_pe ttff_ant_cn " |
| 48 | "ttff_base_cn") |
jasonkmlu | 8cc1c1e | 2020-01-06 17:18:27 +0800 | [diff] [blame] | 49 | TRACK_REPORT = namedtuple( |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 50 | "TRACK_REPORT", "l5flag pe ant_top4cn ant_cn base_top4cn base_cn") |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 51 | LOCAL_PROP_FILE_CONTENTS = """\ |
jasonkmlu | 38bd4d1 | 2019-10-04 16:38:48 +0800 | [diff] [blame] | 52 | log.tag.LocationManagerService=VERBOSE |
| 53 | log.tag.GnssLocationProvider=VERBOSE |
| 54 | log.tag.GnssMeasurementsProvider=VERBOSE |
| 55 | log.tag.GpsNetInitiatedHandler=VERBOSE |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 56 | log.tag.GnssNetInitiatedHandler=VERBOSE |
jasonkmlu | 38bd4d1 | 2019-10-04 16:38:48 +0800 | [diff] [blame] | 57 | log.tag.GnssNetworkConnectivityHandler=VERBOSE |
| 58 | log.tag.ConnectivityService=VERBOSE |
| 59 | log.tag.ConnectivityManager=VERBOSE |
jasonkmlu | dc430ec | 2020-03-27 10:40:39 +0800 | [diff] [blame] | 60 | log.tag.GnssVisibilityControl=VERBOSE |
| 61 | log.tag.NtpTimeHelper=VERBOSE |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 62 | log.tag.NtpTrustedTime=VERBOSE |
| 63 | log.tag.GnssPsdsDownloader=VERBOSE |
| 64 | log.tag.Gnss=VERBOSE |
| 65 | log.tag.GnssConfiguration=VERBOSE""" |
jasonkmlu | 4ba30a0 | 2020-04-09 14:16:49 +0800 | [diff] [blame] | 66 | TEST_PACKAGE_NAME = "com.google.android.apps.maps" |
jasonkmlu | dc430ec | 2020-03-27 10:40:39 +0800 | [diff] [blame] | 67 | LOCATION_PERMISSIONS = [ |
jasonkmlu | 4ba30a0 | 2020-04-09 14:16:49 +0800 | [diff] [blame] | 68 | "android.permission.ACCESS_FINE_LOCATION", |
| 69 | "android.permission.ACCESS_COARSE_LOCATION" |
jasonkmlu | dc430ec | 2020-03-27 10:40:39 +0800 | [diff] [blame] | 70 | ] |
jasonkmlu | 4ba30a0 | 2020-04-09 14:16:49 +0800 | [diff] [blame] | 71 | GNSSTOOL_PACKAGE_NAME = "com.android.gpstool" |
| 72 | GNSSTOOL_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 | ] |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 83 | DISABLE_LTO_FILE_CONTENTS = """\ |
| 84 | LONGTERM_PSDS_SERVER_1="http://" |
| 85 | LONGTERM_PSDS_SERVER_2="http://" |
| 86 | LONGTERM_PSDS_SERVER_3="http://" |
| 87 | NORMAL_PSDS_SERVER="http://" |
| 88 | REALTIME_PSDS_SERVER="http://" |
| 89 | """ |
jasonkmlu | 4ba30a0 | 2020-04-09 14:16:49 +0800 | [diff] [blame] | 90 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 91 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 92 | class GnssTestUtilsError(Exception): |
| 93 | pass |
| 94 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 95 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 96 | def remount_device(ad): |
| 97 | """Remount device file system to read and write. |
| 98 | |
| 99 | Args: |
| 100 | ad: An AndroidDevice object. |
| 101 | """ |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 102 | for retries in range(5): |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 103 | ad.root_adb() |
Scott Hong | 7f3945f | 2020-02-20 18:04:56 +0800 | [diff] [blame] | 104 | if ad.adb.getprop("ro.boot.veritymode") == "enforcing": |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 105 | ad.adb.disable_verity() |
Scott Hong | 7f3945f | 2020-02-20 18:04:56 +0800 | [diff] [blame] | 106 | reboot(ad) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 107 | remount_result = ad.adb.remount() |
| 108 | ad.log.info("Attempt %d - %s" % (retries + 1, remount_result)) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 109 | if "remount succeeded" in remount_result: |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 110 | break |
jasonkmlu | 214f0d6 | 2019-04-08 19:53:59 +0800 | [diff] [blame] | 111 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 112 | |
jasonkmlu | 214f0d6 | 2019-04-08 19:53:59 +0800 | [diff] [blame] | 113 | def 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) |
jasonkmlu | 49c3281 | 2019-04-12 18:11:10 +0800 | [diff] [blame] | 124 | utils.sync_device_time(ad) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 125 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 126 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 127 | def enable_gnss_verbose_logging(ad): |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 128 | """Enable GNSS VERBOSE Logging and persistent logcat. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 129 | |
| 130 | Args: |
| 131 | ad: An AndroidDevice object. |
| 132 | """ |
| 133 | remount_device(ad) |
jasonkmlu | 97ac56e | 2019-05-29 15:04:51 +0800 | [diff] [blame] | 134 | ad.log.info("Enable GNSS VERBOSE Logging and persistent logcat.") |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 135 | 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") |
jasonkmlu | 38bd4d1 | 2019-10-04 16:38:48 +0800 | [diff] [blame] | 140 | ad.adb.shell("echo %r >> /data/local.prop" % LOCAL_PROP_FILE_CONTENTS) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 141 | ad.adb.shell("chmod 644 /data/local.prop") |
jasonkmlu | c1ec305 | 2019-10-25 14:57:53 +0800 | [diff] [blame] | 142 | ad.adb.shell("setprop persist.logd.logpersistd.size 20000") |
jasonkmlu | 180a08c | 2019-04-23 17:24:55 +0800 | [diff] [blame] | 143 | ad.adb.shell("setprop persist.logd.size 16777216") |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 144 | ad.adb.shell("setprop persist.vendor.radio.adb_log_on 1") |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 145 | ad.adb.shell("setprop persist.logd.logpersistd logcatd") |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 146 | ad.adb.shell("setprop log.tag.copresGcore VERBOSE") |
| 147 | ad.adb.shell("sync") |
| 148 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 149 | |
jasonkmlu | 8cc1c1e | 2020-01-06 17:18:27 +0800 | [diff] [blame] | 150 | def 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 | |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 159 | def enable_compact_and_particle_fusion_log(ad): |
jasonkmlu | 8cc1c1e | 2020-01-06 17:18:27 +0800 | [diff] [blame] | 160 | """Enable CompactLog, FLP particle fusion log and disable gms |
| 161 | location-based quake monitoring. |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 162 | |
| 163 | Args: |
| 164 | ad: An AndroidDevice object. |
| 165 | """ |
| 166 | ad.root_adb() |
jasonkmlu | 8cc1c1e | 2020-01-06 17:18:27 +0800 | [diff] [blame] | 167 | 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) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 187 | ad.adb.shell("am force-stop com.google.android.gms") |
| 188 | ad.adb.shell("am broadcast -a com.google.android.gms.INITIALIZE") |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 189 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 190 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 191 | def 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 Hong | accd8a1 | 2020-03-03 20:12:17 +0800 | [diff] [blame] | 199 | 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") |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 201 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 202 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 203 | def 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 Hong | accd8a1 | 2020-03-03 20:12:17 +0800 | [diff] [blame] | 211 | ad.adb.shell("echo -e '\nSUPL_MODE=1' >> /etc/gps_debug.conf") |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 212 | if not check_chipset_vendor_by_qualcomm(ad): |
| 213 | lto_mode(ad, True) |
| 214 | else: |
| 215 | reboot(ad) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 216 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 217 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 218 | def disable_supl_mode(ad): |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 219 | """Kill SUPL to test XTRA/LTO only test item. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 220 | |
| 221 | Args: |
| 222 | ad: An AndroidDevice object. |
| 223 | """ |
| 224 | remount_device(ad) |
| 225 | ad.log.info("Disable SUPL mode.") |
Scott Hong | accd8a1 | 2020-03-03 20:12:17 +0800 | [diff] [blame] | 226 | ad.adb.shell("echo -e '\nSUPL_MODE=0' >> /etc/gps_debug.conf") |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 227 | if not check_chipset_vendor_by_qualcomm(ad): |
| 228 | lto_mode(ad, True) |
| 229 | else: |
| 230 | reboot(ad) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 231 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 232 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 233 | def 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() |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 240 | 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) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 245 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 246 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 247 | def 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 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 260 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 261 | def _init_device(ad): |
| 262 | """Init GNSS test devices. |
| 263 | |
| 264 | Args: |
| 265 | ad: An AndroidDevice object. |
| 266 | """ |
| 267 | enable_gnss_verbose_logging(ad) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 268 | enable_compact_and_particle_fusion_log(ad) |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 269 | if check_chipset_vendor_by_qualcomm(ad): |
| 270 | disable_xtra_throttle(ad) |
| 271 | set_gnss_qxdm_mask(ad, QXDM_MASKS) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 272 | enable_supl_mode(ad) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 273 | 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) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 277 | check_location_service(ad) |
| 278 | set_wifi_and_bt_scanning(ad, True) |
jasonkmlu | 214f0d6 | 2019-04-08 19:53:59 +0800 | [diff] [blame] | 279 | disable_private_dns_mode(ad) |
jasonkmlu | 180a08c | 2019-04-23 17:24:55 +0800 | [diff] [blame] | 280 | reboot(ad) |
jasonkmlu | 4ba30a0 | 2020-04-09 14:16:49 +0800 | [diff] [blame] | 281 | init_gtw_gpstool(ad) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 282 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 283 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 284 | def 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] |
jasonkmlu | b663d3e | 2019-12-30 15:11:07 +0800 | [diff] [blame] | 292 | ad.ed.clear_all_events() |
| 293 | wutils.reset_wifi(ad) |
| 294 | wutils.start_wifi_connection_scan_and_ensure_network_found(ad, SSID) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 295 | wutils.wifi_connect(ad, network, num_of_tries=5) |
| 296 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 297 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 298 | def 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. |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 303 | state: True to turn on "Wi-Fi and Bluetooth scanning". |
| 304 | False to turn off "Wi-Fi and Bluetooth scanning". |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 305 | """ |
| 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 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 316 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 317 | def check_location_service(ad): |
| 318 | """Set location service on. |
| 319 | Verify if location service is available. |
| 320 | |
| 321 | Args: |
| 322 | ad: An AndroidDevice object. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 323 | """ |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 324 | remount_device(ad) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 325 | utils.set_location_service(ad, True) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 326 | 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: |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 329 | raise signals.TestError("Failed to turn Location on") |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 330 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 331 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 332 | def 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 Hong | 0ccbc75 | 2020-10-12 14:18:49 +0800 | [diff] [blame] | 343 | ad.adb.shell( |
| 344 | 'find %s -name "*.txt" -type f -delete' % GNSSSTATUS_LOG_PATH, |
| 345 | ignore_status=True) |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 346 | 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/") |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 351 | ad.adb.shell("rm -rf %s" % output_path, ignore_status=True) |
jasonkmlu | 214f0d6 | 2019-04-08 19:53:59 +0800 | [diff] [blame] | 352 | reboot(ad) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 353 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 354 | |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 355 | def get_gnss_qxdm_log(ad, qdb_path): |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 356 | """Get /storage/emulated/0/Android/data/com.android.gpstool/files and |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 357 | /data/vendor/radio/diag_logs/logs for test item. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 358 | |
| 359 | Args: |
| 360 | ad: An AndroidDevice object. |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 361 | qdb_path: The path of qdsp6m.qdb on different projects. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 362 | """ |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 363 | log_path = ad.device_log_path |
Mark De Ruyter | 72f8df9 | 2020-02-12 13:44:49 -0800 | [diff] [blame] | 364 | os.makedirs(log_path, exist_ok=True) |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 365 | gnss_log_name = "gnssstatus_log_%s_%s" % (ad.model, ad.serial) |
jasonkmlu | 670cfbc | 2019-11-27 18:58:21 +0800 | [diff] [blame] | 366 | gnss_log_path = posixpath.join(log_path, gnss_log_name) |
Mark De Ruyter | 72f8df9 | 2020-02-12 13:44:49 -0800 | [diff] [blame] | 367 | os.makedirs(gnss_log_path, exist_ok=True) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 368 | ad.log.info("Pull GnssStatus Log to %s" % gnss_log_path) |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 369 | ad.adb.pull("%s %s" % (GNSSSTATUS_LOG_PATH+".", gnss_log_path), |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 370 | timeout=PULL_TIMEOUT, ignore_status=True) |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 371 | shutil.make_archive(gnss_log_path, "zip", gnss_log_path) |
| 372 | shutil.rmtree(gnss_log_path) |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 373 | 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) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 382 | if not int(file_count) == 0: |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 383 | qxdm_log_name = "QXDM_%s_%s" % (ad.model, ad.serial) |
jasonkmlu | 670cfbc | 2019-11-27 18:58:21 +0800 | [diff] [blame] | 384 | qxdm_log_path = posixpath.join(log_path, qxdm_log_name) |
Mark De Ruyter | 72f8df9 | 2020-02-12 13:44:49 -0800 | [diff] [blame] | 385 | os.makedirs(qxdm_log_path, exist_ok=True) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 386 | 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) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 389 | 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 |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 395 | shutil.make_archive(qxdm_log_path, "zip", qxdm_log_path) |
| 396 | shutil.rmtree(qxdm_log_path) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 397 | else: |
| 398 | ad.log.error("QXDM file count is %d. There is no QXDM log on device." |
| 399 | % int(file_count)) |
| 400 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 401 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 402 | def 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 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 425 | |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 426 | def gnss_trigger_modem_ssr_by_adb(ad, dwelltime=60): |
| 427 | """Trigger modem SSR crash by adb and verify if modem crash and recover |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 428 | successfully. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 429 | |
| 430 | Args: |
| 431 | ad: An AndroidDevice object. |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 432 | dwelltime: Waiting time for modem reset. Default is 60 seconds. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 433 | |
| 434 | Returns: |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 435 | True if success. |
| 436 | False if failed. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 437 | """ |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 438 | 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) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 449 | ad.send_keycode("HOME") |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 450 | 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 |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 457 | raise signals.TestError("Failed to trigger modem SSR crash") |
| 458 | raise signals.TestError("No SSRObserver found in logcat") |
| 459 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 460 | |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 461 | def 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 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 487 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 488 | def 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") |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 500 | 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.") |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 516 | return False |
| 517 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 518 | |
jasonkmlu | 5e7817c | 2020-05-08 14:06:43 +0800 | [diff] [blame] | 519 | def pull_package_apk(ad, package_name): |
| 520 | """Pull apk of given package_name from device. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 521 | |
| 522 | Args: |
| 523 | ad: An AndroidDevice object. |
jasonkmlu | 5e7817c | 2020-05-08 14:06:43 +0800 | [diff] [blame] | 524 | package_name: Package name of apk to pull. |
| 525 | |
| 526 | Returns: |
| 527 | The temp path of pulled apk. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 528 | """ |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 529 | apk_path = None |
jasonkmlu | 5e7817c | 2020-05-08 14:06:43 +0800 | [diff] [blame] | 530 | out = ad.adb.shell("pm path %s" % package_name) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 531 | result = re.search(r"package:(.*)", out) |
| 532 | if not result: |
jasonkmlu | 5e7817c | 2020-05-08 14:06:43 +0800 | [diff] [blame] | 533 | tutils.abort_all_tests(ad.log, "Couldn't find apk of %s" % package_name) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 534 | else: |
jasonkmlu | 5e7817c | 2020-05-08 14:06:43 +0800 | [diff] [blame] | 535 | 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 |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 540 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 541 | |
jasonkmlu | 5e7817c | 2020-05-08 14:06:43 +0800 | [diff] [blame] | 542 | def reinstall_package_apk(ad, package_name, apk_path): |
| 543 | """Reinstall apk of given package_name. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 544 | |
| 545 | Args: |
| 546 | ad: An AndroidDevice object. |
jasonkmlu | 5e7817c | 2020-05-08 14:06:43 +0800 | [diff] [blame] | 547 | package_name: Package name of apk. |
| 548 | apk_path: The temp path of pulled apk. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 549 | """ |
jasonkmlu | 5e7817c | 2020-05-08 14:06:43 +0800 | [diff] [blame] | 550 | 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) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 564 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 565 | |
jasonkmlu | 180a08c | 2019-04-23 17:24:55 +0800 | [diff] [blame] | 566 | def init_gtw_gpstool(ad): |
| 567 | """Init GTW_GPSTool apk. |
| 568 | |
| 569 | Args: |
| 570 | ad: An AndroidDevice object. |
| 571 | """ |
| 572 | remount_device(ad) |
jasonkmlu | 5e7817c | 2020-05-08 14:06:43 +0800 | [diff] [blame] | 573 | gpstool_path = pull_package_apk(ad, "com.android.gpstool") |
| 574 | reinstall_package_apk(ad, "com.android.gpstool", gpstool_path) |
jasonkmlu | 180a08c | 2019-04-23 17:24:55 +0800 | [diff] [blame] | 575 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 576 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 577 | def 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 |
jasonkmlu | 5e7817c | 2020-05-08 14:06:43 +0800 | [diff] [blame] | 593 | 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") |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 596 | 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 |
jasonkmlu | 5e7817c | 2020-05-08 14:06:43 +0800 | [diff] [blame] | 617 | 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) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 620 | 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) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 636 | return status |
| 637 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 638 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 639 | def 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 | """ |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 647 | if not check_chipset_vendor_by_qualcomm(ad): |
| 648 | delete_lto_file(ad) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 649 | 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 Munuswamy | bc6038c | 2019-10-30 14:46:38 -0700 | [diff] [blame] | 653 | |
Scott Hong | a2e430b | 2020-08-27 15:14:57 +0800 | [diff] [blame] | 654 | def start_gnss_by_gtw_gpstool(ad, |
| 655 | state, |
| 656 | type="gnss", |
| 657 | bgdisplay=False, |
| 658 | freq=0, |
| 659 | lowpower=False, |
| 660 | meas=False): |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 661 | """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. |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 666 | type: Different API for location fix. Use gnss/flp/nmea |
Scott Hong | a2e430b | 2020-08-27 15:14:57 +0800 | [diff] [blame] | 667 | 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. |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 670 | meas: A Boolean to set GNSS measurement registration. |
Scott Hong | a2e430b | 2020-08-27 15:14:57 +0800 | [diff] [blame] | 671 | lowpower: A boolean to set GNSS LowPowerMode. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 672 | """ |
Scott Hong | a2e430b | 2020-08-27 15:14:57 +0800 | [diff] [blame] | 673 | cmd = "am start -S -n com.android.gpstool/.GPSTool --es mode gps" |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 674 | if not state: |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 675 | ad.log.info("Stop %s on GTW_GPSTool." % type) |
Scott Hong | a2e430b | 2020-08-27 15:14:57 +0800 | [diff] [blame] | 676 | 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 Hong | a2e430b | 2020-08-27 15:14:57 +0800 | [diff] [blame] | 681 | ad.adb.shell(cmd) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 682 | time.sleep(3) |
| 683 | |
Jayakumar Munuswamy | bc6038c | 2019-10-30 14:46:38 -0700 | [diff] [blame] | 684 | |
jasonkmlu | 8721ced | 2020-10-26 14:37:46 +0800 | [diff] [blame] | 685 | def process_gnss_by_gtw_gpstool(ad, |
| 686 | criteria, |
| 687 | type="gnss", |
| 688 | clear_data=True, |
| 689 | meas_flag=False): |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 690 | """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. |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 696 | type: Different API for location fix. Use gnss/flp/nmea |
jasonkmlu | 8721ced | 2020-10-26 14:37:46 +0800 | [diff] [blame] | 697 | clear_data: True to clear GNSS aiding data. False is not to. Default |
jasonkmlu | 5a385f2 | 2020-06-08 17:14:15 +0800 | [diff] [blame] | 698 | set to True. |
jasonkmlu | 8721ced | 2020-10-26 14:37:46 +0800 | [diff] [blame] | 699 | meas_flag: True to enable GnssMeasurement. False is not to. Default |
| 700 | set to False. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 701 | |
| 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): |
jasonkmlu | d68fdf0 | 2020-07-23 16:18:11 +0800 | [diff] [blame] | 708 | if not ad.is_adb_logcat_on: |
| 709 | ad.start_adb_logcat() |
| 710 | check_adblog_functionality(ad) |
jasonkmlu | 4ba30a0 | 2020-04-09 14:16:49 +0800 | [diff] [blame] | 711 | check_location_runtime_permissions( |
| 712 | ad, GNSSTOOL_PACKAGE_NAME, GNSSTOOL_PERMISSIONS) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 713 | begin_time = get_current_epoch_time() |
jasonkmlu | 5a385f2 | 2020-06-08 17:14:15 +0800 | [diff] [blame] | 714 | if clear_data: |
| 715 | clear_aiding_data_by_gtw_gpstool(ad) |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 716 | ad.log.info("Start %s on GTW_GPSTool - attempt %d" % (type.upper(), |
| 717 | i+1)) |
jasonkmlu | 8721ced | 2020-10-26 14:37:46 +0800 | [diff] [blame] | 718 | start_gnss_by_gtw_gpstool(ad, state=True, type=type, meas=meas_flag) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 719 | for _ in range(10 + criteria): |
| 720 | logcat_results = ad.search_logcat("First fixed", begin_time) |
| 721 | if logcat_results: |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 722 | ad.log.debug(logcat_results[-1]["log_message"]) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 723 | first_fixed = int(logcat_results[-1]["log_message"].split()[-1]) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 724 | ad.log.info("%s First fixed = %.3f seconds" % |
| 725 | (type.upper(), first_fixed/1000)) |
| 726 | if (first_fixed/1000) <= criteria: |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 727 | return True |
jasonkmlu | 8721ced | 2020-10-26 14:37:46 +0800 | [diff] [blame] | 728 | start_gnss_by_gtw_gpstool(ad, state=False, type=type) |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 729 | raise signals.TestFailure("Fail to get %s location fixed " |
| 730 | "within %d seconds criteria." |
| 731 | % (type.upper(), criteria)) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 732 | time.sleep(1) |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 733 | check_current_focus_app(ad) |
jasonkmlu | 8721ced | 2020-10-26 14:37:46 +0800 | [diff] [blame] | 734 | start_gnss_by_gtw_gpstool(ad, state=False, type=type) |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 735 | raise signals.TestFailure("Fail to get %s location fixed within %d " |
| 736 | "attempts." % (type.upper(), retries)) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 737 | |
Scott Hong | 7226969 | 2019-12-16 16:59:56 +0800 | [diff] [blame] | 738 | def start_ttff_by_gtw_gpstool(ad, ttff_mode, iteration, aid_data=False): |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 739 | """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 Hong | 7226969 | 2019-12-16 16:59:56 +0800 | [diff] [blame] | 745 | aid_data: Boolean for identify aid_data existed or not |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 746 | """ |
jasonkmlu | 97ac56e | 2019-05-29 15:04:51 +0800 | [diff] [blame] | 747 | begin_time = get_current_epoch_time() |
Scott Hong | 7226969 | 2019-12-16 16:59:56 +0800 | [diff] [blame] | 748 | if (ttff_mode == "hs" or ttff_mode == "ws") and not aid_data: |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 749 | ad.log.info("Wait 5 minutes to start TTFF %s..." % ttff_mode.upper()) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 750 | time.sleep(300) |
| 751 | if ttff_mode == "cs": |
| 752 | ad.log.info("Start TTFF Cold Start...") |
| 753 | time.sleep(3) |
jasonkmlu | 97ac56e | 2019-05-29 15:04:51 +0800 | [diff] [blame] | 754 | 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)) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 757 | time.sleep(1) |
jasonkmlu | 97ac56e | 2019-05-29 15:04:51 +0800 | [diff] [blame] | 758 | 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 |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 762 | else: |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 763 | check_current_focus_app(ad) |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 764 | raise signals.TestError("Fail to send TTFF start_test_action.") |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 765 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 766 | |
jasonkmlu | 8721ced | 2020-10-26 14:37:46 +0800 | [diff] [blame] | 767 | def gnss_tracking_via_gtw_gpstool(ad, |
| 768 | criteria, |
| 769 | type="gnss", |
| 770 | testtime=60, |
| 771 | meas_flag=False): |
jasonkmlu | 66fda53 | 2019-07-16 11:12:45 +0800 | [diff] [blame] | 772 | """Start GNSS/FLP tracking tests for input testtime on GTW_GPSTool. |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 773 | |
| 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. |
jasonkmlu | 8721ced | 2020-10-26 14:37:46 +0800 | [diff] [blame] | 779 | meas_flag: True to enable GnssMeasurement. False is not to. Default |
| 780 | set to False. |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 781 | """ |
jasonkmlu | 8721ced | 2020-10-26 14:37:46 +0800 | [diff] [blame] | 782 | process_gnss_by_gtw_gpstool( |
| 783 | ad, criteria=criteria, type=type, meas_flag=meas_flag) |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 784 | ad.log.info("Start %s tracking test for %d minutes" % (type.upper(), |
| 785 | testtime)) |
| 786 | begin_time = get_current_epoch_time() |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 787 | while get_current_epoch_time() - begin_time < testtime * 60 * 1000: |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 788 | if not ad.is_adb_logcat_on: |
| 789 | ad.start_adb_logcat() |
| 790 | crash_result = ad.search_logcat("Force finishing activity " |
| 791 | "com.android.gpstool/.GPSTool", |
| 792 | begin_time) |
| 793 | if crash_result: |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 794 | raise signals.TestError("GPSTool crashed. Abort test.") |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 795 | ad.log.info("Successfully tested for %d minutes" % testtime) |
jasonkmlu | 8721ced | 2020-10-26 14:37:46 +0800 | [diff] [blame] | 796 | start_gnss_by_gtw_gpstool(ad, state=False, type=type) |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 797 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 798 | |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 799 | def parse_gtw_gpstool_log(ad, true_position, type="gnss"): |
| 800 | """Process GNSS/FLP API logs from GTW GPSTool and output track_data to |
| 801 | test_run_info for ACTS plugin to parse and display on MobileHarness as |
| 802 | Property. |
| 803 | |
| 804 | Args: |
| 805 | ad: An AndroidDevice object. |
| 806 | true_position: Coordinate as [latitude, longitude] to calculate |
| 807 | position error. |
| 808 | type: Different API for location fix. Use gnss/flp/nmea |
| 809 | """ |
| 810 | test_logfile = {} |
| 811 | track_data = {} |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 812 | ant_top4_cn = 0 |
| 813 | ant_cn = 0 |
| 814 | base_top4_cn = 0 |
| 815 | base_cn = 0 |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 816 | track_lat = 0 |
| 817 | track_long = 0 |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 818 | l5flag = "false" |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 819 | file_count = int(ad.adb.shell("find %s -type f -iname *.txt | wc -l" |
| 820 | % GNSSSTATUS_LOG_PATH)) |
| 821 | if file_count != 1: |
| 822 | ad.log.error("%d API logs exist." % file_count) |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 823 | dir_file = ad.adb.shell("ls %s" % GNSSSTATUS_LOG_PATH).split() |
| 824 | for path_key in dir_file: |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 825 | if fnmatch.fnmatch(path_key, "*.txt"): |
| 826 | logpath = posixpath.join(GNSSSTATUS_LOG_PATH, path_key) |
| 827 | out = ad.adb.shell("wc -c %s" % logpath) |
| 828 | file_size = int(out.split(" ")[0]) |
| 829 | if file_size < 2000: |
| 830 | ad.log.info("Skip log %s due to log size %d bytes" % |
| 831 | (path_key, file_size)) |
| 832 | continue |
| 833 | test_logfile = logpath |
| 834 | if not test_logfile: |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 835 | raise signals.TestError("Failed to get test log file in device.") |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 836 | lines = ad.adb.shell("cat %s" % test_logfile).split("\n") |
| 837 | for line in lines: |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 838 | if "Antenna_History Avg Top4" in line: |
| 839 | ant_top4_cn = float(line.split(":")[-1].strip()) |
| 840 | elif "Antenna_History Avg" in line: |
| 841 | ant_cn = float(line.split(":")[-1].strip()) |
| 842 | elif "Baseband_History Avg Top4" in line: |
| 843 | base_top4_cn = float(line.split(":")[-1].strip()) |
| 844 | elif "Baseband_History Avg" in line: |
| 845 | base_cn = float(line.split(":")[-1].strip()) |
| 846 | elif "L5 used in fix" in line: |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 847 | l5flag = line.split(":")[-1].strip() |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 848 | elif "Latitude" in line: |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 849 | track_lat = float(line.split(":")[-1].strip()) |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 850 | elif "Longitude" in line: |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 851 | track_long = float(line.split(":")[-1].strip()) |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 852 | elif "Time" in line: |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 853 | track_utc = line.split("Time:")[-1].strip() |
| 854 | if track_utc in track_data.keys(): |
| 855 | continue |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 856 | pe = calculate_position_error(track_lat, track_long, true_position) |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 857 | track_data[track_utc] = TRACK_REPORT(l5flag=l5flag, |
| 858 | pe=pe, |
| 859 | ant_top4cn=ant_top4_cn, |
| 860 | ant_cn=ant_cn, |
| 861 | base_top4cn=base_top4_cn, |
| 862 | base_cn=base_cn) |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 863 | ad.log.debug(track_data) |
| 864 | prop_basename = "TestResult %s_tracking_" % type.upper() |
| 865 | time_list = sorted(track_data.keys()) |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 866 | l5flag_list = [track_data[key].l5flag for key in time_list] |
| 867 | pe_list = [float(track_data[key].pe) for key in time_list] |
| 868 | ant_top4cn_list = [float(track_data[key].ant_top4cn) for key in time_list] |
| 869 | ant_cn_list = [float(track_data[key].ant_cn) for key in time_list] |
| 870 | base_top4cn_list = [float(track_data[key].base_top4cn) for key in time_list] |
| 871 | base_cn_list = [float(track_data[key].base_cn) for key in time_list] |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 872 | ad.log.info(prop_basename+"StartTime %s" % time_list[0].replace(" ", "-")) |
| 873 | ad.log.info(prop_basename+"EndTime %s" % time_list[-1].replace(" ", "-")) |
| 874 | ad.log.info(prop_basename+"TotalFixPoints %d" % len(time_list)) |
| 875 | ad.log.info(prop_basename+"L5FixRate "+'{percent:.2%}'.format( |
| 876 | percent=l5flag_list.count("true")/len(l5flag_list))) |
| 877 | ad.log.info(prop_basename+"AvgDis %.1f" % (sum(pe_list)/len(pe_list))) |
| 878 | ad.log.info(prop_basename+"MaxDis %.1f" % max(pe_list)) |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 879 | ad.log.info(prop_basename+"Ant_AvgTop4Signal %.1f" % ant_top4cn_list[-1]) |
| 880 | ad.log.info(prop_basename+"Ant_AvgSignal %.1f" % ant_cn_list[-1]) |
| 881 | ad.log.info(prop_basename+"Base_AvgTop4Signal %.1f" % base_top4cn_list[-1]) |
| 882 | ad.log.info(prop_basename+"Base_AvgSignal %.1f" % base_cn_list[-1]) |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 883 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 884 | |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 885 | def process_ttff_by_gtw_gpstool(ad, begin_time, true_position, type="gnss"): |
| 886 | """Process TTFF and record results in ttff_data. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 887 | |
| 888 | Args: |
| 889 | ad: An AndroidDevice object. |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 890 | begin_time: test begin time. |
jasonkmlu | 733738f | 2019-09-02 18:59:42 +0800 | [diff] [blame] | 891 | true_position: Coordinate as [latitude, longitude] to calculate |
| 892 | position error. |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 893 | type: Different API for location fix. Use gnss/flp/nmea |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 894 | |
| 895 | Returns: |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 896 | ttff_data: A dict of all TTFF data. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 897 | """ |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 898 | ttff_lat = 0 |
| 899 | ttff_lon = 0 |
| 900 | utc_time = epoch_to_human_time(get_current_epoch_time()) |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 901 | ttff_data = {} |
jasonkmlu | 733738f | 2019-09-02 18:59:42 +0800 | [diff] [blame] | 902 | ttff_loop_time = get_current_epoch_time() |
jasonkmlu | 97ac56e | 2019-05-29 15:04:51 +0800 | [diff] [blame] | 903 | while True: |
jasonkmlu | 733738f | 2019-09-02 18:59:42 +0800 | [diff] [blame] | 904 | if get_current_epoch_time() - ttff_loop_time >= 120000: |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 905 | raise signals.TestError("Fail to search specific GPSService " |
| 906 | "message in logcat. Abort test.") |
jasonkmlu | 97ac56e | 2019-05-29 15:04:51 +0800 | [diff] [blame] | 907 | if not ad.is_adb_logcat_on: |
| 908 | ad.start_adb_logcat() |
jasonkmlu | 61b686f | 2020-07-20 20:07:04 +0800 | [diff] [blame] | 909 | logcat_results = ad.search_logcat("write TTFF log", ttff_loop_time) |
jasonkmlu | 97ac56e | 2019-05-29 15:04:51 +0800 | [diff] [blame] | 910 | if logcat_results: |
jasonkmlu | 61b686f | 2020-07-20 20:07:04 +0800 | [diff] [blame] | 911 | ttff_loop_time = get_current_epoch_time() |
jasonkmlu | 97ac56e | 2019-05-29 15:04:51 +0800 | [diff] [blame] | 912 | ttff_log = logcat_results[-1]["log_message"].split() |
| 913 | ttff_loop = int(ttff_log[8].split(":")[-1]) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 914 | ttff_sec = float(ttff_log[11]) |
| 915 | if ttff_sec != 0.0: |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 916 | ttff_ant_cn = float(ttff_log[18].strip("]")) |
| 917 | ttff_base_cn = float(ttff_log[25].strip("]")) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 918 | if type == "gnss": |
jasonkmlu | 733738f | 2019-09-02 18:59:42 +0800 | [diff] [blame] | 919 | gnss_results = ad.search_logcat("GPSService: Check item", |
| 920 | begin_time) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 921 | if gnss_results: |
| 922 | ad.log.debug(gnss_results[-1]["log_message"]) |
jasonkmlu | 733738f | 2019-09-02 18:59:42 +0800 | [diff] [blame] | 923 | gnss_location_log = \ |
| 924 | gnss_results[-1]["log_message"].split() |
| 925 | ttff_lat = float( |
| 926 | gnss_location_log[8].split("=")[-1].strip(",")) |
| 927 | ttff_lon = float( |
| 928 | gnss_location_log[9].split("=")[-1].strip(",")) |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 929 | loc_time = int( |
| 930 | gnss_location_log[10].split("=")[-1].strip(",")) |
| 931 | utc_time = epoch_to_human_time(loc_time) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 932 | elif type == "flp": |
jasonkmlu | 733738f | 2019-09-02 18:59:42 +0800 | [diff] [blame] | 933 | flp_results = ad.search_logcat("GPSService: FLP Location", |
| 934 | begin_time) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 935 | if flp_results: |
| 936 | ad.log.debug(flp_results[-1]["log_message"]) |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 937 | flp_location_log = flp_results[-1][ |
| 938 | "log_message"].split() |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 939 | ttff_lat = float(flp_location_log[8].split(",")[0]) |
| 940 | ttff_lon = float(flp_location_log[8].split(",")[1]) |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 941 | utc_time = epoch_to_human_time(get_current_epoch_time()) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 942 | else: |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 943 | ttff_ant_cn = float(ttff_log[19].strip("]")) |
| 944 | ttff_base_cn = float(ttff_log[26].strip("]")) |
| 945 | ttff_lat = 0 |
| 946 | ttff_lon = 0 |
| 947 | utc_time = epoch_to_human_time(get_current_epoch_time()) |
jasonkmlu | 2565d89 | 2019-11-12 15:31:26 +0800 | [diff] [blame] | 948 | ad.log.debug("TTFF Loop %d - (Lat, Lon) = (%s, %s)" % (ttff_loop, |
| 949 | ttff_lat, |
| 950 | ttff_lon)) |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 951 | ttff_pe = calculate_position_error( |
| 952 | ttff_lat, ttff_lon, true_position) |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 953 | ttff_data[ttff_loop] = TTFF_REPORT(utc_time=utc_time, |
| 954 | ttff_loop=ttff_loop, |
jasonkmlu | 97ac56e | 2019-05-29 15:04:51 +0800 | [diff] [blame] | 955 | ttff_sec=ttff_sec, |
| 956 | ttff_pe=ttff_pe, |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 957 | ttff_ant_cn=ttff_ant_cn, |
| 958 | ttff_base_cn=ttff_base_cn) |
| 959 | ad.log.info("UTC Time = %s, Loop %d = %.1f seconds, " |
jasonkmlu | 97ac56e | 2019-05-29 15:04:51 +0800 | [diff] [blame] | 960 | "Position Error = %.1f meters, " |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 961 | "Antenna Average Signal = %.1f dbHz, " |
| 962 | "Baseband Average Signal = %.1f dbHz" % (utc_time, |
| 963 | ttff_loop, |
| 964 | ttff_sec, |
| 965 | ttff_pe, |
| 966 | ttff_ant_cn, |
| 967 | ttff_base_cn)) |
| 968 | stop_gps_results = ad.search_logcat("stop gps test", begin_time) |
| 969 | if stop_gps_results: |
| 970 | ad.send_keycode("HOME") |
| 971 | break |
| 972 | crash_result = ad.search_logcat("Force finishing activity " |
| 973 | "com.android.gpstool/.GPSTool", |
| 974 | begin_time) |
| 975 | if crash_result: |
| 976 | raise signals.TestError("GPSTool crashed. Abort test.") |
jasonkmlu | 08cb929 | 2020-07-29 11:49:08 +0800 | [diff] [blame] | 977 | # wait 10 seconds to avoid logs not writing into logcat yet |
| 978 | time.sleep(10) |
jasonkmlu | 97ac56e | 2019-05-29 15:04:51 +0800 | [diff] [blame] | 979 | return ttff_data |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 980 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 981 | |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 982 | def check_ttff_data(ad, ttff_data, ttff_mode, criteria): |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 983 | """Verify all TTFF results from ttff_data. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 984 | |
| 985 | Args: |
| 986 | ad: An AndroidDevice object. |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 987 | ttff_data: TTFF data of secs, position error and signal strength. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 988 | ttff_mode: TTFF Test mode for current test item. |
| 989 | criteria: Criteria for current test item. |
| 990 | |
| 991 | Returns: |
| 992 | True: All TTFF results are within criteria. |
| 993 | False: One or more TTFF results exceed criteria or Timeout. |
| 994 | """ |
| 995 | ad.log.info("%d iterations of TTFF %s tests finished." |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 996 | % (len(ttff_data.keys()), ttff_mode)) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 997 | ad.log.info("%s PASS criteria is %d seconds" % (ttff_mode, criteria)) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 998 | ad.log.debug("%s TTFF data: %s" % (ttff_mode, ttff_data)) |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 999 | ttff_property_key_and_value(ad, ttff_data, ttff_mode) |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 1000 | if len(ttff_data.keys()) == 0: |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1001 | ad.log.error("GTW_GPSTool didn't process TTFF properly.") |
| 1002 | return False |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 1003 | elif any(float(ttff_data[key].ttff_sec) == 0.0 for key in ttff_data.keys()): |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1004 | ad.log.error("One or more TTFF %s Timeout" % ttff_mode) |
| 1005 | return False |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1006 | elif any(float(ttff_data[key].ttff_sec) >= criteria for key in |
| 1007 | ttff_data.keys()): |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1008 | ad.log.error("One or more TTFF %s are over test criteria %d seconds" |
| 1009 | % (ttff_mode, criteria)) |
| 1010 | return False |
| 1011 | ad.log.info("All TTFF %s are within test criteria %d seconds." |
| 1012 | % (ttff_mode, criteria)) |
| 1013 | return True |
| 1014 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 1015 | |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 1016 | def ttff_property_key_and_value(ad, ttff_data, ttff_mode): |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1017 | """Output ttff_data to test_run_info for ACTS plugin to parse and display |
| 1018 | on MobileHarness as Property. |
| 1019 | |
| 1020 | Args: |
| 1021 | ad: An AndroidDevice object. |
| 1022 | ttff_data: TTFF data of secs, position error and signal strength. |
| 1023 | ttff_mode: TTFF Test mode for current test item. |
| 1024 | """ |
| 1025 | prop_basename = "TestResult "+ttff_mode.replace(" ", "_")+"_TTFF_" |
| 1026 | sec_list = [float(ttff_data[key].ttff_sec) for key in ttff_data.keys()] |
| 1027 | pe_list = [float(ttff_data[key].ttff_pe) for key in ttff_data.keys()] |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 1028 | ant_cn_list = [float(ttff_data[key].ttff_ant_cn) for key in |
| 1029 | ttff_data.keys()] |
| 1030 | base_cn_list = [float(ttff_data[key].ttff_base_cn) for key in |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1031 | ttff_data.keys()] |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1032 | timeoutcount = sec_list.count(0.0) |
jasonkmlu | c1ec305 | 2019-10-25 14:57:53 +0800 | [diff] [blame] | 1033 | if len(sec_list) == timeoutcount: |
| 1034 | avgttff = 9527 |
| 1035 | else: |
| 1036 | avgttff = sum(sec_list)/(len(sec_list) - timeoutcount) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1037 | if timeoutcount != 0: |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 1038 | maxttff = 9527 |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1039 | else: |
| 1040 | maxttff = max(sec_list) |
| 1041 | avgdis = sum(pe_list)/len(pe_list) |
| 1042 | maxdis = max(pe_list) |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 1043 | ant_avgcn = sum(ant_cn_list)/len(ant_cn_list) |
| 1044 | base_avgcn = sum(base_cn_list)/len(base_cn_list) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1045 | ad.log.info(prop_basename+"AvgTime %.1f" % avgttff) |
| 1046 | ad.log.info(prop_basename+"MaxTime %.1f" % maxttff) |
| 1047 | ad.log.info(prop_basename+"TimeoutCount %d" % timeoutcount) |
| 1048 | ad.log.info(prop_basename+"AvgDis %.1f" % avgdis) |
| 1049 | ad.log.info(prop_basename+"MaxDis %.1f" % maxdis) |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 1050 | ad.log.info(prop_basename+"Ant_AvgSignal %.1f" % ant_avgcn) |
| 1051 | ad.log.info(prop_basename+"Base_AvgSignal %.1f" % base_avgcn) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1052 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 1053 | |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1054 | def calculate_position_error(latitude, longitude, true_position): |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 1055 | """Use haversine formula to calculate position error base on true location |
| 1056 | coordinate. |
| 1057 | |
| 1058 | Args: |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 1059 | latitude: latitude of location fixed in the present. |
| 1060 | longitude: longitude of location fixed in the present. |
| 1061 | true_position: [latitude, longitude] of true location coordinate. |
| 1062 | |
| 1063 | Returns: |
| 1064 | position_error of location fixed in the present. |
| 1065 | """ |
| 1066 | radius = 6371009 |
| 1067 | dlat = math.radians(latitude - true_position[0]) |
| 1068 | dlon = math.radians(longitude - true_position[1]) |
| 1069 | a = math.sin(dlat/2) * math.sin(dlat/2) + \ |
| 1070 | math.cos(math.radians(true_position[0])) * \ |
| 1071 | math.cos(math.radians(latitude)) * math.sin(dlon/2) * math.sin(dlon/2) |
| 1072 | c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) |
| 1073 | return radius * c |
| 1074 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 1075 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1076 | def launch_google_map(ad): |
| 1077 | """Launch Google Map via intent. |
| 1078 | |
| 1079 | Args: |
| 1080 | ad: An AndroidDevice object. |
| 1081 | """ |
| 1082 | ad.log.info("Launch Google Map.") |
| 1083 | try: |
| 1084 | ad.adb.shell("am start -S -n com.google.android.apps.maps/" |
| 1085 | "com.google.android.maps.MapsActivity") |
| 1086 | ad.send_keycode("BACK") |
| 1087 | ad.force_stop_apk("com.google.android.apps.maps") |
| 1088 | ad.adb.shell("am start -S -n com.google.android.apps.maps/" |
| 1089 | "com.google.android.maps.MapsActivity") |
| 1090 | except Exception as e: |
| 1091 | ad.log.error(e) |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 1092 | raise signals.TestError("Failed to launch google map.") |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1093 | check_current_focus_app(ad) |
jasonkmlu | 49c3281 | 2019-04-12 18:11:10 +0800 | [diff] [blame] | 1094 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 1095 | |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1096 | def check_current_focus_app(ad): |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 1097 | """Check to see current focused window and app. |
jasonkmlu | 49c3281 | 2019-04-12 18:11:10 +0800 | [diff] [blame] | 1098 | |
| 1099 | Args: |
| 1100 | ad: An AndroidDevice object. |
jasonkmlu | 49c3281 | 2019-04-12 18:11:10 +0800 | [diff] [blame] | 1101 | """ |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 1102 | time.sleep(1) |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1103 | current = ad.adb.shell( |
| 1104 | "dumpsys window | grep -E 'mCurrentFocus|mFocusedApp'") |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1105 | ad.log.debug("\n"+current) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1106 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 1107 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1108 | def check_location_api(ad, retries): |
| 1109 | """Verify if GnssLocationProvider API reports location. |
| 1110 | |
| 1111 | Args: |
| 1112 | ad: An AndroidDevice object. |
| 1113 | retries: Retry time. |
| 1114 | |
| 1115 | Returns: |
| 1116 | True: GnssLocationProvider API reports location. |
| 1117 | otherwise return False. |
| 1118 | """ |
| 1119 | for i in range(retries): |
| 1120 | begin_time = get_current_epoch_time() |
| 1121 | ad.log.info("Try to get location report from GnssLocationProvider API " |
| 1122 | "- attempt %d" % (i+1)) |
| 1123 | while get_current_epoch_time() - begin_time <= 30000: |
| 1124 | logcat_results = ad.search_logcat("REPORT_LOCATION", begin_time) |
| 1125 | if logcat_results: |
| 1126 | ad.log.info("%s" % logcat_results[-1]["log_message"]) |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1127 | ad.log.info("GnssLocationProvider reports location " |
| 1128 | "successfully.") |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1129 | return True |
| 1130 | if not ad.is_adb_logcat_on: |
| 1131 | ad.start_adb_logcat() |
| 1132 | ad.log.error("GnssLocationProvider is unable to report location.") |
| 1133 | return False |
| 1134 | |
Scott Hong | 7226969 | 2019-12-16 16:59:56 +0800 | [diff] [blame] | 1135 | def check_network_location(ad, retries, location_type, criteria=30): |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1136 | """Verify if NLP reports location after requesting via GPSTool. |
| 1137 | |
| 1138 | Args: |
| 1139 | ad: An AndroidDevice object. |
| 1140 | retries: Retry time. |
Scott Hong | accd8a1 | 2020-03-03 20:12:17 +0800 | [diff] [blame] | 1141 | location_type: cell or wifi. |
Scott Hong | 7226969 | 2019-12-16 16:59:56 +0800 | [diff] [blame] | 1142 | criteria: expected nlp return time, default 30 seconds |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1143 | |
| 1144 | Returns: |
| 1145 | True: NLP reports location. |
| 1146 | otherwise return False. |
| 1147 | """ |
Scott Hong | 7226969 | 2019-12-16 16:59:56 +0800 | [diff] [blame] | 1148 | criteria = criteria * 1000 |
Scott Hong | accd8a1 | 2020-03-03 20:12:17 +0800 | [diff] [blame] | 1149 | search_pattern = ("GPSTool : networkLocationType = %s" % location_type) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1150 | for i in range(retries): |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1151 | begin_time = get_current_epoch_time() |
| 1152 | ad.log.info("Try to get NLP status - attempt %d" % (i+1)) |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1153 | ad.adb.shell( |
| 1154 | "am start -S -n com.android.gpstool/.GPSTool --es mode nlp") |
Scott Hong | 7226969 | 2019-12-16 16:59:56 +0800 | [diff] [blame] | 1155 | while get_current_epoch_time() - begin_time <= criteria: |
Scott Hong | accd8a1 | 2020-03-03 20:12:17 +0800 | [diff] [blame] | 1156 | # Search pattern in 1 second interval |
| 1157 | time.sleep(1) |
| 1158 | result = ad.search_logcat(search_pattern, begin_time) |
| 1159 | if result: |
| 1160 | ad.log.info("Pattern Found: %s." % result[-1]["log_message"]) |
| 1161 | ad.send_keycode("BACK") |
| 1162 | return True |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1163 | if not ad.is_adb_logcat_on: |
| 1164 | ad.start_adb_logcat() |
| 1165 | ad.send_keycode("BACK") |
| 1166 | ad.log.error("Unable to report network location \"%s\"." % location_type) |
| 1167 | return False |
| 1168 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 1169 | |
jasonkmlu | 8d6bbfc | 2019-03-29 15:57:43 +0800 | [diff] [blame] | 1170 | def set_attenuator_gnss_signal(ad, attenuator, atten_value): |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1171 | """Set attenuation value for different GNSS signal. |
| 1172 | |
| 1173 | Args: |
| 1174 | ad: An AndroidDevice object. |
jasonkmlu | 8d6bbfc | 2019-03-29 15:57:43 +0800 | [diff] [blame] | 1175 | attenuator: The attenuator object. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1176 | atten_value: attenuation value |
| 1177 | """ |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1178 | try: |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1179 | ad.log.info( |
| 1180 | "Set attenuation value to \"%d\" for GNSS signal." % atten_value) |
jasonkmlu | 8d6bbfc | 2019-03-29 15:57:43 +0800 | [diff] [blame] | 1181 | attenuator[0].set_atten(atten_value) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1182 | except Exception as e: |
jasonkmlu | 4fcdcad | 2019-07-10 14:35:12 +0800 | [diff] [blame] | 1183 | ad.log.error(e) |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1184 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 1185 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1186 | def set_battery_saver_mode(ad, state): |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1187 | """Enable or disable battery saver mode via adb. |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1188 | |
| 1189 | Args: |
| 1190 | ad: An AndroidDevice object. |
| 1191 | state: True is enable Battery Saver mode. False is disable. |
| 1192 | """ |
| 1193 | ad.root_adb() |
| 1194 | if state: |
| 1195 | ad.log.info("Enable Battery Saver mode.") |
| 1196 | ad.adb.shell("cmd battery unplug") |
| 1197 | ad.adb.shell("settings put global low_power 1") |
| 1198 | else: |
| 1199 | ad.log.info("Disable Battery Saver mode.") |
| 1200 | ad.adb.shell("settings put global low_power 0") |
| 1201 | ad.adb.shell("cmd battery reset") |
| 1202 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 1203 | |
jasonkmlu | ff0d5b9 | 2019-03-21 11:24:45 +0800 | [diff] [blame] | 1204 | def set_gnss_qxdm_mask(ad, masks): |
| 1205 | """Find defined gnss qxdm mask and set as default logging mask. |
| 1206 | |
| 1207 | Args: |
| 1208 | ad: An AndroidDevice object. |
| 1209 | masks: Defined gnss qxdm mask. |
| 1210 | """ |
| 1211 | try: |
| 1212 | for mask in masks: |
| 1213 | if not tutils.find_qxdm_log_mask(ad, mask): |
| 1214 | continue |
| 1215 | tutils.set_qxdm_logger_command(ad, mask) |
| 1216 | break |
| 1217 | except Exception as e: |
| 1218 | ad.log.error(e) |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 1219 | raise signals.TestError("Failed to set any QXDM masks.") |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 1220 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 1221 | |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 1222 | def start_youtube_video(ad, url=None, retries=0): |
| 1223 | """Start youtube video and verify if audio is in music state. |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1224 | |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 1225 | Args: |
| 1226 | ad: An AndroidDevice object. |
| 1227 | url: Youtube video url. |
| 1228 | retries: Retry times if audio is not in music state. |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1229 | |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 1230 | Returns: |
| 1231 | True if youtube video is playing normally. |
| 1232 | False if youtube video is not playing properly. |
| 1233 | """ |
| 1234 | for i in range(retries): |
| 1235 | ad.log.info("Open an youtube video - attempt %d" % (i+1)) |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 1236 | cmd = ("am start -n com.google.android.youtube/" |
| 1237 | "com.google.android.youtube.UrlActivity -d \"%s\"" % url) |
| 1238 | ad.adb.shell(cmd) |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 1239 | time.sleep(2) |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1240 | out = ad.adb.shell( |
| 1241 | "dumpsys activity | grep NewVersionAvailableActivity") |
jasonkmlu | 903ece8 | 2019-05-16 14:56:19 +0800 | [diff] [blame] | 1242 | if out: |
| 1243 | ad.log.info("Skip Youtube New Version Update.") |
| 1244 | ad.send_keycode("BACK") |
| 1245 | if tutils.wait_for_state(ad.droid.audioIsMusicActive, True, 15, 1): |
| 1246 | ad.log.info("Started a video in youtube, audio is in MUSIC state") |
| 1247 | return True |
| 1248 | ad.log.info("Force-Stop youtube and reopen youtube again.") |
| 1249 | ad.force_stop_apk("com.google.android.youtube") |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1250 | check_current_focus_app(ad) |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 1251 | raise signals.TestError("Started a video in youtube, " |
| 1252 | "but audio is not in MUSIC state") |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1253 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 1254 | |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1255 | def get_baseband_and_gms_version(ad, extra_msg=""): |
| 1256 | """Get current radio baseband and GMSCore version of AndroidDevice object. |
| 1257 | |
| 1258 | Args: |
| 1259 | ad: An AndroidDevice object. |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1260 | extra_msg: Extra message before or after the change. |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1261 | """ |
| 1262 | try: |
jasonkmlu | d93060f | 2019-11-05 15:12:55 +0800 | [diff] [blame] | 1263 | build_version = ad.adb.getprop("ro.build.id") |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1264 | baseband_version = ad.adb.getprop("gsm.version.baseband") |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1265 | gms_version = ad.adb.shell( |
| 1266 | "dumpsys package com.google.android.gms | grep versionName" |
| 1267 | ).split("\n")[0].split("=")[1] |
| 1268 | mpss_version = ad.adb.shell("cat /sys/devices/soc0/images | grep MPSS " |
| 1269 | "| cut -d ':' -f 3") |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1270 | if not extra_msg: |
jasonkmlu | d93060f | 2019-11-05 15:12:55 +0800 | [diff] [blame] | 1271 | ad.log.info("TestResult Build_Version %s" % build_version) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1272 | ad.log.info("TestResult Baseband_Version %s" % baseband_version) |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1273 | ad.log.info( |
| 1274 | "TestResult GMS_Version %s" % gms_version.replace(" ", "")) |
| 1275 | ad.log.info("TestResult MPSS_Version %s" % mpss_version) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1276 | else: |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1277 | ad.log.info( |
| 1278 | "%s, Baseband_Version = %s" % (extra_msg, baseband_version)) |
jasonkmlu | 81b8b03 | 2019-06-21 15:18:27 +0800 | [diff] [blame] | 1279 | except Exception as e: |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1280 | ad.log.error(e) |
| 1281 | |
jasonkmlu | 0f546de | 2019-12-13 20:58:41 +0800 | [diff] [blame] | 1282 | |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1283 | def start_toggle_gnss_by_gtw_gpstool(ad, iteration): |
| 1284 | """Send toggle gnss off/on start_test_action |
| 1285 | |
| 1286 | Args: |
| 1287 | ad: An AndroidDevice object. |
| 1288 | iteration: Iteration of toggle gnss off/on cycles. |
| 1289 | """ |
| 1290 | msg_list = [] |
| 1291 | begin_time = get_current_epoch_time() |
| 1292 | try: |
| 1293 | for i in range(1, 4): |
| 1294 | ad.adb.shell("am start -S -n com.android.gpstool/.GPSTool " |
| 1295 | "--es mode toggle --es cycle %d" % iteration) |
| 1296 | time.sleep(1) |
| 1297 | if ad.search_logcat("cmp=com.android.gpstool/.ToggleGPS", |
| 1298 | begin_time): |
| 1299 | ad.log.info("Send ToggleGPS start_test_action successfully.") |
| 1300 | break |
| 1301 | else: |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1302 | check_current_focus_app(ad) |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 1303 | raise signals.TestError("Fail to send ToggleGPS " |
| 1304 | "start_test_action within 3 attempts.") |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1305 | time.sleep(2) |
| 1306 | test_start = ad.search_logcat("GPSTool_ToggleGPS: startService", |
| 1307 | begin_time) |
| 1308 | if test_start: |
| 1309 | ad.log.info(test_start[-1]["log_message"].split(":")[-1].strip()) |
| 1310 | else: |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 1311 | raise signals.TestError("Fail to start toggle GPS off/on test.") |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1312 | # Every iteration is expected to finish within 4 minutes. |
| 1313 | while get_current_epoch_time() - begin_time <= iteration * 240000: |
| 1314 | crash_end = ad.search_logcat("Force finishing activity " |
| 1315 | "com.android.gpstool/.GPSTool", |
| 1316 | begin_time) |
| 1317 | if crash_end: |
jasonkmlu | 7854063 | 2019-11-15 18:04:20 +0800 | [diff] [blame] | 1318 | raise signals.TestError("GPSTool crashed. Abort test.") |
jasonkmlu | 035eee1 | 2019-10-08 17:11:20 +0800 | [diff] [blame] | 1319 | toggle_results = ad.search_logcat("GPSTool : msg", begin_time) |
| 1320 | if toggle_results: |
| 1321 | for toggle_result in toggle_results: |
| 1322 | msg = toggle_result["log_message"] |
| 1323 | if not msg in msg_list: |
| 1324 | ad.log.info(msg.split(":")[-1].strip()) |
| 1325 | msg_list.append(msg) |
| 1326 | if "timeout" in msg: |
| 1327 | raise signals.TestFailure("Fail to get location fixed " |
| 1328 | "within 60 seconds.") |
| 1329 | if "Test end" in msg: |
| 1330 | raise signals.TestPass("Completed quick toggle GNSS " |
| 1331 | "off/on test.") |
| 1332 | raise signals.TestFailure("Fail to finish toggle GPS off/on test " |
| 1333 | "within %d minutes" % (iteration * 4)) |
| 1334 | finally: |
| 1335 | ad.send_keycode("HOME") |
jasonkmlu | dc430ec | 2020-03-27 10:40:39 +0800 | [diff] [blame] | 1336 | |
jasonkmlu | 4ba30a0 | 2020-04-09 14:16:49 +0800 | [diff] [blame] | 1337 | |
jasonkmlu | dc430ec | 2020-03-27 10:40:39 +0800 | [diff] [blame] | 1338 | def grant_location_permission(ad, option): |
| 1339 | """Grant or revoke location related permission. |
| 1340 | |
| 1341 | Args: |
| 1342 | ad: An AndroidDevice object. |
| 1343 | option: Boolean to grant or revoke location related permissions. |
| 1344 | """ |
jasonkmlu | 4ba30a0 | 2020-04-09 14:16:49 +0800 | [diff] [blame] | 1345 | action = "grant" if option else "revoke" |
jasonkmlu | dc430ec | 2020-03-27 10:40:39 +0800 | [diff] [blame] | 1346 | for permission in LOCATION_PERMISSIONS: |
| 1347 | ad.log.info( |
jasonkmlu | 4ba30a0 | 2020-04-09 14:16:49 +0800 | [diff] [blame] | 1348 | "%s permission:%s on %s" % (action, permission, TEST_PACKAGE_NAME)) |
| 1349 | ad.adb.shell("pm %s %s %s" % (action, TEST_PACKAGE_NAME, permission)) |
| 1350 | |
| 1351 | |
| 1352 | def check_location_runtime_permissions(ad, package, permissions): |
| 1353 | """Check if runtime permissions are granted on selected package. |
| 1354 | |
| 1355 | Args: |
| 1356 | ad: An AndroidDevice object. |
| 1357 | package: Apk package name to check. |
| 1358 | permissions: A list of permissions to be granted. |
| 1359 | """ |
| 1360 | for _ in range(3): |
| 1361 | location_runtime_permission = ad.adb.shell( |
| 1362 | "dumpsys package %s | grep ACCESS_FINE_LOCATION" % package) |
| 1363 | if "true" not in location_runtime_permission: |
| 1364 | ad.log.info("ACCESS_FINE_LOCATION is NOT granted on %s" % package) |
| 1365 | for permission in permissions: |
| 1366 | ad.log.debug("Grant %s on %s" % (permission, package)) |
| 1367 | ad.adb.shell("pm grant %s %s" % (package, permission)) |
| 1368 | else: |
| 1369 | ad.log.info("ACCESS_FINE_LOCATION is granted on %s" % package) |
| 1370 | break |
| 1371 | else: |
| 1372 | raise signals.TestError( |
| 1373 | "Fail to grant ACCESS_FINE_LOCATION on %s" % package) |
jasonkmlu | cb654ac | 2020-07-01 11:08:33 +0800 | [diff] [blame] | 1374 | |
| 1375 | |
| 1376 | def install_mdstest_app(ad, mdsapp): |
| 1377 | """ |
| 1378 | Install MDS test app in DUT |
| 1379 | |
| 1380 | Args: |
| 1381 | ad: An Android Device Object |
| 1382 | mdsapp: Installation path of MDSTest app |
| 1383 | """ |
| 1384 | if not ad.is_apk_installed("com.google.mdstest"): |
| 1385 | ad.adb.install("-r %s" % mdsapp, timeout=300, ignore_status=True) |
| 1386 | |
| 1387 | |
| 1388 | def write_modemconfig(ad, mdsapp, nvitem_dict, modemparfile): |
| 1389 | """ |
| 1390 | Modify the NV items using modem_tool.par |
| 1391 | Note: modem_tool.par |
| 1392 | |
| 1393 | Args: |
| 1394 | ad: An Android Device Object |
| 1395 | mdsapp: Installation path of MDSTest app |
| 1396 | nvitem_dict: dictionary of NV items and values. |
| 1397 | modemparfile: modem_tool.par path. |
| 1398 | """ |
| 1399 | ad.log.info("Verify MDSTest app installed in DUT") |
| 1400 | install_mdstest_app(ad, mdsapp) |
| 1401 | os.system("chmod 777 %s" % modemparfile) |
| 1402 | for key, value in nvitem_dict.items(): |
| 1403 | if key.isdigit(): |
| 1404 | op_name = "WriteEFS" |
| 1405 | else: |
| 1406 | op_name = "WriteNV" |
| 1407 | ad.log.info("Modifying the NV{!r} using {}".format(key, op_name)) |
| 1408 | job.run("{} --op {} --item {} --data '{}'". |
| 1409 | format(modemparfile, op_name, key, value)) |
| 1410 | time.sleep(2) |
| 1411 | |
| 1412 | |
| 1413 | def verify_modemconfig(ad, nvitem_dict, modemparfile): |
| 1414 | """ |
| 1415 | Verify the NV items using modem_tool.par |
| 1416 | Note: modem_tool.par |
| 1417 | |
| 1418 | Args: |
| 1419 | ad: An Android Device Object |
| 1420 | nvitem_dict: dictionary of NV items and values |
| 1421 | modemparfile: modem_tool.par path. |
| 1422 | """ |
| 1423 | os.system("chmod 777 %s" % modemparfile) |
| 1424 | for key, value in nvitem_dict.items(): |
| 1425 | if key.isdigit(): |
| 1426 | op_name = "ReadEFS" |
| 1427 | else: |
| 1428 | op_name = "ReadNV" |
| 1429 | # Sleeptime to avoid Modem communication error |
| 1430 | time.sleep(5) |
| 1431 | result = job.run( |
| 1432 | "{} --op {} --item {}".format(modemparfile, op_name, key)) |
| 1433 | output = str(result.stdout) |
| 1434 | ad.log.info("Actual Value for NV{!r} is {!r}".format(key, output)) |
| 1435 | if not value.casefold() in output: |
| 1436 | ad.log.error("NV Value is wrong {!r} in {!r}".format(value, result)) |
| 1437 | raise ValueError( |
| 1438 | "could not find {!r} in {!r}".format(value, result)) |
Jayakumar Munuswamy | 7efa25b | 2020-07-07 15:30:08 -0700 | [diff] [blame] | 1439 | |
| 1440 | |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1441 | def check_ttff_pe(ad, ttff_data, ttff_mode, pe_criteria): |
Jayakumar Munuswamy | 7efa25b | 2020-07-07 15:30:08 -0700 | [diff] [blame] | 1442 | """Verify all TTFF results from ttff_data. |
| 1443 | |
| 1444 | Args: |
| 1445 | ad: An AndroidDevice object. |
| 1446 | ttff_data: TTFF data of secs, position error and signal strength. |
| 1447 | ttff_mode: TTFF Test mode for current test item. |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1448 | pe_criteria: Criteria for current test item. |
Jayakumar Munuswamy | 7efa25b | 2020-07-07 15:30:08 -0700 | [diff] [blame] | 1449 | |
| 1450 | """ |
| 1451 | ad.log.info("%d iterations of TTFF %s tests finished.", |
| 1452 | (len(ttff_data.keys()), ttff_mode)) |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1453 | ad.log.info("%s PASS criteria is %f meters", (ttff_mode, pe_criteria)) |
Jayakumar Munuswamy | 7efa25b | 2020-07-07 15:30:08 -0700 | [diff] [blame] | 1454 | ad.log.debug("%s TTFF data: %s", (ttff_mode, ttff_data)) |
| 1455 | |
| 1456 | if len(ttff_data.keys()) == 0: |
| 1457 | ad.log.error("GTW_GPSTool didn't process TTFF properly.") |
| 1458 | raise signals.TestFailure("GTW_GPSTool didn't process TTFF properly.") |
| 1459 | |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1460 | elif any(float(ttff_data[key].ttff_pe) >= pe_criteria for key in |
Jayakumar Munuswamy | 7efa25b | 2020-07-07 15:30:08 -0700 | [diff] [blame] | 1461 | ttff_data.keys()): |
| 1462 | ad.log.error("One or more TTFF %s are over test criteria %f meters", |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1463 | (ttff_mode, pe_criteria)) |
Jayakumar Munuswamy | 7efa25b | 2020-07-07 15:30:08 -0700 | [diff] [blame] | 1464 | raise signals.TestFailure("GTW_GPSTool didn't process TTFF properly.") |
| 1465 | ad.log.info("All TTFF %s are within test criteria %f meters.", |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1466 | (ttff_mode, pe_criteria)) |
jasonkmlu | d68fdf0 | 2020-07-23 16:18:11 +0800 | [diff] [blame] | 1467 | |
| 1468 | |
| 1469 | def check_adblog_functionality(ad): |
| 1470 | """Restart adb logcat if system can't write logs into file after checking |
| 1471 | adblog file size. |
| 1472 | |
| 1473 | Args: |
| 1474 | ad: An AndroidDevice object. |
| 1475 | """ |
| 1476 | logcat_path = os.path.join(ad.device_log_path, "adblog_%s_debug.txt" % |
| 1477 | ad.serial) |
| 1478 | if not os.path.exists(logcat_path): |
| 1479 | raise signals.TestError("Logcat file %s does not exist." % logcat_path) |
| 1480 | original_log_size = os.path.getsize(logcat_path) |
| 1481 | ad.log.debug("Original adblog size is %d" % original_log_size) |
| 1482 | time.sleep(.5) |
| 1483 | current_log_size = os.path.getsize(logcat_path) |
| 1484 | ad.log.debug("Current adblog size is %d" % current_log_size) |
| 1485 | if current_log_size == original_log_size: |
| 1486 | ad.log.warn("System can't write logs into file. Restart adb " |
| 1487 | "logcat process now.") |
| 1488 | ad.stop_adb_logcat() |
| 1489 | ad.start_adb_logcat() |
Scott Hong | 0f5dfc4 | 2020-08-22 00:47:53 +0800 | [diff] [blame] | 1490 | |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 1491 | |
Scott Hong | 0f5dfc4 | 2020-08-22 00:47:53 +0800 | [diff] [blame] | 1492 | def build_instrumentation_call(package, |
| 1493 | runner, |
| 1494 | test_methods=None, |
| 1495 | options=None): |
| 1496 | """Build an instrumentation call for the tests |
| 1497 | |
| 1498 | Args: |
| 1499 | package: A string to identify test package. |
| 1500 | runner: A string to identify test runner. |
| 1501 | test_methods: A dictionary contains {class_name, test_method}. |
jasonkmlu | 6ea2a2b | 2020-11-02 13:29:41 +0800 | [diff] [blame] | 1502 | options: A dictionary constant {key, value} param for test. |
Scott Hong | 0f5dfc4 | 2020-08-22 00:47:53 +0800 | [diff] [blame] | 1503 | |
| 1504 | Returns: |
| 1505 | An instrumentation call command. |
| 1506 | """ |
| 1507 | if test_methods is None: |
| 1508 | test_methods = {} |
| 1509 | cmd_builder = InstrumentationCommandBuilder() |
| 1510 | else: |
| 1511 | cmd_builder = InstrumentationTestCommandBuilder() |
Scott Hong | 0f5dfc4 | 2020-08-22 00:47:53 +0800 | [diff] [blame] | 1512 | if options is None: |
| 1513 | options = {} |
Scott Hong | 0f5dfc4 | 2020-08-22 00:47:53 +0800 | [diff] [blame] | 1514 | cmd_builder.set_manifest_package(package) |
| 1515 | cmd_builder.set_runner(runner) |
Scott Hong | a2e430b | 2020-08-27 15:14:57 +0800 | [diff] [blame] | 1516 | cmd_builder.add_flag("-w") |
Scott Hong | 0f5dfc4 | 2020-08-22 00:47:53 +0800 | [diff] [blame] | 1517 | for class_name, test_method in test_methods.items(): |
| 1518 | cmd_builder.add_test_method(class_name, test_method) |
Scott Hong | 0f5dfc4 | 2020-08-22 00:47:53 +0800 | [diff] [blame] | 1519 | for option_key, option_value in options.items(): |
| 1520 | cmd_builder.add_key_value_param(option_key, option_value) |
Scott Hong | 0f5dfc4 | 2020-08-22 00:47:53 +0800 | [diff] [blame] | 1521 | return cmd_builder.build() |
jasonkmlu | c093918 | 2021-02-19 18:34:28 +0800 | [diff] [blame^] | 1522 | |
| 1523 | |
| 1524 | def check_chipset_vendor_by_qualcomm(ad): |
| 1525 | """Check if cipset vendor is by Qualcomm. |
| 1526 | |
| 1527 | Args: |
| 1528 | ad: An AndroidDevice object. |
| 1529 | |
| 1530 | Returns: |
| 1531 | True if it's by Qualcomm. False irf not. |
| 1532 | """ |
| 1533 | ad.root_adb() |
| 1534 | soc = str(ad.adb.shell("getprop gsm.version.ril-impl")) |
| 1535 | ad.log.debug("SOC = %s" % soc) |
| 1536 | return "Qualcomm" in soc |
| 1537 | |
| 1538 | |
| 1539 | def delete_lto_file(ad): |
| 1540 | """Delete downloaded LTO files. |
| 1541 | |
| 1542 | Args: |
| 1543 | ad: An AndroidDevice object. |
| 1544 | """ |
| 1545 | remount_device(ad) |
| 1546 | status = ad.adb.shell("rm -rf /data/vendor/gps/lto*") |
| 1547 | ad.log.info("Delete downloaded LTO files.\n%s" % status) |
| 1548 | |
| 1549 | |
| 1550 | def lto_mode(ad, state): |
| 1551 | """Enable or Disable LTO mode. |
| 1552 | |
| 1553 | Args: |
| 1554 | ad: An AndroidDevice object. |
| 1555 | state: True to enable. False to disable. |
| 1556 | """ |
| 1557 | server_list = ["LONGTERM_PSDS_SERVER_1", |
| 1558 | "LONGTERM_PSDS_SERVER_2", |
| 1559 | "LONGTERM_PSDS_SERVER_3", |
| 1560 | "NORMAL_PSDS_SERVER", |
| 1561 | "REALTIME_PSDS_SERVER"] |
| 1562 | delete_lto_file(ad) |
| 1563 | tmp_path = tempfile.mkdtemp() |
| 1564 | ad.pull_files("/etc/gps_debug.conf", tmp_path) |
| 1565 | gps_conf_path = os.path.join(tmp_path, "gps_debug.conf") |
| 1566 | gps_conf_file = open(gps_conf_path, "r") |
| 1567 | lines = gps_conf_file.readlines() |
| 1568 | gps_conf_file.close() |
| 1569 | fout = open(gps_conf_path, "w") |
| 1570 | if state: |
| 1571 | for line in lines: |
| 1572 | for server in server_list: |
| 1573 | if server in line: |
| 1574 | line = line.replace(line, "") |
| 1575 | fout.write(line) |
| 1576 | fout.close() |
| 1577 | ad.push_system_file(gps_conf_path, "/etc/gps_debug.conf") |
| 1578 | ad.log.info("Push back modified gps_debug.conf") |
| 1579 | ad.log.info("LTO/RTO/RTI enabled") |
| 1580 | else: |
| 1581 | ad.adb.shell("echo %r >> /etc/gps_debug.conf" % |
| 1582 | DISABLE_LTO_FILE_CONTENTS) |
| 1583 | ad.log.info("LTO/RTO/RTI disabled") |
| 1584 | reboot(ad) |
| 1585 | |
| 1586 | |
| 1587 | def start_pixel_logger(ad): |
| 1588 | """adb to start pixel logger for GNSS logging. |
| 1589 | |
| 1590 | Args: |
| 1591 | ad: An AndroidDevice object. |
| 1592 | """ |
| 1593 | start_timeout_sec = 60 |
| 1594 | start_cmd = ("am startservice -a com.android.pixellogger." |
| 1595 | "service.logging.LoggingService.ACTION_START_LOGGING " |
| 1596 | "-e intent_logger brcm_gps") |
| 1597 | begin_time = get_current_epoch_time() |
| 1598 | ad.log.info("Start Pixel Logger.") |
| 1599 | ad.adb.shell(start_cmd) |
| 1600 | while get_current_epoch_time() - begin_time <= start_timeout_sec * 1000: |
| 1601 | start_result = ad.search_logcat("startRecording", begin_time) |
| 1602 | if start_result: |
| 1603 | ad.log.info("Pixel Logger starts recording successfully.") |
| 1604 | break |
| 1605 | else: |
| 1606 | ad.log.warn("Pixel Logger fails to start recording.") |
| 1607 | |
| 1608 | |
| 1609 | def stop_pixel_logger(ad): |
| 1610 | """adb to stop pixel logger for GNSS logging. |
| 1611 | |
| 1612 | Args: |
| 1613 | ad: An AndroidDevice object. |
| 1614 | """ |
| 1615 | stop_timeout_sec = 300 |
| 1616 | stop_cmd = ("am startservice -a com.android.pixellogger." |
| 1617 | "service.logging.LoggingService.ACTION_STOP_LOGGING " |
| 1618 | "-e intent_logger brcm_gps") |
| 1619 | begin_time = get_current_epoch_time() |
| 1620 | ad.log.info("Stop Pixel Logger.") |
| 1621 | ad.adb.shell(stop_cmd) |
| 1622 | while get_current_epoch_time() - begin_time <= stop_timeout_sec * 1000: |
| 1623 | stop_result = ad.search_logcat("LoggingService: Stopping service", |
| 1624 | begin_time) |
| 1625 | if stop_result: |
| 1626 | ad.log.info("Pixel Logger stops successfully.") |
| 1627 | break |
| 1628 | else: |
| 1629 | ad.log.warn( |
| 1630 | "Pixel Logger fails to stop in %d seconds." % stop_timeout_sec) |