diff options
| author | Kevin Chyn <kchyn@google.com> | 2021-03-17 22:21:25 -0700 |
|---|---|---|
| committer | Kevin Chyn <kchyn@google.com> | 2021-03-18 12:58:10 -0700 |
| commit | f8e775a3570420cbb565e464f00506ca3e69af3a (patch) | |
| tree | c78e25bc9542433bb44f3baa99ead34023479cd6 /core/java | |
| parent | 42968075d614229cc69f07cbd047108ad1f59216 (diff) | |
Add BiometricPrompt.Builder#setAllowedSensorIds TestApi
Bug: 163058911
Test: atest CtsBiometricsTestCases
Change-Id: I7007e6f9803051b43d4d4909e210f3b6013b5538
Diffstat (limited to 'core/java')
3 files changed, 57 insertions, 29 deletions
diff --git a/core/java/android/hardware/biometrics/BiometricManager.java b/core/java/android/hardware/biometrics/BiometricManager.java index acfad1354ccf..304b2afc1adb 100644 --- a/core/java/android/hardware/biometrics/BiometricManager.java +++ b/core/java/android/hardware/biometrics/BiometricManager.java @@ -48,13 +48,6 @@ public class BiometricManager { private static final String TAG = "BiometricManager"; /** - * An ID that should match any biometric sensor on the device. - * - * @hide - */ - public static final int SENSOR_ID_ANY = -1; - - /** * No error detected. */ public static final int BIOMETRIC_SUCCESS = diff --git a/core/java/android/hardware/biometrics/BiometricPrompt.java b/core/java/android/hardware/biometrics/BiometricPrompt.java index 4f6a7c75cca6..125824707402 100644 --- a/core/java/android/hardware/biometrics/BiometricPrompt.java +++ b/core/java/android/hardware/biometrics/BiometricPrompt.java @@ -16,6 +16,7 @@ package android.hardware.biometrics; +import static android.Manifest.permission.TEST_BIOMETRIC; import static android.Manifest.permission.USE_BIOMETRIC; import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL; import static android.hardware.biometrics.BiometricManager.Authenticators; @@ -25,6 +26,7 @@ import android.annotation.IntDef; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; +import android.annotation.TestApi; import android.content.Context; import android.content.DialogInterface; import android.hardware.face.FaceManager; @@ -45,6 +47,7 @@ import com.android.internal.R; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.security.Signature; +import java.util.List; import java.util.concurrent.Executor; import javax.crypto.Cipher; @@ -339,6 +342,32 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan } /** + * If non-empty, requests authentication to be performed only if the sensor is contained + * within the list. Note that the actual sensor presented to the user/test will meet all + * constraints specified within this builder. For example, on a device with the below + * configuration: + * + * SensorId: 1, Strength: BIOMETRIC_STRONG + * SensorId: 2, Strength: BIOMETRIC_WEAK + * + * If authentication is invoked with setAllowedAuthenticators(BIOMETRIC_STRONG) and + * setAllowedSensorIds(2), then no sensor will be eligible for authentication. + * + * @see {@link BiometricManager#getSensorProperties()} + * + * @param sensorIds Sensor IDs to constrain this authentication to. + * @return This builder + * @hide + */ + @TestApi + @NonNull + @RequiresPermission(anyOf = {TEST_BIOMETRIC, USE_BIOMETRIC_INTERNAL}) + public Builder setAllowedSensorIds(@NonNull List<Integer> sensorIds) { + mPromptInfo.setAllowedSensorIds(sensorIds); + return this; + } + + /** * If set check the Device Policy Manager for disabled biometrics. * * @param checkDevicePolicyManager @@ -364,21 +393,6 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan } /** - * If set, authenticate using the biometric sensor with the given ID. - * - * @param sensorId The ID of a biometric sensor, or -1 to allow any sensor (default). - * @return This builder. - * - * @hide - */ - @RequiresPermission(USE_BIOMETRIC_INTERNAL) - @NonNull - public Builder setSensorId(int sensorId) { - mPromptInfo.setSensorId(sensorId); - return this; - } - - /** * Creates a {@link BiometricPrompt}. * * @return An instance of {@link BiometricPrompt}. @@ -596,6 +610,16 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan } /** + * @return The values set by {@link Builder#setAllowedSensorIds(List)} + * @hide + */ + @TestApi + @NonNull + public List<Integer> getAllowedSensorIds() { + return mPromptInfo.getAllowedSensorIds(); + } + + /** * A wrapper class for the cryptographic operations supported by BiometricPrompt. * * <p>Currently the framework supports {@link Signature}, {@link Cipher}, {@link Mac}, and diff --git a/core/java/android/hardware/biometrics/PromptInfo.java b/core/java/android/hardware/biometrics/PromptInfo.java index 0e99f31d3b52..20c25fb82b4c 100644 --- a/core/java/android/hardware/biometrics/PromptInfo.java +++ b/core/java/android/hardware/biometrics/PromptInfo.java @@ -21,6 +21,9 @@ import android.annotation.Nullable; import android.os.Parcel; import android.os.Parcelable; +import java.util.ArrayList; +import java.util.List; + /** * Contains the information set/requested by the caller of the {@link BiometricPrompt} * @hide @@ -40,7 +43,7 @@ public class PromptInfo implements Parcelable { private @BiometricManager.Authenticators.Types int mAuthenticators; private boolean mDisallowBiometricsIfPolicyExists; private boolean mReceiveSystemEvents; - private int mSensorId = -1; + @NonNull private List<Integer> mAllowedSensorIds = new ArrayList<>(); public PromptInfo() { @@ -60,7 +63,7 @@ public class PromptInfo implements Parcelable { mAuthenticators = in.readInt(); mDisallowBiometricsIfPolicyExists = in.readBoolean(); mReceiveSystemEvents = in.readBoolean(); - mSensorId = in.readInt(); + mAllowedSensorIds = in.readArrayList(Integer.class.getClassLoader()); } public static final Creator<PromptInfo> CREATOR = new Creator<PromptInfo>() { @@ -95,7 +98,14 @@ public class PromptInfo implements Parcelable { dest.writeInt(mAuthenticators); dest.writeBoolean(mDisallowBiometricsIfPolicyExists); dest.writeBoolean(mReceiveSystemEvents); - dest.writeInt(mSensorId); + dest.writeList(mAllowedSensorIds); + } + + public boolean containsTestConfigurations() { + if (!mAllowedSensorIds.isEmpty()) { + return true; + } + return false; } public boolean containsPrivateApiConfigurations() { @@ -169,8 +179,8 @@ public class PromptInfo implements Parcelable { mReceiveSystemEvents = receiveSystemEvents; } - public void setSensorId(int sensorId) { - mSensorId = sensorId; + public void setAllowedSensorIds(@NonNull List<Integer> sensorIds) { + mAllowedSensorIds = sensorIds; } // Getters @@ -234,7 +244,8 @@ public class PromptInfo implements Parcelable { return mReceiveSystemEvents; } - public int getSensorId() { - return mSensorId; + @NonNull + public List<Integer> getAllowedSensorIds() { + return mAllowedSensorIds; } } |
