Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: build/android/pylib/device/adb_wrapper.py

Issue 1088793002: [Android] Remove android_commands uses from build/android/. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
11 import collections 11 import collections
12 import errno 12 import errno
13 import logging 13 import logging
14 import os 14 import os
15 15
16 from pylib import cmd_helper 16 from pylib import cmd_helper
17 from pylib import constants 17 from pylib import constants
18 from pylib.device import decorators 18 from pylib.device import decorators
19 from pylib.device import device_errors 19 from pylib.device import device_errors
20 from pylib.device import device_filter
20 from pylib.utils import timeout_retry 21 from pylib.utils import timeout_retry
21 22
22 23
23 _DEFAULT_TIMEOUT = 30 24 _DEFAULT_TIMEOUT = 30
24 _DEFAULT_RETRIES = 2 25 _DEFAULT_RETRIES = 2
25 26
26 27
27 def _VerifyLocalFileExists(path): 28 def _VerifyLocalFileExists(path):
28 """Verifies a local file exists. 29 """Verifies a local file exists.
29 30
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 @classmethod 152 @classmethod
152 def KillServer(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): 153 def KillServer(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES):
153 cls._RunAdbCmd(['kill-server'], timeout=timeout, retries=retries) 154 cls._RunAdbCmd(['kill-server'], timeout=timeout, retries=retries)
154 155
155 @classmethod 156 @classmethod
156 def StartServer(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): 157 def StartServer(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES):
157 # CPU affinity is used to reduce adb instability http://crbug.com/268450 158 # CPU affinity is used to reduce adb instability http://crbug.com/268450
158 cls._RunAdbCmd(['start-server'], timeout=timeout, retries=retries, 159 cls._RunAdbCmd(['start-server'], timeout=timeout, retries=retries,
159 cpu_affinity=0) 160 cpu_affinity=0)
160 161
161 # TODO(craigdh): Determine the filter criteria that should be supported.
162 @classmethod 162 @classmethod
163 def GetDevices(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES): 163 def GetDevices(cls, filters=None, timeout=_DEFAULT_TIMEOUT,
164 retries=_DEFAULT_RETRIES):
164 """Get the list of active attached devices. 165 """Get the list of active attached devices.
165 166
166 Args: 167 Args:
168 filters: (optional) A list of binary functions that take an AdbWrapper
169 instance and a string description. Any device for which all provided
170 filter functions do not return True will not be included in the
171 returned list.
perezju 2015/04/14 12:39:10 I feel this is a bit over-complicated, I would eit
jbudorick 2015/04/14 15:29:58 after looking at this, I think we already have thi
perezju 2015/04/15 09:25:44 I'm not sure about this. AdbWrapper is meant to be
jbudorick 2015/04/15 13:06:59 Yeah, I thought about this too and am still not su
167 timeout: (optional) Timeout per try in seconds. 172 timeout: (optional) Timeout per try in seconds.
168 retries: (optional) Number of retries to attempt. 173 retries: (optional) Number of retries to attempt.
169 174
170 Yields: 175 Yields:
171 AdbWrapper instances. 176 AdbWrapper instances.
172 """ 177 """
178 if filters is None:
179 filters = device_filter.DefaultFilters()
180
173 output = cls._RunAdbCmd(['devices'], timeout=timeout, retries=retries) 181 output = cls._RunAdbCmd(['devices'], timeout=timeout, retries=retries)
174 lines = [line.split() for line in output.splitlines()] 182 lines = [line.split() for line in output.splitlines()]
175 return [AdbWrapper(line[0]) for line in lines 183
176 if len(line) == 2 and line[1] == 'device'] 184 devices_and_descriptions = [
185 (AdbWrapper(line[0]), line[1]) for line in lines if len(line) == 2]
186
187 return [dev for dev, desc in devices_and_descriptions
188 if all(f(dev, desc) for f in filters)]
177 189
178 def GetDeviceSerial(self): 190 def GetDeviceSerial(self):
179 """Gets the device serial number associated with this object. 191 """Gets the device serial number associated with this object.
180 192
181 Returns: 193 Returns:
182 Device serial number as a string. 194 Device serial number as a string.
183 """ 195 """
184 return self._device_serial 196 return self._device_serial
185 197
186 def Push(self, local, remote, timeout=60*5, retries=_DEFAULT_RETRIES): 198 def Push(self, local, remote, timeout=60*5, retries=_DEFAULT_RETRIES):
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 """Restarts the adbd daemon with root permissions, if possible. 535 """Restarts the adbd daemon with root permissions, if possible.
524 536
525 Args: 537 Args:
526 timeout: (optional) Timeout per try in seconds. 538 timeout: (optional) Timeout per try in seconds.
527 retries: (optional) Number of retries to attempt. 539 retries: (optional) Number of retries to attempt.
528 """ 540 """
529 output = self._RunDeviceAdbCmd(['root'], timeout, retries) 541 output = self._RunDeviceAdbCmd(['root'], timeout, retries)
530 if 'cannot' in output: 542 if 'cannot' in output:
531 raise device_errors.AdbCommandFailedError( 543 raise device_errors.AdbCommandFailedError(
532 ['root'], output, device_serial=self._device_serial) 544 ['root'], output, device_serial=self._device_serial)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698