| 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 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE)) | 119 'echo %s >> %s' % (adb_key, constants.ADB_KEYS_FILE)) |
| 120 | 120 |
| 121 | 121 |
| 122 def ProvisionDevices(options): | 122 def ProvisionDevices(options): |
| 123 # TODO(jbudorick): Parallelize provisioning of all attached devices after | 123 # TODO(jbudorick): Parallelize provisioning of all attached devices after |
| 124 # swithcing from AndroidCommands. | 124 # swithcing from AndroidCommands. |
| 125 if options.device is not None: | 125 if options.device is not None: |
| 126 devices = [options.device] | 126 devices = [options.device] |
| 127 else: | 127 else: |
| 128 devices = android_commands.GetAttachedDevices() | 128 devices = android_commands.GetAttachedDevices() |
| 129 |
| 130 # Wipe devices (unless --skip-wipe was specified) |
| 131 if not options.skip_wipe: |
| 132 for device_serial in devices: |
| 133 device = device_utils.DeviceUtils(device_serial) |
| 134 device.old_interface.EnableAdbRoot() |
| 135 WipeDeviceData(device) |
| 136 try: |
| 137 device_utils.DeviceUtils.parallel(devices).old_interface.Reboot(True) |
| 138 except errors.DeviceUnresponsiveError: |
| 139 pass |
| 140 for device_serial in devices: |
| 141 device.WaitUntilFullyBooted(timeout=90) |
| 142 |
| 143 # Provision devices |
| 129 for device_serial in devices: | 144 for device_serial in devices: |
| 130 device = device_utils.DeviceUtils(device_serial) | 145 device = device_utils.DeviceUtils(device_serial) |
| 131 device.old_interface.EnableAdbRoot() | 146 device.old_interface.EnableAdbRoot() |
| 132 WipeDeviceData(device) | |
| 133 try: | |
| 134 device_utils.DeviceUtils.parallel(devices).Reboot(True) | |
| 135 except errors.DeviceUnresponsiveError: | |
| 136 pass | |
| 137 for device_serial in devices: | |
| 138 device = device_utils.DeviceUtils(device_serial) | |
| 139 device.WaitUntilFullyBooted(timeout=90) | |
| 140 device.old_interface.EnableAdbRoot() | |
| 141 _ConfigureLocalProperties(device) | 147 _ConfigureLocalProperties(device) |
| 142 device_settings.ConfigureContentSettingsDict( | 148 device_settings.ConfigureContentSettingsDict( |
| 143 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) | 149 device, device_settings.DETERMINISTIC_DEVICE_SETTINGS) |
| 144 # TODO(tonyg): We eventually want network on. However, currently radios | 150 # TODO(tonyg): We eventually want network on. However, currently radios |
| 145 # can cause perfbots to drain faster than they charge. | 151 # can cause perfbots to drain faster than they charge. |
| 146 if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower(): | 152 if 'perf' in os.environ.get('BUILDBOT_BUILDERNAME', '').lower(): |
| 147 device_settings.ConfigureContentSettingsDict( | 153 device_settings.ConfigureContentSettingsDict( |
| 148 device, device_settings.NETWORK_DISABLED_SETTINGS) | 154 device, device_settings.NETWORK_DISABLED_SETTINGS) |
| 149 device.old_interface.RunShellCommandWithSU('date -u %f' % time.time()) | 155 device.old_interface.RunShellCommandWithSU('date -u %f' % time.time()) |
| 150 try: | 156 try: |
| 151 device_utils.DeviceUtils.parallel(devices).Reboot(True) | 157 device_utils.DeviceUtils.parallel(devices).Reboot(True) |
| 152 except errors.DeviceUnresponsiveError: | 158 except errors.DeviceUnresponsiveError: |
| 153 pass | 159 pass |
| 154 for device_serial in devices: | 160 for device_serial in devices: |
| 155 device = device_utils.DeviceUtils(device_serial) | 161 device = device_utils.DeviceUtils(device_serial) |
| 156 device.WaitUntilFullyBooted(timeout=90) | 162 device.WaitUntilFullyBooted(timeout=90) |
| 157 (_, props) = device.old_interface.GetShellCommandStatusAndOutput('getprop') | 163 (_, props) = device.old_interface.GetShellCommandStatusAndOutput('getprop') |
| 158 for prop in props: | 164 for prop in props: |
| 159 print prop | 165 print prop |
| 160 if options.auto_reconnect: | 166 if options.auto_reconnect: |
| 161 PushAndLaunchAdbReboot(devices, options.target) | 167 PushAndLaunchAdbReboot(devices, options.target) |
| 162 | 168 |
| 163 | 169 |
| 164 def main(argv): | 170 def main(argv): |
| 165 logging.basicConfig(level=logging.INFO) | 171 logging.basicConfig(level=logging.INFO) |
| 166 | 172 |
| 167 parser = optparse.OptionParser() | 173 parser = optparse.OptionParser() |
| 168 parser.add_option('-w', '--wipe', action='store_true', | 174 parser.add_option('--skip-wipe', action='store_true', default=False, |
| 169 help='Wipe device data from all attached devices.') | 175 help="Don't wipe device data during provisioning.") |
| 170 parser.add_option('-d', '--device', | 176 parser.add_option('-d', '--device', |
| 171 help='The serial number of the device to be provisioned') | 177 help='The serial number of the device to be provisioned') |
| 172 parser.add_option('-t', '--target', default='Debug', help='The build target') | 178 parser.add_option('-t', '--target', default='Debug', help='The build target') |
| 173 parser.add_option( | 179 parser.add_option( |
| 174 '-r', '--auto-reconnect', action='store_true', | 180 '-r', '--auto-reconnect', action='store_true', |
| 175 help='Push binary which will reboot the device on adb disconnections.') | 181 help='Push binary which will reboot the device on adb disconnections.') |
| 176 options, args = parser.parse_args(argv[1:]) | 182 options, args = parser.parse_args(argv[1:]) |
| 177 constants.SetBuildType(options.target) | 183 constants.SetBuildType(options.target) |
| 178 | 184 |
| 179 if args: | 185 if args: |
| 180 print >> sys.stderr, 'Unused args %s' % args | 186 print >> sys.stderr, 'Unused args %s' % args |
| 181 return 1 | 187 return 1 |
| 182 | 188 |
| 183 if options.wipe: | 189 ProvisionDevices(options) |
| 184 devices = android_commands.GetAttachedDevices() | |
| 185 for device_serial in devices: | |
| 186 device = device_utils.DeviceUtils(device_serial) | |
| 187 WipeDeviceData(device) | |
| 188 try: | |
| 189 device_utils.DeviceUtils.parallel(devices).Reboot(True) | |
| 190 except errors.DeviceUnresponsiveError: | |
| 191 pass | |
| 192 else: | |
| 193 ProvisionDevices(options) | |
| 194 | 190 |
| 195 | 191 |
| 196 if __name__ == '__main__': | 192 if __name__ == '__main__': |
| 197 sys.exit(main(sys.argv)) | 193 sys.exit(main(sys.argv)) |
| OLD | NEW |