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

Side by Side Diff: build/android/pylib/device/battery_utils.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 | « build/android/provision_devices.py ('k') | build/android/pylib/device/battery_utils_test.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 # Copyright 2015 The Chromium Authors. All rights reserved. 1 # Copyright 2015 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Provides a variety of device interactions with power. 5 """Provides a variety of device interactions with power.
6 """ 6 """
7 # pylint: disable=unused-argument 7 # pylint: disable=unused-argument
8 8
9 import collections 9 import collections
10 import contextlib 10 import contextlib
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 device_errors.CommandFailedError: If device is not L or higher. 239 device_errors.CommandFailedError: If device is not L or higher.
240 """ 240 """
241 if (self._device.build_version_sdk < 241 if (self._device.build_version_sdk <
242 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): 242 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP):
243 raise device_errors.DeviceVersionError('Device must be L or higher.') 243 raise device_errors.DeviceVersionError('Device must be L or higher.')
244 try: 244 try:
245 self.DisableBatteryUpdates(timeout=timeout, retries=retries) 245 self.DisableBatteryUpdates(timeout=timeout, retries=retries)
246 yield 246 yield
247 finally: 247 finally:
248 self.EnableBatteryUpdates(timeout=timeout, retries=retries) 248 self.EnableBatteryUpdates(timeout=timeout, retries=retries)
249
250 def ChargeDeviceToLevel(self, level, wait_period=60):
251 """Enables charging and waits for device to be charged to given level.
252
253 Args:
254 level: level of charge to wait for.
255 wait_period: time in seconds to wait between checking.
256 """
257 self.SetCharging(True)
258
259 def device_charged():
260 battery_level = self.GetBatteryInfo().get('level')
261 if battery_level is None:
262 logging.warning('Unable to find current battery level.')
263 battery_level = 100
264 else:
265 logging.info('current battery level: %s', battery_level)
266 battery_level = int(battery_level)
267 return battery_level >= level
268
269 timeout_retry.WaitFor(device_charged, wait_period=wait_period)
OLDNEW
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/device/battery_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698