| 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 | |
| 23 from pylib import constants | 22 from pylib import constants |
| 24 from pylib import device_settings | 23 from pylib import device_settings |
| 24 from pylib.device import adb_wrapper |
| 25 from pylib.device import battery_utils | 25 from pylib.device import battery_utils |
| 26 from pylib.device import device_blacklist | 26 from pylib.device import device_blacklist |
| 27 from pylib.device import device_errors | 27 from pylib.device import device_errors |
| 28 from pylib.device import device_utils | 28 from pylib.device import device_utils |
| 29 from pylib.utils import run_tests_helper | 29 from pylib.utils import run_tests_helper |
| 30 from pylib.utils import timeout_retry | 30 from pylib.utils import timeout_retry |
| 31 | 31 |
| 32 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, | 32 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, |
| 33 'third_party', 'android_testrunner')) | 33 'third_party', 'android_testrunner')) |
| 34 import errors | 34 import errors |
| (...skipping 12 matching lines...) Expand all Loading... |
| 47 PROPERTIES = 'properties' | 47 PROPERTIES = 'properties' |
| 48 FINISH = 'finish' | 48 FINISH = 'finish' |
| 49 | 49 |
| 50 ALL = [WIPE, PROPERTIES, FINISH] | 50 ALL = [WIPE, PROPERTIES, FINISH] |
| 51 | 51 |
| 52 | 52 |
| 53 def ProvisionDevices(options): | 53 def ProvisionDevices(options): |
| 54 if options.device is not None: | 54 if options.device is not None: |
| 55 devices = [options.device] | 55 devices = [options.device] |
| 56 else: | 56 else: |
| 57 devices = android_commands.GetAttachedDevices() | 57 devices = adb_wrapper.AdbWrapper.GetDevices() |
| 58 | 58 |
| 59 parallel_devices = device_utils.DeviceUtils.parallel(devices) | 59 parallel_devices = device_utils.DeviceUtils.parallel(devices) |
| 60 parallel_devices.pMap(ProvisionDevice, options) | 60 parallel_devices.pMap(ProvisionDevice, options) |
| 61 if options.auto_reconnect: | 61 if options.auto_reconnect: |
| 62 _LaunchHostHeartbeat() | 62 _LaunchHostHeartbeat() |
| 63 blacklist = device_blacklist.ReadBlacklist() | 63 blacklist = device_blacklist.ReadBlacklist() |
| 64 if all(d in blacklist for d in devices): | 64 if all(d in blacklist for d in devices): |
| 65 raise device_errors.NoDevicesError | 65 raise device_errors.NoDevicesError |
| 66 return 0 | 66 return 0 |
| 67 | 67 |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 def _ConfigureLocalProperties(device, java_debug=True): | 189 def _ConfigureLocalProperties(device, java_debug=True): |
| 190 """Set standard readonly testing device properties prior to reboot.""" | 190 """Set standard readonly testing device properties prior to reboot.""" |
| 191 local_props = [ | 191 local_props = [ |
| 192 'persist.sys.usb.config=adb', | 192 'persist.sys.usb.config=adb', |
| 193 'ro.monkey=1', | 193 'ro.monkey=1', |
| 194 'ro.test_harness=1', | 194 'ro.test_harness=1', |
| 195 'ro.audio.silent=1', | 195 'ro.audio.silent=1', |
| 196 'ro.setupwizard.mode=DISABLED', | 196 'ro.setupwizard.mode=DISABLED', |
| 197 ] | 197 ] |
| 198 if java_debug: | 198 if java_debug: |
| 199 local_props.append('%s=all' % android_commands.JAVA_ASSERT_PROPERTY) | 199 local_props.append( |
| 200 '%s=all' % device_utils.DeviceUtils.JAVA_ASSERT_PROPERTY) |
| 200 local_props.append('debug.checkjni=1') | 201 local_props.append('debug.checkjni=1') |
| 201 try: | 202 try: |
| 202 device.WriteFile( | 203 device.WriteFile( |
| 203 constants.DEVICE_LOCAL_PROPERTIES_PATH, | 204 constants.DEVICE_LOCAL_PROPERTIES_PATH, |
| 204 '\n'.join(local_props), as_root=True) | 205 '\n'.join(local_props), as_root=True) |
| 205 # Android will not respect the local props file if it is world writable. | 206 # Android will not respect the local props file if it is world writable. |
| 206 device.RunShellCommand( | 207 device.RunShellCommand( |
| 207 ['chmod', '644', constants.DEVICE_LOCAL_PROPERTIES_PATH], | 208 ['chmod', '644', constants.DEVICE_LOCAL_PROPERTIES_PATH], |
| 208 as_root=True, check_return=True) | 209 as_root=True, check_return=True) |
| 209 except device_errors.CommandFailedError: | 210 except device_errors.CommandFailedError: |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 args = parser.parse_args() | 319 args = parser.parse_args() |
| 319 constants.SetBuildType(args.target) | 320 constants.SetBuildType(args.target) |
| 320 | 321 |
| 321 run_tests_helper.SetLogLevel(args.verbose) | 322 run_tests_helper.SetLogLevel(args.verbose) |
| 322 | 323 |
| 323 return ProvisionDevices(args) | 324 return ProvisionDevices(args) |
| 324 | 325 |
| 325 | 326 |
| 326 if __name__ == '__main__': | 327 if __name__ == '__main__': |
| 327 sys.exit(main()) | 328 sys.exit(main()) |
| OLD | NEW |