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 datetime | 14 import datetime |
15 import json | 15 import json |
16 import logging | 16 import logging |
17 import os | 17 import os |
18 import posixpath | 18 import posixpath |
19 import re | 19 import re |
20 import subprocess | 20 import subprocess |
21 import sys | 21 import sys |
22 import time | 22 import time |
23 | 23 |
| 24 from devil.android.sdk import version_codes |
| 25 |
24 from pylib import constants | 26 from pylib import constants |
25 from pylib import device_settings | 27 from pylib import device_settings |
26 from pylib.device import battery_utils | 28 from pylib.device import battery_utils |
27 from pylib.device import device_blacklist | 29 from pylib.device import device_blacklist |
28 from pylib.device import device_errors | 30 from pylib.device import device_errors |
29 from pylib.device import device_utils | 31 from pylib.device import device_utils |
30 from pylib.utils import run_tests_helper | 32 from pylib.utils import run_tests_helper |
31 from pylib.utils import timeout_retry | 33 from pylib.utils import timeout_retry |
32 | 34 |
33 _SYSTEM_WEBVIEW_PATHS = ['/system/app/webview', '/system/app/WebViewGoogle'] | 35 _SYSTEM_WEBVIEW_PATHS = ['/system/app/webview', '/system/app/WebViewGoogle'] |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 with open(args.output_device_blacklist, 'w') as f: | 75 with open(args.output_device_blacklist, 'w') as f: |
74 json.dump(blacklisted_devices, f) | 76 json.dump(blacklisted_devices, f) |
75 if all(d in blacklisted_devices for d in devices): | 77 if all(d in blacklisted_devices for d in devices): |
76 raise device_errors.NoDevicesError | 78 raise device_errors.NoDevicesError |
77 return 0 | 79 return 0 |
78 | 80 |
79 | 81 |
80 def ProvisionDevice(device, blacklist, options): | 82 def ProvisionDevice(device, blacklist, options): |
81 if options.reboot_timeout: | 83 if options.reboot_timeout: |
82 reboot_timeout = options.reboot_timeout | 84 reboot_timeout = options.reboot_timeout |
83 elif (device.build_version_sdk >= | 85 elif (device.build_version_sdk >= version_codes.LOLLIPOP): |
84 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): | |
85 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP | 86 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP |
86 else: | 87 else: |
87 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP | 88 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP |
88 | 89 |
89 def should_run_phase(phase_name): | 90 def should_run_phase(phase_name): |
90 return not options.phases or phase_name in options.phases | 91 return not options.phases or phase_name in options.phases |
91 | 92 |
92 def run_phase(phase_func, reboot=True): | 93 def run_phase(phase_func, reboot=True): |
93 try: | 94 try: |
94 device.WaitUntilFullyBooted(timeout=reboot_timeout, retries=0) | 95 device.WaitUntilFullyBooted(timeout=reboot_timeout, retries=0) |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 'ro.test_harness=1', | 267 'ro.test_harness=1', |
267 'ro.audio.silent=1', | 268 'ro.audio.silent=1', |
268 'ro.setupwizard.mode=DISABLED', | 269 'ro.setupwizard.mode=DISABLED', |
269 ] | 270 ] |
270 if java_debug: | 271 if java_debug: |
271 local_props.append( | 272 local_props.append( |
272 '%s=all' % device_utils.DeviceUtils.JAVA_ASSERT_PROPERTY) | 273 '%s=all' % device_utils.DeviceUtils.JAVA_ASSERT_PROPERTY) |
273 local_props.append('debug.checkjni=1') | 274 local_props.append('debug.checkjni=1') |
274 try: | 275 try: |
275 device.WriteFile( | 276 device.WriteFile( |
276 constants.DEVICE_LOCAL_PROPERTIES_PATH, | 277 device.LOCAL_PROPERTIES_PATH, |
277 '\n'.join(local_props), as_root=True) | 278 '\n'.join(local_props), as_root=True) |
278 # Android will not respect the local props file if it is world writable. | 279 # Android will not respect the local props file if it is world writable. |
279 device.RunShellCommand( | 280 device.RunShellCommand( |
280 ['chmod', '644', constants.DEVICE_LOCAL_PROPERTIES_PATH], | 281 ['chmod', '644', device.LOCAL_PROPERTIES_PATH], |
281 as_root=True, check_return=True) | 282 as_root=True, check_return=True) |
282 except device_errors.CommandFailedError: | 283 except device_errors.CommandFailedError: |
283 logging.exception('Failed to configure local properties.') | 284 logging.exception('Failed to configure local properties.') |
284 | 285 |
285 | 286 |
286 def FinishProvisioning(device, options): | 287 def FinishProvisioning(device, options): |
287 if options.min_battery_level is not None: | 288 if options.min_battery_level is not None: |
288 try: | 289 try: |
289 battery = battery_utils.BatteryUtils(device) | 290 battery = battery_utils.BatteryUtils(device) |
290 battery.ChargeDeviceToLevel(options.min_battery_level) | 291 battery.ChargeDeviceToLevel(options.min_battery_level) |
291 except device_errors.CommandFailedError: | 292 except device_errors.CommandFailedError: |
292 logging.exception('Unable to charge device to specified level.') | 293 logging.exception('Unable to charge device to specified level.') |
293 | 294 |
294 if options.max_battery_temp is not None: | 295 if options.max_battery_temp is not None: |
295 try: | 296 try: |
296 battery = battery_utils.BatteryUtils(device) | 297 battery = battery_utils.BatteryUtils(device) |
297 battery.LetBatteryCoolToTemperature(options.max_battery_temp) | 298 battery.LetBatteryCoolToTemperature(options.max_battery_temp) |
298 except device_errors.CommandFailedError: | 299 except device_errors.CommandFailedError: |
299 logging.exception('Unable to let battery cool to specified temperature.') | 300 logging.exception('Unable to let battery cool to specified temperature.') |
300 | 301 |
301 def _set_and_verify_date(): | 302 def _set_and_verify_date(): |
302 if (device.build_version_sdk | 303 if (device.build_version_sdk >= version_codes.MARSHMALLOW): |
303 >= constants.ANDROID_SDK_VERSION_CODES.MARSHMALLOW): | |
304 date_format = '%m%d%H%M%Y.%S' | 304 date_format = '%m%d%H%M%Y.%S' |
305 set_date_command = ['date'] | 305 set_date_command = ['date'] |
306 else: | 306 else: |
307 date_format = '%Y%m%d.%H%M%S' | 307 date_format = '%Y%m%d.%H%M%S' |
308 set_date_command = ['date', '-s'] | 308 set_date_command = ['date', '-s'] |
309 strgmtime = time.strftime(date_format, time.gmtime()) | 309 strgmtime = time.strftime(date_format, time.gmtime()) |
310 set_date_command.append(strgmtime) | 310 set_date_command.append(strgmtime) |
311 device.RunShellCommand(set_date_command, as_root=True, check_return=True) | 311 device.RunShellCommand(set_date_command, as_root=True, check_return=True) |
312 | 312 |
313 device_time = device.RunShellCommand( | 313 device_time = device.RunShellCommand( |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 args = parser.parse_args() | 451 args = parser.parse_args() |
452 constants.SetBuildType(args.target) | 452 constants.SetBuildType(args.target) |
453 | 453 |
454 run_tests_helper.SetLogLevel(args.verbose) | 454 run_tests_helper.SetLogLevel(args.verbose) |
455 | 455 |
456 return ProvisionDevices(args) | 456 return ProvisionDevices(args) |
457 | 457 |
458 | 458 |
459 if __name__ == '__main__': | 459 if __name__ == '__main__': |
460 sys.exit(main()) | 460 sys.exit(main()) |
OLD | NEW |