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 re | 16 import re |
17 import subprocess | 17 import subprocess |
18 import sys | 18 import sys |
19 import time | 19 import time |
20 | 20 |
21 from pylib import android_commands | 21 from pylib import android_commands |
22 from pylib import constants | 22 from pylib import constants |
23 from pylib import device_settings | 23 from pylib import device_settings |
24 from pylib.device import device_blacklist | 24 from pylib.device import device_blacklist |
25 from pylib.device import device_errors | 25 from pylib.device import device_errors |
26 from pylib.device import device_utils | 26 from pylib.device import device_utils |
27 from pylib.utils import run_tests_helper | 27 from pylib.utils import run_tests_helper |
28 from pylib.utils import timeout_retry | |
28 | 29 |
29 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, | 30 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, |
30 'third_party', 'android_testrunner')) | 31 'third_party', 'android_testrunner')) |
31 import errors | 32 import errors |
32 | 33 |
33 | 34 |
34 class _DEFAULT_TIMEOUTS(object): | 35 class _DEFAULT_TIMEOUTS(object): |
35 # L can take a while to reboot after a wipe. | 36 # L can take a while to reboot after a wipe. |
36 LOLLIPOP = 600 | 37 LOLLIPOP = 600 |
37 PRE_LOLLIPOP = 180 | 38 PRE_LOLLIPOP = 180 |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 # We can safely ignore the exception because we don't expect adb_reboot | 78 # We can safely ignore the exception because we don't expect adb_reboot |
78 # to be running. | 79 # to be running. |
79 pass | 80 pass |
80 # Push adb_reboot | 81 # Push adb_reboot |
81 logging.info(' Pushing adb_reboot ...') | 82 logging.info(' Pushing adb_reboot ...') |
82 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, | 83 adb_reboot = os.path.join(constants.DIR_SOURCE_ROOT, |
83 'out/%s/adb_reboot' % target) | 84 'out/%s/adb_reboot' % target) |
84 device.PushChangedFiles([(adb_reboot, '/data/local/tmp/')]) | 85 device.PushChangedFiles([(adb_reboot, '/data/local/tmp/')]) |
85 # Launch adb_reboot | 86 # Launch adb_reboot |
86 logging.info(' Launching adb_reboot ...') | 87 logging.info(' Launching adb_reboot ...') |
87 device.old_interface.GetAndroidToolStatusAndOutput( | 88 device.RunShellCommand([ |
88 '/data/local/tmp/adb_reboot') | 89 device.GetDevicePieWrapper(), |
90 '/data/local/tmp/adb_reboot']) | |
89 | 91 |
90 | 92 |
91 def _ConfigureLocalProperties(device, java_debug=True): | 93 def _ConfigureLocalProperties(device, java_debug=True): |
92 """Set standard readonly testing device properties prior to reboot.""" | 94 """Set standard readonly testing device properties prior to reboot.""" |
93 local_props = [ | 95 local_props = [ |
94 'persist.sys.usb.config=adb', | 96 'persist.sys.usb.config=adb', |
95 'ro.monkey=1', | 97 'ro.monkey=1', |
96 'ro.test_harness=1', | 98 'ro.test_harness=1', |
97 'ro.audio.silent=1', | 99 'ro.audio.silent=1', |
98 'ro.setupwizard.mode=DISABLED', | 100 'ro.setupwizard.mode=DISABLED', |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 | 144 |
143 def WipeDeviceIfPossible(device, timeout): | 145 def WipeDeviceIfPossible(device, timeout): |
144 try: | 146 try: |
145 device.EnableRoot() | 147 device.EnableRoot() |
146 WipeDeviceData(device) | 148 WipeDeviceData(device) |
147 device.Reboot(True, timeout=timeout, retries=0) | 149 device.Reboot(True, timeout=timeout, retries=0) |
148 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): | 150 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): |
149 pass | 151 pass |
150 | 152 |
151 | 153 |
154 def ChargeDeviceToLevel(device, level): | |
155 def device_charged(): | |
156 battery_level = int(device.GetBatteryInfo().get('level', 100)) | |
perezju
2015/02/23 10:43:32
I see this was also on the previous version of the
jbudorick
2015/02/24 15:44:53
I'm not sure when or why the default was added, bu
| |
157 logging.info('current battery level: %d', battery_level) | |
158 return battery_level >= level | |
159 | |
160 timeout_retry.WaitFor(device_charged, wait_period=60) | |
161 | |
162 | |
152 def ProvisionDevice(device, options): | 163 def ProvisionDevice(device, options): |
153 if options.reboot_timeout: | 164 if options.reboot_timeout: |
154 reboot_timeout = options.reboot_timeout | 165 reboot_timeout = options.reboot_timeout |
155 elif (device.build_version_sdk >= | 166 elif (device.build_version_sdk >= |
156 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): | 167 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): |
157 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP | 168 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP |
158 else: | 169 else: |
159 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP | 170 reboot_timeout = _DEFAULT_TIMEOUTS.PRE_LOLLIPOP |
160 | 171 |
161 try: | 172 try: |
(...skipping 10 matching lines...) Expand all Loading... | |
172 device_settings.ConfigureContentSettings( | 183 device_settings.ConfigureContentSettings( |
173 device, device_settings.DISABLE_LOCATION_SETTINGS) | 184 device, device_settings.DISABLE_LOCATION_SETTINGS) |
174 else: | 185 else: |
175 device_settings.ConfigureContentSettings( | 186 device_settings.ConfigureContentSettings( |
176 device, device_settings.ENABLE_LOCATION_SETTINGS) | 187 device, device_settings.ENABLE_LOCATION_SETTINGS) |
177 device_settings.SetLockScreenSettings(device) | 188 device_settings.SetLockScreenSettings(device) |
178 if options.disable_network: | 189 if options.disable_network: |
179 device_settings.ConfigureContentSettings( | 190 device_settings.ConfigureContentSettings( |
180 device, device_settings.NETWORK_DISABLED_SETTINGS) | 191 device, device_settings.NETWORK_DISABLED_SETTINGS) |
181 if options.min_battery_level is not None: | 192 if options.min_battery_level is not None: |
182 try: | 193 device.SetUsbCharging(True) |
perezju
2015/02/23 10:43:32
There seems to be a change of logic w.r.t. previou
jbudorick
2015/02/24 15:44:53
These changes were both intentional, but on recons
| |
183 battery_info = device.old_interface.GetBatteryInfo() | 194 ChargeDeviceToLevel(device, options.min_battery_level) |
184 except Exception as e: | |
185 battery_info = {} | |
186 logging.error('Unable to obtain battery info for %s, %s', | |
187 str(device), e) | |
188 | 195 |
189 while int(battery_info.get('level', 100)) < options.min_battery_level: | |
190 if not device.old_interface.IsDeviceCharging(): | |
191 if device.old_interface.CanControlUsbCharging(): | |
192 device.old_interface.EnableUsbCharging() | |
193 else: | |
194 logging.error('Device is not charging') | |
195 break | |
196 logging.info('Waiting for device to charge. Current level=%s', | |
197 battery_info.get('level', 0)) | |
198 time.sleep(60) | |
199 battery_info = device.old_interface.GetBatteryInfo() | |
200 if not options.skip_wipe: | 196 if not options.skip_wipe: |
201 device.Reboot(True, timeout=reboot_timeout, retries=0) | 197 device.Reboot(True, timeout=reboot_timeout, retries=0) |
202 device.RunShellCommand('date -s %s' % time.strftime('%Y%m%d.%H%M%S', | 198 device.RunShellCommand('date -s %s' % time.strftime('%Y%m%d.%H%M%S', |
203 time.gmtime()), | 199 time.gmtime()), |
204 as_root=True) | 200 as_root=True) |
205 props = device.RunShellCommand('getprop') | 201 props = device.RunShellCommand('getprop') |
206 for prop in props: | 202 for prop in props: |
207 logging.info(' %s' % prop) | 203 logging.info(' %s' % prop) |
208 if options.auto_reconnect: | 204 if options.auto_reconnect: |
209 PushAndLaunchAdbReboot(device, options.target) | 205 PushAndLaunchAdbReboot(device, options.target) |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 help='push binary which will reboot the device on adb' | 273 help='push binary which will reboot the device on adb' |
278 ' disconnections') | 274 ' disconnections') |
279 args = parser.parse_args() | 275 args = parser.parse_args() |
280 constants.SetBuildType(args.target) | 276 constants.SetBuildType(args.target) |
281 | 277 |
282 return ProvisionDevices(args) | 278 return ProvisionDevices(args) |
283 | 279 |
284 | 280 |
285 if __name__ == '__main__': | 281 if __name__ == '__main__': |
286 sys.exit(main()) | 282 sys.exit(main()) |
OLD | NEW |