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

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
11 import collections 11 import collections
12 from contextlib import contextmanager
jbudorick 2015/03/12 13:25:57 import contextlib, then use @contextlib.contextman
rnephew (Wrong account) 2015/03/12 18:17:58 Done.
12 import itertools 13 import itertools
13 import logging 14 import logging
14 import multiprocessing 15 import multiprocessing
15 import os 16 import os
16 import re 17 import re
17 import sys 18 import sys
18 import tempfile 19 import tempfile
19 import time 20 import time
20 import zipfile 21 import zipfile
21 22
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 'enable_command': ( 63 'enable_command': (
63 'echo 0x4A > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' 64 'echo 0x4A > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && '
64 'echo 1 > /sys/class/power_supply/usb/online'), 65 'echo 1 > /sys/class/power_supply/usb/online'),
65 'disable_command': ( 66 'disable_command': (
66 'echo 0xCA > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' 67 'echo 0xCA > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && '
67 'chmod 644 /sys/class/power_supply/usb/online && ' 68 'chmod 644 /sys/class/power_supply/usb/online && '
68 'echo 0 > /sys/class/power_supply/usb/online'), 69 'echo 0 > /sys/class/power_supply/usb/online'),
69 }, 70 },
70 ] 71 ]
71 72
73 _DEFAULT_CHARGING_COMMANDS = {
74 'witness_file': None,
75 'enable_command': 'dumpsys battery reset',
76 'disable_command': 'dumpsys battery set usb 0',
77 }
perezju 2015/03/12 09:37:14 I think this is no longer used, so you can remove
rnephew (Wrong account) 2015/03/12 18:17:58 Done.
72 78
73 @decorators.WithExplicitTimeoutAndRetries( 79 @decorators.WithExplicitTimeoutAndRetries(
74 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) 80 _DEFAULT_TIMEOUT, _DEFAULT_RETRIES)
75 def GetAVDs(): 81 def GetAVDs():
76 """Returns a list of Android Virtual Devices. 82 """Returns a list of Android Virtual Devices.
77 83
78 Returns: 84 Returns:
79 A list containing the configured AVDs. 85 A list containing the configured AVDs.
80 """ 86 """
81 lines = cmd_helper.GetCmdOutput([ 87 lines = cmd_helper.GetCmdOutput([
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 timeout: timeout in seconds 1413 timeout: timeout in seconds
1408 retries: number of retries 1414 retries: number of retries
1409 Returns: 1415 Returns:
1410 A dict containing various battery information as reported by dumpsys 1416 A dict containing various battery information as reported by dumpsys
1411 battery. 1417 battery.
1412 """ 1418 """
1413 result = {} 1419 result = {}
1414 # Skip the first line, which is just a header. 1420 # Skip the first line, which is just a header.
1415 for line in self.RunShellCommand( 1421 for line in self.RunShellCommand(
1416 ['dumpsys', 'battery'], check_return=True)[1:]: 1422 ['dumpsys', 'battery'], check_return=True)[1:]:
1417 k, v = line.split(': ', 1) 1423 # If usb charging has been disabled, an extra line of header exists.
1418 result[k.strip()] = v.strip() 1424 if 'UPDATES STOPPED' in line:
1425 logging.warning('Dumpsys battery not receiving updates. '
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 29 matching lines...) Expand all
1458 command = self._cache['charging_config']['enable_command'] 1472 command = self._cache['charging_config']['enable_command']
1459 else: 1473 else:
1460 command = self._cache['charging_config']['disable_command'] 1474 command = self._cache['charging_config']['disable_command']
1461 1475
1462 def set_and_verify_charging(): 1476 def set_and_verify_charging():
1463 self.RunShellCommand(command, check_return=True) 1477 self.RunShellCommand(command, check_return=True)
1464 return self.GetCharging() == enabled 1478 return self.GetCharging() == enabled
1465 1479
1466 timeout_retry.WaitFor(set_and_verify_charging, wait_period=1) 1480 timeout_retry.WaitFor(set_and_verify_charging, wait_period=1)
1467 1481
1468 @decorators.WithTimeoutAndRetriesFromInstance() 1482 @decorators.WithTimeoutAndRetriesFromInstance()
perezju 2015/03/12 09:37:14 Not sure, but maybe we should remove the timeout r
jbudorick 2015/03/12 13:25:57 I think I've never seen this decorator applied to
perezju 2015/03/12 13:43:26 +1
rnephew (Wrong account) 2015/03/12 18:17:58 Done.
1483 @contextmanager
1484 def BatteryMeasurement(self, timeout=None, retries=None):
1485 """Enables or disables the power collection since last charge.
perezju 2015/03/12 09:37:14 Update the doc string, and maybe add a small of ex
rnephew (Wrong account) 2015/03/12 18:17:59 Done.
1486
1487 Args:
1488 timeout: timeout in seconds
1489 retries: number of retries
1490 """
1491 def set_and_verify_battery_measurement():
perezju 2015/03/12 09:37:14 I think it will be cleaner/more readable (also in
jbudorick 2015/03/12 13:25:57 agreed
rnephew (Wrong account) 2015/03/12 18:17:58 Also added a separate reset_battery_data because o
1492 self.RunShellCommand(command, check_return=True)
jbudorick 2015/03/12 13:25:57 Note that what you've done here with command is sn
rnephew (Wrong account) 2015/03/12 18:17:58 Acknowledged.
1493 return self.GetCharging() is charging_state
1494
1495 try:
1496 command = 'dumpsys batterystats --reset && dumpsys battery set usb 0'
perezju 2015/03/12 09:37:14 split this into two calls to RunShellCommand, and
rnephew (Wrong account) 2015/03/12 18:17:58 Done.
1497 charging_state = False
1498 timeout_retry.WaitFor(set_and_verify_battery_measurement, wait_period=1)
1499 yield
1500
1501 finally:
1502 command = 'dumpsys battery reset'
perezju 2015/03/12 09:37:14 ditto, use a list of arguments instead of a string
rnephew (Wrong account) 2015/03/12 18:17:58 Done.
1503 charging_state = True
1504 timeout_retry.WaitFor(set_and_verify_battery_measurement, wait_period=1)
1505
1506
1507 @decorators.WithTimeoutAndRetriesFromInstance()
1469 def GetDevicePieWrapper(self, timeout=None, retries=None): 1508 def GetDevicePieWrapper(self, timeout=None, retries=None):
1470 """Gets the absolute path to the run_pie wrapper on the device. 1509 """Gets the absolute path to the run_pie wrapper on the device.
1471 1510
1472 We have to build our device executables to be PIE, but they need to be able 1511 We have to build our device executables to be PIE, but they need to be able
1473 to run on versions of android that don't support PIE (i.e. ICS and below). 1512 to run on versions of android that don't support PIE (i.e. ICS and below).
1474 To do so, we push a wrapper to the device that lets older android versions 1513 To do so, we push a wrapper to the device that lets older android versions
1475 run PIE executables. This method pushes that wrapper to the device if 1514 run PIE executables. This method pushes that wrapper to the device if
1476 necessary and returns the path to it. 1515 necessary and returns the path to it.
1477 1516
1478 This is exposed publicly to allow clients to write scripts using run_pie 1517 This is exposed publicly to allow clients to write scripts using run_pie
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 """ 1558 """
1520 if not devices: 1559 if not devices:
1521 devices = adb_wrapper.AdbWrapper.GetDevices() 1560 devices = adb_wrapper.AdbWrapper.GetDevices()
1522 if not devices: 1561 if not devices:
1523 raise device_errors.NoDevicesError() 1562 raise device_errors.NoDevicesError()
1524 devices = [d if isinstance(d, cls) else cls(d) for d in devices] 1563 devices = [d if isinstance(d, cls) else cls(d) for d in devices]
1525 if async: 1564 if async:
1526 return parallelizer.Parallelizer(devices) 1565 return parallelizer.Parallelizer(devices)
1527 else: 1566 else:
1528 return parallelizer.SyncParallelizer(devices) 1567 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