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

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 usb charging has been disabled, an extra line of header exists.
klundberg 2015/03/11 14:27:14 I'm seeing double :-) Please remove one of the co
rnephew (Wrong account) 2015/03/11 18:27:01 Done.
1424 if 'UPDATES STOPPED' in line:
1425 logging.warning('Dumpsys battery not recieving updates. '
klundberg 2015/03/11 14:27:14 s/recieving/receiving
rnephew (Wrong account) 2015/03/11 18:27:01 Done.
1426 'Run dumpsys battery reset if this is in error.')
1427 elif ':' not in line:
1428 logging.warning('Unknown line found in dumpsys battery.')
1429 logging.warning(line)
1430 else:
1431 k, v = line.split(': ', 1)
1432 result[k.strip()] = v.strip()
1419 return result 1433 return result
1420 1434
1421 @decorators.WithTimeoutAndRetriesFromInstance() 1435 @decorators.WithTimeoutAndRetriesFromInstance()
1422 def GetCharging(self, timeout=None, retries=None): 1436 def GetCharging(self, timeout=None, retries=None):
1423 """Gets the charging state of the device. 1437 """Gets the charging state of the device.
1424 1438
1425 Args: 1439 Args:
1426 timeout: timeout in seconds 1440 timeout: timeout in seconds
1427 retries: number of retries 1441 retries: number of retries
1428 Returns: 1442 Returns:
(...skipping 15 matching lines...) Expand all
1444 disabled. 1458 disabled.
1445 timeout: timeout in seconds 1459 timeout: timeout in seconds
1446 retries: number of retries 1460 retries: number of retries
1447 """ 1461 """
1448 if 'charging_config' not in self._cache: 1462 if 'charging_config' not in self._cache:
1449 for c in _CONTROL_CHARGING_COMMANDS: 1463 for c in _CONTROL_CHARGING_COMMANDS:
1450 if self.FileExists(c['witness_file']): 1464 if self.FileExists(c['witness_file']):
1451 self._cache['charging_config'] = c 1465 self._cache['charging_config'] = c
1452 break 1466 break
1453 else: 1467 else:
1454 raise device_errors.CommandFailedError( 1468 logging.warning('No charging information found.'
1455 'Unable to find charging commands.') 1469 'Defaulting to generic values.')
1470 self._cache['charging_config'] = _DEFAULT_CHARGING_COMMANDS
1456 1471
1457 if enabled: 1472 if enabled:
1458 command = self._cache['charging_config']['enable_command'] 1473 command = self._cache['charging_config']['enable_command']
1459 else: 1474 else:
1460 command = self._cache['charging_config']['disable_command'] 1475 command = self._cache['charging_config']['disable_command']
1461 1476
1462 def set_and_verify_charging(): 1477 def set_and_verify_charging():
1463 self.RunShellCommand(command, check_return=True) 1478 self.RunShellCommand(command, check_return=True)
1464 return self.GetCharging() == enabled 1479 return self.GetCharging() == enabled
1465 1480
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 """ 1534 """
1520 if not devices: 1535 if not devices:
1521 devices = adb_wrapper.AdbWrapper.GetDevices() 1536 devices = adb_wrapper.AdbWrapper.GetDevices()
1522 if not devices: 1537 if not devices:
1523 raise device_errors.NoDevicesError() 1538 raise device_errors.NoDevicesError()
1524 devices = [d if isinstance(d, cls) else cls(d) for d in devices] 1539 devices = [d if isinstance(d, cls) else cls(d) for d in devices]
1525 if async: 1540 if async:
1526 return parallelizer.Parallelizer(devices) 1541 return parallelizer.Parallelizer(devices)
1527 else: 1542 else:
1528 return parallelizer.SyncParallelizer(devices) 1543 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