diff options
author | jbudorick <jbudorick@chromium.org> | 2015-02-27 07:39:26 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-27 15:40:07 +0000 |
commit | eef4b067e1feb24072e7a08aff5226f0cf1b216f (patch) | |
tree | 9eb27bb7f2cfd68f2427f85415c46a67d5e686ba /build/android/pylib/device/device_utils.py | |
parent | 9e383ca4f7183e334d14b47126e0e5d6b205bb36 (diff) | |
download | chromium_src-eef4b067e1feb24072e7a08aff5226f0cf1b216f.zip chromium_src-eef4b067e1feb24072e7a08aff5226f0cf1b216f.tar.gz chromium_src-eef4b067e1feb24072e7a08aff5226f0cf1b216f.tar.bz2 |
[Android] Check for AC and wireless charging when determining charging state.
BUG=461993
Review URL: https://codereview.chromium.org/963093002
Cr-Commit-Position: refs/heads/master@{#318453}
Diffstat (limited to 'build/android/pylib/device/device_utils.py')
-rw-r--r-- | build/android/pylib/device/device_utils.py | 40 |
1 files changed, 22 insertions, 18 deletions
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py index 63ee402..b6fd732 100644 --- a/build/android/pylib/device/device_utils.py +++ b/build/android/pylib/device/device_utils.py @@ -45,7 +45,7 @@ _DEFAULT_RETRIES = 3 # the timeout_retry decorators. DEFAULT = object() -_CONTROL_USB_CHARGING_COMMANDS = [ +_CONTROL_CHARGING_COMMANDS = [ { # Nexus 4 'witness_file': '/sys/module/pm8921_charger/parameters/disabled', @@ -1419,47 +1419,51 @@ class DeviceUtils(object): return result @decorators.WithTimeoutAndRetriesFromInstance() - def GetUsbCharging(self, timeout=None, retries=None): - """Gets the USB charging state of the device. + def GetCharging(self, timeout=None, retries=None): + """Gets the charging state of the device. Args: timeout: timeout in seconds retries: number of retries Returns: - True if the device is charging via USB, false otherwise. + True if the device is charging, false otherwise. """ - return (self.GetBatteryInfo().get('USB powered', '').lower() - in ('true', '1', 'yes')) + battery_info = self.GetBatteryInfo() + for k in ('AC powered', 'USB powered', 'Wireless powered'): + if (k in battery_info and + battery_info[k].lower() in ('true', '1', 'yes')): + return True + return False @decorators.WithTimeoutAndRetriesFromInstance() - def SetUsbCharging(self, enabled, timeout=None, retries=None): - """Enables or disables USB charging on the device. + def SetCharging(self, enabled, timeout=None, retries=None): + """Enables or disables charging on the device. Args: - enabled: A boolean indicating whether USB charging should be enabled or + enabled: A boolean indicating whether charging should be enabled or disabled. timeout: timeout in seconds retries: number of retries """ - if 'usb_charging_config' not in self._cache: - for c in _CONTROL_USB_CHARGING_COMMANDS: + if 'charging_config' not in self._cache: + for c in _CONTROL_CHARGING_COMMANDS: if self.FileExists(c['witness_file']): - self._cache['usb_charging_config'] = c + self._cache['charging_config'] = c break else: raise device_errors.CommandFailedError( 'Unable to find charging commands.') if enabled: - command = self._cache['usb_charging_config']['enable_command'] + command = self._cache['charging_config']['enable_command'] else: - command = self._cache['usb_charging_config']['disable_command'] + command = self._cache['charging_config']['disable_command'] - def set_and_verify_usb_charging(): - self.RunShellCommand(command) - return self.GetUsbCharging() == enabled + def set_and_verify_charging(): + self.RunShellCommand(command, check_return=True) + return self.GetCharging() == enabled - timeout_retry.WaitFor(set_and_verify_usb_charging, wait_period=1) + timeout_retry.WaitFor(set_and_verify_charging, wait_period=1) @decorators.WithTimeoutAndRetriesFromInstance() def GetDevicePieWrapper(self, timeout=None, retries=None): |