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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 device_settings.ConfigureContentSettings( | 175 device_settings.ConfigureContentSettings( |
176 device, device_settings.DISABLE_LOCATION_SETTINGS) | 176 device, device_settings.DISABLE_LOCATION_SETTINGS) |
177 else: | 177 else: |
178 device_settings.ConfigureContentSettings( | 178 device_settings.ConfigureContentSettings( |
179 device, device_settings.ENABLE_LOCATION_SETTINGS) | 179 device, device_settings.ENABLE_LOCATION_SETTINGS) |
180 device_settings.SetLockScreenSettings(device) | 180 device_settings.SetLockScreenSettings(device) |
181 if options.disable_network: | 181 if options.disable_network: |
182 device_settings.ConfigureContentSettings( | 182 device_settings.ConfigureContentSettings( |
183 device, device_settings.NETWORK_DISABLED_SETTINGS) | 183 device, device_settings.NETWORK_DISABLED_SETTINGS) |
184 | 184 |
185 if options.min_battery_level is not None: | |
186 try: | |
187 battery = battery_utils.BatteryUtils(device) | |
188 battery.ChargeDeviceToLevel(options.min_battery_level) | |
189 except device_errors.CommandFailedError as e: | |
190 logging.exception('Unable to charge device to specified level.') | |
191 | |
192 if options.max_battery_temp is not None: | |
193 try: | |
194 battery = battery_utils.BatteryUtils(device) | |
195 battery.LetBatteryCoolToTemperature(options.max_battery_temp) | |
196 except device_errors.CommandFailedError as e: | |
197 logging.exception('Unable to let battery cool to specified temperature.') | |
198 | |
199 def _ConfigureLocalProperties(device, java_debug=True): | 185 def _ConfigureLocalProperties(device, java_debug=True): |
200 """Set standard readonly testing device properties prior to reboot.""" | 186 """Set standard readonly testing device properties prior to reboot.""" |
201 local_props = [ | 187 local_props = [ |
202 'persist.sys.usb.config=adb', | 188 'persist.sys.usb.config=adb', |
203 'ro.monkey=1', | 189 'ro.monkey=1', |
204 'ro.test_harness=1', | 190 'ro.test_harness=1', |
205 'ro.audio.silent=1', | 191 'ro.audio.silent=1', |
206 'ro.setupwizard.mode=DISABLED', | 192 'ro.setupwizard.mode=DISABLED', |
207 ] | 193 ] |
208 if java_debug: | 194 if java_debug: |
209 local_props.append( | 195 local_props.append( |
210 '%s=all' % device_utils.DeviceUtils.JAVA_ASSERT_PROPERTY) | 196 '%s=all' % device_utils.DeviceUtils.JAVA_ASSERT_PROPERTY) |
211 local_props.append('debug.checkjni=1') | 197 local_props.append('debug.checkjni=1') |
212 try: | 198 try: |
213 device.WriteFile( | 199 device.WriteFile( |
214 constants.DEVICE_LOCAL_PROPERTIES_PATH, | 200 constants.DEVICE_LOCAL_PROPERTIES_PATH, |
215 '\n'.join(local_props), as_root=True) | 201 '\n'.join(local_props), as_root=True) |
216 # Android will not respect the local props file if it is world writable. | 202 # Android will not respect the local props file if it is world writable. |
217 device.RunShellCommand( | 203 device.RunShellCommand( |
218 ['chmod', '644', constants.DEVICE_LOCAL_PROPERTIES_PATH], | 204 ['chmod', '644', constants.DEVICE_LOCAL_PROPERTIES_PATH], |
219 as_root=True, check_return=True) | 205 as_root=True, check_return=True) |
220 except device_errors.CommandFailedError: | 206 except device_errors.CommandFailedError: |
221 logging.exception('Failed to configure local properties.') | 207 logging.exception('Failed to configure local properties.') |
222 | 208 |
223 | 209 |
224 def FinishProvisioning(device, options): | 210 def FinishProvisioning(device, options): |
| 211 if options.min_battery_level is not None: |
| 212 try: |
| 213 battery = battery_utils.BatteryUtils(device) |
| 214 battery.ChargeDeviceToLevel(options.min_battery_level) |
| 215 except device_errors.CommandFailedError: |
| 216 logging.exception('Unable to charge device to specified level.') |
| 217 |
| 218 if options.max_battery_temp is not None: |
| 219 try: |
| 220 battery = battery_utils.BatteryUtils(device) |
| 221 battery.LetBatteryCoolToTemperature(options.max_battery_temp) |
| 222 except device_errors.CommandFailedError: |
| 223 logging.exception('Unable to let battery cool to specified temperature.') |
| 224 |
225 device.RunShellCommand( | 225 device.RunShellCommand( |
226 ['date', '-s', time.strftime('%Y%m%d.%H%M%S', time.gmtime())], | 226 ['date', '-s', time.strftime('%Y%m%d.%H%M%S', time.gmtime())], |
227 as_root=True, check_return=True) | 227 as_root=True, check_return=True) |
228 props = device.RunShellCommand('getprop', check_return=True) | 228 props = device.RunShellCommand('getprop', check_return=True) |
229 for prop in props: | 229 for prop in props: |
230 logging.info(' %s' % prop) | 230 logging.info(' %s' % prop) |
231 if options.auto_reconnect: | 231 if options.auto_reconnect: |
232 _PushAndLaunchAdbReboot(device, options.target) | 232 _PushAndLaunchAdbReboot(device, options.target) |
233 | 233 |
234 | 234 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 args = parser.parse_args() | 326 args = parser.parse_args() |
327 constants.SetBuildType(args.target) | 327 constants.SetBuildType(args.target) |
328 | 328 |
329 run_tests_helper.SetLogLevel(args.verbose) | 329 run_tests_helper.SetLogLevel(args.verbose) |
330 | 330 |
331 return ProvisionDevices(args) | 331 return ProvisionDevices(args) |
332 | 332 |
333 | 333 |
334 if __name__ == '__main__': | 334 if __name__ == '__main__': |
335 sys.exit(main()) | 335 sys.exit(main()) |
OLD | NEW |