aboutsummaryrefslogtreecommitdiffstats
path: root/tools/signapk
diff options
context:
space:
mode:
authoradattatr <anisha.dattatraya.kulkarni@intel.com>2015-09-03 11:17:57 -0700
committerBrad Geltz <brad.geltz@intel.com>2015-09-28 11:44:27 -0700
commit50c7c5a72208517237f84b15be6d15c96fa3b2ec (patch)
treece62ae5b86c5632e3198294e498712f8059e29af /tools/signapk
parentcf448ddb4f95f511575e56a729e0d60a45d84e1e (diff)
downloadplatform_build-50c7c5a72208517237f84b15be6d15c96fa3b2ec.tar.gz
platform_build-50c7c5a72208517237f84b15be6d15c96fa3b2ec.tar.bz2
platform_build-50c7c5a72208517237f84b15be6d15c96fa3b2ec.zip
If a console doesn't exist, read password from stdin.
When signapk.jar is invoked by scripts like sign_target_files_apks.py, there is no console as signapk is invoked using popen(). To support signing of APKs using software keys with passwords, we need to read the password from stdin if there is no console. Change-Id: Icf69ba1e58bf1f91979eaf1d3b91cb202782e8fd Signed-off-by: adattatr <anisha.dattatraya.kulkarni@intel.com> Signed-off-by: Brad Geltz <brad.geltz@intel.com>
Diffstat (limited to 'tools/signapk')
-rw-r--r--tools/signapk/SignApk.java21
1 files changed, 16 insertions, 5 deletions
diff --git a/tools/signapk/SignApk.java b/tools/signapk/SignApk.java
index 88f486ab72..3ddab11b80 100644
--- a/tools/signapk/SignApk.java
+++ b/tools/signapk/SignApk.java
@@ -167,18 +167,29 @@ class SignApk {
}
/**
- * Reads the password from console and returns it as a string.
+ * If a console doesn't exist, reads the password from stdin
+ * If a console exists, reads the password from console and returns it as a string.
*
* @param keyFile The file containing the private key. Used to prompt the user.
*/
private static String readPassword(File keyFile) {
Console console;
char[] pwd;
- if((console = System.console()) != null &&
- (pwd = console.readPassword("[%s]", "Enter password for " + keyFile)) != null){
- return String.valueOf(pwd);
+ if ((console = System.console()) == null) {
+ System.out.print("Enter password for " + keyFile + " (password will not be hidden): ");
+ System.out.flush();
+ BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
+ try {
+ return stdin.readLine();
+ } catch (IOException ex) {
+ return null;
+ }
} else {
- return null;
+ if ((pwd = console.readPassword("[%s]", "Enter password for " + keyFile)) != null) {
+ return String.valueOf(pwd);
+ } else {
+ return null;
+ }
}
}