From 1ebfe40f236888f48efc8caf9ba19e23c4c9fb9c Mon Sep 17 00:00:00 2001 From: Shiliu Wang Date: Wed, 11 Sep 2013 16:44:27 +0800 Subject: [PATCH] [Android] When running android test, try killing adb if no devices found It randomly happens that adb devices return empty list even device is actually connected, killing adb and restart it can fix this. CL=https://codereview.chromium.org/24194002 --- build/android/adb_install_apk.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/build/android/adb_install_apk.py b/build/android/adb_install_apk.py index adad48bdef84a..23e4deaca340f 100755 --- a/build/android/adb_install_apk.py +++ b/build/android/adb_install_apk.py @@ -10,6 +10,7 @@ import optparse import os import sys +import time from pylib import android_commands from pylib import constants @@ -58,7 +59,20 @@ def main(argv): if len(args) > 1: raise Exception('Error: Unknown argument:', args[1:]) - devices = android_commands.GetAttachedDevices() + retry_times = 5 + retry_interval = 15 + while retry_times > 0: + devices = android_commands.GetAttachedDevices() + if not devices: + print 'No connected devices found, '\ + 'kill adb server and retry in %d seconds...' % retry_interval + android_commands.AndroidCommands().KillAdbServer() + time.sleep(retry_interval) + retry_interval *= 2 + retry_times -= 1 + else: + break + if not devices: raise Exception('Error: no connected devices')