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

Unified Diff: build/android/pylib/device/device_filter.py

Issue 1083403002: [Android] Remove android_commands uses from build/android/. (reland) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed 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
Index: build/android/pylib/device/device_filter.py
diff --git a/build/android/pylib/device/device_filter.py b/build/android/pylib/device/device_filter.py
new file mode 100644
index 0000000000000000000000000000000000000000..8e54b2597635d8762fb9a52dcbf3ade0814a9734
--- /dev/null
+++ b/build/android/pylib/device/device_filter.py
@@ -0,0 +1,53 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+from pylib.device import device_blacklist
+from pylib.device import device_errors
+
+
+def DefaultFilters():
+ """Returns a list of the most commonly-used device filters.
+
+ These filters match devices that:
+ - are in a "device" state (as opposed to, e.g., "unauthorized" or
+ "emulator")
+ - are not blacklisted.
+
+ Returns:
+ A list of the most commonly-used device filters.
+ """
+ return [DeviceFilter, BlacklistFilter()]
+
+
+def BlacklistFilter():
+ """Returns a filter that matches devices that are not blacklisted.
+
+ Note that this function is not the filter. It creates one when called using
+ the blacklist at that time and returns that.
+
+ Returns:
+ A filter function that matches devices that are not blacklisted.
+ """
+ blacklist = set(device_blacklist.ReadBlacklist())
+ def f(adb):
+ return adb.GetDeviceSerial() not in blacklist
+
+ return f
+
+
+def DeviceFilter(adb):
+ """A filter that matches devices in a "device" state.
+
+ (Basically, this is adb get-state == "device")
+
+ Args:
+ adb: An instance of AdbWrapper.
+ Returns:
+ True if the device is in a "device" state.
+ """
+ try:
+ return adb.GetState() == 'device'
+ except device_errors.CommandFailedError:
+ return False
+

Powered by Google App Engine
This is Rietveld 408576698