summaryrefslogtreecommitdiffstats
path: root/build/android
diff options
context:
space:
mode:
authorjbudorick <jbudorick@chromium.org>2015-02-27 07:39:26 -0800
committerCommit bot <commit-bot@chromium.org>2015-02-27 15:40:07 +0000
commiteef4b067e1feb24072e7a08aff5226f0cf1b216f (patch)
tree9eb27bb7f2cfd68f2427f85415c46a67d5e686ba /build/android
parent9e383ca4f7183e334d14b47126e0e5d6b205bb36 (diff)
downloadchromium_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')
-rwxr-xr-xbuild/android/provision_devices.py2
-rw-r--r--build/android/pylib/device/device_utils.py40
-rwxr-xr-xbuild/android/pylib/device/device_utils_test.py58
3 files changed, 57 insertions, 43 deletions
diff --git a/build/android/provision_devices.py b/build/android/provision_devices.py
index 69e8168..6b3ea1d 100755
--- a/build/android/provision_devices.py
+++ b/build/android/provision_devices.py
@@ -207,7 +207,7 @@ def ProvisionDevice(device, options):
device, device_settings.NETWORK_DISABLED_SETTINGS)
if options.min_battery_level is not None:
try:
- device.SetUsbCharging(True)
+ device.SetCharging(True)
ChargeDeviceToLevel(device, options.min_battery_level)
except device_errors.CommandFailedError as e:
logging.exception('Unable to charge device to specified level.')
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):
diff --git a/build/android/pylib/device/device_utils_test.py b/build/android/pylib/device/device_utils_test.py
index 1b4d1cf..b7e807e 100755
--- a/build/android/pylib/device/device_utils_test.py
+++ b/build/android/pylib/device/device_utils_test.py
@@ -1411,51 +1411,61 @@ class DeviceUtilsGetBatteryInfoTest(DeviceUtilsTest):
self.assertEquals({}, self.device.GetBatteryInfo())
-class DeviceUtilsGetUsbChargingTest(DeviceUtilsTest):
- def testGetUsbCharging_true(self):
+class DeviceUtilsGetChargingTest(DeviceUtilsTest):
+ def testGetCharging_usb(self):
with self.assertCall(
self.call.device.GetBatteryInfo(), {'USB powered': 'true'}):
- self.assertTrue(self.device.GetUsbCharging())
+ self.assertTrue(self.device.GetCharging())
- def testGetUsbCharging_false(self):
+ def testGetCharging_usbFalse(self):
with self.assertCall(
self.call.device.GetBatteryInfo(), {'USB powered': 'false'}):
- self.assertFalse(self.device.GetUsbCharging())
+ self.assertFalse(self.device.GetCharging())
- def testGetUsbCharging_unknown(self):
+ def testGetCharging_ac(self):
with self.assertCall(
self.call.device.GetBatteryInfo(), {'AC powered': 'true'}):
- self.assertFalse(self.device.GetUsbCharging())
+ self.assertTrue(self.device.GetCharging())
+
+ def testGetCharging_wireless(self):
+ with self.assertCall(
+ self.call.device.GetBatteryInfo(), {'Wireless powered': 'true'}):
+ self.assertTrue(self.device.GetCharging())
+
+ def testGetCharging_unknown(self):
+ with self.assertCall(
+ self.call.device.GetBatteryInfo(), {'level': '42'}):
+ self.assertFalse(self.device.GetCharging())
-class DeviceUtilsSetUsbChargingTest(DeviceUtilsTest):
+class DeviceUtilsSetChargingTest(DeviceUtilsTest):
@mock.patch('time.sleep', mock.Mock())
- def testSetUsbCharging_enabled(self):
+ def testSetCharging_enabled(self):
with self.assertCalls(
(self.call.device.FileExists(mock.ANY), True),
- (self.call.device.RunShellCommand(mock.ANY), []),
- (self.call.device.GetUsbCharging(), False),
- (self.call.device.RunShellCommand(mock.ANY), []),
- (self.call.device.GetUsbCharging(), True)):
- self.device.SetUsbCharging(True)
+ (self.call.device.RunShellCommand(mock.ANY, check_return=True), []),
+ (self.call.device.GetCharging(), False),
+ (self.call.device.RunShellCommand(mock.ANY, check_return=True), []),
+ (self.call.device.GetCharging(), True)):
+ self.device.SetCharging(True)
- def testSetUsbCharging_alreadyEnabled(self):
+ def testSetCharging_alreadyEnabled(self):
with self.assertCalls(
(self.call.device.FileExists(mock.ANY), True),
- (self.call.device.RunShellCommand(mock.ANY), []),
- (self.call.device.GetUsbCharging(), True)):
- self.device.SetUsbCharging(True)
+ (self.call.device.RunShellCommand(mock.ANY, check_return=True), []),
+ (self.call.device.GetCharging(), True)):
+ self.device.SetCharging(True)
@mock.patch('time.sleep', mock.Mock())
- def testSetUsbCharging_disabled(self):
+ def testSetCharging_disabled(self):
with self.assertCalls(
(self.call.device.FileExists(mock.ANY), True),
- (self.call.device.RunShellCommand(mock.ANY), []),
- (self.call.device.GetUsbCharging(), True),
- (self.call.device.RunShellCommand(mock.ANY), []),
- (self.call.device.GetUsbCharging(), False)):
- self.device.SetUsbCharging(False)
+ (self.call.device.RunShellCommand(mock.ANY, check_return=True), []),
+ (self.call.device.GetCharging(), True),
+ (self.call.device.RunShellCommand(mock.ANY, check_return=True), []),
+ (self.call.device.GetCharging(), False)):
+ self.device.SetCharging(False)