Commit 4fd6c1f4 authored by qsr@chromium.org's avatar qsr@chromium.org

Add timeout for usb charging commands.

Also check that we are root, as non rooted cannot control usb charging.

BUG=375178
R=tonyg@chromium.org

Review URL: https://codereview.chromium.org/292743005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271670 0039d316-1c4b-4281-b951-d872f2087c98
parent 573b7684
...@@ -1913,6 +1913,8 @@ class AndroidCommands(object): ...@@ -1913,6 +1913,8 @@ class AndroidCommands(object):
if self._control_usb_charging_command['cached']: if self._control_usb_charging_command['cached']:
return self._control_usb_charging_command['command'] return self._control_usb_charging_command['command']
self._control_usb_charging_command['cached'] = True self._control_usb_charging_command['cached'] = True
if not self.IsRootEnabled():
return None
for command in CONTROL_USB_CHARGING_COMMANDS: for command in CONTROL_USB_CHARGING_COMMANDS:
# Assert command is valid. # Assert command is valid.
assert 'disable_command' in command assert 'disable_command' in command
...@@ -1927,26 +1929,32 @@ class AndroidCommands(object): ...@@ -1927,26 +1929,32 @@ class AndroidCommands(object):
def CanControlUsbCharging(self): def CanControlUsbCharging(self):
return self._GetControlUsbChargingCommand() is not None return self._GetControlUsbChargingCommand() is not None
def DisableUsbCharging(self): def DisableUsbCharging(self, timeout=10):
command = self._GetControlUsbChargingCommand() command = self._GetControlUsbChargingCommand()
if not command: if not command:
raise Exception('Unable to act on usb charging.') raise Exception('Unable to act on usb charging.')
disable_command = command['disable_command'] disable_command = command['disable_command']
t0 = time.time()
# Do not loop directly on self.IsDeviceCharging to cut the number of calls # Do not loop directly on self.IsDeviceCharging to cut the number of calls
# to the device. # to the device.
while True: while True:
if t0 + timeout - time.time() < 0:
raise pexpect.TIMEOUT('Unable to enable USB charging in time.')
self.RunShellCommand(disable_command) self.RunShellCommand(disable_command)
if not self.IsDeviceCharging(): if not self.IsDeviceCharging():
break break
def EnableUsbCharging(self): def EnableUsbCharging(self, timeout=10):
command = self._GetControlUsbChargingCommand() command = self._GetControlUsbChargingCommand()
if not command: if not command:
raise Exception('Unable to act on usb charging.') raise Exception('Unable to act on usb charging.')
disable_command = command['enable_command'] disable_command = command['enable_command']
t0 = time.time()
# Do not loop directly on self.IsDeviceCharging to cut the number of calls # Do not loop directly on self.IsDeviceCharging to cut the number of calls
# to the device. # to the device.
while True: while True:
if t0 + timeout - time.time() < 0:
raise pexpect.TIMEOUT('Unable to enable USB charging in time.')
self.RunShellCommand(disable_command) self.RunShellCommand(disable_command)
if self.IsDeviceCharging(): if self.IsDeviceCharging():
break break
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment