summaryrefslogtreecommitdiff
path: root/core/java/android
diff options
context:
space:
mode:
authorKevin Chyn <kchyn@google.com>2019-03-25 18:11:16 -0700
committerKevin Chyn <kchyn@google.com>2019-04-09 22:04:05 -0700
commit5a90a653f5613fb5ef84c760ee35fc64710559a3 (patch)
tree897c5528272abcd73b0be24f12b0f31d23d1e1ed /core/java/android
parentdd07ae579c291a2b6ffe09bd576fd908eb9e5ddd (diff)
Handle cancellation properly for setDeviceCredentialAllowed(true)
Keep the current auth session until ConfirmDeviceCredential succeeds or fails. ConfirmDeviceCredential's BP and LSKF screens can be canceled now. Bug: 123378871 Bug: 128747871 Test: With modified BiometricPromptDemo, ConfirmDeviceCredential's BiometricPrompt and LSKF screens can be canceled Change-Id: Icaf3f0c55b07fd138a2ee9d214941ea83408f0ee
Diffstat (limited to 'core/java/android')
-rw-r--r--core/java/android/hardware/biometrics/BiometricManager.java17
-rw-r--r--core/java/android/hardware/biometrics/BiometricPrompt.java33
-rw-r--r--core/java/android/hardware/biometrics/IBiometricConfirmDeviceCredentialCallback.aidl26
-rw-r--r--core/java/android/hardware/biometrics/IBiometricService.aidl9
4 files changed, 78 insertions, 7 deletions
diff --git a/core/java/android/hardware/biometrics/BiometricManager.java b/core/java/android/hardware/biometrics/BiometricManager.java
index a696eeb6bcc7..6c497d47c645 100644
--- a/core/java/android/hardware/biometrics/BiometricManager.java
+++ b/core/java/android/hardware/biometrics/BiometricManager.java
@@ -207,5 +207,22 @@ public class BiometricManager {
Slog.w(TAG, "onConfirmDeviceCredentialError(): Service not connected");
}
}
+
+ /**
+ * TODO(b/123378871): Remove when moved.
+ * @hide
+ */
+ @RequiresPermission(USE_BIOMETRIC_INTERNAL)
+ public void registerCancellationCallback(IBiometricConfirmDeviceCredentialCallback callback) {
+ if (mService != null) {
+ try {
+ mService.registerCancellationCallback(callback);
+ } catch (RemoteException e) {
+ throw e.rethrowFromSystemServer();
+ }
+ } else {
+ Slog.w(TAG, "registerCancellationCallback(): Service not connected");
+ }
+ }
}
diff --git a/core/java/android/hardware/biometrics/BiometricPrompt.java b/core/java/android/hardware/biometrics/BiometricPrompt.java
index 08035972a0db..1142a07bc66c 100644
--- a/core/java/android/hardware/biometrics/BiometricPrompt.java
+++ b/core/java/android/hardware/biometrics/BiometricPrompt.java
@@ -82,6 +82,11 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
* @hide
*/
public static final String KEY_ALLOW_DEVICE_CREDENTIAL = "allow_device_credential";
+ /**
+ * @hide
+ */
+ public static final String KEY_FROM_CONFIRM_DEVICE_CREDENTIAL
+ = "from_confirm_device_credential";
/**
* Error/help message will show for this amount of time.
@@ -271,6 +276,17 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
}
/**
+ * TODO(123378871): Remove when moved.
+ * @return
+ * @hide
+ */
+ @RequiresPermission(USE_BIOMETRIC_INTERNAL)
+ @NonNull public Builder setFromConfirmDeviceCredential() {
+ mBundle.putBoolean(KEY_FROM_CONFIRM_DEVICE_CREDENTIAL, true);
+ return this;
+ }
+
+ /**
* Creates a {@link BiometricPrompt}.
* @return a {@link BiometricPrompt}
* @throws IllegalArgumentException if any of the required fields are not set.
@@ -494,7 +510,8 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
public void authenticateUser(@NonNull CancellationSignal cancel,
@NonNull @CallbackExecutor Executor executor,
@NonNull AuthenticationCallback callback,
- int userId) {
+ int userId,
+ IBiometricConfirmDeviceCredentialCallback confirmDeviceCredentialCallback) {
if (cancel == null) {
throw new IllegalArgumentException("Must supply a cancellation signal");
}
@@ -504,7 +521,8 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
if (callback == null) {
throw new IllegalArgumentException("Must supply a callback");
}
- authenticateInternal(null /* crypto */, cancel, executor, callback, userId);
+ authenticateInternal(null /* crypto */, cancel, executor, callback, userId,
+ confirmDeviceCredentialCallback);
}
/**
@@ -555,7 +573,8 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
if (mBundle.getBoolean(KEY_ALLOW_DEVICE_CREDENTIAL)) {
throw new IllegalArgumentException("Device credential not supported with crypto");
}
- authenticateInternal(crypto, cancel, executor, callback, mContext.getUserId());
+ authenticateInternal(crypto, cancel, executor, callback, mContext.getUserId(),
+ null /* confirmDeviceCredentialCallback */);
}
/**
@@ -597,7 +616,8 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
if (callback == null) {
throw new IllegalArgumentException("Must supply a callback");
}
- authenticateInternal(null /* crypto */, cancel, executor, callback, mContext.getUserId());
+ authenticateInternal(null /* crypto */, cancel, executor, callback, mContext.getUserId(),
+ null /* confirmDeviceCredentialCallback */);
}
private void cancelAuthentication() {
@@ -614,7 +634,8 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
@NonNull CancellationSignal cancel,
@NonNull @CallbackExecutor Executor executor,
@NonNull AuthenticationCallback callback,
- int userId) {
+ int userId,
+ IBiometricConfirmDeviceCredentialCallback confirmDeviceCredentialCallback) {
try {
if (cancel.isCanceled()) {
Log.w(TAG, "Authentication already canceled");
@@ -629,7 +650,7 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
final long sessionId = crypto != null ? crypto.getOpId() : 0;
if (BiometricManager.hasBiometrics(mContext)) {
mService.authenticate(mToken, sessionId, userId, mBiometricServiceReceiver,
- mContext.getOpPackageName(), mBundle);
+ mContext.getOpPackageName(), mBundle, confirmDeviceCredentialCallback);
} else {
mExecutor.execute(() -> {
callback.onAuthenticationError(BiometricPrompt.BIOMETRIC_ERROR_HW_NOT_PRESENT,
diff --git a/core/java/android/hardware/biometrics/IBiometricConfirmDeviceCredentialCallback.aidl b/core/java/android/hardware/biometrics/IBiometricConfirmDeviceCredentialCallback.aidl
new file mode 100644
index 000000000000..8b35852efd31
--- /dev/null
+++ b/core/java/android/hardware/biometrics/IBiometricConfirmDeviceCredentialCallback.aidl
@@ -0,0 +1,26 @@
+/*
+ * Copyright (C) 2019 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.hardware.biometrics;
+
+/**
+ * Communication channel between ConfirmDeviceCredential / ConfirmLock* and BiometricService.
+ * @hide
+ */
+interface IBiometricConfirmDeviceCredentialCallback {
+ // Invoked when authentication should be canceled.
+ oneway void cancel();
+} \ No newline at end of file
diff --git a/core/java/android/hardware/biometrics/IBiometricService.aidl b/core/java/android/hardware/biometrics/IBiometricService.aidl
index 4971911eb87c..90d4921c3c18 100644
--- a/core/java/android/hardware/biometrics/IBiometricService.aidl
+++ b/core/java/android/hardware/biometrics/IBiometricService.aidl
@@ -17,6 +17,7 @@
package android.hardware.biometrics;
import android.os.Bundle;
+import android.hardware.biometrics.IBiometricConfirmDeviceCredentialCallback;
import android.hardware.biometrics.IBiometricEnabledOnKeyguardCallback;
import android.hardware.biometrics.IBiometricServiceReceiver;
@@ -30,8 +31,10 @@ import android.hardware.biometrics.IBiometricServiceReceiver;
interface IBiometricService {
// Requests authentication. The service choose the appropriate biometric to use, and show
// the corresponding BiometricDialog.
+ // TODO(b/123378871): Remove callback when moved.
void authenticate(IBinder token, long sessionId, int userId,
- IBiometricServiceReceiver receiver, String opPackageName, in Bundle bundle);
+ IBiometricServiceReceiver receiver, String opPackageName, in Bundle bundle,
+ IBiometricConfirmDeviceCredentialCallback callback);
// Cancel authentication for the given sessionId
void cancelAuthentication(IBinder token, String opPackageName);
@@ -59,4 +62,8 @@ interface IBiometricService {
void onConfirmDeviceCredentialSuccess();
// TODO(b/123378871): Remove when moved.
void onConfirmDeviceCredentialError(int error, String message);
+ // TODO(b/123378871): Remove when moved.
+ // When ConfirmLock* is invoked from BiometricPrompt, it needs to register a callback so that
+ // it can receive the cancellation signal.
+ void registerCancellationCallback(IBiometricConfirmDeviceCredentialCallback callback);
}