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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 blacklisted_devices = blacklist.Read() if blacklist else [] | 82 blacklisted_devices = blacklist.Read() if blacklist else [] |
83 if args.output_device_blacklist: | 83 if args.output_device_blacklist: |
84 with open(args.output_device_blacklist, 'w') as f: | 84 with open(args.output_device_blacklist, 'w') as f: |
85 json.dump(blacklisted_devices, f) | 85 json.dump(blacklisted_devices, f) |
86 if all(d in blacklisted_devices for d in devices): | 86 if all(d in blacklisted_devices for d in devices): |
87 raise device_errors.NoDevicesError | 87 raise device_errors.NoDevicesError |
88 return 0 | 88 return 0 |
89 | 89 |
90 | 90 |
91 def ProvisionDevice(device, blacklist, options): | 91 def ProvisionDevice(device, blacklist, options): |
92 if options.reboot_timeout: | |
93 reboot_timeout = options.reboot_timeout | |
94 elif device.build_version_sdk >= version_codes.LOLLIPOP: | |
95 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP | |
96 else: | |
97 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP | |
98 | |
99 def should_run_phase(phase_name): | 92 def should_run_phase(phase_name): |
100 return not options.phases or phase_name in options.phases | 93 return not options.phases or phase_name in options.phases |
101 | 94 |
102 def run_phase(phase_func, reboot=True): | 95 def run_phase(phase_func, reboot_timeout, reboot=True): |
103 try: | 96 try: |
104 device.WaitUntilFullyBooted(timeout=reboot_timeout, retries=0) | 97 device.WaitUntilFullyBooted(timeout=reboot_timeout, retries=0) |
105 except device_errors.CommandTimeoutError: | 98 except device_errors.CommandTimeoutError: |
106 logging.error('Device did not finish booting. Will try to reboot.') | 99 logging.error('Device did not finish booting. Will try to reboot.') |
107 device.Reboot(timeout=reboot_timeout) | 100 device.Reboot(timeout=reboot_timeout) |
108 phase_func(device, options) | 101 phase_func(device, options) |
109 if reboot: | 102 if reboot: |
110 device.Reboot(False, retries=0) | 103 device.Reboot(False, retries=0) |
111 device.adb.WaitForDevice() | 104 device.adb.WaitForDevice() |
112 | 105 |
113 try: | 106 try: |
| 107 if options.reboot_timeout: |
| 108 reboot_timeout = options.reboot_timeout |
| 109 elif device.build_version_sdk >= version_codes.LOLLIPOP: |
| 110 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP |
| 111 else: |
| 112 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP |
| 113 |
114 if should_run_phase(_PHASES.WIPE): | 114 if should_run_phase(_PHASES.WIPE): |
115 if (options.chrome_specific_wipe or device.IsUserBuild() or | 115 if (options.chrome_specific_wipe or device.IsUserBuild() or |
116 device.build_version_sdk >= version_codes.MARSHMALLOW): | 116 device.build_version_sdk >= version_codes.MARSHMALLOW): |
117 run_phase(WipeChromeData) | 117 run_phase(WipeChromeData, reboot_timeout) |
118 else: | 118 else: |
119 run_phase(WipeDevice) | 119 run_phase(WipeDevice, reboot_timeout) |
120 | 120 |
121 if should_run_phase(_PHASES.PROPERTIES): | 121 if should_run_phase(_PHASES.PROPERTIES): |
122 run_phase(SetProperties) | 122 run_phase(SetProperties, reboot_timeout) |
123 | 123 |
124 if should_run_phase(_PHASES.FINISH): | 124 if should_run_phase(_PHASES.FINISH): |
125 run_phase(FinishProvisioning, reboot=False) | 125 run_phase(FinishProvisioning, reboot_timeout, reboot=False) |
126 | 126 |
127 if options.chrome_specific_wipe: | 127 if options.chrome_specific_wipe: |
128 package = "com.google.android.gms" | 128 package = "com.google.android.gms" |
129 version_name = device.GetApplicationVersion(package) | 129 version_name = device.GetApplicationVersion(package) |
130 logging.info("Version name for %s is %s", package, version_name) | 130 logging.info("Version name for %s is %s", package, version_name) |
131 | 131 |
132 CheckExternalStorage(device) | 132 CheckExternalStorage(device) |
133 | 133 |
134 except device_errors.CommandTimeoutError: | 134 except device_errors.CommandTimeoutError: |
135 logging.exception('Timed out waiting for device %s. Adding to blacklist.', | 135 logging.exception('Timed out waiting for device %s. Adding to blacklist.', |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
547 devil_chromium.Initialize(adb_path=args.adb_path) | 547 devil_chromium.Initialize(adb_path=args.adb_path) |
548 | 548 |
549 try: | 549 try: |
550 return ProvisionDevices(args) | 550 return ProvisionDevices(args) |
551 except (device_errors.DeviceUnreachableError, device_errors.NoDevicesError): | 551 except (device_errors.DeviceUnreachableError, device_errors.NoDevicesError): |
552 return exit_codes.INFRA | 552 return exit_codes.INFRA |
553 | 553 |
554 | 554 |
555 if __name__ == '__main__': | 555 if __name__ == '__main__': |
556 sys.exit(main()) | 556 sys.exit(main()) |
OLD | NEW |