| 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'.
|
|
|