Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Provisions Android devices with settings required for bots. | 7 """Provisions Android devices with settings required for bots. |
| 8 | 8 |
| 9 Usage: | 9 Usage: |
| 10 ./provision_devices.py [-d <device serial number>] | 10 ./provision_devices.py [-d <device serial number>] |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 communicate with the device, but after reboot the device will need to be | 112 communicate with the device, but after reboot the device will need to be |
| 113 re-authorized because the adb keys file is stored in /data/misc/adb/. | 113 re-authorized because the adb keys file is stored in /data/misc/adb/. |
| 114 Thus, adb_keys file is rewritten so the device does not need to be | 114 Thus, adb_keys file is rewritten so the device does not need to be |
| 115 re-authorized. | 115 re-authorized. |
| 116 | 116 |
| 117 Arguments: | 117 Arguments: |
| 118 device: the device to wipe | 118 device: the device to wipe |
| 119 """ | 119 """ |
| 120 device_authorized = device.FileExists(constants.ADB_KEYS_FILE) | 120 device_authorized = device.FileExists(constants.ADB_KEYS_FILE) |
| 121 if device_authorized: | 121 if device_authorized: |
| 122 adb_keys = device.RunShellCommand('cat %s' % constants.ADB_KEYS_FILE, | 122 adb_keys = device.ReadFile(constants.ADB_KEYS_FILE, as_root=True) |
|
jbudorick
2014/12/15 23:13:42
These will both now check a return value where the
| |
| 123 as_root=True) | |
| 124 device.RunShellCommand('wipe data', as_root=True) | 123 device.RunShellCommand('wipe data', as_root=True) |
| 125 if device_authorized: | 124 if device_authorized: |
| 126 path_list = constants.ADB_KEYS_FILE.split('/') | 125 path_list = constants.ADB_KEYS_FILE.split('/') |
| 127 dir_path = '/'.join(path_list[:len(path_list)-1]) | 126 dir_path = '/'.join(path_list[:len(path_list)-1]) |
| 128 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True) | 127 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True) |
| 129 device.RunShellCommand('restorecon %s' % dir_path, as_root=True) | 128 device.RunShellCommand('restorecon %s' % dir_path, as_root=True) |
| 130 device.RunShellCommand('echo %s > %s' % | 129 device.WriteFile(constants.ADB_KEYS_FILE, adb_keys, as_root=True) |
| 131 (adb_keys[0], constants.ADB_KEYS_FILE), as_root=True) | |
| 132 for adb_key in adb_keys[1:]: | |
| 133 device.RunShellCommand( | |
| 134 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE), as_root=True) | |
| 135 device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE, | 130 device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE, |
| 136 as_root=True) | 131 as_root=True) |
| 137 | 132 |
| 138 | 133 |
| 139 def WipeDeviceIfPossible(device): | 134 def WipeDeviceIfPossible(device): |
| 140 try: | 135 try: |
| 141 device.EnableRoot() | 136 device.EnableRoot() |
| 142 WipeDeviceData(device) | 137 WipeDeviceData(device) |
| 143 # TODO(jbudorick): Tune the timeout per OS version. | 138 # TODO(jbudorick): Tune the timeout per OS version. |
| 144 device.Reboot(True, timeout=600, retries=0) | 139 device.Reboot(True, timeout=600, retries=0) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 | 250 |
| 256 if args: | 251 if args: |
| 257 print >> sys.stderr, 'Unused args %s' % args | 252 print >> sys.stderr, 'Unused args %s' % args |
| 258 return 1 | 253 return 1 |
| 259 | 254 |
| 260 return ProvisionDevices(options) | 255 return ProvisionDevices(options) |
| 261 | 256 |
| 262 | 257 |
| 263 if __name__ == '__main__': | 258 if __name__ == '__main__': |
| 264 sys.exit(main(sys.argv)) | 259 sys.exit(main(sys.argv)) |
| OLD | NEW |