diff options
author | Raphael <raphael@google.com> | 2012-02-15 10:31:31 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2012-02-15 10:31:31 -0800 |
commit | 7cd66d43cfc38a268623f63f896a626a4dbe744c (patch) | |
tree | 4c78d96c6134f1842982418528e4e954b12ecf98 /sdkmanager/libs/sdkuilib | |
parent | f11708cbe8cff7d884a32e4ab8ea32bd55bae8e3 (diff) | |
parent | 56a6d5e290d78888d3640a555385d123abb0d503 (diff) | |
download | sdk-7cd66d43cfc38a268623f63f896a626a4dbe744c.zip sdk-7cd66d43cfc38a268623f63f896a626a4dbe744c.tar.gz sdk-7cd66d43cfc38a268623f63f896a626a4dbe744c.tar.bz2 |
Merge "SDK Manager: use find_lock.exe when install dir is locked."
Diffstat (limited to 'sdkmanager/libs/sdkuilib')
-rwxr-xr-x | sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterNoWindow.java | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterNoWindow.java b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterNoWindow.java index 7b94c94..89f084c 100755 --- a/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterNoWindow.java +++ b/sdkmanager/libs/sdkuilib/src/com/android/sdkuilib/internal/repository/SdkUpdaterNoWindow.java @@ -347,11 +347,37 @@ public class SdkUpdaterNoWindow { @Override public boolean displayPrompt(final String title, final String message) { // TODO Make it interactive if mForce==false - mSdkLog.printf("\n%s\n%s\n[y/n] => %s\n", + mSdkLog.printf("\n%1$s\n%2$s\n%3$s", //$NON-NLS-1$ title, message, - mForce ? "yes" : "no (use --force to override)"); - return mForce; + mForce ? "--force used, will reply yes\n" : + "Note: you can use --force to override to yes.\n"); + if (mForce) { + return true; + } + + while (true) { + mSdkLog.printf("%1$s", "[y/n] =>"); //$NON-NLS-1$ + try { + byte[] readBuffer = new byte[2048]; + String reply = readLine(readBuffer).trim(); + mSdkLog.printf("\n"); //$NON-NLS-1$ + if (reply.length() > 0 && reply.length() <= 3) { + char c = reply.charAt(0); + if (c == 'y' || c == 'Y') { + return true; + } else if (c == 'n' || c == 'N') { + return false; + } + } + mSdkLog.printf("Unknown reply '%s'. Please use y[es]/n[o].\n"); //$NON-NLS-1$ + + } catch (IOException e) { + // Exception. Be conservative and say no. + mSdkLog.printf("\n"); //$NON-NLS-1$ + return false; + } + } } /** @@ -417,6 +443,14 @@ public class SdkUpdaterNoWindow { return new UserCredentials(login, password, workstation, domain); } + /** + * Reads current console input in the given buffer. + * + * @param buffer Buffer to hold the user input. Must be larger than the largest + * expected input. Cannot be null. + * @return A new string. May be empty but not null. + * @throws IOException in case the buffer isn't long enough. + */ private String readLine(byte[] buffer) throws IOException { int count = System.in.read(buffer); |