Lines Matching full:device
10 ./provision_devices.py [-d <device serial number>]
72 if args.device:
73 devices = [d for d in devices if d == args.device]
75 raise device_errors.DeviceUnreachableError(args.device)
92 def ProvisionDevice(device, denylist, options): argument
98 device.WaitUntilFullyBooted(timeout=reboot_timeout, retries=0)
100 logging.error('Device did not finish booting. Will try to reboot.')
101 device.Reboot(timeout=reboot_timeout)
102 phase_func(device, options)
104 device.Reboot(False, retries=0)
105 device.adb.WaitForDevice()
110 elif device.build_version_sdk >= version_codes.LOLLIPOP:
116 if (options.chrome_specific_wipe or device.IsUserBuild() or
117 device.build_version_sdk >= version_codes.MARSHMALLOW):
130 version_name = device.GetApplicationVersion(package)
133 CheckExternalStorage(device)
136 logging.exception('Timed out waiting for device %s. Adding to denylist.',
137 str(device))
139 denylist.Extend([str(device)], reason='provision_timeout')
143 logging.exception('Failed to provision device %s. Adding to denylist.',
144 str(device))
146 denylist.Extend([str(device)], reason='provision_failure')
149 def CheckExternalStorage(device): argument
153 device: The device to check.
157 device.adb, suffix='.sh', dir=device.GetExternalStoragePath()) as f:
158 device.WriteFile(f.name, 'test')
161 device.RunShellCommand(['mount', '-o', 'remount,rw', '/'],
163 device.EnableRoot()
165 device.adb, suffix='.sh', dir=device.GetExternalStoragePath()) as f:
166 device.WriteFile(f.name, 'test')
168 def WipeChromeData(device, options): argument
169 """Wipes chrome specific data from device
183 device: the device to wipe
189 if device.IsUserBuild():
190 _UninstallIfMatch(device, _CHROME_PACKAGE_REGEX,
192 device.RunShellCommand('rm -rf %s/*' % device.GetExternalStoragePath(),
194 device.RunShellCommand('rm -rf /data/local/tmp/*', check_return=True)
196 device.EnableRoot()
197 _UninstallIfMatch(device, _CHROME_PACKAGE_REGEX,
199 _WipeUnderDirIfMatch(device, '/data/app-lib/', _CHROME_PACKAGE_REGEX)
200 _WipeUnderDirIfMatch(device, '/data/tombstones/', _TOMBSTONE_REGEX)
202 _WipeFileOrDir(device, '/data/local.prop')
203 _WipeFileOrDir(device, '/data/local/chrome-command-line')
204 _WipeFileOrDir(device, '/data/local/.config/')
205 _WipeFileOrDir(device, '/data/local/tmp/')
206 device.RunShellCommand('rm -rf %s/*' % device.GetExternalStoragePath(),
209 logging.exception('Possible failure while wiping the device. '
213 def WipeDevice(device, options): argument
214 """Wipes data from device, keeping only the adb_keys for authorization.
216 After wiping data on a device that has been authorized, adb can still
217 communicate with the device, but after reboot the device will need to be
219 Thus, adb_keys file is rewritten so the device does not need to be
223 device: the device to wipe
229 device.EnableRoot()
230 device_authorized = device.FileExists(constants.ADB_KEYS_FILE)
232 adb_keys = device.ReadFile(constants.ADB_KEYS_FILE,
234 device.RunShellCommand(['wipe', 'data'],
236 device.adb.WaitForDevice()
247 _WriteAdbKeysFile(device, '\n'.join(adb_keys_set))
249 logging.exception('Possible failure while wiping the device. '
253 def _WriteAdbKeysFile(device, adb_keys_string): argument
255 device.RunShellCommand(['mkdir', '-p', dir_path],
257 device.RunShellCommand(['restorecon', dir_path],
259 device.WriteFile(constants.ADB_KEYS_FILE, adb_keys_string, as_root=True)
260 device.RunShellCommand(['restorecon', constants.ADB_KEYS_FILE],
264 def SetProperties(device, options): argument
266 device.EnableRoot()
270 if not device.IsUserBuild():
271 _ConfigureLocalProperties(device, options.enable_java_debug)
275 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS)
278 device, device_settings.DISABLE_LOCATION_SETTINGS)
281 device, device_settings.ENABLE_LOCATION_SETTINGS)
285 device, device_settings.DISABLE_MOCK_LOCATION_SETTINGS)
288 device, device_settings.ENABLE_MOCK_LOCATION_SETTINGS)
290 device_settings.SetLockScreenSettings(device)
293 device, device_settings.NETWORK_DISABLED_SETTINGS)
294 if device.build_version_sdk >= version_codes.MARSHMALLOW:
296 device.RunShellCommand(['svc', 'nfc', 'disable'],
300 # The system chrome version on the device interferes with some tests.
301 device.RunShellCommand(['pm', 'disable', 'com.android.chrome'],
305 if any(device.PathExists(p) for p in _SYSTEM_WEBVIEW_PATHS):
307 if device.HasRoot():
309 if device.build_version_sdk >= version_codes.MARSHMALLOW:
310 device.adb.DisableVerity()
311 device.Reboot()
312 device.WaitUntilFullyBooted()
313 device.EnableRoot()
315 # This is required, e.g., to replace the system webview on a device.
316 device.adb.Remount()
317 device.RunShellCommand(['stop'], check_return=True)
318 device.RunShellCommand(['rm', '-rf'] + _SYSTEM_WEBVIEW_PATHS,
320 device.RunShellCommand(['start'], check_return=True)
322 logging.warning('Cannot remove system webview from a non-rooted device')
326 # Some device types can momentarily disappear after setting properties.
327 device.adb.WaitForDevice()
330 def _ConfigureLocalProperties(device, java_debug=True): argument
331 """Set standard readonly testing device properties prior to reboot."""
344 device.WriteFile(
345 device.LOCAL_PROPERTIES_PATH,
348 device.RunShellCommand(
349 ['chmod', '644', device.LOCAL_PROPERTIES_PATH],
355 def FinishProvisioning(device, options): argument
358 if device.IsUserBuild():
359 device.SendKeyEvent(keyevent.KEYCODE_MENU)
362 battery = battery_utils.BatteryUtils(device)
366 device.Reboot()
371 battery = battery_utils.BatteryUtils(device)
377 if device.build_version_sdk >= version_codes.MARSHMALLOW:
390 device.RunShellCommand(set_date_command, as_root=True, check_return=True)
393 device_time = device.RunShellCommand(
399 logging.info('Date/time successfully set on %s', device)
401 logging.error('Date mismatch. Device: %s Correct: %s',
406 if device.IsUserBuild():
413 'Failed to set date & time.', device_serial=str(device))
415 props = device.RunShellCommand('getprop', check_return=True)
419 _PushAndLaunchAdbReboot(device, options.target)
422 def _UninstallIfMatch(device, pattern, app_to_keep): argument
423 installed_packages = device.RunShellCommand(['pm', 'list', 'packages'])
425 pkg.split(':')[1] for pkg in device.RunShellCommand(['pm', 'list',
430 if not device.IsUserBuild() or package not in installed_system_packages:
431 device.Uninstall(package)
434 def _WipeUnderDirIfMatch(device, path, pattern): argument
435 for filename in device.ListDirectory(path):
437 _WipeFileOrDir(device, posixpath.join(path, filename))
440 def _WipeFileOrDir(device, path): argument
441 if device.PathExists(path):
442 device.RunShellCommand(['rm', '-rf', path], check_return=True)
445 def _PushAndLaunchAdbReboot(device, target): argument
446 """Pushes and launches the adb_reboot binary on the device.
449 device: The DeviceUtils instance for the device to which the adb_reboot
454 logging.info('Will push and launch adb_reboot on %s', str(device))
456 device.KillAll('adb_reboot', blocking=True, timeout=2, quiet=True)
461 device.PushChangedFiles([(adb_reboot, '/data/local/tmp/')])
464 device.RunShellCommand(
498 parser.add_argument('-d', '--device', metavar='SERIAL',
499 help='the serial number of the device to be provisioned'
503 parser.add_argument('--denylist-file', help='Device denylist JSON file.')
509 help="don't wipe device data during provisioning")
511 help='when wiping the device, max number of seconds to'
515 help='wait for the device to reach this minimum battery'
533 help='push binary which will reboot the device on adb'
536 help='list of adb keys to push to device')
541 parser.add_argument('--output-device-denylist',
542 help='Json file to output the device denylist.')