| 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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 logging.exception('Unable to charge device to specified level.') | 292 logging.exception('Unable to charge device to specified level.') |
| 293 | 293 |
| 294 if options.max_battery_temp is not None: | 294 if options.max_battery_temp is not None: |
| 295 try: | 295 try: |
| 296 battery = battery_utils.BatteryUtils(device) | 296 battery = battery_utils.BatteryUtils(device) |
| 297 battery.LetBatteryCoolToTemperature(options.max_battery_temp) | 297 battery.LetBatteryCoolToTemperature(options.max_battery_temp) |
| 298 except device_errors.CommandFailedError: | 298 except device_errors.CommandFailedError: |
| 299 logging.exception('Unable to let battery cool to specified temperature.') | 299 logging.exception('Unable to let battery cool to specified temperature.') |
| 300 | 300 |
| 301 def _set_and_verify_date(): | 301 def _set_and_verify_date(): |
| 302 strgmtime = time.strftime('%Y%m%d.%H%M%S', time.gmtime()) | 302 if (device.build_version_sdk |
| 303 device.RunShellCommand(['date', '-s', strgmtime], as_root=True, | 303 >= constants.ANDROID_SDK_VERSION_CODES.MARSHMALLOW): |
| 304 check_return=True) | 304 date_format = '%m%d%H%M%Y.%S' |
| 305 set_date_command = ['date'] |
| 306 else: |
| 307 date_format = '%Y%m%d.%H%M%S' |
| 308 set_date_command = ['date', '-s'] |
| 309 strgmtime = time.strftime(date_format, time.gmtime()) |
| 310 set_date_command.append(strgmtime) |
| 311 device.RunShellCommand(set_date_command, as_root=True, check_return=True) |
| 305 | 312 |
| 306 device_time = device.RunShellCommand( | 313 device_time = device.RunShellCommand( |
| 307 ['date', '+"%Y%m%d.%H%M%S"'], as_root=True, | 314 ['date', '+"%Y%m%d.%H%M%S"'], as_root=True, |
| 308 single_line=True).replace('"', '') | 315 single_line=True).replace('"', '') |
| 309 correct_time = datetime.datetime.strptime(strgmtime,"%Y%m%d.%H%M%S") | 316 device_time = datetime.datetime.strptime(device_time, "%Y%m%d.%H%M%S") |
| 310 tdelta = (correct_time - datetime.datetime.strptime(device_time, | 317 correct_time = datetime.datetime.strptime(strgmtime, date_format) |
| 311 "%Y%m%d.%H%M%S")).seconds | 318 tdelta = (correct_time - device_time).seconds |
| 312 if tdelta <= 1: | 319 if tdelta <= 1: |
| 313 logging.info('Date/time successfully set on %s' % device) | 320 logging.info('Date/time successfully set on %s', device) |
| 314 return True | 321 return True |
| 315 else: | 322 else: |
| 316 return False | 323 return False |
| 317 | 324 |
| 318 # Sometimes the date is not set correctly on the devices. Retry on failure. | 325 # Sometimes the date is not set correctly on the devices. Retry on failure. |
| 319 if not timeout_retry.WaitFor(_set_and_verify_date, wait_period=1, | 326 if not timeout_retry.WaitFor(_set_and_verify_date, wait_period=1, |
| 320 max_tries=2): | 327 max_tries=2): |
| 321 logging.warning('Error setting time on device %s.', device) | 328 raise device_errors.CommandFailedError( |
| 322 device_blacklist.ExtendBlacklist([str(device)]) | 329 'Failed to set date & time.', device_serial=str(device)) |
| 323 | 330 |
| 324 props = device.RunShellCommand('getprop', check_return=True) | 331 props = device.RunShellCommand('getprop', check_return=True) |
| 325 for prop in props: | 332 for prop in props: |
| 326 logging.info(' %s' % prop) | 333 logging.info(' %s' % prop) |
| 327 if options.auto_reconnect: | 334 if options.auto_reconnect: |
| 328 _PushAndLaunchAdbReboot(device, options.target) | 335 _PushAndLaunchAdbReboot(device, options.target) |
| 329 | 336 |
| 330 | 337 |
| 331 def _WipeUnderDirIfMatch(device, path, pattern, app_to_keep=None): | 338 def _WipeUnderDirIfMatch(device, path, pattern, app_to_keep=None): |
| 332 ls_result = device.Ls(path) | 339 ls_result = device.Ls(path) |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 args = parser.parse_args() | 451 args = parser.parse_args() |
| 445 constants.SetBuildType(args.target) | 452 constants.SetBuildType(args.target) |
| 446 | 453 |
| 447 run_tests_helper.SetLogLevel(args.verbose) | 454 run_tests_helper.SetLogLevel(args.verbose) |
| 448 | 455 |
| 449 return ProvisionDevices(args) | 456 return ProvisionDevices(args) |
| 450 | 457 |
| 451 | 458 |
| 452 if __name__ == '__main__': | 459 if __name__ == '__main__': |
| 453 sys.exit(main()) | 460 sys.exit(main()) |
| OLD | NEW |