Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(657)

Side by Side Diff: build/android/provision_devices.py

Issue 1057563002: [Android] Convert to BatteryUtils (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | tools/telemetry/telemetry/core/platform/power_monitor/android_dumpsys_power_monitor.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 posixpath 16 import posixpath
17 import re 17 import re
18 import subprocess 18 import subprocess
19 import sys 19 import sys
20 import time 20 import time
21 21
22 from pylib import android_commands 22 from pylib import android_commands
23 from pylib import constants 23 from pylib import constants
24 from pylib import device_settings 24 from pylib import device_settings
25 from pylib.device import battery_utils
25 from pylib.device import device_blacklist 26 from pylib.device import device_blacklist
26 from pylib.device import device_errors 27 from pylib.device import device_errors
27 from pylib.device import device_utils 28 from pylib.device import device_utils
28 from pylib.utils import run_tests_helper 29 from pylib.utils import run_tests_helper
29 from pylib.utils import timeout_retry 30 from pylib.utils import timeout_retry
30 31
31 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT, 32 sys.path.append(os.path.join(constants.DIR_SOURCE_ROOT,
32 'third_party', 'android_testrunner')) 33 'third_party', 'android_testrunner'))
33 import errors 34 import errors
34 35
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 157
157 def WipeDeviceIfPossible(device, timeout, options): 158 def WipeDeviceIfPossible(device, timeout, options):
158 try: 159 try:
159 device.EnableRoot() 160 device.EnableRoot()
160 WipeDeviceData(device, options) 161 WipeDeviceData(device, options)
161 device.Reboot(True, timeout=timeout, retries=0) 162 device.Reboot(True, timeout=timeout, retries=0)
162 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError): 163 except (errors.DeviceUnresponsiveError, device_errors.CommandFailedError):
163 pass 164 pass
164 165
165 166
166 def ChargeDeviceToLevel(device, level): 167 def ChargeDeviceToLevel(device, level):
nednguyen 2015/04/01 21:22:16 Shouldn't this be a method of BatteryUtils class?
rnephew (Wrong account) 2015/04/01 21:58:11 Good idea, moved.
167 def device_charged(): 168 def device_charged():
168 battery_level = device.GetBatteryInfo().get('level') 169 battery_level = battery.GetBatteryInfo().get('level')
169 if battery_level is None: 170 if battery_level is None:
170 logging.warning('Unable to find current battery level.') 171 logging.warning('Unable to find current battery level.')
171 battery_level = 100 172 battery_level = 100
172 else: 173 else:
173 logging.info('current battery level: %d', battery_level) 174 logging.info('current battery level: %d', battery_level)
174 battery_level = int(battery_level) 175 battery_level = int(battery_level)
175 return battery_level >= level 176 return battery_level >= level
176 177
178 battery = battery_utils.BatteryUtils(device)
179 battery.SetCharging(True)
177 timeout_retry.WaitFor(device_charged, wait_period=60) 180 timeout_retry.WaitFor(device_charged, wait_period=60)
178 181
179 182
180 def ProvisionDevice(device, options): 183 def ProvisionDevice(device, options):
181 if options.reboot_timeout: 184 if options.reboot_timeout:
182 reboot_timeout = options.reboot_timeout 185 reboot_timeout = options.reboot_timeout
183 elif (device.build_version_sdk >= 186 elif (device.build_version_sdk >=
184 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): 187 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP):
185 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP 188 reboot_timeout = _DEFAULT_TIMEOUTS.LOLLIPOP
186 else: 189 else:
(...skipping 14 matching lines...) Expand all
201 device, device_settings.DISABLE_LOCATION_SETTINGS) 204 device, device_settings.DISABLE_LOCATION_SETTINGS)
202 else: 205 else:
203 device_settings.ConfigureContentSettings( 206 device_settings.ConfigureContentSettings(
204 device, device_settings.ENABLE_LOCATION_SETTINGS) 207 device, device_settings.ENABLE_LOCATION_SETTINGS)
205 device_settings.SetLockScreenSettings(device) 208 device_settings.SetLockScreenSettings(device)
206 if options.disable_network: 209 if options.disable_network:
207 device_settings.ConfigureContentSettings( 210 device_settings.ConfigureContentSettings(
208 device, device_settings.NETWORK_DISABLED_SETTINGS) 211 device, device_settings.NETWORK_DISABLED_SETTINGS)
209 if options.min_battery_level is not None: 212 if options.min_battery_level is not None:
210 try: 213 try:
211 device.SetCharging(True)
nednguyen 2015/04/01 21:22:15 This removal looks like a functional change.
rnephew (Wrong account) 2015/04/01 21:58:11 It was moved into ChargeDeviceToLevel instead of b
212 ChargeDeviceToLevel(device, options.min_battery_level) 214 ChargeDeviceToLevel(device, options.min_battery_level)
213 except device_errors.CommandFailedError as e: 215 except device_errors.CommandFailedError as e:
214 logging.exception('Unable to charge device to specified level.') 216 logging.exception('Unable to charge device to specified level.')
215 217
216 if not options.skip_wipe: 218 if not options.skip_wipe:
217 device.Reboot(True, timeout=reboot_timeout, retries=0) 219 device.Reboot(True, timeout=reboot_timeout, retries=0)
218 device.RunShellCommand('date -s %s' % time.strftime('%Y%m%d.%H%M%S', 220 device.RunShellCommand('date -s %s' % time.strftime('%Y%m%d.%H%M%S',
219 time.gmtime()), 221 time.gmtime()),
220 as_root=True) 222 as_root=True)
221 props = device.RunShellCommand('getprop') 223 props = device.RunShellCommand('getprop')
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 parser.add_argument('--adb-key-files', type=str, nargs='+', 297 parser.add_argument('--adb-key-files', type=str, nargs='+',
296 help='list of adb keys to push to device') 298 help='list of adb keys to push to device')
297 args = parser.parse_args() 299 args = parser.parse_args()
298 constants.SetBuildType(args.target) 300 constants.SetBuildType(args.target)
299 301
300 return ProvisionDevices(args) 302 return ProvisionDevices(args)
301 303
302 304
303 if __name__ == '__main__': 305 if __name__ == '__main__':
304 sys.exit(main()) 306 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | tools/telemetry/telemetry/core/platform/power_monitor/android_dumpsys_power_monitor.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698