Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 """Provides a variety of device interactions with power. | 5 """Provides a variety of device interactions with power. |
| 6 """ | 6 """ |
| 7 # pylint: disable=unused-argument | 7 # pylint: disable=unused-argument |
| 8 | 8 |
| 9 import collections | 9 import collections |
| 10 import contextlib | 10 import contextlib |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 231 retries: number of retries | 231 retries: number of retries |
| 232 | 232 |
| 233 Raises: | 233 Raises: |
| 234 device_errors.CommandFailedError: When resetting batterystats fails to | 234 device_errors.CommandFailedError: When resetting batterystats fails to |
| 235 reset power values. | 235 reset power values. |
| 236 """ | 236 """ |
| 237 def battery_updates_disabled(): | 237 def battery_updates_disabled(): |
| 238 return self.GetCharging() is False | 238 return self.GetCharging() is False |
| 239 | 239 |
| 240 self._device.RunShellCommand( | 240 self._device.RunShellCommand( |
| 241 ['dumpsys', 'battery', 'set', 'usb', '1'], check_return=True) | 241 ['dumpsys', 'battery', 'reset'], check_return=True) |
| 242 self._device.RunShellCommand( | 242 self._device.RunShellCommand( |
| 243 ['dumpsys', 'batterystats', '--reset'], check_return=True) | 243 ['dumpsys', 'batterystats', '--reset'], check_return=True) |
| 244 battery_data = self._device.RunShellCommand( | 244 battery_data = self._device.RunShellCommand( |
| 245 ['dumpsys', 'batterystats', '--charged', '--checkin'], | 245 ['dumpsys', 'batterystats', '--charged', '--checkin'], |
| 246 check_return=True) | 246 check_return=True) |
| 247 ROW_TYPE_INDEX = 3 | 247 ROW_TYPE_INDEX = 3 |
| 248 PWI_POWER_INDEX = 5 | 248 PWI_POWER_INDEX = 5 |
| 249 for line in battery_data: | 249 for line in battery_data: |
| 250 l = line.split(',') | 250 l = line.split(',') |
| 251 if (len(l) > PWI_POWER_INDEX and l[ROW_TYPE_INDEX] == 'pwi' | 251 if (len(l) > PWI_POWER_INDEX and l[ROW_TYPE_INDEX] == 'pwi' |
| 252 and l[PWI_POWER_INDEX] != 0): | 252 and l[PWI_POWER_INDEX] != 0): |
| 253 raise device_errors.CommandFailedError( | 253 raise device_errors.CommandFailedError( |
| 254 'Non-zero pmi value found after reset.') | 254 'Non-zero pmi value found after reset.') |
| 255 self._device.RunShellCommand(['dumpsys', 'battery', 'set', 'ac', '0'], | |
| 256 check_return=True) | |
| 255 self._device.RunShellCommand(['dumpsys', 'battery', 'set', 'usb', '0'], | 257 self._device.RunShellCommand(['dumpsys', 'battery', 'set', 'usb', '0'], |
| 256 check_return=True) | 258 check_return=True) |
| 257 timeout_retry.WaitFor(battery_updates_disabled, wait_period=1) | 259 timeout_retry.WaitFor(battery_updates_disabled, wait_period=1) |
| 258 | 260 |
| 259 # TODO(rnephew): Make private when all use cases can use the context manager. | 261 # TODO(rnephew): Make private when all use cases can use the context manager. |
| 260 def EnableBatteryUpdates(self, timeout=None, retries=None): | 262 def EnableBatteryUpdates(self, timeout=None, retries=None): |
| 261 """ Restarts device charging so that dumpsys no longer collects power data. | 263 """ Restarts device charging so that dumpsys no longer collects power data. |
| 262 | 264 |
| 263 Args: | 265 Args: |
| 264 timeout: timeout in seconds | 266 timeout: timeout in seconds |
| 265 retries: number of retries | 267 retries: number of retries |
| 266 """ | 268 """ |
| 267 def battery_updates_enabled(): | 269 def battery_updates_enabled(): |
| 268 return self.GetCharging() is True | 270 return self.GetCharging() is True |
| 269 | 271 |
| 270 self._device.RunShellCommand(['dumpsys', 'battery', 'set', 'usb', '1'], | |
|
rnephew (Wrong account)
2015/04/07 23:51:40
This is in there because on K devices reset takes
fmeawad
2015/04/07 23:56:13
I cannot set the ac to 1 as well as this will set
fmeawad
2015/04/08 00:54:29
I checked the code, and this code is never called
| |
| 271 check_return=True) | |
| 272 self._device.RunShellCommand(['dumpsys', 'battery', 'reset'], | 272 self._device.RunShellCommand(['dumpsys', 'battery', 'reset'], |
| 273 check_return=True) | 273 check_return=True) |
| 274 timeout_retry.WaitFor(battery_updates_enabled, wait_period=1) | 274 timeout_retry.WaitFor(battery_updates_enabled, wait_period=1) |
| 275 | 275 |
| 276 @contextlib.contextmanager | 276 @contextlib.contextmanager |
| 277 def BatteryMeasurement(self, timeout=None, retries=None): | 277 def BatteryMeasurement(self, timeout=None, retries=None): |
| 278 """Context manager that enables battery data collection. It makes | 278 """Context manager that enables battery data collection. It makes |
| 279 the device appear to stop charging so that dumpsys will start collecting | 279 the device appear to stop charging so that dumpsys will start collecting |
| 280 power data since last charge. Once the with block is exited, charging is | 280 power data since last charge. Once the with block is exited, charging is |
| 281 resumed and power data since last charge is no longer collected. | 281 resumed and power data since last charge is no longer collected. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 318 battery_level = self.GetBatteryInfo().get('level') | 318 battery_level = self.GetBatteryInfo().get('level') |
| 319 if battery_level is None: | 319 if battery_level is None: |
| 320 logging.warning('Unable to find current battery level.') | 320 logging.warning('Unable to find current battery level.') |
| 321 battery_level = 100 | 321 battery_level = 100 |
| 322 else: | 322 else: |
| 323 logging.info('current battery level: %s', battery_level) | 323 logging.info('current battery level: %s', battery_level) |
| 324 battery_level = int(battery_level) | 324 battery_level = int(battery_level) |
| 325 return battery_level >= level | 325 return battery_level >= level |
| 326 | 326 |
| 327 timeout_retry.WaitFor(device_charged, wait_period=wait_period) | 327 timeout_retry.WaitFor(device_charged, wait_period=wait_period) |
| OLD | NEW |