| Index: build/android/provision_devices.py
|
| diff --git a/build/android/provision_devices.py b/build/android/provision_devices.py
|
| index 5cf1cc5d5cd36a262244d06366ced7b78caf9fce..53eb373ef8c43aa492bd1677c7b35fbb58c15c20 100755
|
| --- a/build/android/provision_devices.py
|
| +++ b/build/android/provision_devices.py
|
| @@ -21,6 +21,7 @@ import time
|
| from pylib import android_commands
|
| from pylib import constants
|
| from pylib import device_settings
|
| +from pylib.cmd_helper import GetCmdOutput
|
|
|
|
|
| def KillHostHeartbeat():
|
| @@ -83,6 +84,33 @@ def _ConfigureLocalProperties(adb):
|
| android_commands.LOCAL_PROPERTIES_PATH)
|
|
|
|
|
| +def WipeDeviceData(device):
|
| + """Wipes data from device, keeping only the adb_keys for authorization.
|
| +
|
| + After wiping data on a device that has been authorized, adb can still
|
| + communicate with the device, but after reboot the device will need to be
|
| + re-authorized because the adb keys file is stored in /data/misc/adb/.
|
| + Thus, before reboot the adb_keys file is rewritten so the device does not need
|
| + to be re-authorized.
|
| +
|
| + Arguments:
|
| + device: the device to wipe
|
| + """
|
| + android_cmd = android_commands.AndroidCommands(device)
|
| + device_authorized = android_cmd.FileExistsOnDevice(constants.ADB_KEYS_FILE)
|
| + if device_authorized:
|
| + adb_keys = android_cmd.RunShellCommandWithSU(
|
| + 'cat %s' % constants.ADB_KEYS_FILE)[0]
|
| + android_cmd.RunShellCommandWithSU('wipe data')
|
| + if device_authorized:
|
| + path_list = constants.ADB_KEYS_FILE.split('/')
|
| + dir_path = '/'.join(path_list[:len(path_list)-1])
|
| + android_cmd.RunShellCommandWithSU('mkdir -p %s' % dir_path)
|
| + adb_keys = android_cmd.RunShellCommand(
|
| + 'echo %s > %s' % (adb_keys, constants.ADB_KEYS_FILE))
|
| + android_cmd.Reboot()
|
| +
|
| +
|
| def ProvisionDevices(options):
|
| if options.device is not None:
|
| devices = [options.device]
|
| @@ -90,6 +118,14 @@ def ProvisionDevices(options):
|
| devices = android_commands.GetAttachedDevices()
|
| for device in devices:
|
| android_cmd = android_commands.AndroidCommands(device)
|
| + install_output = GetCmdOutput(
|
| + ['%s/build/android/adb_install_apk.py' % constants.DIR_SOURCE_ROOT,
|
| + '--apk',
|
| + '%s/build/android/CheckInstallApk-debug.apk' % constants.DIR_SOURCE_ROOT
|
| + ])
|
| + failure_string = 'Failure [INSTALL_FAILED_INSUFFICIENT_STORAGE]'
|
| + if failure_string in install_output:
|
| + WipeDeviceData(device)
|
| _ConfigureLocalProperties(android_cmd)
|
| device_settings.ConfigureContentSettingsDict(
|
| android_cmd, device_settings.DETERMINISTIC_DEVICE_SETTINGS)
|
|
|