Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e0e58521 authored by Curtis Belmonte's avatar Curtis Belmonte Committed by Android (Google) Code Review
Browse files

Merge "Add auth type to BiometricPrompt.AuthenticationResult"

parents e84964fa 6601bc34
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -16852,6 +16852,8 @@ package android.hardware.biometrics {
    method @Nullable public CharSequence getSubtitle();
    method @NonNull public CharSequence getTitle();
    method public boolean isConfirmationRequired();
    field public static final int AUTHENTICATION_RESULT_TYPE_BIOMETRIC = 2; // 0x2
    field public static final int AUTHENTICATION_RESULT_TYPE_DEVICE_CREDENTIAL = 1; // 0x1
    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
@@ -16881,6 +16883,7 @@ package android.hardware.biometrics {
  }
  public static class BiometricPrompt.AuthenticationResult {
    method public int getAuthenticationType();
    method public android.hardware.biometrics.BiometricPrompt.CryptoObject getCryptoObject();
  }
+20 −4
Original line number Diff line number Diff line
@@ -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
+48 −9
Original line number Diff line number Diff line
@@ -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);
            });
        }
@@ -575,29 +580,63 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
        }
    }

    /**
     * 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();
        }
    }

    /**
+2 −2
Original line number Diff line number Diff line
@@ -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.
+2 −1
Original line number Diff line number Diff line
@@ -1400,7 +1400,8 @@ public class BiometricService extends SystemService {
                    if (mCurrentAuthSession.mTokenEscrow != null) {
                        mKeyStore.addAuthToken(mCurrentAuthSession.mTokenEscrow);
                    }
                    mCurrentAuthSession.mClientReceiver.onAuthenticationSucceeded();
                    mCurrentAuthSession.mClientReceiver.onAuthenticationSucceeded(
                            Utils.getAuthenticationTypeForResult(reason));
                    break;

                case BiometricPrompt.DISMISSED_REASON_NEGATIVE:
Loading