| 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 and entry[_PWS_AGGREGATION_INDEX] == 'l'): | 274 and entry[_PWS_AGGREGATION_INDEX] == 'l'): |
| 275 # This entry should only appear once. | 275 # This entry should only appear once. |
| 276 assert system_total is None | 276 assert system_total is None |
| 277 system_total = float(entry[_PWS_POWER_CONSUMPTION_INDEX]) | 277 system_total = float(entry[_PWS_POWER_CONSUMPTION_INDEX]) |
| 278 | 278 |
| 279 per_package = {p: {'uid': uid, 'data': pwi_entries[uid]} | 279 per_package = {p: {'uid': uid, 'data': pwi_entries[uid]} |
| 280 for p, uid in self._cache['uids'].iteritems()} | 280 for p, uid in self._cache['uids'].iteritems()} |
| 281 return {'system_total': system_total, 'per_package': per_package} | 281 return {'system_total': system_total, 'per_package': per_package} |
| 282 | 282 |
| 283 @decorators.WithTimeoutAndRetriesFromInstance() | 283 @decorators.WithTimeoutAndRetriesFromInstance() |
| 284 def _ForceResetBatteryInfo(self, timeout=None, retries=None): | |
| 285 # Sometimes battery information stops updating. This kick starts it. | |
| 286 self._device.RunShellCommand(['dumpsys', 'battery', 'set', 'level', '50'], | |
| 287 check_return=True) | |
| 288 self._device.RunShellCommand(['dumpsys', 'battery', 'reset'], | |
| 289 check_return=True) | |
| 290 | |
| 291 @decorators.WithTimeoutAndRetriesFromInstance() | |
| 292 def GetBatteryInfo(self, timeout=None, retries=None): | 284 def GetBatteryInfo(self, timeout=None, retries=None): |
| 293 """Gets battery info for the device. | 285 """Gets battery info for the device. |
| 294 | 286 |
| 295 Args: | 287 Args: |
| 296 timeout: timeout in seconds | 288 timeout: timeout in seconds |
| 297 retries: number of retries | 289 retries: number of retries |
| 298 Returns: | 290 Returns: |
| 299 A dict containing various battery information as reported by dumpsys | 291 A dict containing various battery information as reported by dumpsys |
| 300 battery. | 292 battery. |
| 301 """ | 293 """ |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 def ChargeDeviceToLevel(self, level, wait_period=60): | 437 def ChargeDeviceToLevel(self, level, wait_period=60): |
| 446 """Enables charging and waits for device to be charged to given level. | 438 """Enables charging and waits for device to be charged to given level. |
| 447 | 439 |
| 448 Args: | 440 Args: |
| 449 level: level of charge to wait for. | 441 level: level of charge to wait for. |
| 450 wait_period: time in seconds to wait between checking. | 442 wait_period: time in seconds to wait between checking. |
| 451 """ | 443 """ |
| 452 self.SetCharging(True) | 444 self.SetCharging(True) |
| 453 | 445 |
| 454 def device_charged(): | 446 def device_charged(): |
| 455 self._ForceResetBatteryInfo() | |
| 456 battery_level = self.GetBatteryInfo().get('level') | 447 battery_level = self.GetBatteryInfo().get('level') |
| 457 if battery_level is None: | 448 if battery_level is None: |
| 458 logging.warning('Unable to find current battery level.') | 449 logging.warning('Unable to find current battery level.') |
| 459 battery_level = 100 | 450 battery_level = 100 |
| 460 else: | 451 else: |
| 461 logging.info('current battery level: %s', battery_level) | 452 logging.info('current battery level: %s', battery_level) |
| 462 battery_level = int(battery_level) | 453 battery_level = int(battery_level) |
| 463 return battery_level >= level | 454 return battery_level >= level |
| 464 | 455 |
| 465 timeout_retry.WaitFor(device_charged, wait_period=wait_period) | 456 timeout_retry.WaitFor(device_charged, wait_period=wait_period) |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 630 self._cache['profile'] = { | 621 self._cache['profile'] = { |
| 631 'name': None, | 622 'name': None, |
| 632 'witness_file': None, | 623 'witness_file': None, |
| 633 'enable_command': None, | 624 'enable_command': None, |
| 634 'disable_command': None, | 625 'disable_command': None, |
| 635 'charge_counter': None, | 626 'charge_counter': None, |
| 636 'voltage': None, | 627 'voltage': None, |
| 637 'current': None, | 628 'current': None, |
| 638 } | 629 } |
| 639 return False | 630 return False |
| OLD | NEW |