Skip to content

Commit

Permalink
Reuse ADB instance
Browse files Browse the repository at this point in the history
When we force a new debug bridge, `kill-server` command will be sent to an existing instance.
There are some difficulties to proper start adb server after this.
This results in stanfy/spoon-gradle-plugin#4

Also `waitForAdb` implementation is changed to check whether devices list is ready.
See
https://android.googlesource.com/platform/tools/base/+/gradle_1.1.3/build-system/builder/src/main/java/com/android/builder/testing/ConnectedDeviceProvider.java#60
  • Loading branch information
Roman Mazur committed Mar 18, 2015
1 parent cb3eb95 commit e81a8b3
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions spoon-runner/src/main/java/com/squareup/spoon/SpoonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import javax.imageio.ImageIO;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -99,7 +100,7 @@ static Set<String> findAllDevices(AndroidDebugBridge adb) {
static AndroidDebugBridge initAdb(File sdk) {
AndroidDebugBridge.initIfNeeded(false);
File adbPath = FileUtils.getFile(sdk, "platform-tools", "adb");
AndroidDebugBridge adb = AndroidDebugBridge.createBridge(adbPath.getAbsolutePath(), true);
AndroidDebugBridge adb = AndroidDebugBridge.createBridge(adbPath.getAbsolutePath(), false);
waitForAdb(adb);
return adb;
}
Expand Down Expand Up @@ -129,17 +130,19 @@ static void createAnimatedGif(List<File> testScreenshots, File animatedGif) thro
}

private static void waitForAdb(AndroidDebugBridge adb) {
for (int i = 1; i < 10; i++) {
long timeOutMs = TimeUnit.SECONDS.toMillis(30);
long sleepTimeMs = TimeUnit.SECONDS.toMillis(1);
while (!adb.hasInitialDeviceList() && timeOutMs > 0) {
try {
Thread.sleep(i * 100);
Thread.sleep(sleepTimeMs);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
if (adb.isConnected()) {
return;
}
timeOutMs -= sleepTimeMs;
}
if (timeOutMs <= 0 && !adb.hasInitialDeviceList()) {
throw new RuntimeException("Timeout getting device list.", null);
}
throw new RuntimeException("Unable to connect to adb.");
}

private SpoonUtils() {
Expand Down

0 comments on commit e81a8b3

Please sign in to comment.