OSDN Git Service

Improve waitForConnection for booting devices.
authorBill Napier <napier@google.com>
Thu, 23 Sep 2010 16:43:30 +0000 (09:43 -0700)
committerBill Napier <napier@google.com>
Thu, 23 Sep 2010 16:48:59 +0000 (09:48 -0700)
Have waitForConnection actually wait until the device is ONLINE before returning
it.  Also give the on device monkey some more time to startup.

Change-Id: I86193a8532a84d64dddd9a60012af4f3ef507841

monkeyrunner/src/com/android/monkeyrunner/adb/AdbBackend.java
monkeyrunner/src/com/android/monkeyrunner/adb/AdbMonkeyDevice.java

index 63badf5..b9549a3 100644 (file)
@@ -69,7 +69,8 @@ public class AdbBackend implements MonkeyRunnerBackend {
     public MonkeyDevice waitForConnection(long timeoutMs, String deviceIdRegex) {
         do {
             IDevice device = findAttacedDevice(deviceIdRegex);
-            if (device != null) {
+            // Only return the device when it is online
+            if (device != null && device.getState() == IDevice.DeviceState.ONLINE) {
                 AdbMonkeyDevice amd = new AdbMonkeyDevice(device);
                 devices.add(amd);
                 return amd;
index dedc1ea..b180ccd 100644 (file)
@@ -51,7 +51,8 @@ public class AdbMonkeyDevice extends MonkeyDevice {
     private static final Logger LOG = Logger.getLogger(AdbMonkeyDevice.class.getName());
 
     private static final String[] ZERO_LENGTH_STRING_ARRAY = new String[0];
-    private static final long MANAGER_CREATE_TIMEOUT_MS = 5 * 1000; // 5 seconds
+    private static final long MANAGER_CREATE_TIMEOUT_MS = 30 * 1000; // 30 seconds
+    private static final long MANAGER_CREATE_WAIT_TIME_MS = 1000; // wait 1 second
 
     private final ExecutorService executor = Executors.newCachedThreadPool();
 
@@ -151,6 +152,12 @@ public class AdbMonkeyDevice extends MonkeyDevice {
                 return null;
             }
 
+            try {
+                Thread.sleep(MANAGER_CREATE_WAIT_TIME_MS);
+            } catch (InterruptedException e) {
+                LOG.log(Level.SEVERE, "Unable to sleep", e);
+            }
+
             Socket monkeySocket;
             try {
                 monkeySocket = new Socket(addr, port);