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

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

Issue 993733002: Add new method to disable android device charging. (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 | « no previous file | 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 'enable_command': ( 62 'enable_command': (
63 'echo 0x4A > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' 63 'echo 0x4A > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && '
64 'echo 1 > /sys/class/power_supply/usb/online'), 64 'echo 1 > /sys/class/power_supply/usb/online'),
65 'disable_command': ( 65 'disable_command': (
66 'echo 0xCA > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' 66 'echo 0xCA > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && '
67 'chmod 644 /sys/class/power_supply/usb/online && ' 67 'chmod 644 /sys/class/power_supply/usb/online && '
68 'echo 0 > /sys/class/power_supply/usb/online'), 68 'echo 0 > /sys/class/power_supply/usb/online'),
69 }, 69 },
70 ] 70 ]
71 71
72 _DEFAULT_CHARGING_COMMANDS = {
73 'witness_file': None,
74 'enable_command': 'dumpsys battery reset',
75 'disable_command': 'dumpsys battery set usb 0',
76 }
72 77
73 @decorators.WithExplicitTimeoutAndRetries( 78 @decorators.WithExplicitTimeoutAndRetries(
74 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) 79 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES)
75 def GetAVDs(): 80 def GetAVDs():
76 """Returns a list of Android Virtual Devices. 81 """Returns a list of Android Virtual Devices.
77 82
78 Returns: 83 Returns:
79 A list containing the configured AVDs. 84 A list containing the configured AVDs.
80 """ 85 """
81 lines = cmd_helper.GetCmdOutput([ 86 lines = cmd_helper.GetCmdOutput([
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 timeout: timeout in seconds 1412 timeout: timeout in seconds
1408 retries: number of retries 1413 retries: number of retries
1409 Returns: 1414 Returns:
1410 A dict containing various battery information as reported by dumpsys 1415 A dict containing various battery information as reported by dumpsys
1411 battery. 1416 battery.
1412 """ 1417 """
1413 result = {} 1418 result = {}
1414 # Skip the first line, which is just a header. 1419 # Skip the first line, which is just a header.
1415 for line in self.RunShellCommand( 1420 for line in self.RunShellCommand(
1416 ['dumpsys', 'battery'], check_return=True)[1:]: 1421 ['dumpsys', 'battery'], check_return=True)[1:]:
1417 k, v = line.split(': ', 1) 1422 # If usb charging has been disabled, an extra line of header exists.
1418 result[k.strip()] = v.strip() 1423 if ':' in line:
1424 k, v = line.split(': ', 1)
1425 result[k.strip()] = v.strip()
perezju 2015/03/10 09:46:09 I think you should just log a warning on all skipp
1419 return result 1426 return result
1420 1427
1421 @decorators.WithTimeoutAndRetriesFromInstance() 1428 @decorators.WithTimeoutAndRetriesFromInstance()
1422 def GetCharging(self, timeout=None, retries=None): 1429 def GetCharging(self, timeout=None, retries=None):
1423 """Gets the charging state of the device. 1430 """Gets the charging state of the device.
1424 1431
1425 Args: 1432 Args:
1426 timeout: timeout in seconds 1433 timeout: timeout in seconds
1427 retries: number of retries 1434 retries: number of retries
1428 Returns: 1435 Returns:
(...skipping 15 matching lines...) Expand all
1444 disabled. 1451 disabled.
1445 timeout: timeout in seconds 1452 timeout: timeout in seconds
1446 retries: number of retries 1453 retries: number of retries
1447 """ 1454 """
1448 if 'charging_config' not in self._cache: 1455 if 'charging_config' not in self._cache:
1449 for c in _CONTROL_CHARGING_COMMANDS: 1456 for c in _CONTROL_CHARGING_COMMANDS:
1450 if self.FileExists(c['witness_file']): 1457 if self.FileExists(c['witness_file']):
1451 self._cache['charging_config'] = c 1458 self._cache['charging_config'] = c
1452 break 1459 break
1453 else: 1460 else:
1454 raise device_errors.CommandFailedError( 1461 logging.warning('No charging information found.'
1455 'Unable to find charging commands.') 1462 'Defaulting to generic values.')
1463 self._cache['charging_config'] = _DEFAULT_CHARGING_COMMANDS
jbudorick 2015/03/10 00:04:43 This isn't quite what I suggested in the last CL.
perezju 2015/03/10 09:46:09 I'm not entirely sure I understand what these dump
jbudorick 2015/03/10 13:22:35 AFAIK this actually affects charging to some degre
1456 1464
1457 if enabled: 1465 if enabled:
1458 command = self._cache['charging_config']['enable_command'] 1466 command = self._cache['charging_config']['enable_command']
1459 else: 1467 else:
1460 command = self._cache['charging_config']['disable_command'] 1468 command = self._cache['charging_config']['disable_command']
1461 1469
1462 def set_and_verify_charging(): 1470 def set_and_verify_charging():
1463 self.RunShellCommand(command, check_return=True) 1471 self.RunShellCommand(command, check_return=True)
1464 return self.GetCharging() == enabled 1472 return self.GetCharging() == enabled
1465 1473
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 """ 1527 """
1520 if not devices: 1528 if not devices:
1521 devices = adb_wrapper.AdbWrapper.GetDevices() 1529 devices = adb_wrapper.AdbWrapper.GetDevices()
1522 if not devices: 1530 if not devices:
1523 raise device_errors.NoDevicesError() 1531 raise device_errors.NoDevicesError()
1524 devices = [d if isinstance(d, cls) else cls(d) for d in devices] 1532 devices = [d if isinstance(d, cls) else cls(d) for d in devices]
1525 if async: 1533 if async:
1526 return parallelizer.Parallelizer(devices) 1534 return parallelizer.Parallelizer(devices)
1527 else: 1535 else:
1528 return parallelizer.SyncParallelizer(devices) 1536 return parallelizer.SyncParallelizer(devices)
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698