Index: build/android/pylib/device/battery_utils.py |
diff --git a/build/android/pylib/device/battery_utils.py b/build/android/pylib/device/battery_utils.py |
index 96e3bf660c5841642ba3fc0fb88e560b11314df5..91fa93bfc37145cc1e9d9baa9e7b0a68a2b2a271 100644 |
--- a/build/android/pylib/device/battery_utils.py |
+++ b/build/android/pylib/device/battery_utils.py |
@@ -246,3 +246,24 @@ class BatteryUtils(object): |
yield |
finally: |
self.EnableBatteryUpdates(timeout=timeout, retries=retries) |
+ |
+ def ChargeDeviceToLevel(self, level, wait_period=60): |
+ """Enables charging and waits for device to be charged to given level. |
+ |
+ Args: |
+ level: level of charge to wait for. |
+ wait_period: time in seconds to wait between checking. |
+ """ |
+ self.SetCharging(True) |
+ |
+ def device_charged(): |
+ battery_level = self.GetBatteryInfo().get('level') |
+ if battery_level is None: |
+ logging.warning('Unable to find current battery level.') |
+ battery_level = 100 |
+ else: |
+ logging.info('current battery level: %s', battery_level) |
+ battery_level = int(battery_level) |
+ return battery_level >= level |
+ |
+ timeout_retry.WaitFor(device_charged, wait_period=wait_period) |