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_filter |
28 from pylib.device import device_utils | 29 from pylib.device import device_utils |
29 from pylib.utils import run_tests_helper | 30 from pylib.utils import run_tests_helper |
30 from pylib.utils import timeout_retry | 31 from pylib.utils import timeout_retry |
31 | 32 |
32 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, | 33 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, |
33 'third_party', 'android_testrunner')) | 34 'third_party', 'android_testrunner')) |
34 import errors | 35 import errors |
35 | 36 |
36 | 37 |
37 class _DEFAULT_TIMEOUTS(object): | 38 class _DEFAULT_TIMEOUTS(object): |
38 # L can take a while to reboot after a wipe. | 39 # L can take a while to reboot after a wipe. |
39 LOLLIPOP = 600 | 40 LOLLIPOP = 600 |
40 PRE_LOLLIPOP = 180 | 41 PRE_LOLLIPOP = 180 |
41 | 42 |
42 HELP_TEXT = '{}s on L, {}s on pre-L'.format(LOLLIPOP, PRE_LOLLIPOP) | 43 HELP_TEXT = '{}s on L, {}s on pre-L'.format(LOLLIPOP, PRE_LOLLIPOP) |
43 | 44 |
44 | 45 |
45 class _PHASES(object): | 46 class _PHASES(object): |
46 WIPE = 'wipe' | 47 WIPE = 'wipe' |
47 PROPERTIES = 'properties' | 48 PROPERTIES = 'properties' |
48 FINISH = 'finish' | 49 FINISH = 'finish' |
49 | 50 |
50 ALL = [WIPE, PROPERTIES, FINISH] | 51 ALL = [WIPE, PROPERTIES, FINISH] |
51 | 52 |
52 | 53 |
53 def ProvisionDevices(options): | 54 def ProvisionDevices(options): |
54 if options.device is not None: | 55 if options.device is not None: |
55 devices = [options.device] | 56 devices = [options.device] |
56 else: | 57 else: |
57 devices = android_commands.GetAttachedDevices() | 58 devices = adb_wrapper.AdbWrapper.Devices( |
| 59 filters=device_filter.DefaultFilters()) |
58 | 60 |
59 parallel_devices = device_utils.DeviceUtils.parallel(devices) | 61 parallel_devices = device_utils.DeviceUtils.parallel(devices) |
60 parallel_devices.pMap(ProvisionDevice, options) | 62 parallel_devices.pMap(ProvisionDevice, options) |
61 if options.auto_reconnect: | 63 if options.auto_reconnect: |
62 _LaunchHostHeartbeat() | 64 _LaunchHostHeartbeat() |
63 blacklist = device_blacklist.ReadBlacklist() | 65 blacklist = device_blacklist.ReadBlacklist() |
64 if all(d in blacklist for d in devices): | 66 if all(d in blacklist for d in devices): |
65 raise device_errors.NoDevicesError | 67 raise device_errors.NoDevicesError |
66 return 0 | 68 return 0 |
67 | 69 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
189 def _ConfigureLocalProperties(device, java_debug=True): | 191 def _ConfigureLocalProperties(device, java_debug=True): |
190 """Set standard readonly testing device properties prior to reboot.""" | 192 """Set standard readonly testing device properties prior to reboot.""" |
191 local_props = [ | 193 local_props = [ |
192 'persist.sys.usb.config=adb', | 194 'persist.sys.usb.config=adb', |
193 'ro.monkey=1', | 195 'ro.monkey=1', |
194 'ro.test_harness=1', | 196 'ro.test_harness=1', |
195 'ro.audio.silent=1', | 197 'ro.audio.silent=1', |
196 'ro.setupwizard.mode=DISABLED', | 198 'ro.setupwizard.mode=DISABLED', |
197 ] | 199 ] |
198 if java_debug: | 200 if java_debug: |
199 local_props.append('%s=all' % android_commands.JAVA_ASSERT_PROPERTY) | 201 local_props.append( |
| 202 '%s=all' % device_utils.DeviceUtils.JAVA_ASSERT_PROPERTY) |
200 local_props.append('debug.checkjni=1') | 203 local_props.append('debug.checkjni=1') |
201 try: | 204 try: |
202 device.WriteFile( | 205 device.WriteFile( |
203 constants.DEVICE_LOCAL_PROPERTIES_PATH, | 206 constants.DEVICE_LOCAL_PROPERTIES_PATH, |
204 '\n'.join(local_props), as_root=True) | 207 '\n'.join(local_props), as_root=True) |
205 # Android will not respect the local props file if it is world writable. | 208 # Android will not respect the local props file if it is world writable. |
206 device.RunShellCommand( | 209 device.RunShellCommand( |
207 ['chmod', '644', constants.DEVICE_LOCAL_PROPERTIES_PATH], | 210 ['chmod', '644', constants.DEVICE_LOCAL_PROPERTIES_PATH], |
208 as_root=True, check_return=True) | 211 as_root=True, check_return=True) |
209 except device_errors.CommandFailedError: | 212 except device_errors.CommandFailedError: |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 args = parser.parse_args() | 314 args = parser.parse_args() |
312 constants.SetBuildType(args.target) | 315 constants.SetBuildType(args.target) |
313 | 316 |
314 run_tests_helper.SetLogLevel(args.verbose) | 317 run_tests_helper.SetLogLevel(args.verbose) |
315 | 318 |
316 return ProvisionDevices(args) | 319 return ProvisionDevices(args) |
317 | 320 |
318 | 321 |
319 if __name__ == '__main__': | 322 if __name__ == '__main__': |
320 sys.exit(main()) | 323 sys.exit(main()) |
OLD | NEW |