Skip to content
Permalink
Browse files

[FIXED JENKINS-35004] Disable console auth token at startup.

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 31c1582fea973e5ab530f188b7f360c261b8d4ef
@@ -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) {
@@ -248,6 +248,15 @@ public Tool getExecutable() {
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.
*
@@ -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> {

@@ -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.
*

0 comments on commit 31c1582

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