summaryrefslogtreecommitdiff
path: root/keystore/java/android/security/AndroidProtectedConfirmation.java
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2021-01-05 23:29:35 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2021-01-05 23:29:35 +0000
commit30841f177c920b81d163a1c59e33c3e0e319532d (patch)
treee550e3e2e69e0c2162e2391ed79c09b4d5dff3f9 /keystore/java/android/security/AndroidProtectedConfirmation.java
parent7f2de331ac0005d3874ec8598155d21d92a62bf7 (diff)
parent81d75b4c5276f67921d199ff0dfac1f0bb19ca67 (diff)
Merge "Keystore 2.0: Android Protected Confirmation"
Diffstat (limited to 'keystore/java/android/security/AndroidProtectedConfirmation.java')
-rw-r--r--keystore/java/android/security/AndroidProtectedConfirmation.java118
1 files changed, 118 insertions, 0 deletions
diff --git a/keystore/java/android/security/AndroidProtectedConfirmation.java b/keystore/java/android/security/AndroidProtectedConfirmation.java
new file mode 100644
index 000000000000..dfe485ac8274
--- /dev/null
+++ b/keystore/java/android/security/AndroidProtectedConfirmation.java
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2020 The Android Open Source Project
+ *
+ * Licensed 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.
+ */
+
+package android.security;
+
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.ServiceSpecificException;
+import android.security.apc.IConfirmationCallback;
+import android.security.apc.IProtectedConfirmation;
+import android.security.apc.ResponseCode;
+import android.util.Log;
+
+/**
+ * @hide
+ */
+public class AndroidProtectedConfirmation {
+ private static final String TAG = "AndroidProtectedConfirmation";
+
+ public static final int ERROR_OK = ResponseCode.OK;
+ public static final int ERROR_CANCELED = ResponseCode.CANCELLED;
+ public static final int ERROR_ABORTED = ResponseCode.ABORTED;
+ public static final int ERROR_OPERATION_PENDING = ResponseCode.OPERATION_PENDING;
+ public static final int ERROR_IGNORED = ResponseCode.IGNORED;
+ public static final int ERROR_SYSTEM_ERROR = ResponseCode.SYSTEM_ERROR;
+ public static final int ERROR_UNIMPLEMENTED = ResponseCode.UNIMPLEMENTED;
+
+ public static final int FLAG_UI_OPTION_INVERTED =
+ IProtectedConfirmation.FLAG_UI_OPTION_INVERTED;
+ public static final int FLAG_UI_OPTION_MAGNIFIED =
+ IProtectedConfirmation.FLAG_UI_OPTION_MAGNIFIED;
+
+ private IProtectedConfirmation mProtectedConfirmation;
+
+ public AndroidProtectedConfirmation() {
+ mProtectedConfirmation = null;
+ }
+
+ private synchronized IProtectedConfirmation getService() {
+ if (mProtectedConfirmation == null) {
+ mProtectedConfirmation = IProtectedConfirmation.Stub.asInterface(ServiceManager
+ .getService("android.security.apc"));
+ }
+ return mProtectedConfirmation;
+ }
+
+ /**
+ * Requests keystore call into the confirmationui HAL to display a prompt.
+ *
+ * @param listener the binder to use for callbacks.
+ * @param promptText the prompt to display.
+ * @param extraData extra data / nonce from application.
+ * @param locale the locale as a BCP 47 language tag.
+ * @param uiOptionsAsFlags the UI options to use, as flags.
+ * @return one of the {@code CONFIRMATIONUI_*} constants, for
+ * example {@code KeyStore.CONFIRMATIONUI_OK}.
+ */
+ public int presentConfirmationPrompt(IConfirmationCallback listener, String promptText,
+ byte[] extraData, String locale, int uiOptionsAsFlags) {
+ try {
+ getService().presentPrompt(listener, promptText, extraData, locale,
+ uiOptionsAsFlags);
+ return ERROR_OK;
+ } catch (RemoteException e) {
+ Log.w(TAG, "Cannot connect to keystore", e);
+ return ERROR_SYSTEM_ERROR;
+ } catch (ServiceSpecificException e) {
+ return e.errorCode;
+ }
+ }
+
+ /**
+ * Requests keystore call into the confirmationui HAL to cancel displaying a prompt.
+ *
+ * @param listener the binder passed to the {@link #presentConfirmationPrompt} method.
+ * @return one of the {@code CONFIRMATIONUI_*} constants, for
+ * example {@code KeyStore.CONFIRMATIONUI_OK}.
+ */
+ public int cancelConfirmationPrompt(IConfirmationCallback listener) {
+ try {
+ getService().cancelPrompt(listener);
+ return ERROR_OK;
+ } catch (RemoteException e) {
+ Log.w(TAG, "Cannot connect to keystore", e);
+ return ERROR_SYSTEM_ERROR;
+ } catch (ServiceSpecificException e) {
+ return e.errorCode;
+ }
+ }
+
+ /**
+ * Requests keystore to check if the confirmationui HAL is available.
+ *
+ * @return whether the confirmationUI HAL is available.
+ */
+ public boolean isConfirmationPromptSupported() {
+ try {
+ return getService().isSupported();
+ } catch (RemoteException e) {
+ Log.w(TAG, "Cannot connect to keystore", e);
+ return false;
+ }
+ }
+
+}