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>] |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import argparse | 13 import argparse |
| 14 import logging | 14 import logging |
| 15 import os | 15 import os |
| 16 import posixpath | 16 import posixpath |
| 17 import re | 17 import re |
| 18 import subprocess | 18 import subprocess |
| 19 import sys | 19 import sys |
| 20 import time | 20 import time |
| 21 | 21 |
| 22 from pylib import android_commands | 22 from pylib import android_commands |
| 23 from pylib import constants | 23 from pylib import constants |
| 24 from pylib import device_settings | 24 from pylib import device_settings |
| 25 from pylib.device import battery_utils | |
| 25 from pylib.device import device_blacklist | 26 from pylib.device import device_blacklist |
| 26 from pylib.device import device_errors | 27 from pylib.device import device_errors |
| 27 from pylib.device import device_utils | 28 from pylib.device import device_utils |
| 28 from pylib.utils import run_tests_helper | 29 from pylib.utils import run_tests_helper |
| 29 from pylib.utils import timeout_retry | 30 from pylib.utils import timeout_retry |
| 30 | 31 |
| 31 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, | 32 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, |
| 32 'third_party', 'android_testrunner')) | 33 'third_party', 'android_testrunner')) |
| 33 import errors | 34 import errors |
| 34 | 35 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 158 try: | 159 try: |
| 159 device.EnableRoot() | 160 device.EnableRoot() |
| 160 WipeDeviceData(device, options) | 161 WipeDeviceData(device, options) |
| 161 device.Reboot(True, timeout=timeout, retries=0) | 162 device.Reboot(True, timeout=timeout, retries=0) |
| 162 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): | 163 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): |
| 163 pass | 164 pass |
| 164 | 165 |
| 165 | 166 |
| 166 def ChargeDeviceToLevel(device, level): | 167 def ChargeDeviceToLevel(device, level): |
| 167 def device_charged(): | 168 def device_charged(): |
| 168 battery_level = device.GetBatteryInfo().get('level') | 169 battery = battery_utils.BatteryUtils(device) |
| 170 battery_level = battery.GetBatteryInfo().get('level') | |
| 169 if battery_level is None: | 171 if battery_level is None: |
| 170 logging.warning('Unable to find current battery level.') | 172 logging.warning('Unable to find current battery level.') |
| 171 battery_level = 100 | 173 battery_level = 100 |
| 172 else: | 174 else: |
| 173 logging.info('current battery level: %d', battery_level) | 175 logging.info('current battery level: %d', battery_level) |
| 174 battery_level = int(battery_level) | 176 battery_level = int(battery_level) |
| 175 return battery_level >= level | 177 return battery_level >= level |
| 176 | 178 |
| 177 timeout_retry.WaitFor(device_charged, wait_period=60) | 179 timeout_retry.WaitFor(device_charged, wait_period=60) |
| 178 | 180 |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 201 device, device_settings.DISABLE_LOCATION_SETTINGS) | 203 device, device_settings.DISABLE_LOCATION_SETTINGS) |
| 202 else: | 204 else: |
| 203 device_settings.ConfigureContentSettings( | 205 device_settings.ConfigureContentSettings( |
| 204 device, device_settings.ENABLE_LOCATION_SETTINGS) | 206 device, device_settings.ENABLE_LOCATION_SETTINGS) |
| 205 device_settings.SetLockScreenSettings(device) | 207 device_settings.SetLockScreenSettings(device) |
| 206 if options.disable_network: | 208 if options.disable_network: |
| 207 device_settings.ConfigureContentSettings( | 209 device_settings.ConfigureContentSettings( |
| 208 device, device_settings.NETWORK_DISABLED_SETTINGS) | 210 device, device_settings.NETWORK_DISABLED_SETTINGS) |
| 209 if options.min_battery_level is not None: | 211 if options.min_battery_level is not None: |
| 210 try: | 212 try: |
| 211 device.SetCharging(True) | 213 battery = battery_utils.BatteryUtils(device) |
|
jbudorick
2015/04/01 17:29:47
Let's just move this into ChargeDeviceToLevel.
rnephew (Wrong account)
2015/04/01 17:42:54
Done.
| |
| 214 battery.SetCharging(True) | |
| 212 ChargeDeviceToLevel(device, options.min_battery_level) | 215 ChargeDeviceToLevel(device, options.min_battery_level) |
| 213 except device_errors.CommandFailedError as e: | 216 except device_errors.CommandFailedError as e: |
| 214 logging.exception('Unable to charge device to specified level.') | 217 logging.exception('Unable to charge device to specified level.') |
| 215 | 218 |
| 216 if not options.skip_wipe: | 219 if not options.skip_wipe: |
| 217 device.Reboot(True, timeout=reboot_timeout, retries=0) | 220 device.Reboot(True, timeout=reboot_timeout, retries=0) |
| 218 device.RunShellCommand('date -s %s' % time.strftime('%Y%m%d.%H%M%S', | 221 device.RunShellCommand('date -s %s' % time.strftime('%Y%m%d.%H%M%S', |
| 219 time.gmtime()), | 222 time.gmtime()), |
| 220 as_root=True) | 223 as_root=True) |
| 221 props = device.RunShellCommand('getprop') | 224 props = device.RunShellCommand('getprop') |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 parser.add_argument('--adb-key-files', type=str, nargs='+', | 298 parser.add_argument('--adb-key-files', type=str, nargs='+', |
| 296 help='list of adb keys to push to device') | 299 help='list of adb keys to push to device') |
| 297 args = parser.parse_args() | 300 args = parser.parse_args() |
| 298 constants.SetBuildType(args.target) | 301 constants.SetBuildType(args.target) |
| 299 | 302 |
| 300 return ProvisionDevices(args) | 303 return ProvisionDevices(args) |
| 301 | 304 |
| 302 | 305 |
| 303 if __name__ == '__main__': | 306 if __name__ == '__main__': |
| 304 sys.exit(main()) | 307 sys.exit(main()) |
| OLD | NEW |