| 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 Args: | 194 Args: |
| 195 enabled: A boolean indicating whether charging should be enabled or | 195 enabled: A boolean indicating whether charging should be enabled or |
| 196 disabled. | 196 disabled. |
| 197 timeout: timeout in seconds | 197 timeout: timeout in seconds |
| 198 retries: number of retries | 198 retries: number of retries |
| 199 | 199 |
| 200 Raises: | 200 Raises: |
| 201 device_errors.CommandFailedError: If method of disabling charging cannot | 201 device_errors.CommandFailedError: If method of disabling charging cannot |
| 202 be determined. | 202 be determined. |
| 203 device_errors.DeviceVersionError: If device is not L or higher. | |
| 204 """ | 203 """ |
| 205 if 'charging_config' not in self._cache: | 204 if 'charging_config' not in self._cache: |
| 206 for c in _CONTROL_CHARGING_COMMANDS: | 205 for c in _CONTROL_CHARGING_COMMANDS: |
| 207 if self._device.FileExists(c['witness_file']): | 206 if self._device.FileExists(c['witness_file']): |
| 208 self._cache['charging_config'] = c | 207 self._cache['charging_config'] = c |
| 209 break | 208 break |
| 210 else: | 209 else: |
| 211 raise device_errors.CommandFailedError( | 210 raise device_errors.CommandFailedError( |
| 212 'Unable to find charging commands.') | 211 'Unable to find charging commands.') |
| 213 | 212 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 check_return=True) | 263 check_return=True) |
| 265 timeout_retry.WaitFor(battery_updates_disabled, wait_period=1) | 264 timeout_retry.WaitFor(battery_updates_disabled, wait_period=1) |
| 266 | 265 |
| 267 # TODO(rnephew): Make private when all use cases can use the context manager. | 266 # TODO(rnephew): Make private when all use cases can use the context manager. |
| 268 def EnableBatteryUpdates(self, timeout=None, retries=None): | 267 def EnableBatteryUpdates(self, timeout=None, retries=None): |
| 269 """ Restarts device charging so that dumpsys no longer collects power data. | 268 """ Restarts device charging so that dumpsys no longer collects power data. |
| 270 | 269 |
| 271 Args: | 270 Args: |
| 272 timeout: timeout in seconds | 271 timeout: timeout in seconds |
| 273 retries: number of retries | 272 retries: number of retries |
| 273 |
| 274 Raises: |
| 275 device_errors.DeviceVersionError: If device is not L or higher. |
| 274 """ | 276 """ |
| 275 def battery_updates_enabled(): | 277 def battery_updates_enabled(): |
| 276 return self.GetCharging() is True | 278 return self.GetCharging() is True |
| 277 | 279 |
| 278 if (self._device.build_version_sdk < | 280 if (self._device.build_version_sdk < |
| 279 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): | 281 constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP): |
| 280 raise device_errors.DeviceVersionError('Device must be L or higher.') | 282 raise device_errors.DeviceVersionError('Device must be L or higher.') |
| 281 | 283 |
| 282 self._device.RunShellCommand(['dumpsys', 'battery', 'reset'], | 284 self._device.RunShellCommand(['dumpsys', 'battery', 'reset'], |
| 283 check_return=True) | 285 check_return=True) |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 battery_level = self.GetBatteryInfo().get('level') | 330 battery_level = self.GetBatteryInfo().get('level') |
| 329 if battery_level is None: | 331 if battery_level is None: |
| 330 logging.warning('Unable to find current battery level.') | 332 logging.warning('Unable to find current battery level.') |
| 331 battery_level = 100 | 333 battery_level = 100 |
| 332 else: | 334 else: |
| 333 logging.info('current battery level: %s', battery_level) | 335 logging.info('current battery level: %s', battery_level) |
| 334 battery_level = int(battery_level) | 336 battery_level = int(battery_level) |
| 335 return battery_level >= level | 337 return battery_level >= level |
| 336 | 338 |
| 337 timeout_retry.WaitFor(device_charged, wait_period=wait_period) | 339 timeout_retry.WaitFor(device_charged, wait_period=wait_period) |
| OLD | NEW |