Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(409)

Side by Side Diff: build/android/pylib/device/device_utils.py

Issue 963093002: [Android] Check for AC and wireless charging when determining charging state. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 based on adb. 5 """Provides a variety of device interactions based on adb.
6 6
7 Eventually, this will be based on adb_wrapper. 7 Eventually, this will be based on adb_wrapper.
8 """ 8 """
9 # pylint: disable=unused-argument 9 # pylint: disable=unused-argument
10 10
(...skipping 27 matching lines...) Expand all
38 from pylib.utils import zip_utils 38 from pylib.utils import zip_utils
39 39
40 _DEFAULT_TIMEOUT = 30 40 _DEFAULT_TIMEOUT = 30
41 _DEFAULT_RETRIES = 3 41 _DEFAULT_RETRIES = 3
42 42
43 # A sentinel object for default values 43 # A sentinel object for default values
44 # TODO(jbudorick,perezju): revisit how default values are handled by 44 # TODO(jbudorick,perezju): revisit how default values are handled by
45 # the timeout_retry decorators. 45 # the timeout_retry decorators.
46 DEFAULT = object() 46 DEFAULT = object()
47 47
48 _CONTROL_USB_CHARGING_COMMANDS = [ 48 _CONTROL_CHARGING_COMMANDS = [
49 { 49 {
50 # Nexus 4 50 # Nexus 4
51 'witness_file': '/sys/module/pm8921_charger/parameters/disabled', 51 'witness_file': '/sys/module/pm8921_charger/parameters/disabled',
52 'enable_command': 'echo 0 > /sys/module/pm8921_charger/parameters/disabled', 52 'enable_command': 'echo 0 > /sys/module/pm8921_charger/parameters/disabled',
53 'disable_command': 53 'disable_command':
54 'echo 1 > /sys/module/pm8921_charger/parameters/disabled', 54 'echo 1 > /sys/module/pm8921_charger/parameters/disabled',
55 }, 55 },
56 { 56 {
57 # Nexus 5 57 # Nexus 5
58 # Setting the HIZ bit of the bq24192 causes the charger to actually ignore 58 # Setting the HIZ bit of the bq24192 causes the charger to actually ignore
(...skipping 1353 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 """ 1412 """
1413 result = {} 1413 result = {}
1414 # Skip the first line, which is just a header. 1414 # Skip the first line, which is just a header.
1415 for line in self.RunShellCommand( 1415 for line in self.RunShellCommand(
1416 ['dumpsys', 'battery'], check_return=True)[1:]: 1416 ['dumpsys', 'battery'], check_return=True)[1:]:
1417 k, v = line.split(': ', 1) 1417 k, v = line.split(': ', 1)
1418 result[k.strip()] = v.strip() 1418 result[k.strip()] = v.strip()
1419 return result 1419 return result
1420 1420
1421 @decorators.WithTimeoutAndRetriesFromInstance() 1421 @decorators.WithTimeoutAndRetriesFromInstance()
1422 def GetUsbCharging(self, timeout=None, retries=None): 1422 def GetCharging(self, timeout=None, retries=None):
1423 """Gets the USB charging state of the device. 1423 """Gets the charging state of the device.
1424 1424
1425 Args: 1425 Args:
1426 timeout: timeout in seconds 1426 timeout: timeout in seconds
1427 retries: number of retries 1427 retries: number of retries
1428 Returns: 1428 Returns:
1429 True if the device is charging via USB, false otherwise. 1429 True if the device is charging, false otherwise.
1430 """ 1430 """
1431 return (self.GetBatteryInfo().get('USB powered', '').lower() 1431 battery_info = self.GetBatteryInfo()
1432 in ('true', '1', 'yes')) 1432 for k in ('AC powered', 'USB powered', 'Wireless powered'):
1433 if (k in battery_info and
1434 battery_info[k].lower() in ('true', '1', 'yes')):
1435 return True
1436 return False
1433 1437
1434 @decorators.WithTimeoutAndRetriesFromInstance() 1438 @decorators.WithTimeoutAndRetriesFromInstance()
1435 def SetUsbCharging(self, enabled, timeout=None, retries=None): 1439 def SetCharging(self, enabled, timeout=None, retries=None):
1436 """Enables or disables USB charging on the device. 1440 """Enables or disables charging on the device.
1437 1441
1438 Args: 1442 Args:
1439 enabled: A boolean indicating whether USB charging should be enabled or 1443 enabled: A boolean indicating whether charging should be enabled or
1440 disabled. 1444 disabled.
1441 timeout: timeout in seconds 1445 timeout: timeout in seconds
1442 retries: number of retries 1446 retries: number of retries
1443 """ 1447 """
1444 if 'usb_charging_config' not in self._cache: 1448 if 'charging_config' not in self._cache:
1445 for c in _CONTROL_USB_CHARGING_COMMANDS: 1449 for c in _CONTROL_CHARGING_COMMANDS:
1446 if self.FileExists(c['witness_file']): 1450 if self.FileExists(c['witness_file']):
1447 self._cache['usb_charging_config'] = c 1451 self._cache['charging_config'] = c
1448 break 1452 break
1449 else: 1453 else:
1450 raise device_errors.CommandFailedError( 1454 raise device_errors.CommandFailedError(
1451 'Unable to find charging commands.') 1455 'Unable to find charging commands.')
1452 1456
1453 if enabled: 1457 if enabled:
1454 command = self._cache['usb_charging_config']['enable_command'] 1458 command = self._cache['charging_config']['enable_command']
1455 else: 1459 else:
1456 command = self._cache['usb_charging_config']['disable_command'] 1460 command = self._cache['charging_config']['disable_command']
1457 1461
1458 def set_and_verify_usb_charging(): 1462 def set_and_verify_charging():
1459 self.RunShellCommand(command) 1463 self.RunShellCommand(command, check_return=True)
1460 return self.GetUsbCharging() == enabled 1464 return self.GetCharging() == enabled
1461 1465
1462 timeout_retry.WaitFor(set_and_verify_usb_charging, wait_period=1) 1466 timeout_retry.WaitFor(set_and_verify_charging, wait_period=1)
1463 1467
1464 @decorators.WithTimeoutAndRetriesFromInstance() 1468 @decorators.WithTimeoutAndRetriesFromInstance()
1465 def GetDevicePieWrapper(self, timeout=None, retries=None): 1469 def GetDevicePieWrapper(self, timeout=None, retries=None):
1466 """Gets the absolute path to the run_pie wrapper on the device. 1470 """Gets the absolute path to the run_pie wrapper on the device.
1467 1471
1468 We have to build our device executables to be PIE, but they need to be able 1472 We have to build our device executables to be PIE, but they need to be able
1469 to run on versions of android that don't support PIE (i.e. ICS and below). 1473 to run on versions of android that don't support PIE (i.e. ICS and below).
1470 To do so, we push a wrapper to the device that lets older android versions 1474 To do so, we push a wrapper to the device that lets older android versions
1471 run PIE executables. This method pushes that wrapper to the device if 1475 run PIE executables. This method pushes that wrapper to the device if
1472 necessary and returns the path to it. 1476 necessary and returns the path to it.
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 """ 1519 """
1516 if not devices: 1520 if not devices:
1517 devices = adb_wrapper.AdbWrapper.GetDevices() 1521 devices = adb_wrapper.AdbWrapper.GetDevices()
1518 if not devices: 1522 if not devices:
1519 raise device_errors.NoDevicesError() 1523 raise device_errors.NoDevicesError()
1520 devices = [d if isinstance(d, cls) else cls(d) for d in devices] 1524 devices = [d if isinstance(d, cls) else cls(d) for d in devices]
1521 if async: 1525 if async:
1522 return parallelizer.Parallelizer(devices) 1526 return parallelizer.Parallelizer(devices)
1523 else: 1527 else:
1524 return parallelizer.SyncParallelizer(devices) 1528 return parallelizer.SyncParallelizer(devices)
OLDNEW
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698