summaryrefslogtreecommitdiffstats
path: root/luni
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2014-06-20 16:56:49 +0100
committerNeil Fuller <nfuller@google.com>2014-06-23 10:32:28 +0100
commit1f3014901704f3ae81538773b8a0b382945adc8d (patch)
treec80912598f2c1d86e21e23f127c5b74b461344ac /luni
parent2eb56b69de339978a29d94531759b465742f027f (diff)
downloadlibcore-1f3014901704f3ae81538773b8a0b382945adc8d.zip
libcore-1f3014901704f3ae81538773b8a0b382945adc8d.tar.gz
libcore-1f3014901704f3ae81538773b8a0b382945adc8d.tar.bz2
Unimplement Console.readPassword and remove test
ConsoleTest.test_readPassword* fails CTS tests. Context: Under standard Android applications the System.console() method will return null. The Console.readPassword() method must turn off echo. Under automated tests the ConsoleTest is exercising a Console object with fake stdout / stdin streams to get around the absence of a System.console(). setEcho() is hardcoded to use stdin / stdout in the native code. Under the test runners stdin / stdout are not connected to a TTY leading to a ENOTTY. Under Android readPassword is unimportant. Rather than leaving untested security-related code the password methods are being unimplemented. It is unlikely this code has ever been used on Android given the absence of a System Console instance. Bug: 12491103 Change-Id: I755c014e6b53236f5bef0535be137dd721918b44
Diffstat (limited to 'luni')
-rw-r--r--luni/src/main/java/java/io/Console.java39
-rw-r--r--luni/src/main/native/java_io_Console.cpp51
-rw-r--r--luni/src/main/native/sub.mk1
3 files changed, 4 insertions, 87 deletions
diff --git a/luni/src/main/java/java/io/Console.java b/luni/src/main/java/java/io/Console.java
index b6532eb..fe07694c 100644
--- a/luni/src/main/java/java/io/Console.java
+++ b/luni/src/main/java/java/io/Console.java
@@ -127,48 +127,17 @@ public final class Console implements Flushable {
}
/**
- * Reads a password from the console. The password will not be echoed to the display.
- *
- * @return a character array containing the password, or null at EOF.
+ * This method is unimplemented on Android.
*/
public char[] readPassword() {
- synchronized (CONSOLE_LOCK) {
- int previousState = setEcho(false, 0);
- try {
- String password = readLine();
- writer.println(); // We won't have echoed the user's newline.
- return (password == null) ? null : password.toCharArray();
- } finally {
- setEcho(true, previousState);
- }
- }
- }
-
- private static int setEcho(boolean on, int previousState) {
- try {
- return setEchoImpl(on, previousState);
- } catch (IOException ex) {
- throw new IOError(ex);
- }
+ throw new UnsupportedOperationException();
}
- private static native int setEchoImpl(boolean on, int previousState) throws IOException;
/**
- * Reads a password from the console. The password will not be echoed to the display.
- * A formatted prompt is also displayed.
- *
- * @param format the format string (see {@link java.util.Formatter#format})
- * @param args
- * the list of arguments passed to the formatter. If there are
- * more arguments than required by {@code format},
- * additional arguments are ignored.
- * @return a character array containing the password, or null at EOF.
+ * This method is unimplemented on Android.
*/
public char[] readPassword(String format, Object... args) {
- synchronized (CONSOLE_LOCK) {
- format(format, args);
- return readPassword();
- }
+ throw new UnsupportedOperationException();
}
/**
diff --git a/luni/src/main/native/java_io_Console.cpp b/luni/src/main/native/java_io_Console.cpp
deleted file mode 100644
index 512bc72..0000000
--- a/luni/src/main/native/java_io_Console.cpp
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#define LOG_TAG "Console"
-
-#include "JNIHelp.h"
-#include "JniConstants.h"
-
-#include <errno.h>
-#include <termios.h>
-#include <unistd.h>
-
-static jint Console_setEchoImpl(JNIEnv* env, jclass, jboolean on, jint previousState) {
- termios state;
- if (TEMP_FAILURE_RETRY(tcgetattr(STDIN_FILENO, &state)) == -1) {
- jniThrowIOException(env, errno);
- return 0;
- }
- if (on) {
- state.c_lflag = previousState;
- } else {
- previousState = state.c_lflag;
- state.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL);
- }
- if (TEMP_FAILURE_RETRY(tcsetattr(STDIN_FILENO, TCSAFLUSH, &state)) == -1){
- jniThrowIOException(env, errno);
- return 0;
- }
- return previousState;
-}
-
-static JNINativeMethod gMethods[] = {
- NATIVE_METHOD(Console, setEchoImpl, "(ZI)I"),
-};
-void register_java_io_Console(JNIEnv* env) {
- jniRegisterNativeMethods(env, "java/io/Console", gMethods, NELEM(gMethods));
-}
diff --git a/luni/src/main/native/sub.mk b/luni/src/main/native/sub.mk
index 9ca5054..88085c6 100644
--- a/luni/src/main/native/sub.mk
+++ b/luni/src/main/native/sub.mk
@@ -14,7 +14,6 @@ LOCAL_SRC_FILES := \
android_system_OsConstants.cpp \
canonicalize_path.cpp \
cbigint.cpp \
- java_io_Console.cpp \
java_io_File.cpp \
java_io_ObjectStreamClass.cpp \
java_lang_Character.cpp \