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

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
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):
nednguyen 2015/04/01 22:17:39 Maybe this needn't be addressed in this patch but
jbudorick 2015/04/01 22:32:21 Why does this matter?
jbudorick 2015/04/01 22:34:15 Actually, this comment should just make it explici
nednguyen 2015/04/01 22:49:06 Just looking at the method name, it's unclear what
jbudorick 2015/04/01 22:58:51 We generally want our devices in a charging state
rnephew (Wrong account) 2015/04/01 23:01:04 Added comment saying it enabled charging.
251 """ Waits for device to be charged to given level.
252
253 Args:
254 level: level of charge to wait for.
255 """
256 self.SetCharging(True)
nednguyen 2015/04/01 22:17:39 Assume that the device's charging state is off, an
jbudorick 2015/04/01 22:32:21 I don't see why a user asking for a device to be c
257
258 def device_charged():
259 battery_level = self.GetBatteryInfo().get('level')
260 if battery_level is None:
261 logging.warning('Unable to find current battery level.')
262 battery_level = 100
263 else:
264 logging.info('current battery level: %s', battery_level)
265 battery_level = int(battery_level)
266 return battery_level >= level
267
268 timeout_retry.WaitFor(device_charged, wait_period=60)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698