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_USB_CHARGING_COMMANDS = [ |
| 77 { |
| 78 # Nexus 4 |
| 79 'witness_file': '/sys/module/pm8921_charger/parameters/disabled', |
| 80 'enable_command': 'echo 0 > /sys/module/pm8921_charger/parameters/disabled', |
| 81 'disable_command': |
| 82 'echo 1 > /sys/module/pm8921_charger/parameters/disabled', |
| 83 }, |
| 84 ] |
76 | 85 |
77 def GetAVDs(): | 86 def GetAVDs(): |
78 """Returns a list of AVDs.""" | 87 """Returns a list of AVDs.""" |
79 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE) | 88 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE) |
80 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd'])) | 89 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd'])) |
81 return avds | 90 return avds |
82 | 91 |
83 def ResetBadDevices(): | 92 def ResetBadDevices(): |
84 """Removes the blacklist that keeps track of bad devices for a current | 93 """Removes the blacklist that keeps track of bad devices for a current |
85 build. | 94 build. |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 self.logcat_process = None | 287 self.logcat_process = None |
279 self._logcat_tmpoutfile = None | 288 self._logcat_tmpoutfile = None |
280 self._pushed_files = [] | 289 self._pushed_files = [] |
281 self._device_utc_offset = None | 290 self._device_utc_offset = None |
282 self._potential_push_size = 0 | 291 self._potential_push_size = 0 |
283 self._actual_push_size = 0 | 292 self._actual_push_size = 0 |
284 self._external_storage = '' | 293 self._external_storage = '' |
285 self._util_wrapper = '' | 294 self._util_wrapper = '' |
286 self._system_properties = system_properties.SystemProperties(self.Adb()) | 295 self._system_properties = system_properties.SystemProperties(self.Adb()) |
287 self._push_if_needed_cache = {} | 296 self._push_if_needed_cache = {} |
| 297 self._control_usb_charging_command = { |
| 298 'command': None, |
| 299 'cached': False, |
| 300 } |
288 | 301 |
289 @property | 302 @property |
290 def system_properties(self): | 303 def system_properties(self): |
291 return self._system_properties | 304 return self._system_properties |
292 | 305 |
293 def _LogShell(self, cmd): | 306 def _LogShell(self, cmd): |
294 """Logs the adb shell command.""" | 307 """Logs the adb shell command.""" |
295 if self._device: | 308 if self._device: |
296 device_repr = self._device[-4:] | 309 device_repr = self._device[-4:] |
297 else: | 310 else: |
(...skipping 1520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1818 out = self.RunShellCommand('sh %s %s %s' % (temp_script_file, source, dest), | 1831 out = self.RunShellCommand('sh %s %s %s' % (temp_script_file, source, dest), |
1819 timeout_time=120) | 1832 timeout_time=120) |
1820 if self._device: | 1833 if self._device: |
1821 device_repr = self._device[-4:] | 1834 device_repr = self._device[-4:] |
1822 else: | 1835 else: |
1823 device_repr = '????' | 1836 device_repr = '????' |
1824 for line in out: | 1837 for line in out: |
1825 logging.info('[%s]> %s', device_repr, line) | 1838 logging.info('[%s]> %s', device_repr, line) |
1826 self.RunShellCommand('rm %s' % temp_script_file) | 1839 self.RunShellCommand('rm %s' % temp_script_file) |
1827 | 1840 |
| 1841 def _GetControlUsbChargingCommand(self): |
| 1842 if self._control_usb_charging_command['cached']: |
| 1843 return self._control_usb_charging_command['command'] |
| 1844 self._control_usb_charging_command['cached'] = True |
| 1845 for command in CONTROL_USB_CHARGING_COMMANDS: |
| 1846 # Assert command is valid. |
| 1847 assert 'disable_command' in command |
| 1848 assert 'enable_command' in command |
| 1849 assert 'witness_file' in command |
| 1850 witness_file = command['witness_file'] |
| 1851 if self.FileExistsOnDevice(witness_file): |
| 1852 self._control_usb_charging_command['command'] = command |
| 1853 return command |
| 1854 return None |
| 1855 |
| 1856 def CanControlUsbCharging(self): |
| 1857 return self._GetControlUsbChargingCommand() is not None |
| 1858 |
| 1859 def DisableUsbCharging(self): |
| 1860 command = self._GetControlUsbChargingCommand() |
| 1861 if not command: |
| 1862 raise Exception('Unable to act on usb charging.') |
| 1863 disable_command = command['disable_command'] |
| 1864 self.RunShellCommand(disable_command) |
| 1865 |
| 1866 def EnableUsbCharging(self): |
| 1867 command = self._GetControlUsbChargingCommand() |
| 1868 if not command: |
| 1869 raise Exception('Unable to act on usb charging.') |
| 1870 disable_command = command['enable_command'] |
| 1871 self.RunShellCommand(disable_command) |
| 1872 |
1828 | 1873 |
1829 class NewLineNormalizer(object): | 1874 class NewLineNormalizer(object): |
1830 """A file-like object to normalize EOLs to '\n'. | 1875 """A file-like object to normalize EOLs to '\n'. |
1831 | 1876 |
1832 Pexpect runs adb within a pseudo-tty device (see | 1877 Pexpect runs adb within a pseudo-tty device (see |
1833 http://www.noah.org/wiki/pexpect), so any '\n' printed by adb is written | 1878 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 | 1879 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 | 1880 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. | 1881 filter replaces the above with a single '\n' in the data stream. |
1837 """ | 1882 """ |
1838 def __init__(self, output): | 1883 def __init__(self, output): |
1839 self._output = output | 1884 self._output = output |
1840 | 1885 |
1841 def write(self, data): | 1886 def write(self, data): |
1842 data = data.replace('\r\r\n', '\n') | 1887 data = data.replace('\r\r\n', '\n') |
1843 self._output.write(data) | 1888 self._output.write(data) |
1844 | 1889 |
1845 def flush(self): | 1890 def flush(self): |
1846 self._output.flush() | 1891 self._output.flush() |
OLD | NEW |