| Index: build/android/provision_devices.py
|
| diff --git a/build/android/provision_devices.py b/build/android/provision_devices.py
|
| index 48350731fa75a0414e616f1a7da44434ed2986c2..5f00b31e8a817440b99d845b6745401c6d46c947 100755
|
| --- a/build/android/provision_devices.py
|
| +++ b/build/android/provision_devices.py
|
| @@ -13,6 +13,7 @@ Usage:
|
| import argparse
|
| import logging
|
| import os
|
| +import posixpath
|
| import re
|
| import subprocess
|
| import sys
|
| @@ -115,8 +116,16 @@ def _ConfigureLocalProperties(device, java_debug=True):
|
|
|
| # LOCAL_PROPERTIES_PATH = '/data/local.prop'
|
|
|
| +def WriteAdbKeysFile(device, adb_keys_string):
|
| + dir_path = posixpath.dirname(constants.ADB_KEYS_FILE)
|
| + device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True)
|
| + device.RunShellCommand('restorecon %s' % dir_path, as_root=True)
|
| + device.WriteFile(constants.ADB_KEYS_FILE, adb_keys_string, as_root=True)
|
| + device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE,
|
| + as_root=True)
|
|
|
| -def WipeDeviceData(device):
|
| +
|
| +def WipeDeviceData(device, options):
|
| """Wipes data from device, keeping only the adb_keys for authorization.
|
|
|
| After wiping data on a device that has been authorized, adb can still
|
| @@ -130,22 +139,25 @@ def WipeDeviceData(device):
|
| """
|
| device_authorized = device.FileExists(constants.ADB_KEYS_FILE)
|
| if device_authorized:
|
| - adb_keys = device.ReadFile(constants.ADB_KEYS_FILE, as_root=True)
|
| + adb_keys = device.ReadFile(constants.ADB_KEYS_FILE,
|
| + as_root=True).splitlines()
|
| device.RunShellCommand('wipe data', as_root=True)
|
| if device_authorized:
|
| - path_list = constants.ADB_KEYS_FILE.split('/')
|
| - dir_path = '/'.join(path_list[:len(path_list)-1])
|
| - device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True)
|
| - device.RunShellCommand('restorecon %s' % dir_path, as_root=True)
|
| - device.WriteFile(constants.ADB_KEYS_FILE, adb_keys, as_root=True)
|
| - device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE,
|
| - as_root=True)
|
| + adb_keys_set = set(adb_keys)
|
| + for adb_key_file in options.adb_key_files or []:
|
| + try:
|
| + with open(adb_key_file, 'r') as f:
|
| + adb_public_keys = f.readlines()
|
| + adb_keys_set.update(adb_public_keys)
|
| + except IOError:
|
| + logging.warning('Unable to find adb keys file %s.' % adb_key_file)
|
| + WriteAdbKeysFile(device, '\n'.join(adb_keys_set))
|
|
|
|
|
| -def WipeDeviceIfPossible(device, timeout):
|
| +def WipeDeviceIfPossible(device, timeout, options):
|
| try:
|
| device.EnableRoot()
|
| - WipeDeviceData(device)
|
| + WipeDeviceData(device, options)
|
| device.Reboot(True, timeout=timeout, retries=0)
|
| except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError):
|
| pass
|
| @@ -176,7 +188,7 @@ def ProvisionDevice(device, options):
|
|
|
| try:
|
| if not options.skip_wipe:
|
| - WipeDeviceIfPossible(device, reboot_timeout)
|
| + WipeDeviceIfPossible(device, reboot_timeout, options)
|
| try:
|
| device.EnableRoot()
|
| except device_errors.CommandFailedError as e:
|
| @@ -196,7 +208,7 @@ def ProvisionDevice(device, options):
|
| device, device_settings.NETWORK_DISABLED_SETTINGS)
|
| if options.min_battery_level is not None:
|
| try:
|
| - device.SetUsbCharging(True)
|
| + device.SetCharging(True)
|
| ChargeDeviceToLevel(device, options.min_battery_level)
|
| except device_errors.CommandFailedError as e:
|
| logging.exception('Unable to charge device to specified level.')
|
| @@ -280,6 +292,8 @@ def main():
|
| parser.add_argument('-r', '--auto-reconnect', action='store_true',
|
| help='push binary which will reboot the device on adb'
|
| ' disconnections')
|
| + parser.add_argument('--adb-key-files', type=str, nargs='+',
|
| + help='list of adb keys to push to device')
|
| args = parser.parse_args()
|
| constants.SetBuildType(args.target)
|
|
|
|
|