Add auth type to BiometricPrompt.AuthenticationResult

Now that BiometricPrompt supports primary auth via device credential,
we want the high-level type of authentication used to be available to a
developer via the AuthenticationResult in onAuthenticationSucceeded.
Rather than include information about the strength of the biometric
sensor by reusing the existing Authenticators.Types constants, this
commit adds new integer constants that provide similar information but
at a lower level of granularity (device credential vs. biometric).

Test: atest com.android.server.biometrics
Test: atest com.android.systemui.biometrics
Test: Manually inspect new AuthenticationResult object on Pixel 3/4

Bug: 80525177
Bug: 141025588

Change-Id: Ic09ffdff995afe374f11721e6e777632de9ae867
This commit is contained in:
Curtis Belmonte
2020-01-09 17:46:31 -08:00
parent 193c7167d5
commit 6601bc3403
8 changed files with 124 additions and 18 deletions

View File

@@ -18,6 +18,7 @@ package android.hardware.biometrics;
import android.annotation.CallbackExecutor;
import android.annotation.NonNull;
import android.hardware.biometrics.BiometricPrompt.AuthenticationResultType;
import android.os.CancellationSignal;
import android.os.Parcelable;
@@ -119,6 +120,7 @@ public interface BiometricAuthenticator {
class AuthenticationResult {
private Identifier mIdentifier;
private CryptoObject mCryptoObject;
private @AuthenticationResultType int mAuthenticationType;
private int mUserId;
/**
@@ -129,26 +131,40 @@ public interface BiometricAuthenticator {
/**
* Authentication result
* @param crypto
* @param authenticationType
* @param identifier
* @param userId
* @hide
*/
public AuthenticationResult(CryptoObject crypto, Identifier identifier,
public AuthenticationResult(CryptoObject crypto,
@AuthenticationResultType int authenticationType, Identifier identifier,
int userId) {
mCryptoObject = crypto;
mAuthenticationType = authenticationType;
mIdentifier = identifier;
mUserId = userId;
}
/**
* Obtain the crypto object associated with this transaction
* @return crypto object provided to {@link BiometricAuthenticator#authenticate(
* CryptoObject, CancellationSignal, Executor, AuthenticationCallback)}
* Provides the crypto object associated with this transaction.
* @return The crypto object provided to {@link BiometricPrompt#authenticate(
* BiometricPrompt.CryptoObject, CancellationSignal, Executor,
* BiometricPrompt.AuthenticationCallback)}
*/
public CryptoObject getCryptoObject() {
return mCryptoObject;
}
/**
* Provides the type of authentication (e.g. device credential or biometric) that was
* requested from and successfully provided by the user.
*
* @return An integer value representing the authentication method used.
*/
public @AuthenticationResultType int getAuthenticationType() {
return mAuthenticationType;
}
/**
* Obtain the biometric identifier associated with this operation. Applications are strongly
* discouraged from associating specific identifiers with specific applications or

View File

@@ -21,6 +21,7 @@ import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
import static android.hardware.biometrics.BiometricManager.Authenticators;
import android.annotation.CallbackExecutor;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.RequiresPermission;
@@ -40,6 +41,8 @@ import android.util.Log;
import com.android.internal.R;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.security.Signature;
import java.util.concurrent.Executor;
@@ -397,9 +400,11 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
new IBiometricServiceReceiver.Stub() {
@Override
public void onAuthenticationSucceeded() throws RemoteException {
public void onAuthenticationSucceeded(@AuthenticationResultType int authenticationType)
throws RemoteException {
mExecutor.execute(() -> {
final AuthenticationResult result = new AuthenticationResult(mCryptoObject);
final AuthenticationResult result =
new AuthenticationResult(mCryptoObject, authenticationType);
mAuthenticationCallback.onAuthenticationSucceeded(result);
});
}
@@ -576,28 +581,62 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
}
/**
* Container for callback data from {@link #authenticate( CancellationSignal, Executor,
* Authentication type reported by {@link AuthenticationResult} when the user authenticated by
* entering their device PIN, pattern, or password.
*/
public static final int AUTHENTICATION_RESULT_TYPE_DEVICE_CREDENTIAL = 1;
/**
* Authentication type reported by {@link AuthenticationResult} when the user authenticated by
* presenting some form of biometric (e.g. fingerprint or face).
*/
public static final int AUTHENTICATION_RESULT_TYPE_BIOMETRIC = 2;
/**
* An {@link IntDef} representing the type of auth, as reported by {@link AuthenticationResult}.
* @hide
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef({AUTHENTICATION_RESULT_TYPE_DEVICE_CREDENTIAL, AUTHENTICATION_RESULT_TYPE_BIOMETRIC})
public @interface AuthenticationResultType {
}
/**
* Container for callback data from {@link #authenticate(CancellationSignal, Executor,
* AuthenticationCallback)} and {@link #authenticate(CryptoObject, CancellationSignal, Executor,
* AuthenticationCallback)}
* AuthenticationCallback)}.
*/
public static class AuthenticationResult extends BiometricAuthenticator.AuthenticationResult {
/**
* Authentication result
* @param crypto
* @param authenticationType
* @hide
*/
public AuthenticationResult(CryptoObject crypto) {
public AuthenticationResult(CryptoObject crypto,
@AuthenticationResultType int authenticationType) {
// Identifier and userId is not used for BiometricPrompt.
super(crypto, null /* identifier */, 0 /* userId */);
super(crypto, authenticationType, null /* identifier */, 0 /* userId */);
}
/**
* Obtain the crypto object associated with this transaction
* @return crypto object provided to {@link #authenticate( CryptoObject, CancellationSignal,
* Executor, AuthenticationCallback)}
* Provides the crypto object associated with this transaction.
* @return The crypto object provided to {@link #authenticate(CryptoObject,
* CancellationSignal, Executor, AuthenticationCallback)}
*/
public CryptoObject getCryptoObject() {
return (CryptoObject) super.getCryptoObject();
}
/**
* Provides the type of authentication (e.g. device credential or biometric) that was
* requested from and successfully provided by the user.
*
* @return An integer value representing the authentication method used.
*/
public @AuthenticationResultType int getAuthenticationType() {
return super.getAuthenticationType();
}
}
/**

View File

@@ -20,8 +20,8 @@ package android.hardware.biometrics;
* @hide
*/
oneway interface IBiometricServiceReceiver {
// Notify BiometricPrompt that authentication was successful
void onAuthenticationSucceeded();
// Notify BiometricPrompt that authentication was successful.
void onAuthenticationSucceeded(int authenticationType);
// Noties that authentication failed.
void onAuthenticationFailed();
// Notify BiometricPrompt that an error has occurred.