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 | 9 |
10 import collections | 10 import collections |
11 import datetime | 11 import datetime |
12 import inspect | 12 import inspect |
| 13 import json |
13 import logging | 14 import logging |
14 import os | 15 import os |
15 import re | 16 import re |
16 import shlex | 17 import shlex |
17 import signal | 18 import signal |
18 import subprocess | 19 import subprocess |
19 import sys | 20 import sys |
20 import tempfile | 21 import tempfile |
21 import time | 22 import time |
22 | 23 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER | 71 MD5SUM_LD_LIBRARY_PATH = 'LD_LIBRARY_PATH=%s' % MD5SUM_DEVICE_FOLDER |
71 | 72 |
72 | 73 |
73 def GetAVDs(): | 74 def GetAVDs(): |
74 """Returns a list of AVDs.""" | 75 """Returns a list of AVDs.""" |
75 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE) | 76 re_avd = re.compile('^[ ]+Name: ([a-zA-Z0-9_:.-]+)', re.MULTILINE) |
76 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd'])) | 77 avds = re_avd.findall(cmd_helper.GetCmdOutput(['android', 'list', 'avd'])) |
77 return avds | 78 return avds |
78 | 79 |
79 | 80 |
| 81 def ResetBadDevices(): |
| 82 """Removes the file that keeps track of bad devices for a current build.""" |
| 83 if os.path.exists(constants.BAD_DEVICES_JSON): |
| 84 os.remove(constants.BAD_DEVICES_JSON) |
| 85 |
| 86 |
| 87 def ExtendBadDevices(devices): |
| 88 """Adds devices to BAD_DEVICES_JSON file. |
| 89 |
| 90 The devices listed in the BAD_DEVICES_JSON file will not be returned by |
| 91 GetAttachedDevices. |
| 92 |
| 93 Args: |
| 94 devices: list of bad devices to be added to the BAD_DEVICES_JSON file. |
| 95 """ |
| 96 if os.path.exists(constants.BAD_DEVICES_JSON): |
| 97 with open(constants.BAD_DEVICES_JSON, 'r') as f: |
| 98 bad_devices = json.load(f) |
| 99 devices.extend(bad_devices) |
| 100 with open(constants.BAD_DEVICES_JSON, 'w') as f: |
| 101 json.dump(list(set(devices)), f) |
| 102 |
| 103 |
80 def GetAttachedDevices(hardware=True, emulator=True, offline=False): | 104 def GetAttachedDevices(hardware=True, emulator=True, offline=False): |
81 """Returns a list of attached, android devices and emulators. | 105 """Returns a list of attached, android devices and emulators. |
82 | 106 |
83 If a preferred device has been set with ANDROID_SERIAL, it will be first in | 107 If a preferred device has been set with ANDROID_SERIAL, it will be first in |
84 the returned list. The arguments specify what devices to include in the list. | 108 the returned list. The arguments specify what devices to include in the list. |
85 | 109 |
86 Example output: | 110 Example output: |
87 | 111 |
88 * daemon not running. starting it now on port 5037 * | 112 * daemon not running. starting it now on port 5037 * |
89 * daemon started successfully * | 113 * daemon started successfully * |
(...skipping 27 matching lines...) Expand all Loading... |
117 elif hardware: | 141 elif hardware: |
118 devices = [device for device in online_devices | 142 devices = [device for device in online_devices |
119 if device not in emulator_devices] | 143 if device not in emulator_devices] |
120 elif emulator: | 144 elif emulator: |
121 devices = emulator_devices | 145 devices = emulator_devices |
122 | 146 |
123 # Now add offline devices if offline is true | 147 # Now add offline devices if offline is true |
124 if offline: | 148 if offline: |
125 devices = devices + offline_devices | 149 devices = devices + offline_devices |
126 | 150 |
| 151 # Remove bad devices listed in the bad_devices json file. |
| 152 if os.path.exists(constants.BAD_DEVICES_JSON): |
| 153 with open(constants.BAD_DEVICES_JSON, 'r') as f: |
| 154 bad_devices = json.load(f) |
| 155 logging.info('Avoiding bad devices %s', ' '.join(bad_devices)) |
| 156 devices = [device for device in devices if device not in bad_devices] |
| 157 |
127 preferred_device = os.environ.get('ANDROID_SERIAL') | 158 preferred_device = os.environ.get('ANDROID_SERIAL') |
128 if preferred_device in devices: | 159 if preferred_device in devices: |
129 devices.remove(preferred_device) | 160 devices.remove(preferred_device) |
130 devices.insert(0, preferred_device) | 161 devices.insert(0, preferred_device) |
131 return devices | 162 return devices |
132 | 163 |
133 | 164 |
134 def IsDeviceAttached(device): | 165 def IsDeviceAttached(device): |
135 """Return true if the device is attached and online.""" | 166 """Return true if the device is attached and online.""" |
136 return device in GetAttachedDevices() | 167 return device in GetAttachedDevices() |
(...skipping 1639 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1776 """ | 1807 """ |
1777 def __init__(self, output): | 1808 def __init__(self, output): |
1778 self._output = output | 1809 self._output = output |
1779 | 1810 |
1780 def write(self, data): | 1811 def write(self, data): |
1781 data = data.replace('\r\r\n', '\n') | 1812 data = data.replace('\r\r\n', '\n') |
1782 self._output.write(data) | 1813 self._output.write(data) |
1783 | 1814 |
1784 def flush(self): | 1815 def flush(self): |
1785 self._output.flush() | 1816 self._output.flush() |
OLD | NEW |