Add setAllowedAuthenticators(int) to BiometricPrompt
Introduces a BiometricPrompt.PromptInfo#setAllowedAuthenticators(int)
method to allow a caller to specify whether to allow BiometricPrompt to
authenticate with device credential, biometric auth, or either. Also
renames the non-public Authenticator class to Authenticators, to avoid a
name collision and potential confusion with other Authenticator classes.
Test: make -j update-api
Test: atest AuthBiometricViewTest
Test: atest AuthContainerViewTest
Test: atest AuthControllerTest
Test: atest BiometricServiceTest
Bug: 80525177
Change-Id: I51da3ff0dcc7e49adb2d7f1c9cdaa12a55b11565
diff --git a/api/current.txt b/api/current.txt
index 243b0e1..771d8c8 100644
--- a/api/current.txt
+++ b/api/current.txt
@@ -16782,9 +16782,21 @@
field public static final int BIOMETRIC_SUCCESS = 0; // 0x0
}
+ public static interface BiometricManager.Authenticators {
+ field public static final int BIOMETRIC_STRONG = 15; // 0xf
+ field public static final int BIOMETRIC_WEAK = 255; // 0xff
+ field public static final int DEVICE_CREDENTIAL = 32768; // 0x8000
+ }
+
public class BiometricPrompt {
method @RequiresPermission(android.Manifest.permission.USE_BIOMETRIC) public void authenticate(@NonNull android.hardware.biometrics.BiometricPrompt.CryptoObject, @NonNull android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.hardware.biometrics.BiometricPrompt.AuthenticationCallback);
method @RequiresPermission(android.Manifest.permission.USE_BIOMETRIC) public void authenticate(@NonNull android.os.CancellationSignal, @NonNull java.util.concurrent.Executor, @NonNull android.hardware.biometrics.BiometricPrompt.AuthenticationCallback);
+ method @Nullable public int getAllowedAuthenticators();
+ method @Nullable public CharSequence getDescription();
+ method @Nullable public CharSequence getNegativeButtonText();
+ method @Nullable public CharSequence getSubtitle();
+ method @NonNull public CharSequence getTitle();
+ method public boolean isConfirmationRequired();
field public static final int BIOMETRIC_ACQUIRED_GOOD = 0; // 0x0
field public static final int BIOMETRIC_ACQUIRED_IMAGER_DIRTY = 3; // 0x3
field public static final int BIOMETRIC_ACQUIRED_INSUFFICIENT = 2; // 0x2
@@ -16820,9 +16832,10 @@
public static class BiometricPrompt.Builder {
ctor public BiometricPrompt.Builder(android.content.Context);
method @NonNull public android.hardware.biometrics.BiometricPrompt build();
+ method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setAllowedAuthenticators(int);
method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setConfirmationRequired(boolean);
method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setDescription(@NonNull CharSequence);
- method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setDeviceCredentialAllowed(boolean);
+ method @Deprecated @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setDeviceCredentialAllowed(boolean);
method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setNegativeButton(@NonNull CharSequence, @NonNull java.util.concurrent.Executor, @NonNull android.content.DialogInterface.OnClickListener);
method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setSubtitle(@NonNull CharSequence);
method @NonNull public android.hardware.biometrics.BiometricPrompt.Builder setTitle(@NonNull CharSequence);
diff --git a/api/system-current.txt b/api/system-current.txt
index 7fdf9ed..ab8f4c1 100644
--- a/api/system-current.txt
+++ b/api/system-current.txt
@@ -2172,6 +2172,15 @@
}
+package android.hardware.biometrics {
+
+ public static interface BiometricManager.Authenticators {
+ field public static final int BIOMETRIC_CONVENIENCE = 4095; // 0xfff
+ field public static final int EMPTY_SET = 0; // 0x0
+ }
+
+}
+
package android.hardware.camera2 {
public abstract class CameraDevice implements java.lang.AutoCloseable {
diff --git a/core/java/android/hardware/biometrics/Authenticator.java b/core/java/android/hardware/biometrics/Authenticator.java
deleted file mode 100644
index 6d7e748..0000000
--- a/core/java/android/hardware/biometrics/Authenticator.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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;
-
-/**
- * Type of authenticators defined on a granularity that the BiometricManager / BiometricPrompt
- * supports.
- * @hide
- */
-public class Authenticator {
-
- /**
- * Device credential, e.g. Pin/Pattern/Password.
- */
- public static final int TYPE_CREDENTIAL = 1 << 0;
- /**
- * Encompasses all biometrics on the device, e.g. Fingerprint/Iris/Face.
- */
- public static final int TYPE_BIOMETRIC = 1 << 1;
-
-}
diff --git a/core/java/android/hardware/biometrics/BiometricManager.java b/core/java/android/hardware/biometrics/BiometricManager.java
index f17b3ae..c184fba 100644
--- a/core/java/android/hardware/biometrics/BiometricManager.java
+++ b/core/java/android/hardware/biometrics/BiometricManager.java
@@ -21,6 +21,7 @@
import android.annotation.IntDef;
import android.annotation.RequiresPermission;
+import android.annotation.SystemApi;
import android.annotation.SystemService;
import android.content.Context;
import android.content.pm.PackageManager;
@@ -65,6 +66,77 @@
BIOMETRIC_ERROR_NO_HARDWARE})
@interface BiometricError {}
+ /**
+ * Types of authenticators, defined at a level of granularity supported by
+ * {@link BiometricManager} and {@link BiometricPrompt}.
+ *
+ * <p>Types may combined via bitwise OR into a single integer representing multiple
+ * authenticators (e.g. <code>DEVICE_CREDENTIAL | BIOMETRIC_WEAK</code>).
+ */
+ public interface Authenticators {
+ /**
+ * An {@link IntDef} representing valid combinations of authenticator types.
+ * @hide
+ */
+ @IntDef(flag = true, value = {
+ BIOMETRIC_STRONG,
+ BIOMETRIC_WEAK,
+ DEVICE_CREDENTIAL,
+ })
+ @interface Types {}
+
+ /**
+ * Empty set with no authenticators specified.
+ * @hide
+ */
+ @SystemApi
+ int EMPTY_SET = 0x0;
+
+ /**
+ * Placeholder for the theoretical strongest biometric security tier.
+ * @hide
+ */
+ int BIOMETRIC_MAX_STRENGTH = 0x001;
+
+ /**
+ * Any biometric (e.g. fingerprint, iris, or face) on the device that meets or exceeds the
+ * requirements for <strong>Strong</strong>, as defined by the Android CDD.
+ */
+ int BIOMETRIC_STRONG = 0x00F;
+
+ /**
+ * Any biometric (e.g. fingerprint, iris, or face) on the device that meets or exceeds the
+ * requirements for <strong>Weak</strong>, as defined by the Android CDD.
+ *
+ * <p>Note that this is a superset of {@link #BIOMETRIC_STRONG} and is defined such that
+ * <code>BIOMETRIC_STRONG | BIOMETRIC_WEAK == BIOMETRIC_WEAK</code>.
+ */
+ int BIOMETRIC_WEAK = 0x0FF;
+
+ /**
+ * Any biometric (e.g. fingerprint, iris, or face) on the device that meets or exceeds the
+ * requirements for <strong>Convenience</strong>, as defined by the Android CDD. This
+ * is not a valid parameter to any of the {@link android.hardware.biometrics} APIs, since
+ * the CDD allows only {@link #BIOMETRIC_WEAK} and stronger authenticators to participate.
+ * @hide
+ */
+ @SystemApi
+ int BIOMETRIC_CONVENIENCE = 0xFFF;
+
+ /**
+ * Placeholder for the theoretical weakest biometric security tier.
+ * @hide
+ */
+ int BIOMETRIC_MIN_STRENGTH = 0x7FFF;
+
+ /**
+ * The non-biometric credential used to secure the device (i.e., PIN, pattern, or password).
+ * This should typically only be used in combination with a biometric auth type, such as
+ * {@link #BIOMETRIC_WEAK}.
+ */
+ int DEVICE_CREDENTIAL = 1 << 15;
+ }
+
private final Context mContext;
private final IAuthService mService;
private final boolean mHasHardware;
diff --git a/core/java/android/hardware/biometrics/BiometricPrompt.java b/core/java/android/hardware/biometrics/BiometricPrompt.java
index 9c51b52..6f9c9e6 100644
--- a/core/java/android/hardware/biometrics/BiometricPrompt.java
+++ b/core/java/android/hardware/biometrics/BiometricPrompt.java
@@ -18,6 +18,7 @@
import static android.Manifest.permission.USE_BIOMETRIC;
import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
+import static android.hardware.biometrics.BiometricManager.Authenticators;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
@@ -149,7 +150,7 @@
/**
* A builder that collects arguments to be shown on the system-provided biometric dialog.
- **/
+ */
public static class Builder {
private final Bundle mBundle;
private ButtonInfo mPositiveButtonInfo;
@@ -157,8 +158,8 @@
private Context mContext;
/**
- * Creates a builder for a biometric dialog.
- * @param context
+ * Creates a builder for a {@link BiometricPrompt} dialog.
+ * @param context The {@link Context} that will be used to build the prompt.
*/
public Builder(Context context) {
mBundle = new Bundle();
@@ -166,58 +167,67 @@
}
/**
- * Required: Set the title to display.
- * @param title
- * @return
+ * Required: Sets the title that will be shown on the prompt.
+ * @param title The title to display.
+ * @return This builder.
*/
- @NonNull public Builder setTitle(@NonNull CharSequence title) {
+ @NonNull
+ public Builder setTitle(@NonNull CharSequence title) {
mBundle.putCharSequence(KEY_TITLE, title);
return this;
}
/**
- * For internal use currently. Only takes effect if title is null/empty. Shows a default
- * modality-specific title.
+ * Shows a default, modality-specific title for the prompt if the title would otherwise be
+ * null or empty. Currently for internal use only.
+ * @return This builder.
* @hide
*/
@RequiresPermission(USE_BIOMETRIC_INTERNAL)
- @NonNull public Builder setUseDefaultTitle() {
+ @NonNull
+ public Builder setUseDefaultTitle() {
mBundle.putBoolean(KEY_USE_DEFAULT_TITLE, true);
return this;
}
/**
- * Optional: Set the subtitle to display.
- * @param subtitle
- * @return
+ * Optional: Sets a subtitle that will be shown on the prompt.
+ * @param subtitle The subtitle to display.
+ * @return This builder.
*/
- @NonNull public Builder setSubtitle(@NonNull CharSequence subtitle) {
+ @NonNull
+ public Builder setSubtitle(@NonNull CharSequence subtitle) {
mBundle.putCharSequence(KEY_SUBTITLE, subtitle);
return this;
}
/**
- * Optional: Set the description to display.
- * @param description
- * @return
+ * Optional: Sets a description that will be shown on the prompt.
+ * @param description The description to display.
+ * @return This builder.
*/
- @NonNull public Builder setDescription(@NonNull CharSequence description) {
+ @NonNull
+ public Builder setDescription(@NonNull CharSequence description) {
mBundle.putCharSequence(KEY_DESCRIPTION, description);
return this;
}
/**
- * Required: Set the text for the negative button. This would typically be used as a
- * "Cancel" button, but may be also used to show an alternative method for authentication,
- * such as screen that asks for a backup password.
+ * Required: Sets the text, executor, and click listener for the negative button on the
+ * prompt. This is typically a cancel button, but may be also used to show an alternative
+ * method for authentication, such as a screen that asks for a backup password.
*
- * Note that this should not be set if {@link #setDeviceCredentialAllowed(boolean)}(boolean)
- * is set to true.
+ * <p>Note that this setting is not required, and in fact is explicitly disallowed, if
+ * device credential authentication is enabled via {@link #setAllowedAuthenticators(int)} or
+ * {@link #setDeviceCredentialAllowed(boolean)}.
*
- * @param text
- * @return
+ * @param text Text to be shown on the negative button for the prompt.
+ * @param executor Executor that will be used to run the on click callback.
+ * @param listener Listener containing a callback to be run when the button is pressed.
+ * @return This builder.
*/
- @NonNull public Builder setNegativeButton(@NonNull CharSequence text,
+ @NonNull
+ public Builder setNegativeButton(@NonNull CharSequence text,
@NonNull @CallbackExecutor Executor executor,
@NonNull DialogInterface.OnClickListener listener) {
if (TextUtils.isEmpty(text)) {
@@ -235,70 +245,112 @@
}
/**
- * Optional: A hint to the system to require user confirmation after a biometric has been
- * authenticated. For example, implicit modalities like Face and Iris authentication are
- * passive, meaning they don't require an explicit user action to complete. When set to
- * 'false', the user action (e.g. pressing a button) will not be required. BiometricPrompt
- * will require confirmation by default.
+ * Optional: Sets a hint to the system for whether to require user confirmation after
+ * authentication. For example, implicit modalities like face and iris are passive, meaning
+ * they don't require an explicit user action to complete authentication. If set to true,
+ * these modalities should require the user to take some action (e.g. press a button)
+ * before {@link AuthenticationCallback#onAuthenticationSucceeded(AuthenticationResult)} is
+ * called. Defaults to true.
*
- * A typical use case for not requiring confirmation would be for low-risk transactions,
+ * <p>A typical use case for not requiring confirmation would be for low-risk transactions,
* such as re-authenticating a recently authenticated application. A typical use case for
* requiring confirmation would be for authorizing a purchase.
*
- * Note that this is a hint to the system. The system may choose to ignore the flag. For
- * example, if the user disables implicit authentication in Settings, or if it does not
- * apply to a modality (e.g. Fingerprint). When ignored, the system will default to
- * requiring confirmation.
+ * <p>Note that this just passes a hint to the system, which the system may then ignore. For
+ * example, a value of false may be ignored if the user has disabled implicit authentication
+ * in Settings, or if it does not apply to a particular modality (e.g. fingerprint).
*
- * @param requireConfirmation
+ * @param requireConfirmation true if explicit user confirmation should be required, or
+ * false otherwise.
+ * @return This builder.
*/
- @NonNull public Builder setConfirmationRequired(boolean requireConfirmation) {
+ @NonNull
+ public Builder setConfirmationRequired(boolean requireConfirmation) {
mBundle.putBoolean(KEY_REQUIRE_CONFIRMATION, requireConfirmation);
return this;
}
/**
- * The user will first be prompted to authenticate with biometrics, but also given the
- * option to authenticate with their device PIN, pattern, or password. Developers should
- * first check {@link KeyguardManager#isDeviceSecure()} before enabling this. If the device
- * is not secure, {@link BiometricPrompt#BIOMETRIC_ERROR_NO_DEVICE_CREDENTIAL} will be
- * returned in {@link AuthenticationCallback#onAuthenticationError(int, CharSequence)}}.
+ * Optional: If enabled, the user will first be prompted to authenticate with biometrics,
+ * but also given the option to authenticate with their device PIN, pattern, or password.
+ * Developers should first check {@link KeyguardManager#isDeviceSecure()} before enabling.
+ * If the device is not secure, {@link BiometricPrompt#BIOMETRIC_ERROR_NO_DEVICE_CREDENTIAL}
+ * will be given to {@link AuthenticationCallback#onAuthenticationError(int, CharSequence)}.
* Defaults to false.
*
- * Note that {@link #setNegativeButton(CharSequence, Executor,
- * DialogInterface.OnClickListener)} should not be set if this is set to true.
+ * <p>Note that enabling this option replaces the negative button on the prompt with one
+ * that allows the user to authenticate with their device credential, making it an error to
+ * call {@link #setNegativeButton(CharSequence, Executor, DialogInterface.OnClickListener)}.
*
- * @param allowed When true, the prompt will fall back to ask for the user's device
- * credentials (PIN, pattern, or password).
- * @return
+ * @param allowed true if the prompt should fall back to asking for the user's device
+ * credential (PIN/pattern/password), or false otherwise.
+ * @return This builder.
+ *
+ * @deprecated Replaced by {@link #setAllowedAuthenticators(int)}.
*/
- @NonNull public Builder setDeviceCredentialAllowed(boolean allowed) {
+ @Deprecated
+ @NonNull
+ public Builder setDeviceCredentialAllowed(boolean allowed) {
mBundle.putBoolean(KEY_ALLOW_DEVICE_CREDENTIAL, allowed);
return this;
}
/**
- * Creates a {@link BiometricPrompt}.
- * @return a {@link BiometricPrompt}
- * @throws IllegalArgumentException if any of the required fields are not set.
+ * Optional: Specifies the type(s) of authenticators that may be invoked by
+ * {@link BiometricPrompt} to authenticate the user. Available authenticator types are
+ * defined in {@link Authenticators} and can be combined via bitwise OR. Defaults to:
+ * <ul>
+ * <li>{@link Authenticators#BIOMETRIC_WEAK} for non-crypto authentication, or</li>
+ * <li>{@link Authenticators#BIOMETRIC_STRONG} for crypto-based authentication.</li>
+ * </ul>
+ *
+ * <p>If this method is used and no authenticator of any of the specified types is available
+ * at the time <code>BiometricPrompt#authenticate(...)</code> is called, authentication will
+ * be canceled and {@link AuthenticationCallback#onAuthenticationError(int, CharSequence)}
+ * will be invoked with an appropriate error code.
+ *
+ * <p>This method should be preferred over {@link #setDeviceCredentialAllowed(boolean)} and
+ * overrides the latter if both are used. Using this method to enable device credential
+ * authentication (with {@link Authenticators#DEVICE_CREDENTIAL}) will replace the negative
+ * button on the prompt, making it an error to also call
+ * {@link #setNegativeButton(CharSequence, Executor, DialogInterface.OnClickListener)}.
+ *
+ * @param authenticators A bit field representing all valid authenticator types that may be
+ * invoked by the prompt.
+ * @return This builder.
*/
- @NonNull public BiometricPrompt build() {
+ @NonNull
+ public Builder setAllowedAuthenticators(@Authenticators.Types int authenticators) {
+ mBundle.putInt(KEY_AUTHENTICATORS_ALLOWED, authenticators);
+ return this;
+ }
+
+ /**
+ * Creates a {@link BiometricPrompt}.
+ *
+ * @return An instance of {@link BiometricPrompt}.
+ *
+ * @throws IllegalArgumentException If any required fields are unset, or if given any
+ * invalid combination of field values.
+ */
+ @NonNull
+ public BiometricPrompt build() {
final CharSequence title = mBundle.getCharSequence(KEY_TITLE);
final CharSequence negative = mBundle.getCharSequence(KEY_NEGATIVE_TEXT);
- final boolean useDefaultTitle = mBundle.getBoolean(KEY_USE_DEFAULT_TITLE);
- final boolean allowCredential = mBundle.getBoolean(KEY_ALLOW_DEVICE_CREDENTIAL);
- final Object authenticatorsAllowed = mBundle.get(KEY_AUTHENTICATORS_ALLOWED);
+ final boolean useDefaultTitle = mBundle.getBoolean(KEY_USE_DEFAULT_TITLE, false);
+ final boolean deviceCredentialAllowed = mBundle.getBoolean(KEY_ALLOW_DEVICE_CREDENTIAL);
+ final @Authenticators.Types int authenticators =
+ mBundle.getInt(KEY_AUTHENTICATORS_ALLOWED, 0);
+ final boolean willShowDeviceCredentialButton = deviceCredentialAllowed
+ || (authenticators & Authenticators.DEVICE_CREDENTIAL) != 0;
if (TextUtils.isEmpty(title) && !useDefaultTitle) {
throw new IllegalArgumentException("Title must be set and non-empty");
- } else if (TextUtils.isEmpty(negative) && !allowCredential) {
+ } else if (TextUtils.isEmpty(negative) && !willShowDeviceCredentialButton) {
throw new IllegalArgumentException("Negative text must be set and non-empty");
- } else if (!TextUtils.isEmpty(negative) && allowCredential) {
+ } else if (!TextUtils.isEmpty(negative) && willShowDeviceCredentialButton) {
throw new IllegalArgumentException("Can't have both negative button behavior"
+ " and device credential enabled");
- } else if (authenticatorsAllowed != null && allowCredential) {
- throw new IllegalArgumentException("setAuthenticatorsAllowed and"
- + " setDeviceCredentialAllowed should not be used simultaneously");
}
return new BiometricPrompt(mContext, mBundle, mPositiveButtonInfo, mNegativeButtonInfo);
}
@@ -394,6 +446,75 @@
}
/**
+ * Gets the title for the prompt, as set by {@link Builder#setTitle(CharSequence)}.
+ * @return The title of the prompt, which is guaranteed to be non-null.
+ */
+ @NonNull
+ public CharSequence getTitle() {
+ return mBundle.getCharSequence(KEY_TITLE, "");
+ }
+
+ /**
+ * Whether to use a default modality-specific title. For internal use only.
+ * @return See {@link Builder#setUseDefaultTitle()}.
+ * @hide
+ */
+ @RequiresPermission(USE_BIOMETRIC_INTERNAL)
+ public boolean shouldUseDefaultTitle() {
+ return mBundle.getBoolean(KEY_USE_DEFAULT_TITLE, false);
+ }
+
+ /**
+ * Gets the subtitle for the prompt, as set by {@link Builder#setSubtitle(CharSequence)}.
+ * @return The subtitle for the prompt, or null if the prompt has no subtitle.
+ */
+ @Nullable
+ public CharSequence getSubtitle() {
+ return mBundle.getCharSequence(KEY_SUBTITLE);
+ }
+
+ /**
+ * Gets the description for the prompt, as set by {@link Builder#setDescription(CharSequence)}.
+ * @return The description for the prompt, or null if the prompt has no description.
+ */
+ @Nullable
+ public CharSequence getDescription() {
+ return mBundle.getCharSequence(KEY_DESCRIPTION);
+ }
+
+ /**
+ * Gets the negative button text for the prompt, as set by
+ * {@link Builder#setNegativeButton(CharSequence, Executor, DialogInterface.OnClickListener)}.
+ * @return The negative button text for the prompt, or null if no negative button text was set.
+ */
+ @Nullable
+ public CharSequence getNegativeButtonText() {
+ return mBundle.getCharSequence(KEY_NEGATIVE_TEXT);
+ }
+
+ /**
+ * Determines if explicit user confirmation is required by the prompt, as set by
+ * {@link Builder#setConfirmationRequired(boolean)}.
+ *
+ * @return true if explicit user confirmation is required, or false otherwise.
+ */
+ public boolean isConfirmationRequired() {
+ return mBundle.getBoolean(KEY_REQUIRE_CONFIRMATION, true);
+ }
+
+ /**
+ * Gets the type(s) of authenticators that may be invoked by the prompt to authenticate the
+ * user, as set by {@link Builder#setAllowedAuthenticators(int)}.
+ *
+ * @return A bit field representing the type(s) of authenticators that may be invoked by the
+ * prompt (as defined by {@link Authenticators}), or 0 if this field was not set.
+ */
+ @Nullable
+ public int getAllowedAuthenticators() {
+ return mBundle.getInt(KEY_AUTHENTICATORS_ALLOWED, 0);
+ }
+
+ /**
* A wrapper class for the crypto objects supported by BiometricPrompt. Currently the framework
* supports {@link Signature}, {@link Cipher} and {@link Mac} objects.
*/
@@ -509,10 +630,12 @@
/**
* Authenticates for the given user.
+ *
* @param cancel An object that can be used to cancel authentication
* @param executor An executor to handle callback events
* @param callback An object to receive authentication events
* @param userId The user to authenticate
+ *
* @hide
*/
@RequiresPermission(USE_BIOMETRIC_INTERNAL)
@@ -542,23 +665,33 @@
* authentication errors through {@link AuthenticationCallback}, and button events through the
* corresponding callback set in {@link Builder#setNegativeButton(CharSequence, Executor,
* DialogInterface.OnClickListener)}. It is safe to reuse the {@link BiometricPrompt} object,
- * and calling {@link BiometricPrompt#authenticate( CancellationSignal, Executor,
+ * and calling {@link BiometricPrompt#authenticate(CancellationSignal, Executor,
* AuthenticationCallback)} while an existing authentication attempt is occurring will stop the
* previous client and start a new authentication. The interrupted client will receive a
* cancelled notification through {@link AuthenticationCallback#onAuthenticationError(int,
* CharSequence)}.
*
- * Note: Applications generally should not cancel and start authentication in quick succession.
- * For example, to properly handle authentication across configuration changes, it's recommended
- * to use BiometricPrompt in a fragment with setRetainInstance(true). By doing so, the
- * application will not need to cancel/restart authentication during the configuration change.
+ * <p>Note: Applications generally should not cancel and start authentication in quick
+ * succession. For example, to properly handle authentication across configuration changes, it's
+ * recommended to use BiometricPrompt in a fragment with setRetainInstance(true). By doing so,
+ * the application will not need to cancel/restart authentication during the configuration
+ * change.
*
- * @throws IllegalArgumentException If any of the arguments are null
+ * <p>Per the Android CDD, only biometric authenticators that meet or exceed the requirements
+ * for <strong>Strong</strong> are permitted to integrate with Keystore to perform related
+ * cryptographic operations. Therefore, it is an error to call this method after explicitly
+ * calling {@link Builder#setAllowedAuthenticators(int)} with any value other than
+ * {@link Authenticators#BIOMETRIC_STRONG}.
*
- * @param crypto Object associated with the call
- * @param cancel An object that can be used to cancel authentication
- * @param executor An executor to handle callback events
- * @param callback An object to receive authentication events
+ * @throws IllegalArgumentException If any of the arguments are null, if
+ * {@link Builder#setDeviceCredentialAllowed(boolean)} was explicitly set to true, or if
+ * {@link Builder#setAllowedAuthenticators(int)} was explicitly called with any value other than
+ * {@link Authenticators#BIOMETRIC_STRONG}.
+ *
+ * @param crypto A cryptographic operation to be unlocked after successful authentication.
+ * @param cancel An object that can be used to cancel authentication.
+ * @param executor An executor to handle callback events.
+ * @param callback An object to receive authentication events.
*/
@RequiresPermission(USE_BIOMETRIC)
public void authenticate(@NonNull CryptoObject crypto,
@@ -577,9 +710,20 @@
if (callback == null) {
throw new IllegalArgumentException("Must supply a callback");
}
- if (mBundle.getBoolean(KEY_ALLOW_DEVICE_CREDENTIAL)) {
+
+ @Authenticators.Types int authenticators = mBundle.getInt(
+ KEY_AUTHENTICATORS_ALLOWED, Authenticators.BIOMETRIC_STRONG);
+
+ if (mBundle.getBoolean(KEY_ALLOW_DEVICE_CREDENTIAL)
+ || (authenticators & Authenticators.DEVICE_CREDENTIAL) != 0) {
throw new IllegalArgumentException("Device credential not supported with crypto");
}
+
+ // Disallow any non-Strong biometric authenticator types.
+ if ((authenticators & ~Authenticators.BIOMETRIC_STRONG) != 0) {
+ throw new IllegalArgumentException("Only Strong biometrics supported with crypto");
+ }
+
authenticateInternal(crypto, cancel, executor, callback, mContext.getUserId());
}
@@ -598,16 +742,17 @@
* authentication. The interrupted client will receive a cancelled notification through {@link
* AuthenticationCallback#onAuthenticationError(int, CharSequence)}.
*
- * Note: Applications generally should not cancel and start authentication in quick succession.
- * For example, to properly handle authentication across configuration changes, it's recommended
- * to use BiometricPrompt in a fragment with setRetainInstance(true). By doing so, the
- * application will not need to cancel/restart authentication during the configuration change.
+ * <p>Note: Applications generally should not cancel and start authentication in quick
+ * succession. For example, to properly handle authentication across configuration changes, it's
+ * recommended to use BiometricPrompt in a fragment with setRetainInstance(true). By doing so,
+ * the application will not need to cancel/restart authentication during the configuration
+ * change.
*
- * @throws IllegalArgumentException If any of the arguments are null
+ * @throws IllegalArgumentException If any of the arguments are null.
*
- * @param cancel An object that can be used to cancel authentication
- * @param executor An executor to handle callback events
- * @param callback An object to receive authentication events
+ * @param cancel An object that can be used to cancel authentication.
+ * @param executor An executor to handle callback events.
+ * @param callback An object to receive authentication events.
*/
@RequiresPermission(USE_BIOMETRIC)
public void authenticate(@NonNull CancellationSignal cancel,
@@ -653,8 +798,22 @@
mAuthenticationCallback = callback;
final long sessionId = crypto != null ? crypto.getOpId() : 0;
if (BiometricManager.hasBiometrics(mContext)) {
+ final Bundle bundle;
+ if (crypto != null) {
+ // Allowed authenticators should default to BIOMETRIC_STRONG for crypto auth.
+ // Note that we use a new bundle here so as to not overwrite the application's
+ // preference, since it is possible that the same prompt configuration be used
+ // without a crypto object later.
+ bundle = new Bundle(mBundle);
+ bundle.putInt(KEY_AUTHENTICATORS_ALLOWED,
+ mBundle.getInt(KEY_AUTHENTICATORS_ALLOWED,
+ Authenticators.BIOMETRIC_STRONG));
+ } else {
+ bundle = mBundle;
+ }
+
mService.authenticate(mToken, sessionId, userId, mBiometricServiceReceiver,
- mContext.getOpPackageName(), mBundle);
+ mContext.getOpPackageName(), bundle);
} else {
mExecutor.execute(() -> {
callback.onAuthenticationError(BiometricPrompt.BIOMETRIC_ERROR_HW_NOT_PRESENT,
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java b/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java
index 6b0d3c8..0eb2023 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/AuthController.java
@@ -18,6 +18,7 @@
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FACE;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FINGERPRINT;
+import static android.hardware.biometrics.BiometricManager.Authenticators;
import android.app.ActivityManager;
import android.app.ActivityTaskManager;
@@ -29,7 +30,6 @@
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
-import android.hardware.biometrics.Authenticator;
import android.hardware.biometrics.BiometricConstants;
import android.hardware.biometrics.BiometricPrompt;
import android.hardware.biometrics.IBiometricServiceReceiverInternal;
@@ -416,7 +416,7 @@
// TODO: Clean this up
Bundle bundle = (Bundle) mCurrentDialogArgs.arg1;
bundle.putInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED,
- Authenticator.TYPE_CREDENTIAL);
+ Authenticators.DEVICE_CREDENTIAL);
}
showDialog(mCurrentDialogArgs, true /* skipAnimation */, savedState);
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/Utils.java b/packages/SystemUI/src/com/android/systemui/biometrics/Utils.java
index d6f830d..7d237c4 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/Utils.java
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/Utils.java
@@ -16,23 +16,21 @@
package com.android.systemui.biometrics;
+import static android.hardware.biometrics.BiometricManager.Authenticators;
import static android.view.accessibility.AccessibilityEvent.CONTENT_CHANGE_TYPE_SUBTREE;
import android.annotation.IntDef;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
-import android.hardware.biometrics.Authenticator;
import android.hardware.biometrics.BiometricPrompt;
import android.os.Bundle;
import android.os.UserManager;
import android.util.DisplayMetrics;
-import android.view.View;
import android.view.ViewGroup;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import com.android.internal.widget.LockPatternUtils;
-import com.android.systemui.R;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@@ -71,12 +69,12 @@
static boolean isDeviceCredentialAllowed(Bundle biometricPromptBundle) {
final int authenticators = getAuthenticators(biometricPromptBundle);
- return (authenticators & Authenticator.TYPE_CREDENTIAL) != 0;
+ return (authenticators & Authenticators.DEVICE_CREDENTIAL) != 0;
}
static boolean isBiometricAllowed(Bundle biometricPromptBundle) {
final int authenticators = getAuthenticators(biometricPromptBundle);
- return (authenticators & Authenticator.TYPE_BIOMETRIC) != 0;
+ return (authenticators & Authenticators.BIOMETRIC_WEAK) != 0;
}
static int getAuthenticators(Bundle biometricPromptBundle) {
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricViewTest.java
index df67637..25cc9a3 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthBiometricViewTest.java
@@ -16,6 +16,8 @@
package com.android.systemui.biometrics;
+import static android.hardware.biometrics.BiometricManager.Authenticators;
+
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -24,7 +26,6 @@
import static org.mockito.Mockito.verify;
import android.content.Context;
-import android.hardware.biometrics.Authenticator;
import android.hardware.biometrics.BiometricPrompt;
import android.os.Bundle;
import android.test.suitebuilder.annotation.SmallTest;
@@ -292,9 +293,9 @@
private Bundle buildBiometricPromptBundle(boolean allowDeviceCredential) {
Bundle bundle = new Bundle();
bundle.putCharSequence(BiometricPrompt.KEY_TITLE, "Title");
- int authenticators = Authenticator.TYPE_BIOMETRIC;
+ int authenticators = Authenticators.BIOMETRIC_WEAK;
if (allowDeviceCredential) {
- authenticators |= Authenticator.TYPE_CREDENTIAL;
+ authenticators |= Authenticators.DEVICE_CREDENTIAL;
} else {
bundle.putCharSequence(BiometricPrompt.KEY_NEGATIVE_TEXT, "Negative");
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java
index 6e438e8..162b16e 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthContainerViewTest.java
@@ -16,6 +16,8 @@
package com.android.systemui.biometrics;
+import static android.hardware.biometrics.BiometricManager.Authenticators;
+
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -26,7 +28,6 @@
import static org.mockito.Mockito.verify;
import android.content.Context;
-import android.hardware.biometrics.Authenticator;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricPrompt;
import android.os.Bundle;
@@ -64,7 +65,7 @@
@Test
public void testActionAuthenticated_sendsDismissedAuthenticated() {
- initializeContainer(Authenticator.TYPE_BIOMETRIC);
+ initializeContainer(Authenticators.BIOMETRIC_WEAK);
mAuthContainer.mBiometricCallback.onAction(
AuthBiometricView.Callback.ACTION_AUTHENTICATED);
@@ -73,7 +74,7 @@
@Test
public void testActionUserCanceled_sendsDismissedUserCanceled() {
- initializeContainer(Authenticator.TYPE_BIOMETRIC);
+ initializeContainer(Authenticators.BIOMETRIC_WEAK);
mAuthContainer.mBiometricCallback.onAction(
AuthBiometricView.Callback.ACTION_USER_CANCELED);
@@ -82,7 +83,7 @@
@Test
public void testActionButtonNegative_sendsDismissedButtonNegative() {
- initializeContainer(Authenticator.TYPE_BIOMETRIC);
+ initializeContainer(Authenticators.BIOMETRIC_WEAK);
mAuthContainer.mBiometricCallback.onAction(
AuthBiometricView.Callback.ACTION_BUTTON_NEGATIVE);
@@ -91,7 +92,7 @@
@Test
public void testActionTryAgain_sendsTryAgain() {
- initializeContainer(Authenticator.TYPE_BIOMETRIC);
+ initializeContainer(Authenticators.BIOMETRIC_WEAK);
mAuthContainer.mBiometricCallback.onAction(
AuthBiometricView.Callback.ACTION_BUTTON_TRY_AGAIN);
@@ -100,7 +101,7 @@
@Test
public void testActionError_sendsDismissedError() {
- initializeContainer(Authenticator.TYPE_BIOMETRIC);
+ initializeContainer(Authenticators.BIOMETRIC_WEAK);
mAuthContainer.mBiometricCallback.onAction(
AuthBiometricView.Callback.ACTION_ERROR);
@@ -110,7 +111,7 @@
@Test
public void testActionUseDeviceCredential_sendsOnDeviceCredentialPressed() {
initializeContainer(
- Authenticator.TYPE_BIOMETRIC | Authenticator.TYPE_CREDENTIAL);
+ Authenticators.BIOMETRIC_WEAK | Authenticators.DEVICE_CREDENTIAL);
mAuthContainer.mBiometricCallback.onAction(
AuthBiometricView.Callback.ACTION_USE_DEVICE_CREDENTIAL);
@@ -125,7 +126,7 @@
@Test
public void testAnimateToCredentialUI_invokesStartTransitionToCredentialUI() {
initializeContainer(
- Authenticator.TYPE_BIOMETRIC | Authenticator.TYPE_CREDENTIAL);
+ Authenticators.BIOMETRIC_WEAK | Authenticators.DEVICE_CREDENTIAL);
mAuthContainer.mBiometricView = mock(AuthBiometricView.class);
mAuthContainer.animateToCredentialUI();
@@ -134,7 +135,7 @@
@Test
public void testShowBiometricUI() {
- initializeContainer(Authenticator.TYPE_BIOMETRIC);
+ initializeContainer(Authenticators.BIOMETRIC_WEAK);
assertNotEquals(null, mAuthContainer.mBiometricView);
@@ -146,7 +147,7 @@
@Test
public void testShowCredentialUI_doesNotInflateBiometricUI() {
- initializeContainer(Authenticator.TYPE_CREDENTIAL);
+ initializeContainer(Authenticators.DEVICE_CREDENTIAL);
mAuthContainer.onAttachedToWindowInternal();
diff --git a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java
index f6375fc..6637a08 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/biometrics/AuthControllerTest.java
@@ -16,6 +16,8 @@
package com.android.systemui.biometrics;
+import static android.hardware.biometrics.BiometricManager.Authenticators;
+
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static junit.framework.TestCase.assertNotNull;
@@ -38,7 +40,6 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
-import android.hardware.biometrics.Authenticator;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricConstants;
import android.hardware.biometrics.BiometricPrompt;
@@ -109,28 +110,28 @@
@Test
public void testSendsReasonUserCanceled_whenDismissedByUserCancel() throws Exception {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.onDismissed(AuthDialogCallback.DISMISSED_USER_CANCELED);
verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_USER_CANCEL);
}
@Test
public void testSendsReasonNegative_whenDismissedByButtonNegative() throws Exception {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BUTTON_NEGATIVE);
verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_NEGATIVE);
}
@Test
public void testSendsReasonConfirmed_whenDismissedByButtonPositive() throws Exception {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BUTTON_POSITIVE);
verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRMED);
}
@Test
public void testSendsReasonConfirmNotRequired_whenDismissedByAuthenticated() throws Exception {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BIOMETRIC_AUTHENTICATED);
verify(mReceiver).onDialogDismissed(
BiometricPrompt.DISMISSED_REASON_BIOMETRIC_CONFIRM_NOT_REQUIRED);
@@ -138,14 +139,14 @@
@Test
public void testSendsReasonError_whenDismissedByError() throws Exception {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.onDismissed(AuthDialogCallback.DISMISSED_ERROR);
verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_ERROR);
}
@Test
public void testSendsReasonServerRequested_whenDismissedByServer() throws Exception {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BY_SYSTEM_SERVER);
verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_SERVER_REQUESTED);
}
@@ -153,7 +154,7 @@
@Test
public void testSendsReasonCredentialConfirmed_whenDeviceCredentialAuthenticated()
throws Exception {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.onDismissed(AuthDialogCallback.DISMISSED_CREDENTIAL_AUTHENTICATED);
verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_CREDENTIAL_CONFIRMED);
}
@@ -163,20 +164,20 @@
@Test
public void testShowInvoked_whenSystemRequested()
throws Exception {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
verify(mDialog1).show(any(), any());
}
@Test
public void testOnAuthenticationSucceededInvoked_whenSystemRequested() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.onBiometricAuthenticated();
verify(mDialog1).onAuthenticationSucceeded();
}
@Test
public void testOnAuthenticationFailedInvoked_whenBiometricRejected() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.onBiometricError(BiometricAuthenticator.TYPE_NONE,
BiometricConstants.BIOMETRIC_PAUSED_REJECTED,
0 /* vendorCode */);
@@ -189,7 +190,7 @@
@Test
public void testOnAuthenticationFailedInvoked_whenBiometricTimedOut() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
final int error = BiometricConstants.BIOMETRIC_ERROR_TIMEOUT;
final int vendorCode = 0;
mAuthController.onBiometricError(BiometricAuthenticator.TYPE_FACE, error, vendorCode);
@@ -202,7 +203,7 @@
@Test
public void testOnHelpInvoked_whenSystemRequested() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
final String helpMessage = "help";
mAuthController.onBiometricHelp(helpMessage);
@@ -214,7 +215,7 @@
@Test
public void testOnErrorInvoked_whenSystemRequested() throws Exception {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
final int error = 1;
final int vendorCode = 0;
mAuthController.onBiometricError(BiometricAuthenticator.TYPE_FACE, error, vendorCode);
@@ -227,7 +228,7 @@
@Test
public void testErrorLockout_whenCredentialAllowed_AnimatesToCredentialUI() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
final int error = BiometricConstants.BIOMETRIC_ERROR_LOCKOUT;
final int vendorCode = 0;
@@ -240,7 +241,7 @@
@Test
public void testErrorLockoutPermanent_whenCredentialAllowed_AnimatesToCredentialUI() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
final int error = BiometricConstants.BIOMETRIC_ERROR_LOCKOUT_PERMANENT;
final int vendorCode = 0;
@@ -253,7 +254,7 @@
@Test
public void testErrorLockout_whenCredentialNotAllowed_sendsOnError() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
final int error = BiometricConstants.BIOMETRIC_ERROR_LOCKOUT;
final int vendorCode = 0;
@@ -266,7 +267,7 @@
@Test
public void testErrorLockoutPermanent_whenCredentialNotAllowed_sendsOnError() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
final int error = BiometricConstants.BIOMETRIC_ERROR_LOCKOUT_PERMANENT;
final int vendorCode = 0;
@@ -279,14 +280,14 @@
@Test
public void testDismissWithoutCallbackInvoked_whenSystemRequested() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.hideAuthenticationDialog();
verify(mDialog1).dismissFromSystemServer();
}
@Test
public void testClientNotified_whenDismissedBySystemServer() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.hideAuthenticationDialog();
verify(mDialog1).dismissFromSystemServer();
@@ -298,10 +299,10 @@
@Test
public void testShowNewDialog_beforeOldDialogDismissed_SkipsAnimations() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
verify(mDialog1).show(any(), any());
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
// First dialog should be dismissed without animation
verify(mDialog1).dismissWithoutCallback(eq(false) /* animate */);
@@ -312,7 +313,7 @@
@Test
public void testConfigurationPersists_whenOnConfigurationChanged() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
verify(mDialog1).show(any(), any());
// Return that the UI is in "showing" state
@@ -342,7 +343,7 @@
@Test
public void testConfigurationPersists_whenBiometricFallbackToCredential() {
- showDialog(Authenticator.TYPE_CREDENTIAL | Authenticator.TYPE_BIOMETRIC,
+ showDialog(Authenticators.DEVICE_CREDENTIAL | Authenticators.BIOMETRIC_WEAK,
BiometricPrompt.TYPE_FACE);
verify(mDialog1).show(any(), any());
@@ -361,14 +362,14 @@
// Check that the new dialog was initialized to the credential UI.
ArgumentCaptor<Bundle> captor = ArgumentCaptor.forClass(Bundle.class);
verify(mDialog2).show(any(), captor.capture());
- assertEquals(Authenticator.TYPE_CREDENTIAL,
+ assertEquals(Authenticators.DEVICE_CREDENTIAL,
mAuthController.mLastBiometricPromptBundle
.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED));
}
@Test
public void testClientNotified_whenTaskStackChangesDuringAuthentication() throws Exception {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
List<ActivityManager.RunningTaskInfo> tasks = new ArrayList<>();
ActivityManager.RunningTaskInfo taskInfo = mock(ActivityManager.RunningTaskInfo.class);
@@ -388,21 +389,21 @@
@Test
public void testDoesNotCrash_whenTryAgainPressedAfterDismissal() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.onDismissed(AuthDialogCallback.DISMISSED_USER_CANCELED);
mAuthController.onTryAgainPressed();
}
@Test
public void testDoesNotCrash_whenDeviceCredentialPressedAfterDismissal() {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
mAuthController.onDismissed(AuthDialogCallback.DISMISSED_USER_CANCELED);
mAuthController.onDeviceCredentialPressed();
}
@Test
public void testActionCloseSystemDialogs_dismissesDialogIfShowing() throws Exception {
- showDialog(Authenticator.TYPE_BIOMETRIC, BiometricPrompt.TYPE_FACE);
+ showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);
Intent intent = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
mAuthController.mBroadcastReceiver.onReceive(mContext, intent);
waitForIdleSync();
diff --git a/services/core/java/com/android/server/biometrics/BiometricService.java b/services/core/java/com/android/server/biometrics/BiometricService.java
index 5d36793..a4d092b 100644
--- a/services/core/java/com/android/server/biometrics/BiometricService.java
+++ b/services/core/java/com/android/server/biometrics/BiometricService.java
@@ -23,6 +23,7 @@
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FINGERPRINT;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_IRIS;
import static android.hardware.biometrics.BiometricAuthenticator.TYPE_NONE;
+import static android.hardware.biometrics.BiometricManager.Authenticators;
import android.app.ActivityManager;
import android.app.IActivityManager;
@@ -31,7 +32,6 @@
import android.content.Context;
import android.content.pm.PackageManager;
import android.database.ContentObserver;
-import android.hardware.biometrics.Authenticator;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricConstants;
import android.hardware.biometrics.BiometricPrompt;
@@ -606,14 +606,10 @@
return;
}
- if (bundle.get(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED) != null) {
- checkInternalPermission();
- }
-
Utils.combineAuthenticatorBundles(bundle);
- // Check the usage of this in system server. Need to remove this check if it becomes
- // a public API.
+ // Check the usage of this in system server. Need to remove this check if it becomes a
+ // public API.
final boolean useDefaultTitle =
bundle.getBoolean(BiometricPrompt.KEY_USE_DEFAULT_TITLE, false);
if (useDefaultTitle) {
@@ -1135,10 +1131,11 @@
// If any error is received while preparing the auth session (lockout, etc),
// and if device credential is allowed, just show the credential UI.
if (mPendingAuthSession.isAllowDeviceCredential()) {
- int authenticators = mPendingAuthSession.mBundle
- .getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED, 0);
+ @Authenticators.Types int authenticators =
+ mPendingAuthSession.mBundle.getInt(
+ BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED, 0);
// Disallow biometric and notify SystemUI to show the authentication prompt.
- authenticators &= ~Authenticator.TYPE_BIOMETRIC;
+ authenticators &= ~Authenticators.BIOMETRIC_WEAK;
mPendingAuthSession.mBundle.putInt(
BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED,
authenticators);
@@ -1365,7 +1362,7 @@
if (error != BiometricConstants.BIOMETRIC_SUCCESS && credentialAllowed) {
// If there's a problem but device credential is allowed, only show credential UI.
bundle.putInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED,
- Authenticator.TYPE_CREDENTIAL);
+ Authenticators.DEVICE_CREDENTIAL);
} else if (error != BiometricConstants.BIOMETRIC_SUCCESS) {
// Check for errors, notify callback, and return
try {
@@ -1407,7 +1404,8 @@
// with the cookie. Once all cookies are received, we can show the prompt
// and let the services start authenticating. The cookie should be non-zero.
final int cookie = mRandom.nextInt(Integer.MAX_VALUE - 1) + 1;
- final int authenticators = bundle.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED);
+ final @Authenticators.Types int authenticators = bundle.getInt(
+ BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED, 0);
Slog.d(TAG, "Creating auth session. Modality: " + modality
+ ", cookie: " + cookie
+ ", authenticators: " + authenticators);
@@ -1415,7 +1413,7 @@
// If it's only device credential, we don't need to wait - LockSettingsService is
// always ready to check credential (SystemUI invokes that path).
- if ((authenticators & ~Authenticator.TYPE_CREDENTIAL) != 0) {
+ if ((authenticators & ~Authenticators.DEVICE_CREDENTIAL) != 0) {
modalities.put(modality, cookie);
}
mPendingAuthSession = new AuthSession(modalities, token, sessionId, userId,
@@ -1423,7 +1421,7 @@
modality, requireConfirmation);
try {
- if (authenticators == Authenticator.TYPE_CREDENTIAL) {
+ if (authenticators == Authenticators.DEVICE_CREDENTIAL) {
mPendingAuthSession.mState = STATE_SHOWING_DEVICE_CREDENTIAL;
mCurrentAuthSession = mPendingAuthSession;
mPendingAuthSession = null;
diff --git a/services/core/java/com/android/server/biometrics/Utils.java b/services/core/java/com/android/server/biometrics/Utils.java
index ed5f9de..eb17162 100644
--- a/services/core/java/com/android/server/biometrics/Utils.java
+++ b/services/core/java/com/android/server/biometrics/Utils.java
@@ -16,16 +16,15 @@
package com.android.server.biometrics;
+import static android.hardware.biometrics.BiometricManager.Authenticators;
+
import android.content.Context;
-import android.hardware.biometrics.Authenticator;
import android.hardware.biometrics.BiometricPrompt;
import android.os.Build;
import android.os.Bundle;
import android.os.UserHandle;
import android.provider.Settings;
-import com.android.internal.annotations.VisibleForTesting;
-
public class Utils {
public static boolean isDebugEnabled(Context context, int targetUserId) {
if (targetUserId == UserHandle.USER_NULL) {
@@ -45,32 +44,26 @@
}
/**
- * Combine {@link BiometricPrompt#KEY_ALLOW_DEVICE_CREDENTIAL} with
- * {@link BiometricPrompt#KEY_AUTHENTICATORS_ALLOWED}, as the former is not flexible
- * enough.
+ * Combines {@link BiometricPrompt#KEY_ALLOW_DEVICE_CREDENTIAL} with
+ * {@link BiometricPrompt#KEY_AUTHENTICATORS_ALLOWED}, as the former is not flexible enough.
*/
public static void combineAuthenticatorBundles(Bundle bundle) {
- boolean biometricEnabled = true; // enabled by default
- boolean credentialEnabled = bundle.getBoolean(
- BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL, false);
- if (bundle.get(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED) != null) {
- final int authenticatorFlags =
- bundle.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED);
- biometricEnabled = (authenticatorFlags & Authenticator.TYPE_BIOMETRIC) != 0;
- // Using both KEY_ALLOW_DEVICE_CREDENTIAL and KEY_AUTHENTICATORS_ALLOWED together
- // is not supported. Default to overwriting.
- credentialEnabled = (authenticatorFlags & Authenticator.TYPE_CREDENTIAL) != 0;
- }
-
+ // Cache and remove explicit ALLOW_DEVICE_CREDENTIAL boolean flag from the bundle.
+ final boolean deviceCredentialAllowed =
+ bundle.getBoolean(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL, false);
bundle.remove(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL);
- int authenticators = 0;
- if (biometricEnabled) {
- authenticators |= Authenticator.TYPE_BIOMETRIC;
+ final @Authenticators.Types int authenticators;
+ if (bundle.containsKey(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED)) {
+ // Ignore ALLOW_DEVICE_CREDENTIAL flag if AUTH_TYPES_ALLOWED is defined.
+ authenticators = bundle.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED, 0);
+ } else {
+ // Otherwise, use ALLOW_DEVICE_CREDENTIAL flag along with Weak+ biometrics by default.
+ authenticators = deviceCredentialAllowed
+ ? Authenticators.DEVICE_CREDENTIAL | Authenticators.BIOMETRIC_WEAK
+ : Authenticators.BIOMETRIC_WEAK;
}
- if (credentialEnabled) {
- authenticators |= Authenticator.TYPE_CREDENTIAL;
- }
+
bundle.putInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED, authenticators);
}
@@ -80,6 +73,6 @@
*/
public static boolean isDeviceCredentialAllowed(Bundle bundle) {
final int authenticators = bundle.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED);
- return (authenticators & Authenticator.TYPE_CREDENTIAL) != 0;
+ return (authenticators & Authenticators.DEVICE_CREDENTIAL) != 0;
}
}
diff --git a/services/tests/servicestests/src/com/android/server/biometrics/AuthServiceTest.java b/services/tests/servicestests/src/com/android/server/biometrics/AuthServiceTest.java
index 106a723..8766292 100644
--- a/services/tests/servicestests/src/com/android/server/biometrics/AuthServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/biometrics/AuthServiceTest.java
@@ -104,8 +104,7 @@
}
@Test
- public void testCanAuthenticate_callsBiometricServiceCanAuthenticate() throws
- Exception {
+ public void testCanAuthenticate_callsBiometricServiceCanAuthenticate() throws Exception {
mAuthService = new AuthService(mContext, mInjector);
mAuthService.onStart();
diff --git a/services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java b/services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java
index 4ced421..731db63 100644
--- a/services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java
+++ b/services/tests/servicestests/src/com/android/server/biometrics/BiometricServiceTest.java
@@ -16,6 +16,8 @@
package com.android.server.biometrics;
+import static android.hardware.biometrics.BiometricManager.Authenticators;
+
import static junit.framework.Assert.assertEquals;
import static junit.framework.TestCase.assertNotNull;
@@ -37,7 +39,6 @@
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
-import android.hardware.biometrics.Authenticator;
import android.hardware.biometrics.BiometricAuthenticator;
import android.hardware.biometrics.BiometricConstants;
import android.hardware.biometrics.BiometricPrompt;
@@ -322,7 +323,7 @@
assertEquals(BiometricService.STATE_SHOWING_DEVICE_CREDENTIAL,
mBiometricService.mCurrentAuthSession.mState);
- assertEquals(Authenticator.TYPE_CREDENTIAL,
+ assertEquals(Authenticators.DEVICE_CREDENTIAL,
mBiometricService.mCurrentAuthSession.mBundle
.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED));
verify(mBiometricService.mStatusBarService).showAuthenticationDialog(
@@ -576,7 +577,7 @@
assertNotNull(mBiometricService.mCurrentAuthSession);
assertEquals(BiometricService.STATE_SHOWING_DEVICE_CREDENTIAL,
mBiometricService.mCurrentAuthSession.mState);
- assertEquals(Authenticator.TYPE_CREDENTIAL,
+ assertEquals(Authenticators.DEVICE_CREDENTIAL,
mBiometricService.mCurrentAuthSession.mBundle.getInt(
BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED));
verify(mBiometricService.mStatusBarService).showAuthenticationDialog(
@@ -609,50 +610,55 @@
}
@Test
- public void testCombineAuthenticatorBundle_keyAllowDeviceCredentialAlwaysRemoved() {
- Bundle bundle;
- int authenticators;
+ public void testCombineAuthenticatorBundles_withKeyDeviceCredential_andKeyAuthenticators() {
+ final boolean allowDeviceCredential = false;
+ final @Authenticators.Types int authenticators =
+ Authenticators.DEVICE_CREDENTIAL | Authenticators.BIOMETRIC_WEAK;
+ final Bundle bundle = new Bundle();
- // In:
- // KEY_ALLOW_DEVICE_CREDENTIAL = true
- // KEY_AUTHENTICATORS_ALLOWED = TYPE_BIOMETRIC | TYPE_CREDENTIAL
- // Out:
- // KEY_ALLOW_DEVICE_CREDENTIAL = null
- // KEY_AUTHENTICATORS_ALLOWED = TYPE_BIOMETRIC | TYPE_CREDENTIAL
- bundle = new Bundle();
- bundle.putBoolean(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL, true);
- authenticators = Authenticator.TYPE_CREDENTIAL | Authenticator.TYPE_BIOMETRIC;
+ bundle.putBoolean(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL, allowDeviceCredential);
bundle.putInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED, authenticators);
Utils.combineAuthenticatorBundles(bundle);
- assertNull(bundle.get(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL));
- assertEquals(authenticators, bundle.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED));
- // In:
- // KEY_ALLOW_DEVICE_CREDENTIAL = true
- // KEY_AUTHENTICATORS_ALLOWED = TYPE_BIOMETRIC
- // Out:
- // KEY_ALLOW_DEVICE_CREDENTIAL = null
- // KEY_AUTHENTICATORS_ALLOWED = TYPE_BIOMETRIC | TYPE_CREDENTIAL
- bundle = new Bundle();
- bundle.putBoolean(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL, true);
- authenticators = Authenticator.TYPE_BIOMETRIC;
+ assertNull(bundle.get(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL));
+ assertEquals(bundle.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED), authenticators);
+ }
+
+ @Test
+ public void testCombineAuthenticatorBundles_withNoKeyDeviceCredential_andKeyAuthenticators() {
+ final @Authenticators.Types int authenticators =
+ Authenticators.DEVICE_CREDENTIAL | Authenticators.BIOMETRIC_WEAK;
+ final Bundle bundle = new Bundle();
+
bundle.putInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED, authenticators);
Utils.combineAuthenticatorBundles(bundle);
- assertNull(bundle.get(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL));
- assertEquals(authenticators, bundle.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED));
- // In:
- // KEY_ALLOW_DEVICE_CREDENTIAL = null
- // KEY_AUTHENTICATORS_ALLOWED = TYPE_BIOMETRIC | TYPE_CREDENTIAL
- // Out:
- // KEY_ALLOW_DEVICE_CREDENTIAL = null
- // KEY_AUTHENTICATORS_ALLOWED = TYPE_BIOMETRIC | TYPE_CREDENTIAL
- bundle = new Bundle();
- authenticators = Authenticator.TYPE_BIOMETRIC | Authenticator.TYPE_CREDENTIAL;
- bundle.putInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED, authenticators);
- Utils.combineAuthenticatorBundles(bundle);
assertNull(bundle.get(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL));
- assertEquals(authenticators, bundle.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED));
+ assertEquals(bundle.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED), authenticators);
+ }
+
+ @Test
+ public void testCombineAuthenticatorBundles_withKeyDeviceCredential_andNoKeyAuthenticators() {
+ final boolean allowDeviceCredential = true;
+ final Bundle bundle = new Bundle();
+
+ bundle.putBoolean(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL, allowDeviceCredential);
+ Utils.combineAuthenticatorBundles(bundle);
+
+ assertNull(bundle.get(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL));
+ assertEquals(bundle.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED),
+ Authenticators.DEVICE_CREDENTIAL | Authenticators.BIOMETRIC_WEAK);
+ }
+
+ @Test
+ public void testCombineAuthenticatorBundles_withNoKeyDeviceCredential_andNoKeyAuthenticators() {
+ final Bundle bundle = new Bundle();
+
+ Utils.combineAuthenticatorBundles(bundle);
+
+ assertNull(bundle.get(BiometricPrompt.KEY_ALLOW_DEVICE_CREDENTIAL));
+ assertEquals(bundle.getInt(BiometricPrompt.KEY_AUTHENTICATORS_ALLOWED),
+ Authenticators.BIOMETRIC_WEAK);
}
@Test