Chromium Code Reviews| Index: build/android/pylib/device/device_utils.py |
| diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py |
| index b6fd7323bb9a3c71e566049719a963bba2ce9023..b34c0bcd14cb887759a35650428459f05fdf1c4f 100644 |
| --- a/build/android/pylib/device/device_utils.py |
| +++ b/build/android/pylib/device/device_utils.py |
| @@ -69,6 +69,7 @@ _CONTROL_CHARGING_COMMANDS = [ |
| }, |
| ] |
| +_DUMPSYS_BATTERY_DISABLED = ' (UPDATES STOPPED -- use \'reset\' to restart)' |
| @decorators.WithExplicitTimeoutAndRetries( |
| _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) |
| @@ -1414,8 +1415,13 @@ class DeviceUtils(object): |
| # Skip the first line, which is just a header. |
| for line in self.RunShellCommand( |
| ['dumpsys', 'battery'], check_return=True)[1:]: |
| - k, v = line.split(': ', 1) |
| - result[k.strip()] = v.strip() |
| + # If usb charging has been disabled, an extra line of header exists. |
| + if line != _DUMPSYS_BATTERY_DISABLED: |
|
jbudorick
2015/03/09 21:49:55
If this line appears, is it the only thing printed
rnephew (Wrong account)
2015/03/09 23:58:09
The output looks like this:
Current Battery Servic
jbudorick
2015/03/10 00:04:43
Interesting, that's not what I expected.
I don't
rnephew (Wrong account)
2015/03/10 14:56:35
Done.
|
| + k, v = line.split(': ', 1) |
| + result[k.strip()] = v.strip() |
| + else: |
| + logging.warning('Dumpsys battery not recieving updates. ' |
| + 'Run dumpsys battery reset if this is in error') |
| return result |
| @decorators.WithTimeoutAndRetriesFromInstance() |
| @@ -1436,6 +1442,28 @@ class DeviceUtils(object): |
| return False |
| @decorators.WithTimeoutAndRetriesFromInstance() |
| + def SoftSetCharging(self, enabled, timeout=None, retries=None): |
|
jbudorick
2015/03/09 21:49:55
I don't think this should be separate from SetChar
rnephew (Wrong account)
2015/03/09 23:58:09
Done.
|
| + """Enables or disables charging for dumpsys. Device still will |
| + silently be charging. Allows for power data collection through dumpsys. |
| + |
| + Args: |
| + enabled: A boolean indicating whether charging should be enabled or |
| + disabled. |
| + timeout: timeout in seconds |
| + retries: number of retries |
| + """ |
| + if enabled: |
| + command = 'dumpsys battery reset' |
| + else: |
| + command = 'dumpsys battery set usb 0' |
| + |
| + def set_and_verify_charging(): |
| + self.RunShellCommand(command, check_return=True) |
| + return self.GetCharging() == enabled |
| + |
| + timeout_retry.WaitFor(set_and_verify_charging, wait_period=1) |
| + |
| + @decorators.WithTimeoutAndRetriesFromInstance() |
| def SetCharging(self, enabled, timeout=None, retries=None): |
| """Enables or disables charging on the device. |