Skip to content

Commit

Permalink
[JENKINS-11952] Remove redundant (dis)connect calls while waiting for…
Browse files Browse the repository at this point in the history
… startup.

These shouldn't be required, since emulators are now always started in the port
range that adb automatically recognises.
  • Loading branch information
orrc committed Oct 20, 2014
1 parent f577c75 commit f2fcd2f
Showing 1 changed file with 1 addition and 38 deletions.
Expand Up @@ -417,9 +417,6 @@ private Environment doSetUp(final AbstractBuild<?, ?> build, final Launcher laun
// The delay here is a function of boot time, i.e. relative to the slowness of the host
Thread.sleep(bootDuration / 4);

// Make sure we're still connected
connectEmulator(emu);

log(logger, Messages.UNLOCKING_SCREEN());
final String keyEventArgs = String.format("-s %s shell input keyevent %%d", emu.serial());
final String menuArgs = String.format(keyEventArgs, 82);
Expand All @@ -440,9 +437,6 @@ private Environment doSetUp(final AbstractBuild<?, ?> build, final Launcher laun
log(logger, Messages.WAITING_INITIAL_SNAPSHOT());
Thread.sleep((long) (bootDuration * 0.8));

// Make sure we're still connected
connectEmulator(emu);

// Clear main log before creating snapshot
final String clearArgs = String.format("-s %s logcat -c", emu.serial());
ArgumentListBuilder adbCmd = emu.getToolCommand(Tool.ADB, clearArgs);
Expand Down Expand Up @@ -474,9 +468,6 @@ private Environment doSetUp(final AbstractBuild<?, ?> build, final Launcher laun
}
}

// Make sure we're still connected
connectEmulator(emu);

// Done!
final long bootCompleteTime = System.currentTimeMillis();
log(logger, Messages.EMULATOR_IS_READY((bootCompleteTime - bootTime) / 1000));
Expand Down Expand Up @@ -516,20 +507,6 @@ public boolean tearDown(AbstractBuild build, BuildListener listener)
};
}

private static void connectEmulator(AndroidEmulatorContext emu)
throws IOException, InterruptedException {
ArgumentListBuilder adbConnectCmd = emu.getToolCommand(Tool.ADB, "connect " + emu.serial());
emu.getProcStarter(adbConnectCmd).start().joinWithTimeout(5L, TimeUnit.SECONDS, emu.launcher().getListener());
}

private static void disconnectEmulator(AndroidEmulatorContext emu)
throws IOException, InterruptedException {
final String args = "disconnect "+ emu.serial();
ArgumentListBuilder adbDisconnectCmd = emu.getToolCommand(Tool.ADB, args);
emu.getProcStarter(adbDisconnectCmd).start().joinWithTimeout(5L, TimeUnit.SECONDS, emu.launcher().getListener());
}


/** Helper method for writing to the build log in a consistent manner. */
public synchronized static void log(final PrintStream logger, final String message) {
log(logger, message, false);
Expand Down Expand Up @@ -577,9 +554,6 @@ private void cleanUp(EmulatorConfig emulatorConfig, AndroidEmulatorContext emu,
// Launcher.kill(EnvVars) does not appear to help either.
// This is (a) inconsistent; (b) very annoying.

// Disconnect emulator from adb
disconnectEmulator(emu);

// Stop emulator process
log(emu.logger(), Messages.STOPPING_EMULATOR());
boolean killed = emu.sendCommand("kill");
Expand Down Expand Up @@ -724,18 +698,7 @@ private boolean waitForBootCompletion(final boolean ignoreProcess,
}
}

// Otherwise continue...

/* Ensure the emulator is connected to adb, in case it had crashed.
* We also disconnect it every 3 tries, in case it's stuck in an offline state.
*/
if (++iterations % 3 == 0) {
try {
disconnectEmulator(emu);
} catch (Exception ex) { }
}
connectEmulator(emu);

// "getprop" failed, so sleep and try again later
Thread.sleep(sleep);
}
} catch (InterruptedException ex) {
Expand Down

0 comments on commit f2fcd2f

Please sign in to comment.