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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | build/android/pylib/device/device_utils_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/device/device_utils.py
diff --git a/build/android/pylib/device/device_utils.py b/build/android/pylib/device/device_utils.py
index b6fd7323bb9a3c71e566049719a963bba2ce9023..f17e8050696fc55306c8acd2a58bdf1e62a5e527 100644
--- a/build/android/pylib/device/device_utils.py
+++ b/build/android/pylib/device/device_utils.py
@@ -9,6 +9,7 @@ Eventually, this will be based on adb_wrapper.
# pylint: disable=unused-argument
import collections
+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.
import itertools
import logging
import multiprocessing
@@ -69,6 +70,11 @@ _CONTROL_CHARGING_COMMANDS = [
},
]
+_DEFAULT_CHARGING_COMMANDS = {
+ 'witness_file': None,
+ 'enable_command': 'dumpsys battery reset',
+ 'disable_command': 'dumpsys battery set usb 0',
+}
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.
@decorators.WithExplicitTimeoutAndRetries(
_DEFAULT_TIMEOUT, _DEFAULT_RETRIES)
@@ -1414,8 +1420,16 @@ class DeviceUtils(object):
# Skip the first line, which is just a header.
for line in self.RunShellCommand(
['dumpsys', 'battery'], check_return=True)[1:]:
- k, v = line.split(': ', 1)
- result[k.strip()] = v.strip()
+ # If usb charging has been disabled, an extra line of header exists.
+ if 'UPDATES STOPPED' in line:
+ logging.warning('Dumpsys battery not receiving updates. '
+ 'Run dumpsys battery reset if this is in error.')
+ elif ':' not in line:
+ logging.warning('Unknown line found in dumpsys battery.')
+ logging.warning(line)
+ else:
+ k, v = line.split(': ', 1)
+ result[k.strip()] = v.strip()
return result
@decorators.WithTimeoutAndRetriesFromInstance()
@@ -1466,6 +1480,31 @@ class DeviceUtils(object):
timeout_retry.WaitFor(set_and_verify_charging, wait_period=1)
@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.
+ @contextmanager
+ def BatteryMeasurement(self, timeout=None, retries=None):
+ """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.
+
+ Args:
+ timeout: timeout in seconds
+ retries: number of retries
+ """
+ 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
+ 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.
+ return self.GetCharging() is charging_state
+
+ try:
+ 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.
+ charging_state = False
+ timeout_retry.WaitFor(set_and_verify_battery_measurement, wait_period=1)
+ yield
+
+ finally:
+ 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.
+ charging_state = True
+ timeout_retry.WaitFor(set_and_verify_battery_measurement, wait_period=1)
+
+
+ @decorators.WithTimeoutAndRetriesFromInstance()
def GetDevicePieWrapper(self, timeout=None, retries=None):
"""Gets the absolute path to the run_pie wrapper on the device.
« 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