| OLD | NEW |
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """This module wraps Android's adb tool. | 5 """This module wraps Android's adb tool. |
| 6 | 6 |
| 7 This is a thin wrapper around the adb interface. Any additional complexity | 7 This is a thin wrapper around the adb interface. Any additional complexity |
| 8 should be delegated to a higher level (ex. DeviceUtils). | 8 should be delegated to a higher level (ex. DeviceUtils). |
| 9 """ | 9 """ |
| 10 | 10 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 original command in them, that is what it detects ror. | 104 original command in them, that is what it detects ror. |
| 105 | 105 |
| 106 Args: | 106 Args: |
| 107 line: Output line to check. | 107 line: Output line to check. |
| 108 send_cmd: Command that was sent to adb persistent shell. | 108 send_cmd: Command that was sent to adb persistent shell. |
| 109 """ | 109 """ |
| 110 return send_cmd.rstrip() in line | 110 return send_cmd.rstrip() in line |
| 111 | 111 |
| 112 | 112 |
| 113 class AdbWrapper(object): | 113 class AdbWrapper(object): |
| 114 """A wrapper around a local Android Debug Bridge executable.""" | 114 """A wrapper around a local Android Debug Bridge executable. |
| 115 |
| 116 WARNING: Not all features are supported when using a USB ID. |
| 117 """ |
| 115 | 118 |
| 116 _adb_path = lazy.WeakConstant(_FindAdb) | 119 _adb_path = lazy.WeakConstant(_FindAdb) |
| 117 _adb_version = lazy.WeakConstant(_GetVersion) | 120 _adb_version = lazy.WeakConstant(_GetVersion) |
| 118 | 121 |
| 119 def __init__(self, device_serial): | 122 def __init__(self, device_serial): |
| 120 """Initializes the AdbWrapper. | 123 """Initializes the AdbWrapper. |
| 121 | 124 |
| 122 Args: | 125 Args: |
| 123 device_serial: The device serial number as a string. | 126 device_serial: The device serial number or USB bus ID as a string. |
| 127 |
| 124 """ | 128 """ |
| 125 if not device_serial: | 129 if not device_serial: |
| 126 raise ValueError('A device serial must be specified') | 130 raise ValueError('A device serial must be specified') |
| 131 |
| 132 # TODO: Improve support for instances created from a USB ID. |
| 133 if "usb:" in device_serial: |
| 134 logger.warning("Not all features are supported when using a USB ID.") |
| 135 |
| 127 self._device_serial = str(device_serial) | 136 self._device_serial = str(device_serial) |
| 128 | 137 |
| 129 class PersistentShell(object): | 138 class PersistentShell(object): |
| 130 '''Class to use persistent shell for ADB. | 139 '''Class to use persistent shell for ADB. |
| 131 | 140 |
| 132 This class allows a persistent ADB shell to be created, where multiple | 141 This class allows a persistent ADB shell to be created, where multiple |
| 133 commands can be passed into it. This avoids the overhead of starting | 142 commands can be passed into it. This avoids the overhead of starting |
| 134 up a new ADB shell for each command. | 143 up a new ADB shell for each command. |
| 135 | 144 |
| 136 Example of use: | 145 Example of use: |
| (...skipping 680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 self._RunDeviceAdbCmd(['wait-for-device'], timeout, retries) | 826 self._RunDeviceAdbCmd(['wait-for-device'], timeout, retries) |
| 818 | 827 |
| 819 def GetState(self, timeout=DEFAULT_TIMEOUT, retries=DEFAULT_RETRIES): | 828 def GetState(self, timeout=DEFAULT_TIMEOUT, retries=DEFAULT_RETRIES): |
| 820 """Get device state. | 829 """Get device state. |
| 821 | 830 |
| 822 Args: | 831 Args: |
| 823 timeout: (optional) Timeout per try in seconds. | 832 timeout: (optional) Timeout per try in seconds. |
| 824 retries: (optional) Number of retries to attempt. | 833 retries: (optional) Number of retries to attempt. |
| 825 | 834 |
| 826 Returns: | 835 Returns: |
| 827 One of 'offline', 'bootloader', or 'device'. | 836 One of 'offline', 'bootloader', or 'unauthorized', or |
| 837 'no' [permissions], or 'device' |
| 828 """ | 838 """ |
| 829 # TODO(jbudorick): Revert to using get-state once it doesn't cause a | 839 # TODO(jbudorick): Revert to using get-state once it doesn't cause a |
| 830 # a protocol fault. | 840 # a protocol fault. |
| 831 # return self._RunDeviceAdbCmd(['get-state'], timeout, retries).strip() | 841 # return self._RunDeviceAdbCmd(['get-state'], timeout, retries).strip() |
| 832 | 842 |
| 833 lines = self._RawDevices(timeout=timeout, retries=retries) | 843 lines = self._RawDevices(timeout=timeout, retries=retries, long_list=True) |
| 834 for line in lines: | 844 for line in lines: |
| 835 if len(line) >= 2 and line[0] == self._device_serial: | 845 if len(line) >= 3 and (line[0] == self._device_serial or line[2] == |
| 846 self._device_serial): |
| 836 return line[1] | 847 return line[1] |
| 837 return 'offline' | 848 return 'offline' |
| 838 | 849 |
| 839 def GetDevPath(self, timeout=DEFAULT_TIMEOUT, retries=DEFAULT_RETRIES): | 850 def GetDevPath(self, timeout=DEFAULT_TIMEOUT, retries=DEFAULT_RETRIES): |
| 840 """Gets the device path. | 851 """Gets the device path. |
| 841 | 852 |
| 842 Args: | 853 Args: |
| 843 timeout: (optional) Timeout per try in seconds. | 854 timeout: (optional) Timeout per try in seconds. |
| 844 retries: (optional) Number of retries to attempt. | 855 retries: (optional) Number of retries to attempt. |
| 845 | 856 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 914 @property | 925 @property |
| 915 def is_emulator(self): | 926 def is_emulator(self): |
| 916 return _EMULATOR_RE.match(self._device_serial) | 927 return _EMULATOR_RE.match(self._device_serial) |
| 917 | 928 |
| 918 @property | 929 @property |
| 919 def is_ready(self): | 930 def is_ready(self): |
| 920 try: | 931 try: |
| 921 return self.GetState() == _READY_STATE | 932 return self.GetState() == _READY_STATE |
| 922 except device_errors.CommandFailedError: | 933 except device_errors.CommandFailedError: |
| 923 return False | 934 return False |
| OLD | NEW |