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

Unified Diff: build/android/pylib/android_commands.py

Issue 218613011: Adding battery control API for android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Follow reviews Created 6 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 | tools/telemetry/telemetry/core/backends/adb_commands.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/android_commands.py
diff --git a/build/android/pylib/android_commands.py b/build/android/pylib/android_commands.py
index f000682b70641709bfe193dc6e13ebded47424c8..d0fc6c9f2003ada8f79d1346d18786c02127a644 100644
--- a/build/android/pylib/android_commands.py
+++ b/build/android/pylib/android_commands.py
@@ -73,6 +73,15 @@ MD5SUM_DEVICE_FOLDER = constants.TEST_EXECUTABLE_DIR + '/md5sum/'
MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin'
MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER
+CONTROL_USB_CHARGING_COMMANDS = [
+ {
+ # Nexus 4
+ 'witness_file': '/sys/module/pm8921_charger/parameters/disabled',
+ 'enable_command': 'echo 0 > /sys/module/pm8921_charger/parameters/disabled',
+ 'disable_command':
+ 'echo 1 > /sys/module/pm8921_charger/parameters/disabled',
+ },
+]
def GetAVDs():
"""Returns a list of AVDs."""
@@ -285,6 +294,10 @@ class AndroidCommands(object):
self._util_wrapper = ''
self._system_properties = system_properties.SystemProperties(self.Adb())
self._push_if_needed_cache = {}
+ self._control_usb_charging_command = {
+ 'command': None,
+ 'cached': False,
+ }
@property
def system_properties(self):
@@ -1825,6 +1838,38 @@ class AndroidCommands(object):
logging.info('[%s]> %s', device_repr, line)
self.RunShellCommand('rm %s' % temp_script_file)
+ def _GetControlUsbChargingCommand(self):
+ if self._control_usb_charging_command['cached']:
+ return self._control_usb_charging_command['command']
+ self._control_usb_charging_command['cached'] = True
+ for command in CONTROL_USB_CHARGING_COMMANDS:
+ # Assert command is valid.
+ assert 'disable_command' in command
+ assert 'enable_command' in command
+ assert 'witness_file' in command
+ witness_file = command['witness_file']
+ if self.FileExistsOnDevice(witness_file):
+ self._control_usb_charging_command['command'] = command
+ return command
+ return None
+
+ def CanControlUsbCharging(self):
+ return self._GetControlUsbChargingCommand() is not None
+
+ def DisableUsbCharging(self):
+ command = self._GetControlUsbChargingCommand()
+ if not command:
+ raise Exception('Unable to act on usb charging.')
+ disable_command = command['disable_command']
+ self.RunShellCommand(disable_command)
+
+ def EnableUsbCharging(self):
+ command = self._GetControlUsbChargingCommand()
+ if not command:
+ raise Exception('Unable to act on usb charging.')
+ disable_command = command['enable_command']
+ self.RunShellCommand(disable_command)
+
class NewLineNormalizer(object):
"""A file-like object to normalize EOLs to '\n'.
« no previous file with comments | « no previous file | tools/telemetry/telemetry/core/backends/adb_commands.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698