| 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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 After wiping data on a device that has been authorized, adb can still | 120 After wiping data on a device that has been authorized, adb can still |
| 121 communicate with the device, but after reboot the device will need to be | 121 communicate with the device, but after reboot the device will need to be |
| 122 re-authorized because the adb keys file is stored in /data/misc/adb/. | 122 re-authorized because the adb keys file is stored in /data/misc/adb/. |
| 123 Thus, adb_keys file is rewritten so the device does not need to be | 123 Thus, adb_keys file is rewritten so the device does not need to be |
| 124 re-authorized. | 124 re-authorized. |
| 125 | 125 |
| 126 Arguments: | 126 Arguments: |
| 127 device: the device to wipe | 127 device: the device to wipe |
| 128 """ | 128 """ |
| 129 device_authorized = device.FileExists(constants.ADB_KEYS_FILE) | 129 device_authorized = device.FileExists(constants.ADB_KEYS_FILE) |
| 130 adb_public_key = '' |
| 131 with open(constants.ADB_PUBLIC_KEY, 'r') as f: |
| 132 adb_public_key = f.readlines() |
| 130 if device_authorized: | 133 if device_authorized: |
| 131 adb_keys = device.ReadFile(constants.ADB_KEYS_FILE, as_root=True) | 134 adb_keys = device.ReadFile(constants.ADB_KEYS_FILE, as_root=True) |
| 132 device.RunShellCommand('wipe data', as_root=True) | 135 device.RunShellCommand('wipe data', as_root=True) |
| 133 if device_authorized: | 136 if device_authorized: |
| 134 path_list = constants.ADB_KEYS_FILE.split('/') | 137 path_list = constants.ADB_KEYS_FILE.split('/') |
| 135 dir_path = '/'.join(path_list[:len(path_list)-1]) | 138 dir_path = '/'.join(path_list[:len(path_list)-1]) |
| 136 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True) | 139 device.RunShellCommand('mkdir -p %s' % dir_path, as_root=True) |
| 137 device.RunShellCommand('restorecon %s' % dir_path, as_root=True) | 140 device.RunShellCommand('restorecon %s' % dir_path, as_root=True) |
| 141 if 'chrome-infrastructure-adb-key' not in adb_keys: |
| 142 adb_keys += ''.join(adb_public_key) |
| 138 device.WriteFile(constants.ADB_KEYS_FILE, adb_keys, as_root=True) | 143 device.WriteFile(constants.ADB_KEYS_FILE, adb_keys, as_root=True) |
| 139 device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE, | 144 device.RunShellCommand('restorecon %s' % constants.ADB_KEYS_FILE, |
| 140 as_root=True) | 145 as_root=True) |
| 141 | 146 else: |
| 147 device.WriteFile(constants.ADB_KEYS_FILE, adb_public_key, as_root=True) |
| 142 | 148 |
| 143 def WipeDeviceIfPossible(device, timeout): | 149 def WipeDeviceIfPossible(device, timeout): |
| 144 try: | 150 try: |
| 145 device.EnableRoot() | 151 device.EnableRoot() |
| 146 WipeDeviceData(device) | 152 WipeDeviceData(device) |
| 147 device.Reboot(True, timeout=timeout, retries=0) | 153 device.Reboot(True, timeout=timeout, retries=0) |
| 148 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): | 154 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): |
| 149 pass | 155 pass |
| 150 | 156 |
| 151 | 157 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 help='push binary which will reboot the device on adb' | 283 help='push binary which will reboot the device on adb' |
| 278 ' disconnections') | 284 ' disconnections') |
| 279 args = parser.parse_args() | 285 args = parser.parse_args() |
| 280 constants.SetBuildType(args.target) | 286 constants.SetBuildType(args.target) |
| 281 | 287 |
| 282 return ProvisionDevices(args) | 288 return ProvisionDevices(args) |
| 283 | 289 |
| 284 | 290 |
| 285 if __name__ == '__main__': | 291 if __name__ == '__main__': |
| 286 sys.exit(main()) | 292 sys.exit(main()) |
| OLD | NEW |