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 20 matching lines...) Expand all Loading... |
31 from pylib import pexpect | 31 from pylib import pexpect |
32 except ImportError: | 32 except ImportError: |
33 pexpect = None | 33 pexpect = None |
34 | 34 |
35 sys.path.append(os.path.join( | 35 sys.path.append(os.path.join( |
36 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) | 36 constants.DIR_SOURCE_ROOT, 'third_party', 'android_testrunner')) |
37 import adb_interface | 37 import adb_interface |
38 import am_instrument_parser | 38 import am_instrument_parser |
39 import errors | 39 import errors |
40 | 40 |
| 41 from pylib.device import device_blacklist |
41 | 42 |
42 # Pattern to search for the next whole line of pexpect output and capture it | 43 # Pattern to search for the next whole line of pexpect output and capture it |
43 # into a match group. We can't use ^ and $ for line start end with pexpect, | 44 # into a match group. We can't use ^ and $ for line start end with pexpect, |
44 # see http://www.noah.org/python/pexpect/#doc for explanation why. | 45 # see http://www.noah.org/python/pexpect/#doc for explanation why. |
45 PEXPECT_LINE_RE = re.compile('\n([^\r]*)\r') | 46 PEXPECT_LINE_RE = re.compile('\n([^\r]*)\r') |
46 | 47 |
47 # Set the adb shell prompt to be a unique marker that will [hopefully] not | 48 # Set the adb shell prompt to be a unique marker that will [hopefully] not |
48 # appear at the start of any line of a command's output. | 49 # appear at the start of any line of a command's output. |
49 SHELL_PROMPT = '~+~PQ\x17RS~+~' | 50 SHELL_PROMPT = '~+~PQ\x17RS~+~' |
50 | 51 |
(...skipping 20 matching lines...) Expand all Loading... |
71 MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin' | 72 MD5SUM_DEVICE_PATH = MD5SUM_DEVICE_FOLDER + 'md5sum_bin' |
72 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER | 73 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER |
73 | 74 |
74 | 75 |
75 def GetAVDs(): | 76 def GetAVDs(): |
76 """Returns a list of AVDs.""" | 77 """Returns a list of AVDs.""" |
77 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE) | 78 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE) |
78 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd'])) | 79 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd'])) |
79 return avds | 80 return avds |
80 | 81 |
81 | |
82 def ResetBadDevices(): | 82 def ResetBadDevices(): |
83 """Removes the file that keeps track of bad devices for a current build.""" | 83 """Removes the blacklist that keeps track of bad devices for a current |
84 if os.path.exists(constants.BAD_DEVICES_JSON): | 84 build. |
85 os.remove(constants.BAD_DEVICES_JSON) | 85 """ |
86 | 86 device_blacklist.ResetBlacklist() |
87 | 87 |
88 def ExtendBadDevices(devices): | 88 def ExtendBadDevices(devices): |
89 """Adds devices to BAD_DEVICES_JSON file. | 89 """Adds devices to the blacklist that keeps track of bad devices for a |
| 90 current build. |
90 | 91 |
91 The devices listed in the BAD_DEVICES_JSON file will not be returned by | 92 The devices listed in the bad devices file will not be returned by |
92 GetAttachedDevices. | 93 GetAttachedDevices. |
93 | 94 |
94 Args: | 95 Args: |
95 devices: list of bad devices to be added to the BAD_DEVICES_JSON file. | 96 devices: list of bad devices to be added to the bad devices file. |
96 """ | 97 """ |
97 if os.path.exists(constants.BAD_DEVICES_JSON): | 98 device_blacklist.ExtendBlacklist(devices) |
98 with open(constants.BAD_DEVICES_JSON, 'r') as f: | |
99 bad_devices = json.load(f) | |
100 devices.extend(bad_devices) | |
101 with open(constants.BAD_DEVICES_JSON, 'w') as f: | |
102 json.dump(list(set(devices)), f) | |
103 | 99 |
104 | 100 |
105 def GetAttachedDevices(hardware=True, emulator=True, offline=False): | 101 def GetAttachedDevices(hardware=True, emulator=True, offline=False): |
106 """Returns a list of attached, android devices and emulators. | 102 """Returns a list of attached, android devices and emulators. |
107 | 103 |
108 If a preferred device has been set with ANDROID_SERIAL, it will be first in | 104 If a preferred device has been set with ANDROID_SERIAL, it will be first in |
109 the returned list. The arguments specify what devices to include in the list. | 105 the returned list. The arguments specify what devices to include in the list. |
110 | 106 |
111 Example output: | 107 Example output: |
112 | 108 |
(...skipping 29 matching lines...) Expand all Loading... |
142 elif hardware: | 138 elif hardware: |
143 devices = [device for device in online_devices | 139 devices = [device for device in online_devices |
144 if device not in emulator_devices] | 140 if device not in emulator_devices] |
145 elif emulator: | 141 elif emulator: |
146 devices = emulator_devices | 142 devices = emulator_devices |
147 | 143 |
148 # Now add offline devices if offline is true | 144 # Now add offline devices if offline is true |
149 if offline: | 145 if offline: |
150 devices = devices + offline_devices | 146 devices = devices + offline_devices |
151 | 147 |
152 # Remove bad devices listed in the bad_devices json file. | 148 # Remove any devices in the blacklist. |
153 if os.path.exists(constants.BAD_DEVICES_JSON): | 149 blacklist = device_blacklist.ReadBlacklist() |
154 with open(constants.BAD_DEVICES_JSON, 'r') as f: | 150 if len(blacklist): |
155 bad_devices = json.load(f) | 151 logging.info('Avoiding bad devices %s', ' '.join(blacklist)) |
156 logging.info('Avoiding bad devices %s', ' '.join(bad_devices)) | 152 devices = [device for device in devices if device not in blacklist] |
157 devices = [device for device in devices if device not in bad_devices] | |
158 | 153 |
159 preferred_device = os.environ.get('ANDROID_SERIAL') | 154 preferred_device = os.environ.get('ANDROID_SERIAL') |
160 if preferred_device in devices: | 155 if preferred_device in devices: |
161 devices.remove(preferred_device) | 156 devices.remove(preferred_device) |
162 devices.insert(0, preferred_device) | 157 devices.insert(0, preferred_device) |
163 return devices | 158 return devices |
164 | 159 |
165 | 160 |
166 def IsDeviceAttached(device): | 161 def IsDeviceAttached(device): |
167 """Return true if the device is attached and online.""" | 162 """Return true if the device is attached and online.""" |
(...skipping 1675 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1843 """ | 1838 """ |
1844 def __init__(self, output): | 1839 def __init__(self, output): |
1845 self._output = output | 1840 self._output = output |
1846 | 1841 |
1847 def write(self, data): | 1842 def write(self, data): |
1848 data = data.replace('\r\r\n', '\n') | 1843 data = data.replace('\r\r\n', '\n') |
1849 self._output.write(data) | 1844 self._output.write(data) |
1850 | 1845 |
1851 def flush(self): | 1846 def flush(self): |
1852 self._output.flush() | 1847 self._output.flush() |
OLD | NEW |