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 |
11 import csv | 11 import csv |
12 import logging | 12 import logging |
13 | 13 |
14 from devil.android import decorators | 14 from devil.android import decorators |
15 from devil.android import device_errors | 15 from devil.android import device_errors |
16 from devil.android import device_utils | 16 from devil.android import device_utils |
17 from devil.android.sdk import version_codes | 17 from devil.android.sdk import version_codes |
18 from devil.utils import timeout_retry | 18 from devil.utils import timeout_retry |
19 from pylib import constants | |
20 | 19 |
21 _DEFAULT_TIMEOUT = 30 | 20 _DEFAULT_TIMEOUT = 30 |
22 _DEFAULT_RETRIES = 3 | 21 _DEFAULT_RETRIES = 3 |
23 | 22 |
24 | 23 |
25 _DEVICE_PROFILES = [ | 24 _DEVICE_PROFILES = [ |
26 { | 25 { |
27 'name': 'Nexus 4', | 26 'name': 'Nexus 4', |
28 'witness_file': '/sys/module/pm8921_charger/parameters/disabled', | 27 'witness_file': '/sys/module/pm8921_charger/parameters/disabled', |
29 'enable_command': ( | 28 'enable_command': ( |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 after_measurements() # Anything that runs after power | 416 after_measurements() # Anything that runs after power |
418 # measurements are collected | 417 # measurements are collected |
419 | 418 |
420 Args: | 419 Args: |
421 timeout: timeout in seconds | 420 timeout: timeout in seconds |
422 retries: number of retries | 421 retries: number of retries |
423 | 422 |
424 Raises: | 423 Raises: |
425 device_errors.DeviceVersionError: If device is not L or higher. | 424 device_errors.DeviceVersionError: If device is not L or higher. |
426 """ | 425 """ |
427 if (self._device.build_version_sdk < version_codes.LOLLIPOP): | 426 if self._device.build_version_sdk < version_codes.LOLLIPOP: |
428 raise device_errors.DeviceVersionError('Device must be L or higher.') | 427 raise device_errors.DeviceVersionError('Device must be L or higher.') |
429 try: | 428 try: |
430 self.DisableBatteryUpdates(timeout=timeout, retries=retries) | 429 self.DisableBatteryUpdates(timeout=timeout, retries=retries) |
431 yield | 430 yield |
432 finally: | 431 finally: |
433 self.EnableBatteryUpdates(timeout=timeout, retries=retries) | 432 self.EnableBatteryUpdates(timeout=timeout, retries=retries) |
434 | 433 |
435 def _DischargeDevice(self, percent, wait_period=120): | 434 def _DischargeDevice(self, percent, wait_period=120): |
436 """Disables charging and waits for device to discharge given amount | 435 """Disables charging and waits for device to discharge given amount |
437 | 436 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
576 charging so that it will collect power data since last charge. | 575 charging so that it will collect power data since last charge. |
577 | 576 |
578 Returns: | 577 Returns: |
579 True if power data cleared. | 578 True if power data cleared. |
580 False if power data clearing is not supported (pre-L) | 579 False if power data clearing is not supported (pre-L) |
581 | 580 |
582 Raises: | 581 Raises: |
583 device_errors.DeviceVersionError: If power clearing is supported, | 582 device_errors.DeviceVersionError: If power clearing is supported, |
584 but fails. | 583 but fails. |
585 """ | 584 """ |
586 if (self._device.build_version_sdk < version_codes.LOLLIPOP): | 585 if self._device.build_version_sdk < version_codes.LOLLIPOP: |
587 logging.warning('Dumpsys power data only available on 5.0 and above. ' | 586 logging.warning('Dumpsys power data only available on 5.0 and above. ' |
588 'Cannot clear power data.') | 587 'Cannot clear power data.') |
589 return False | 588 return False |
590 | 589 |
591 self._device.RunShellCommand( | 590 self._device.RunShellCommand( |
592 ['dumpsys', 'battery', 'set', 'usb', '1'], check_return=True) | 591 ['dumpsys', 'battery', 'set', 'usb', '1'], check_return=True) |
593 self._device.RunShellCommand( | 592 self._device.RunShellCommand( |
594 ['dumpsys', 'battery', 'set', 'ac', '1'], check_return=True) | 593 ['dumpsys', 'battery', 'set', 'ac', '1'], check_return=True) |
595 self._device.RunShellCommand( | 594 self._device.RunShellCommand( |
596 ['dumpsys', 'batterystats', '--reset'], check_return=True) | 595 ['dumpsys', 'batterystats', '--reset'], check_return=True) |
(...skipping 28 matching lines...) Expand all Loading... |
625 self._cache['profile'] = { | 624 self._cache['profile'] = { |
626 'name': None, | 625 'name': None, |
627 'witness_file': None, | 626 'witness_file': None, |
628 'enable_command': None, | 627 'enable_command': None, |
629 'disable_command': None, | 628 'disable_command': None, |
630 'charge_counter': None, | 629 'charge_counter': None, |
631 'voltage': None, | 630 'voltage': None, |
632 'current': None, | 631 'current': None, |
633 } | 632 } |
634 return False | 633 return False |
OLD | NEW |