Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 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 an interface to communicate with the device via the adb command. | 5 """Provides an interface to communicate with the device via the adb command. |
| 6 | 6 |
| 7 Assumes adb binary is currently on system path. | 7 Assumes adb binary is currently on system path. |
| 8 """ | 8 """ |
| 9 # pylint: disable-all | 9 # pylint: disable-all |
| 10 | 10 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 66 KEYCODE_DPAD_UP = 19 | 66 KEYCODE_DPAD_UP = 19 |
| 67 KEYCODE_DPAD_DOWN = 20 | 67 KEYCODE_DPAD_DOWN = 20 |
| 68 KEYCODE_DPAD_RIGHT = 22 | 68 KEYCODE_DPAD_RIGHT = 22 |
| 69 KEYCODE_ENTER = 66 | 69 KEYCODE_ENTER = 66 |
| 70 KEYCODE_MENU = 82 | 70 KEYCODE_MENU = 82 |
| 71 | 71 |
| 72 MD5SUM_DEVICE_FOLDER = constants.TEST_EXECUTABLE_DIR + '/md5sum/' | 72 MD5SUM_DEVICE_FOLDER = constants.TEST_EXECUTABLE_DIR + '/md5sum/' |
| 73 MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin' | 73 MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin' |
| 74 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER | 74 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER |
| 75 | 75 |
| 76 CONTROL_BATTERY_CHARGING_COMMAND = [ | |
|
Philippe
2014/04/01 09:51:58
Nit: s/COMMAND/COMMANDS?
qsr
2014/04/02 09:14:57
Done.
| |
| 77 { | |
|
tonyg
2014/04/01 16:13:18
WDYT about adding a comment listing some example d
qsr
2014/04/02 09:14:57
Done. This one if for the N4 and the only one I ha
| |
| 78 'witness_file': '/sys/module/pm8921_charger/parameters/disabled', | |
| 79 'enable_command': 'echo 0 > /sys/module/pm8921_charger/parameters/disabled', | |
| 80 'disable_command': | |
| 81 'echo 1 > /sys/module/pm8921_charger/parameters/disabled', | |
| 82 }, | |
| 83 ]; | |
| 76 | 84 |
| 77 def GetAVDs(): | 85 def GetAVDs(): |
| 78 """Returns a list of AVDs.""" | 86 """Returns a list of AVDs.""" |
| 79 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE) | 87 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE) |
| 80 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd'])) | 88 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd'])) |
| 81 return avds | 89 return avds |
| 82 | 90 |
| 83 def ResetBadDevices(): | 91 def ResetBadDevices(): |
| 84 """Removes the blacklist that keeps track of bad devices for a current | 92 """Removes the blacklist that keeps track of bad devices for a current |
| 85 build. | 93 build. |
| (...skipping 1732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1818 out = self.RunShellCommand('sh %s %s %s' % (temp_script_file, source, dest), | 1826 out = self.RunShellCommand('sh %s %s %s' % (temp_script_file, source, dest), |
| 1819 timeout_time=120) | 1827 timeout_time=120) |
| 1820 if self._device: | 1828 if self._device: |
| 1821 device_repr = self._device[-4:] | 1829 device_repr = self._device[-4:] |
| 1822 else: | 1830 else: |
| 1823 device_repr = '????' | 1831 device_repr = '????' |
| 1824 for line in out: | 1832 for line in out: |
| 1825 logging.info('[%s]> %s', device_repr, line) | 1833 logging.info('[%s]> %s', device_repr, line) |
| 1826 self.RunShellCommand('rm %s' % temp_script_file) | 1834 self.RunShellCommand('rm %s' % temp_script_file) |
| 1827 | 1835 |
| 1836 def _GetControlBatteryChargingCommand(self): | |
| 1837 for command in CONTROL_BATTERY_CHARGING_COMMAND: | |
| 1838 witness_file = command['witness_file'] | |
| 1839 if self.FileExistsOnDevice(witness_file): | |
|
tonyg
2014/04/01 16:13:18
Maybe we should add an assert that all of the requ
qsr
2014/04/02 09:14:57
Done.
| |
| 1840 return command | |
| 1841 return None | |
| 1842 | |
| 1843 def CanControlBatteryCharging(self): | |
|
tonyg
2014/04/01 16:13:18
Is BatteryCharging really the intent of this API?
qsr
2014/04/02 09:14:57
You are right. Will rename.
| |
| 1844 return self._GetControlBatteryChargingCommand() is not None | |
| 1845 | |
| 1846 def DisableBatteryCharging(self): | |
| 1847 command = self._GetControlBatteryChargingCommand() | |
|
tonyg
2014/04/01 16:13:18
Can we cache the enable/disable command in _GetCon
qsr
2014/04/02 09:14:57
Done.
| |
| 1848 if not command: | |
| 1849 raise Exception('Unable to act on battery charing.') | |
|
tonyg
2014/04/01 16:13:18
s/charing/charging/
qsr
2014/04/02 09:14:57
Done.
| |
| 1850 disable_command = command['disable_command'] | |
| 1851 self.RunShellCommand(disable_command) | |
| 1852 | |
| 1853 def EnableBatteryCharging(self): | |
| 1854 command = self._GetControlBatteryChargingCommand() | |
| 1855 if not command: | |
| 1856 raise Exception('Unable to act on battery charing.') | |
| 1857 disable_command = command['enable_command'] | |
| 1858 self.RunShellCommand(disable_command) | |
| 1859 | |
| 1828 | 1860 |
| 1829 class NewLineNormalizer(object): | 1861 class NewLineNormalizer(object): |
| 1830 """A file-like object to normalize EOLs to '\n'. | 1862 """A file-like object to normalize EOLs to '\n'. |
| 1831 | 1863 |
| 1832 Pexpect runs adb within a pseudo-tty device (see | 1864 Pexpect runs adb within a pseudo-tty device (see |
| 1833 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written | 1865 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written |
| 1834 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate | 1866 as '\r\n' to the logfile. Since adb already uses '\r\n' to terminate |
| 1835 lines, the log ends up having '\r\r\n' at the end of each line. This | 1867 lines, the log ends up having '\r\r\n' at the end of each line. This |
| 1836 filter replaces the above with a single '\n' in the data stream. | 1868 filter replaces the above with a single '\n' in the data stream. |
| 1837 """ | 1869 """ |
| 1838 def __init__(self, output): | 1870 def __init__(self, output): |
| 1839 self._output = output | 1871 self._output = output |
| 1840 | 1872 |
| 1841 def write(self, data): | 1873 def write(self, data): |
| 1842 data = data.replace('\r\r\n', '\n') | 1874 data = data.replace('\r\r\n', '\n') |
| 1843 self._output.write(data) | 1875 self._output.write(data) |
| 1844 | 1876 |
| 1845 def flush(self): | 1877 def flush(self): |
| 1846 self._output.flush() | 1878 self._output.flush() |
| OLD | NEW |