summaryrefslogtreecommitdiffstats
path: root/build
diff options
context:
space:
mode:
authorrnephew <rnephew@chromium.org>2015-08-20 08:11:40 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-20 15:12:09 +0000
commit4cb37c24040fb2ad25b6241dcf0f23efad9b2000 (patch)
treed336d5607ad2468137dc00818c2ebe1f6ad863d7 /build
parentdd3592c2a0460aa863221a2f34ab325d0fd5f428 (diff)
downloadchromium_src-4cb37c24040fb2ad25b6241dcf0f23efad9b2000.zip
chromium_src-4cb37c24040fb2ad25b6241dcf0f23efad9b2000.tar.gz
chromium_src-4cb37c24040fb2ad25b6241dcf0f23efad9b2000.tar.bz2
[Android] Add nexus 5 work around for letting battery cool
The nexus 5 has a problem where battery temperature only updates when the battery charge level has changed. BUG=512167, 522127 Review URL: https://codereview.chromium.org/1297423002 Cr-Commit-Position: refs/heads/master@{#344504}
Diffstat (limited to 'build')
-rw-r--r--build/android/pylib/device/battery_utils.py38
-rwxr-xr-xbuild/android/pylib/device/battery_utils_test.py70
2 files changed, 108 insertions, 0 deletions
diff --git a/build/android/pylib/device/battery_utils.py b/build/android/pylib/device/battery_utils.py
index 35bf6ce..1a8c9f5 100644
--- a/build/android/pylib/device/battery_utils.py
+++ b/build/android/pylib/device/battery_utils.py
@@ -434,6 +434,40 @@ class BatteryUtils(object):
finally:
self.EnableBatteryUpdates(timeout=timeout, retries=retries)
+ def _DischargeDevice(self, percent, wait_period=120):
+ """Disables charging and waits for device to discharge given amount
+
+ Args:
+ percent: level of charge to discharge.
+
+ Raises:
+ ValueError: If percent is not between 1 and 99.
+ """
+ battery_level = int(self.GetBatteryInfo().get('level'))
+ if not 0 < percent < 100:
+ raise ValueError('Discharge amount(%s) must be between 1 and 99'
+ % percent)
+ if battery_level is None:
+ logging.warning('Unable to find current battery level. Cannot discharge.')
+ return
+ # Do not discharge if it would make battery level too low.
+ if percent >= battery_level - 10:
+ logging.warning('Battery is too low or discharge amount requested is too '
+ 'high. Cannot discharge phone %s percent.', percent)
+ return
+
+ self.SetCharging(False)
+ def device_discharged():
+ self.SetCharging(True)
+ current_level = int(self.GetBatteryInfo().get('level'))
+ logging.info('current battery level: %s', current_level)
+ if battery_level - current_level >= percent:
+ return True
+ self.SetCharging(False)
+ return False
+
+ timeout_retry.WaitFor(device_discharged, wait_period=wait_period)
+
def ChargeDeviceToLevel(self, level, wait_period=60):
"""Enables charging and waits for device to be charged to given level.
@@ -462,6 +496,8 @@ class BatteryUtils(object):
wait_period: time in seconds to wait between checking.
"""
def cool_device():
+ if self._cache['profile']['name'] == 'Nexus 5':
+ self._DischargeDevice(1)
temp = self.GetBatteryInfo().get('temperature')
if temp is None:
logging.warning('Unable to find current battery temperature.')
@@ -469,6 +505,8 @@ class BatteryUtils(object):
else:
logging.info('Current battery temperature: %s', temp)
return int(temp) <= target_temp
+
+ self._DiscoverDeviceProfile()
self.EnableBatteryUpdates()
logging.info('Waiting for the device to cool down to %s (0.1 C)',
target_temp)
diff --git a/build/android/pylib/device/battery_utils_test.py b/build/android/pylib/device/battery_utils_test.py
index 2063efa..ff961e7 100755
--- a/build/android/pylib/device/battery_utils_test.py
+++ b/build/android/pylib/device/battery_utils_test.py
@@ -269,6 +269,62 @@ class BatteryUtilsChargeDevice(BatteryUtilsTest):
self.battery.ChargeDeviceToLevel(95)
+class BatteryUtilsDischargeDevice(BatteryUtilsTest):
+
+ @mock.patch('time.sleep', mock.Mock())
+ def testDischargeDevice_exact(self):
+ with self.assertCalls(
+ (self.call.battery.GetBatteryInfo(), {'level': '100'}),
+ (self.call.battery.SetCharging(False)),
+ (self.call.battery.SetCharging(True)),
+ (self.call.battery.GetBatteryInfo(), {'level': '99'})):
+ self.battery._DischargeDevice(1)
+
+ @mock.patch('time.sleep', mock.Mock())
+ def testDischargeDevice_over(self):
+ with self.assertCalls(
+ (self.call.battery.GetBatteryInfo(), {'level': '100'}),
+ (self.call.battery.SetCharging(False)),
+ (self.call.battery.SetCharging(True)),
+ (self.call.battery.GetBatteryInfo(), {'level': '50'})):
+ self.battery._DischargeDevice(1)
+
+ @mock.patch('time.sleep', mock.Mock())
+ def testDischargeDevice_takeslong(self):
+ with self.assertCalls(
+ (self.call.battery.GetBatteryInfo(), {'level': '100'}),
+ (self.call.battery.SetCharging(False)),
+ (self.call.battery.SetCharging(True)),
+ (self.call.battery.GetBatteryInfo(), {'level': '100'}),
+ (self.call.battery.SetCharging(False)),
+ (self.call.battery.SetCharging(True)),
+ (self.call.battery.GetBatteryInfo(), {'level': '99'}),
+ (self.call.battery.SetCharging(False)),
+ (self.call.battery.SetCharging(True)),
+ (self.call.battery.GetBatteryInfo(), {'level': '98'}),
+ (self.call.battery.SetCharging(False)),
+ (self.call.battery.SetCharging(True)),
+ (self.call.battery.GetBatteryInfo(), {'level': '97'})):
+ self.battery._DischargeDevice(3)
+
+ @mock.patch('time.sleep', mock.Mock())
+ def testDischargeDevice_dischargeTooClose(self):
+ with self.assertCalls(
+ (self.call.battery.GetBatteryInfo(), {'level': '100'})):
+ self.battery._DischargeDevice(99)
+
+ @mock.patch('time.sleep', mock.Mock())
+ def testDischargeDevice_percentageOutOfBounds(self):
+ with self.assertCalls(
+ (self.call.battery.GetBatteryInfo(), {'level': '100'})):
+ with self.assertRaises(ValueError):
+ self.battery._DischargeDevice(100)
+ with self.assertCalls(
+ (self.call.battery.GetBatteryInfo(), {'level': '100'})):
+ with self.assertRaises(ValueError):
+ self.battery._DischargeDevice(0)
+
+
class BatteryUtilsGetBatteryInfoTest(BatteryUtilsTest):
def testGetBatteryInfo_normal(self):
@@ -381,6 +437,7 @@ class BatteryUtilsLetBatteryCoolToTemperatureTest(BatteryUtilsTest):
@mock.patch('time.sleep', mock.Mock())
def testLetBatteryCoolToTemperature_startUnder(self):
+ self.battery._cache['profile'] = self._NEXUS_6
with self.assertCalls(
(self.call.battery.EnableBatteryUpdates(), []),
(self.call.battery.GetBatteryInfo(), {'temperature': '500'})):
@@ -388,12 +445,25 @@ class BatteryUtilsLetBatteryCoolToTemperatureTest(BatteryUtilsTest):
@mock.patch('time.sleep', mock.Mock())
def testLetBatteryCoolToTemperature_startOver(self):
+ self.battery._cache['profile'] = self._NEXUS_6
with self.assertCalls(
(self.call.battery.EnableBatteryUpdates(), []),
(self.call.battery.GetBatteryInfo(), {'temperature': '500'}),
(self.call.battery.GetBatteryInfo(), {'temperature': '400'})):
self.battery.LetBatteryCoolToTemperature(400)
+ @mock.patch('time.sleep', mock.Mock())
+ def testLetBatteryCoolToTemperature_nexus5(self):
+ self.battery._cache['profile'] = self._NEXUS_5
+ with self.assertCalls(
+ (self.call.battery.EnableBatteryUpdates(), []),
+ (self.call.battery._DischargeDevice(1), []),
+ (self.call.battery.GetBatteryInfo(), {'temperature': '500'}),
+ (self.call.battery._DischargeDevice(1), []),
+ (self.call.battery.GetBatteryInfo(), {'temperature': '400'})):
+ self.battery.LetBatteryCoolToTemperature(400)
+
+
class BatteryUtilsSupportsFuelGaugeTest(BatteryUtilsTest):
def testSupportsFuelGauge_false(self):