blob: 751579ab7249d52ebd1139f7abb9d51538a54453 [file] [log] [blame]
Xianyuan Jia63751fb2020-11-17 00:07:40 +00001from acts_contrib.test_utils.instrumentation.device.apps.app_installer import AppInstaller
2from acts_contrib.test_utils.instrumentation.power import instrumentation_power_test
Preston O'Neala918b8e2020-04-30 19:17:18 -07003
4import time
5
6
7class ApolloBaseTest(instrumentation_power_test.InstrumentationPowerTest):
8 """Test class for running instrumentation test idle system cases.
9
10 Many functions shamelessly copied from:
11 google3/wireless/android/apollo/test/lib/apollo_decorator.py
12 """
13
14 def __init__(self, configs):
15 super().__init__(configs)
16 self.supported_hooks = {'start', 'stop'}
17 self._apk_install_wait_time_seconds = 5
18 self._scan_interval_seconds = None
19 self._scan_time_seconds = None
Preston O'Neal9d5fabc2020-05-29 15:18:43 -070020 # TODO: remove once b/156301031 is resolved
21 self._disable_consent_dialog = True
Preston O'Neala918b8e2020-04-30 19:17:18 -070022
23 def _prepare_device(self):
24 super()._prepare_device()
25 self.base_device_configuration()
26
27 def setup_test(self):
28 super().setup_test()
29 # clear command options that won't work on OEM devices.
30 self._instr_cmd_builder.set_output_as_text()
31 self._instr_cmd_builder.remove_flag('--no-isolated-storage')
32
33 def _set_nearby_phenotype_flag(self, flag_name, flag_type, flag_value):
34 self.adb_run(f'am broadcast -a "com.google.android.gms.phenotype.FLAG_OVERRIDE" --es package "com.google.android.gms.nearby" ' \
35 f'--es user "*" --esa flags "{flag_name}" --esa values "{flag_value}" --esa types "{flag_type}" com.google.android.gms')
36
37 def _set_installation_overrides(self):
38 self._set_nearby_phenotype_flag('exposure_notification_enable_client_apps_whitelist', 'boolean', 'false')
Preston O'Neal9d5fabc2020-05-29 15:18:43 -070039 if self._disable_consent_dialog:
40 self._set_nearby_phenotype_flag('exposure_notification_use_consent_dialog_for_all_clients', 'boolean', 'false')
Preston O'Neala918b8e2020-04-30 19:17:18 -070041
42 # Scanning interval and scanning time need to be set here, before scanning starts
43 if self._scan_interval_seconds:
44 self._set_nearby_phenotype_flag('contact_tracing_scan_interval_second', 'long', str(self._scan_interval_seconds))
45 if self._scan_time_seconds:
46 self._set_nearby_phenotype_flag('contact_tracing_scan_time_second', 'long', str(self._scan_time_seconds))
47
48 def _start_scanning(self):
49 self._issue_apollo_test_hook_command('start')
50
51 def _issue_apollo_test_hook_command(self, hook_command, payload=None, time_to_wait_seconds=10):
52 if hook_command not in self.supported_hooks:
53 raise ValueError(f'Unsupported apollo test hook {hook_command}')
54 # Send a hook command, which is handled by the apollo test APK
55 self.adb_run(f'am start-foreground-service -a {hook_command} com.google.android.apps.exposurenotification/.debug.HookService')
56 # Wait for success and timeout on a failure. The test app does not explicitly tell you if the call failed.
57 start_time = time.time()
58 while time.time() - start_time < time_to_wait_seconds:
59 if self.ad_dut.search_logcat(f'HookService: Success:{hook_command}'):
60 return True
61 time.sleep(1)
62 raise RuntimeError(f'HookService:{hook_command} did not finish in {time_to_wait_seconds} seconds')
63
64 def _sideload_apollo(self):
65 self.ad_dut.adb.ensure_root()
66
67 self.adb_run('logcat -c') # Clear previous logcat information - reflashing is not performed for Apollo
68
69 # Uninstall old APK's and clear flags
Hectorf3438c22020-05-18 23:26:36 -070070 gmscore_apk_file = self.get_file_from_config('gmscore_file_' + self.ad_dut.serial)
Preston O'Neala918b8e2020-04-30 19:17:18 -070071 gmscore_apk = AppInstaller(self.ad_dut, gmscore_apk_file)
72 gmscore_apk.uninstall()
Hectorf3438c22020-05-18 23:26:36 -070073 nearby_module_apk_file = self.get_file_from_config('gmscore_nearby_en_file_' + self.ad_dut.serial)
Preston O'Neala918b8e2020-04-30 19:17:18 -070074 nearby_module_apk = AppInstaller(self.ad_dut, nearby_module_apk_file)
75 nearby_module_apk.uninstall()
Hectorf3438c22020-05-18 23:26:36 -070076 apollo_test_apk_file = self.get_file_from_config('exposure_notification_app')
Preston O'Neala918b8e2020-04-30 19:17:18 -070077 apollo_test_apk = AppInstaller(self.ad_dut, apollo_test_apk_file)
78 apollo_test_apk.uninstall()
79
80 # Set up BT and location
81 self.adb_run('service call bluetooth_manager 6')
82 self.adb_run('settings put secure location_providers_allowed +gps')
83 self.adb_run('settings put secure location_mode 3')
84
85 # Install gmscore
86 gmscore_apk.install()
87 # Give gmscore some time to initialize (there doesn't appear to be a logcat message to key off)
88 time.sleep(self._apk_install_wait_time_seconds)
89
90 # Whitelist EN for sideloading
91 self.adb_run('am broadcast -a com.google.gservices.intent.action.GSERVICES_OVERRIDE -e gms:chimera:dev_module_packages "com.google.android.gms.policy_nearby"')
92 # Install EN module
93 nearby_module_apk.install()
94 # Give EN some time to initialize (there doesn't appear to be a logcat message to key off)
95 time.sleep(self._apk_install_wait_time_seconds)
96
97 # Whitelist test app and disable consent dialogs
98 self._set_installation_overrides()
99
100 # Install test apk
101 apollo_test_apk.install()
102 # Give the test app some time to initialize (there doesn't appear to be a logcat message to key off)
103 time.sleep(self._apk_install_wait_time_seconds)