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 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 Args: | 480 Args: |
481 enabled: A boolean indicating whether charging should be enabled or | 481 enabled: A boolean indicating whether charging should be enabled or |
482 disabled. | 482 disabled. |
483 timeout: timeout in seconds | 483 timeout: timeout in seconds |
484 retries: number of retries | 484 retries: number of retries |
485 """ | 485 """ |
486 if self.GetCharging() == enabled: | 486 if self.GetCharging() == enabled: |
487 logging.warning('Device charging already in expected state: %s', enabled) | 487 logging.warning('Device charging already in expected state: %s', enabled) |
488 return | 488 return |
489 | 489 |
490 self._DiscoverDeviceProfile() | |
490 if enabled: | 491 if enabled: |
491 try: | 492 if self._cache['profile']['enable_command']: |
492 self.SetCharging(enabled) | 493 self.SetCharging(enabled) |
493 except device_errors.CommandFailedError: | 494 else: |
perezju
2015/08/18 09:14:15
nit: maybe keep a logging.info to indicate whether
rnephew (Wrong account)
2015/08/18 14:54:53
Done.
| |
494 logging.info('Unable to enable charging via hardware.' | |
495 ' Falling back to software enabling.') | |
496 self.EnableBatteryUpdates() | 495 self.EnableBatteryUpdates() |
497 else: | 496 else: |
498 try: | 497 if self._cache['profile']['enable_command']: |
499 self._ClearPowerData() | 498 self._ClearPowerData() |
500 self.SetCharging(enabled) | 499 self.SetCharging(enabled) |
501 except device_errors.CommandFailedError: | 500 else: |
502 logging.info('Unable to disable charging via hardware.' | |
503 ' Falling back to software disabling.') | |
504 self.DisableBatteryUpdates() | 501 self.DisableBatteryUpdates() |
505 | 502 |
506 @contextlib.contextmanager | 503 @contextlib.contextmanager |
507 def PowerMeasurement(self, timeout=None, retries=None): | 504 def PowerMeasurement(self, timeout=None, retries=None): |
508 """Context manager that enables battery power collection. | 505 """Context manager that enables battery power collection. |
509 | 506 |
510 Once the with block is exited, charging is resumed. Will attempt to disable | 507 Once the with block is exited, charging is resumed. Will attempt to disable |
511 charging at the hardware level, and if that fails will fall back to software | 508 charging at the hardware level, and if that fails will fall back to software |
512 disabling of battery updates. | 509 disabling of battery updates. |
513 | 510 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 self._cache['profile'] = { | 582 self._cache['profile'] = { |
586 'name': None, | 583 'name': None, |
587 'witness_file': None, | 584 'witness_file': None, |
588 'enable_command': None, | 585 'enable_command': None, |
589 'disable_command': None, | 586 'disable_command': None, |
590 'charge_counter': None, | 587 'charge_counter': None, |
591 'voltage': None, | 588 'voltage': None, |
592 'current': None, | 589 'current': None, |
593 } | 590 } |
594 return False | 591 return False |
OLD | NEW |