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

Unified 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: docstrings for device_filter.py 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/device/adb_wrapper_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/pylib/device/adb_wrapper.py
diff --git a/build/android/pylib/device/adb_wrapper.py b/build/android/pylib/device/adb_wrapper.py
index 36f8f484b00fbe2ec05c4c440ab13af10dde71f2..18977ce68757157fd539db4cf2b62214d5420d8d 100644
--- a/build/android/pylib/device/adb_wrapper.py
+++ b/build/android/pylib/device/adb_wrapper.py
@@ -17,6 +17,7 @@ from pylib import cmd_helper
from pylib import constants
from pylib.device import decorators
from pylib.device import device_errors
+from pylib.device import device_filter
from pylib.utils import timeout_retry
@@ -158,12 +159,23 @@ class AdbWrapper(object):
cls._RunAdbCmd(['start-server'], timeout=timeout, retries=retries,
cpu_affinity=0)
- # TODO(craigdh): Determine the filter criteria that should be supported.
@classmethod
- def GetDevices(cls, timeout=_DEFAULT_TIMEOUT, retries=_DEFAULT_RETRIES):
+ def GetDevices(cls, filters=None, timeout=_DEFAULT_TIMEOUT,
+ retries=_DEFAULT_RETRIES):
+ """DEPRECATED. Refer to Devices(...) below."""
+ # TODO(jbudorick): Remove this function once no more clients are using it.
+ return cls.Devices(filters=filters, timeout=timeout, retries=retries)
+
+ @classmethod
+ def Devices(cls, filters=None, timeout=_DEFAULT_TIMEOUT,
+ retries=_DEFAULT_RETRIES):
"""Get the list of active attached devices.
Args:
+ filters: (optional) A list of binary functions that take an AdbWrapper
+ instance and a string description. Any device for which all provided
+ filter functions do not return True will not be included in the
+ returned list.
timeout: (optional) Timeout per try in seconds.
retries: (optional) Number of retries to attempt.
@@ -171,9 +183,18 @@ class AdbWrapper(object):
AdbWrapper instances.
"""
output = cls._RunAdbCmd(['devices'], timeout=timeout, retries=retries)
- lines = [line.split() for line in output.splitlines()]
- return [AdbWrapper(line[0]) for line in lines
- if len(line) == 2 and line[1] == 'device']
+ lines = (line.split() for line in output.splitlines())
+ devices = (AdbWrapper(line[0]) for line in lines if len(line) == 2)
+
+ def matches_all_filters(device):
+ for f in filters:
+ if not f(device):
+ logging.info('Device %s failed filter %s', device.GetDeviceSerial(),
+ f.__name__)
+ return False
+ return True
+
+ return [d for d in devices if matches_all_filters(d)]
def GetDeviceSerial(self):
"""Gets the device serial number associated with this object.
« no previous file with comments | « build/android/provision_devices.py ('k') | build/android/pylib/device/adb_wrapper_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698