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 17 matching lines...) Expand all Loading... |
28 | 28 |
29 import devil_chromium | 29 import devil_chromium |
30 from devil import devil_env | 30 from devil import devil_env |
31 from devil.android import battery_utils | 31 from devil.android import battery_utils |
32 from devil.android import device_blacklist | 32 from devil.android import device_blacklist |
33 from devil.android import device_errors | 33 from devil.android import device_errors |
34 from devil.android import device_temp_file | 34 from devil.android import device_temp_file |
35 from devil.android import device_utils | 35 from devil.android import device_utils |
36 from devil.android.sdk import keyevent | 36 from devil.android.sdk import keyevent |
37 from devil.android.sdk import version_codes | 37 from devil.android.sdk import version_codes |
| 38 from devil.constants import exit_codes |
38 from devil.utils import run_tests_helper | 39 from devil.utils import run_tests_helper |
39 from devil.utils import timeout_retry | 40 from devil.utils import timeout_retry |
40 from pylib import constants | 41 from pylib import constants |
41 from pylib import device_settings | 42 from pylib import device_settings |
42 from pylib.constants import host_paths | 43 from pylib.constants import host_paths |
43 | 44 |
44 _SYSTEM_WEBVIEW_PATHS = ['/system/app/webview', '/system/app/WebViewGoogle'] | 45 _SYSTEM_WEBVIEW_PATHS = ['/system/app/webview', '/system/app/WebViewGoogle'] |
45 _CHROME_PACKAGE_REGEX = re.compile('.*chrom.*') | 46 _CHROME_PACKAGE_REGEX = re.compile('.*chrom.*') |
46 _TOMBSTONE_REGEX = re.compile('tombstone.*') | 47 _TOMBSTONE_REGEX = re.compile('tombstone.*') |
47 | 48 |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 try: | 364 try: |
364 battery = battery_utils.BatteryUtils(device) | 365 battery = battery_utils.BatteryUtils(device) |
365 battery.LetBatteryCoolToTemperature(options.max_battery_temp) | 366 battery.LetBatteryCoolToTemperature(options.max_battery_temp) |
366 except device_errors.CommandFailedError: | 367 except device_errors.CommandFailedError: |
367 logging.exception('Unable to let battery cool to specified temperature.') | 368 logging.exception('Unable to let battery cool to specified temperature.') |
368 | 369 |
369 def _set_and_verify_date(): | 370 def _set_and_verify_date(): |
370 if device.build_version_sdk >= version_codes.MARSHMALLOW: | 371 if device.build_version_sdk >= version_codes.MARSHMALLOW: |
371 date_format = '%m%d%H%M%Y.%S' | 372 date_format = '%m%d%H%M%Y.%S' |
372 set_date_command = ['date', '-u'] | 373 set_date_command = ['date', '-u'] |
| 374 get_date_command = ['date', '-u'] |
373 else: | 375 else: |
374 date_format = '%Y%m%d.%H%M%S' | 376 date_format = '%Y%m%d.%H%M%S' |
375 set_date_command = ['date', '-u', '-s'] | 377 set_date_command = ['date', '-s'] |
| 378 get_date_command = ['date'] |
| 379 |
| 380 # TODO(jbudorick): This is wrong on pre-M devices -- get/set are |
| 381 # dealing in local time, but we're setting based on GMT. |
376 strgmtime = time.strftime(date_format, time.gmtime()) | 382 strgmtime = time.strftime(date_format, time.gmtime()) |
377 set_date_command.append(strgmtime) | 383 set_date_command.append(strgmtime) |
378 device.RunShellCommand(set_date_command, as_root=True, check_return=True) | 384 device.RunShellCommand(set_date_command, as_root=True, check_return=True) |
379 | 385 |
| 386 get_date_command.append('+"%Y%m%d.%H%M%S"') |
380 device_time = device.RunShellCommand( | 387 device_time = device.RunShellCommand( |
381 ['date', '-u', '+"%Y%m%d.%H%M%S"'], as_root=True, | 388 get_date_command, as_root=True, single_line=True).replace('"', '') |
382 single_line=True).replace('"', '') | |
383 device_time = datetime.datetime.strptime(device_time, "%Y%m%d.%H%M%S") | 389 device_time = datetime.datetime.strptime(device_time, "%Y%m%d.%H%M%S") |
384 correct_time = datetime.datetime.strptime(strgmtime, date_format) | 390 correct_time = datetime.datetime.strptime(strgmtime, date_format) |
385 tdelta = (correct_time - device_time).seconds | 391 tdelta = (correct_time - device_time).seconds |
386 if tdelta <= 1: | 392 if tdelta <= 1: |
387 logging.info('Date/time successfully set on %s', device) | 393 logging.info('Date/time successfully set on %s', device) |
388 return True | 394 return True |
389 else: | 395 else: |
390 logging.error('Date mismatch. Device: %s Correct: %s', | 396 logging.error('Date mismatch. Device: %s Correct: %s', |
391 device_time.isoformat(), correct_time.isoformat()) | 397 device_time.isoformat(), correct_time.isoformat()) |
392 return False | 398 return False |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 devil_custom_deps = None | 548 devil_custom_deps = None |
543 if args.adb_path: | 549 if args.adb_path: |
544 devil_custom_deps = { | 550 devil_custom_deps = { |
545 'adb': { | 551 'adb': { |
546 devil_env.GetPlatform(): [args.adb_path], | 552 devil_env.GetPlatform(): [args.adb_path], |
547 }, | 553 }, |
548 } | 554 } |
549 | 555 |
550 devil_chromium.Initialize(custom_deps=devil_custom_deps) | 556 devil_chromium.Initialize(custom_deps=devil_custom_deps) |
551 | 557 |
552 return ProvisionDevices(args) | 558 try: |
| 559 return ProvisionDevices(args) |
| 560 except (device_errors.DeviceUnreachableError, device_errors.NoDevicesError): |
| 561 return exit_codes.INFRA |
553 | 562 |
554 | 563 |
555 if __name__ == '__main__': | 564 if __name__ == '__main__': |
556 sys.exit(main()) | 565 sys.exit(main()) |
OLD | NEW |