From c0202d6ab7d128fe54e6fea8ab654918e5e2f3f2 Mon Sep 17 00:00:00 2001 From: rnephew Date: Tue, 18 Aug 2015 08:58:00 -0700 Subject: [PATCH] [Android] Change battery_utils TieredSetCharging from exceptions based to discovery based Currently, it throws an exception to know it cannot do hardware level disable, this changes it to use profile discovery to decide how to disable charging. BUG=520958 Review URL: https://codereview.chromium.org/1293143002 Cr-Commit-Position: refs/heads/master@{#343929} --- build/android/pylib/device/battery_utils.py | 17 +++++++++-------- build/android/pylib/device/battery_utils_test.py | 2 -- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/build/android/pylib/device/battery_utils.py b/build/android/pylib/device/battery_utils.py index ac5e7a87ae91..1c7a06e7defc 100644 --- a/build/android/pylib/device/battery_utils.py +++ b/build/android/pylib/device/battery_utils.py @@ -487,20 +487,21 @@ class BatteryUtils(object): logging.warning('Device charging already in expected state: %s', enabled) return + self._DiscoverDeviceProfile() if enabled: - try: + if self._cache['profile']['enable_command']: self.SetCharging(enabled) - except device_errors.CommandFailedError: - logging.info('Unable to enable charging via hardware.' - ' Falling back to software enabling.') + else: + logging.info('Unable to enable charging via hardware. ' + 'Falling back to software enabling.') self.EnableBatteryUpdates() else: - try: + if self._cache['profile']['enable_command']: self._ClearPowerData() self.SetCharging(enabled) - except device_errors.CommandFailedError: - logging.info('Unable to disable charging via hardware.' - ' Falling back to software disabling.') + else: + logging.info('Unable to disable charging via hardware. ' + 'Falling back to software disabling.') self.DisableBatteryUpdates() @contextlib.contextmanager diff --git a/build/android/pylib/device/battery_utils_test.py b/build/android/pylib/device/battery_utils_test.py index bc1e34122f0d..c740e930d532 100755 --- a/build/android/pylib/device/battery_utils_test.py +++ b/build/android/pylib/device/battery_utils_test.py @@ -439,7 +439,6 @@ class BatteryUtilsTieredSetCharging(BatteryUtilsTest): with self.assertCalls( (self.call.battery.GetCharging(), True), (self.call.battery._ClearPowerData(), True), - (self.call.battery._ClearPowerData(), True), (self.call.device.RunShellCommand( ['dumpsys', 'battery', 'set', 'ac', '0'], check_return=True), []), (self.call.device.RunShellCommand( @@ -492,7 +491,6 @@ class BatteryUtilsPowerMeasurement(BatteryUtilsTest): with self.assertCalls( (self.call.battery.GetCharging(), True), (self.call.battery._ClearPowerData(), True), - (self.call.battery._ClearPowerData(), True), (self.call.device.RunShellCommand( ['dumpsys', 'battery', 'set', 'ac', '0'], check_return=True), []), (self.call.device.RunShellCommand( -- 2.11.4.GIT