Use information about blacklisted devices in video_quality_loopback_test

BUG=webrtc:7724
NOTRY=True

Review-Url: https://codereview.webrtc.org/2937123002
Cr-Commit-Position: refs/heads/master@{#18654}
diff --git a/webrtc/examples/androidtests/video_quality_loopback_test.py b/webrtc/examples/androidtests/video_quality_loopback_test.py
index e8c4381..aa0d8a9 100755
--- a/webrtc/examples/androidtests/video_quality_loopback_test.py
+++ b/webrtc/examples/androidtests/video_quality_loopback_test.py
@@ -19,6 +19,7 @@
 """
 
 import argparse
+import json
 import logging
 import os
 import shutil
@@ -31,6 +32,9 @@
 SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
 SRC_DIR = os.path.normpath(os.path.join(SCRIPT_DIR, os.pardir, os.pardir,
                                         os.pardir))
+BAD_DEVICES_JSON = os.path.join(SRC_DIR,
+                                os.environ.get('CHROMIUM_OUT_DIR', 'out'),
+                                'bad_devices.json')
 
 
 class Error(Exception):
@@ -109,10 +113,19 @@
   _RunCommand([sys.executable, setup_apprtc_script, temp_dir])
 
   # Select an Android device in case multiple are connected
+  try:
+    with open(BAD_DEVICES_JSON) as bad_devices_file:
+      bad_devices = json.load(bad_devices_file)
+  except IOError:
+    if os.environ.get('CHROME_HEADLESS'):
+      logging.warning('Cannot read %r', BAD_DEVICES_JSON)
+    bad_devices = {}
+
   for line in _RunCommandWithOutput([adb_path, 'devices']).splitlines():
     if line.endswith('\tdevice'):
       android_device = line.split('\t')[0]
-      break
+      if android_device not in bad_devices:
+        break
   else:
     raise VideoQualityTestError('Cannot find any connected Android device.')