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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 | 115 |
rnephew (Reviews Here)
2017/05/30 18:21:12
Warning should be moved up here, not in the args s
kavefish
2017/05/30 19:27:20
I was following perezju's suggestion here: https:/
rnephew (Reviews Here)
2017/05/30 19:40:32
If Juan said that is the correct place, its fine t
| |
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: Not all devil features are supported when using a USB ID. | |
rnephew (Reviews Here)
2017/05/30 18:21:12
I'm wondering if we can detect if we suspect that
kavefish
2017/05/30 19:27:20
That's interesting. Detection should be straightfo
| |
126 | |
127 # TODO: Improve support for instances created from a USB ID. | |
128 | |
124 """ | 129 """ |
125 if not device_serial: | 130 if not device_serial: |
rnephew (Reviews Here)
2017/05/30 18:21:12
TODO should be moved here outside the class level
| |
126 raise ValueError('A device serial must be specified') | 131 raise ValueError('A device serial must be specified') |
127 self._device_serial = str(device_serial) | 132 self._device_serial = str(device_serial) |
128 | 133 |
129 class PersistentShell(object): | 134 class PersistentShell(object): |
130 '''Class to use persistent shell for ADB. | 135 '''Class to use persistent shell for ADB. |
131 | 136 |
132 This class allows a persistent ADB shell to be created, where multiple | 137 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 | 138 commands can be passed into it. This avoids the overhead of starting |
134 up a new ADB shell for each command. | 139 up a new ADB shell for each command. |
135 | 140 |
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
817 self._RunDeviceAdbCmd(['wait-for-device'], timeout, retries) | 822 self._RunDeviceAdbCmd(['wait-for-device'], timeout, retries) |
818 | 823 |
819 def GetState(self, timeout=DEFAULT_TIMEOUT, retries=DEFAULT_RETRIES): | 824 def GetState(self, timeout=DEFAULT_TIMEOUT, retries=DEFAULT_RETRIES): |
820 """Get device state. | 825 """Get device state. |
821 | 826 |
822 Args: | 827 Args: |
823 timeout: (optional) Timeout per try in seconds. | 828 timeout: (optional) Timeout per try in seconds. |
824 retries: (optional) Number of retries to attempt. | 829 retries: (optional) Number of retries to attempt. |
825 | 830 |
826 Returns: | 831 Returns: |
827 One of 'offline', 'bootloader', or 'device'. | 832 One of 'offline', 'bootloader', or 'unauthorized', or |
833 'no' [permissions], or 'device' | |
828 """ | 834 """ |
829 # TODO(jbudorick): Revert to using get-state once it doesn't cause a | 835 # TODO(jbudorick): Revert to using get-state once it doesn't cause a |
830 # a protocol fault. | 836 # a protocol fault. |
831 # return self._RunDeviceAdbCmd(['get-state'], timeout, retries).strip() | 837 # return self._RunDeviceAdbCmd(['get-state'], timeout, retries).strip() |
832 | 838 |
833 lines = self._RawDevices(timeout=timeout, retries=retries) | 839 lines = self._RawDevices(timeout=timeout, retries=retries, long_list=True) |
834 for line in lines: | 840 for line in lines: |
835 if len(line) >= 2 and line[0] == self._device_serial: | 841 if len(line) >= 3 and (line[0] == self._device_serial or line[2] == |
842 self._device_serial): | |
836 return line[1] | 843 return line[1] |
837 return 'offline' | 844 return 'offline' |
838 | 845 |
839 def GetDevPath(self, timeout=DEFAULT_TIMEOUT, retries=DEFAULT_RETRIES): | 846 def GetDevPath(self, timeout=DEFAULT_TIMEOUT, retries=DEFAULT_RETRIES): |
840 """Gets the device path. | 847 """Gets the device path. |
841 | 848 |
842 Args: | 849 Args: |
843 timeout: (optional) Timeout per try in seconds. | 850 timeout: (optional) Timeout per try in seconds. |
844 retries: (optional) Number of retries to attempt. | 851 retries: (optional) Number of retries to attempt. |
845 | 852 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
914 @property | 921 @property |
915 def is_emulator(self): | 922 def is_emulator(self): |
916 return _EMULATOR_RE.match(self._device_serial) | 923 return _EMULATOR_RE.match(self._device_serial) |
917 | 924 |
918 @property | 925 @property |
919 def is_ready(self): | 926 def is_ready(self): |
920 try: | 927 try: |
921 return self.GetState() == _READY_STATE | 928 return self.GetState() == _READY_STATE |
922 except device_errors.CommandFailedError: | 929 except device_errors.CommandFailedError: |
923 return False | 930 return False |
OLD | NEW |