Chromium Code Reviews| Index: build/android/pylib/android_commands.py |
| diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py |
| index 8faa1be4f860d4f779ee4743404b78dc9973cb96..1205cb8f6534a8406ccc5746e4d9f176b098adc6 100644 |
| --- a/build/android/pylib/android_commands.py |
| +++ b/build/android/pylib/android_commands.py |
| @@ -1870,14 +1870,30 @@ class AndroidCommands(object): |
| if not command: |
| raise Exception('Unable to act on usb charging.') |
| disable_command = command['disable_command'] |
| - self.RunShellCommand(disable_command) |
| + # Do not loop directly on self.IsDeviceCharging to cut the number of calls |
| + # to the device. |
| + while True: |
| + self.RunShellCommand(disable_command) |
| + if not self.IsDeviceCharging(): |
| + break |
| def EnableUsbCharging(self): |
| command = self._GetControlUsbChargingCommand() |
| if not command: |
| raise Exception('Unable to act on usb charging.') |
| disable_command = command['enable_command'] |
| - self.RunShellCommand(disable_command) |
| + # Do not loop directly on self.IsDeviceCharging to cut the number of calls |
| + # to the device. |
| + while True: |
| + self.RunShellCommand(disable_command) |
| + if self.IsDeviceCharging(): |
| + break |
| + |
| + def IsDeviceCharging(self): |
| + for line in self.RunShellCommand('dumpsys battery'): |
| + if 'powered: ' in line: |
| + if 'true' == line.split('powered: ')[1]: |
|
Philippe
2014/04/08 11:27:08
Nit: I would swap the two operands here for readab
qsr
2014/04/08 15:37:05
Done.
|
| + return True |
| class NewLineNormalizer(object): |