Skip to content
Permalink
Browse files

Auto-reconnect to ADB while checking for boot completion, in case ADB…

… crashed.

As suggested in JENKINS-7693, this prevents the build from failing due to an ADB crash.
Such ADB crashes can sometimes be triggered by other emulators starting up in parallel.
  • Loading branch information
orrc committed Apr 6, 2011
1 parent fb9e2bd commit 71989230f7d7d40b624015c8f5aadcb850fc1671
Showing with 10 additions and 4 deletions.
  1. +10 −4 src/main/java/hudson/plugins/android_emulator/AndroidEmulator.java
@@ -343,7 +343,8 @@ private Environment doSetUp(final AbstractBuild<?, ?> build, final Launcher laun
if (!emulatorAlreadyExists || emuConfig.shouldWipeData() || snapshotState == SnapshotState.INITIALISE) {
bootTimeout *= 4;
}
boolean bootSucceeded = waitForBootCompletion(logger, launcher, androidSdk, emulatorProcess, serial, bootTimeout);
boolean bootSucceeded = waitForBootCompletion(logger, launcher, androidSdk, emulatorProcess,
serial, adbConnectArgs, bootTimeout);
if (!bootSucceeded) {
if ((System.currentTimeMillis() - bootTime) < bootTimeout) {
log(logger, Messages.EMULATOR_STOPPED_DURING_BOOT());
@@ -612,19 +613,21 @@ private boolean waitForSocket(Launcher launcher, int port, int timeout) {
* @return <code>true</code> if the emulator has booted, <code>false</code> if we timed-out.
*/
private boolean waitForBootCompletion(final PrintStream logger, final Launcher launcher,
final AndroidSdk androidSdk, final Proc emulatorProcess, final String serial, final int timeout) {
final AndroidSdk androidSdk, final Proc emulatorProcess, final String serial,
final String adbConnectArgs, final int timeout) {
long start = System.currentTimeMillis();
int sleep = timeout / (int) Math.sqrt(timeout / 1000);

final String args = String.format("-s %s shell getprop dev.bootcomplete", serial);
ArgumentListBuilder cmd = Utils.getToolCommand(androidSdk, launcher.isUnix(), Tool.ADB, args);
ArgumentListBuilder bootCheckCmd = Utils.getToolCommand(androidSdk, launcher.isUnix(), Tool.ADB, args);
ArgumentListBuilder connectCmd = Utils.getToolCommand(androidSdk, launcher.isUnix(), Tool.ADB, adbConnectArgs);

try {
while (System.currentTimeMillis() < start + timeout && emulatorProcess.isAlive()) {
ByteArrayOutputStream stream = new ByteArrayOutputStream(4);

// Run "getprop"
launcher.launch().cmds(cmd).stdout(stream).start().join();
launcher.launch().cmds(bootCheckCmd).stdout(stream).start().join();

// Check output
String result = stream.toString().trim();
@@ -634,6 +637,9 @@ private boolean waitForBootCompletion(final PrintStream logger, final Launcher l

// Otherwise continue...
Thread.sleep(sleep);

// Ensure the emulator is connected to adb, in case it had crashed
launcher.launch().cmds(connectCmd).start().join();
}
} catch (InterruptedException ex) {
log(logger, Messages.INTERRUPTED_DURING_BOOT_COMPLETION());

0 comments on commit 7198923

Please sign in to comment.
You can’t perform that action at this time.