Skip to content

Commit

Permalink
[FIXED JENKINS-35004] Disable console auth token at startup.
Browse files Browse the repository at this point in the history
Otherwise, by default starting with SDK Tools 25.1.6, you need to authenticate
before you can start using the telnet interface.  So here we use the documented
way of disabling this feature, i.e. returning to the old behaviour.
  • Loading branch information
orrc committed May 23, 2016
1 parent 834c206 commit 31c1582
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
Expand Up @@ -298,6 +298,10 @@ private Environment doSetUp(final AbstractBuild<?, ?> build, final Launcher laun
launcher.getChannel().call(task);
}

// Write the auth token file for the emulator
Callable<Void, IOException> authFileTask = emuConfig.getEmulatorAuthFileTask();
launcher.getChannel().callAsync(authFileTask);

// Delay start up by the configured amount of time
final int delaySecs = startupDelay;
if (delaySecs > 0) {
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/hudson/plugins/android_emulator/EmulatorConfig.java
Expand Up @@ -248,6 +248,15 @@ public Callable<Void, IOException> getEmulatorConfigTask(HardwareProperty[] hard
return new EmulatorConfigTask(hardwareProperties, listener);
}

/**
* Gets a task that writes an empty emulator auth file to the machine where the AVD will run.
*
* @return A Callable that will write an empty auth file.
*/
public Callable<Void, IOException> getEmulatorAuthFileTask() {
return new EmulatorAuthFileTask();
}

/**
* Gets a task that deletes the AVD corresponding to this instance's configuration.
*
Expand Down Expand Up @@ -707,6 +716,30 @@ public Void call() throws IOException {
}
}

/** Writes an empty emulator auth file. */
private final class EmulatorAuthFileTask extends MasterToSlaveCallable<Void, IOException> {

private static final long serialVersionUID = 1L;

public Void call() throws IOException {
// Create an empty auth file to prevent the emulator telnet interface from requiring authentication
final File userHome = Utils.getHomeDirectory();
if (userHome != null) {
try {
FilePath authFile = new FilePath(userHome).child(".emulator_console_auth_token");
authFile.write("", "UTF-8");
} catch (IOException e) {
throw new IOException(String.format("Failed to write auth file to %s.", userHome, e));
} catch (InterruptedException e) {
throw new IOException(String.format("Interrupted while writing auth file to %s.", userHome, e));
}
}

return null;
}

}

/** A task that deletes the AVD corresponding to our local state. */
private final class EmulatorDeletionTask extends MasterToSlaveCallable<Boolean, Exception> {

Expand Down
31 changes: 31 additions & 0 deletions src/main/java/hudson/plugins/android_emulator/util/Utils.java
Expand Up @@ -296,6 +296,37 @@ public static File getHomeDirectory(String androidSdkHome) {
return new File(homeDirPath);
}

/**
* Locates the current user's home directory using the same scheme as the Android SDK does.
*
* @return A {@link File} representing the home directory.
*/
public static File getHomeDirectory() {
// From https://android.googlesource.com/platform/external/qemu/android/base/system/System.cpp
String path = null;
if (Functions.isWindows()) {
// The emulator queries for the Win32 "CSIDL_PROFILE" path, which should equal USERPROFILE
path = System.getenv("USERPROFILE");

// Otherwise, fall back to the Windows equivalent of HOME
if (path == null) {
String homeDrive = System.getenv("HOMEDRIVE");
String homePath = System.getenv("HOMEPATH");
if (homeDrive != null && homePath != null) {
path = homeDrive + homePath;
}
}
} else {
path = System.getenv("HOME");
}

// Path may not have been discovered
if (path == null) {
return null;
}
return new File(path);
}

/**
* Detects the root directory of an SDK installation based on the Android tools on the PATH.
*
Expand Down

0 comments on commit 31c1582

Please sign in to comment.