[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-Original-Commit-Position: refs/heads/master@{#343929} Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src Cr-Mirrored-Commit: c0202d6ab7d128fe54e6fea8ab654918e5e2f3f2
This commit is contained in:
Родитель
703cebc118
Коммит
e980d5680e
|
@ -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
|
||||
|
|
|
@ -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(
|
||||
|
|
Загрузка…
Ссылка в новой задаче