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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 115 |
116 _adb_path = lazy.WeakConstant(_FindAdb) | 116 _adb_path = lazy.WeakConstant(_FindAdb) |
117 _adb_version = lazy.WeakConstant(_GetVersion) | 117 _adb_version = lazy.WeakConstant(_GetVersion) |
118 | 118 |
119 def __init__(self, device_serial): | 119 def __init__(self, device_serial): |
120 """Initializes the AdbWrapper. | 120 """Initializes the AdbWrapper. |
121 | 121 |
122 Args: | 122 Args: |
123 device_serial: The device serial number as a string. | 123 device_serial: The device serial number or USB bus ID as a string. |
| 124 |
| 125 WARNING: Some features may not be supported with USB ID. |
| 126 |
124 """ | 127 """ |
125 if not device_serial: | 128 if not device_serial: |
126 raise ValueError('A device serial must be specified') | 129 raise ValueError('A device serial must be specified') |
| 130 |
| 131 # TODO: Improve support for instances created from a USB ID. |
| 132 if "usb:" in device_serial: |
| 133 logger.warning("Some features may not be supported when selecting " |
| 134 "devices by 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', 'unauthorized', 'no' [permissions], |
| 837 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 not len(line) >= 3: |
| 846 continue |
| 847 |
| 848 if line[0] == self._device_serial or line[2] == self._device_serial: |
836 return line[1] | 849 return line[1] |
| 850 |
837 return 'offline' | 851 return 'offline' |
838 | 852 |
839 def GetDevPath(self, timeout=DEFAULT_TIMEOUT, retries=DEFAULT_RETRIES): | 853 def GetDevPath(self, timeout=DEFAULT_TIMEOUT, retries=DEFAULT_RETRIES): |
840 """Gets the device path. | 854 """Gets the device path. |
841 | 855 |
842 Args: | 856 Args: |
843 timeout: (optional) Timeout per try in seconds. | 857 timeout: (optional) Timeout per try in seconds. |
844 retries: (optional) Number of retries to attempt. | 858 retries: (optional) Number of retries to attempt. |
845 | 859 |
846 Returns: | 860 Returns: |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 @property | 928 @property |
915 def is_emulator(self): | 929 def is_emulator(self): |
916 return _EMULATOR_RE.match(self._device_serial) | 930 return _EMULATOR_RE.match(self._device_serial) |
917 | 931 |
918 @property | 932 @property |
919 def is_ready(self): | 933 def is_ready(self): |
920 try: | 934 try: |
921 return self.GetState() == _READY_STATE | 935 return self.GetState() == _READY_STATE |
922 except device_errors.CommandFailedError: | 936 except device_errors.CommandFailedError: |
923 return False | 937 return False |
OLD | NEW |