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

Commit a37cf954 authored by Vincent Wang's avatar Vincent Wang Committed by Android (Google) Code Review
Browse files

Merge "Redesign Biometric API to be transactional"

parents 05562ecd 8b32d017
Loading
Loading
Loading
Loading
+22 −1
Original line number Diff line number Diff line
@@ -472,6 +472,10 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan

        @Override
        public void onCancel() {
            if (!mIsPromptShowing) {
                Log.w(TAG, "BP is not showing");
                return;
            }
            Log.d(TAG, "Cancel BP authentication requested for: " + mAuthRequestId);
            cancelAuthentication(mAuthRequestId);
        }
@@ -496,6 +500,7 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
                final AuthenticationResult result =
                        new AuthenticationResult(mCryptoObject, authenticationType);
                mAuthenticationCallback.onAuthenticationSucceeded(result);
                mIsPromptShowing = false;
            });
        }

@@ -503,6 +508,7 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
        public void onAuthenticationFailed() {
            mExecutor.execute(() -> {
                mAuthenticationCallback.onAuthenticationFailed();
                mIsPromptShowing = false;
            });
        }

@@ -550,6 +556,7 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            final String stringToSend = errorMessage;
            mExecutor.execute(() -> {
                mAuthenticationCallback.onAuthenticationError(error, stringToSend);
                mIsPromptShowing = false;
            });
        }

@@ -566,8 +573,10 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            if (reason == DISMISSED_REASON_NEGATIVE) {
                mNegativeButtonInfo.executor.execute(() -> {
                    mNegativeButtonInfo.listener.onClick(null, DialogInterface.BUTTON_NEGATIVE);
                    mIsPromptShowing = false;
                });
            } else {
                mIsPromptShowing = false;
                Log.e(TAG, "Unknown reason: " + reason);
            }
        }
@@ -580,12 +589,15 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
        }
    };

    private boolean mIsPromptShowing;

    private BiometricPrompt(Context context, PromptInfo promptInfo, ButtonInfo negativeButtonInfo) {
        mContext = context;
        mPromptInfo = promptInfo;
        mNegativeButtonInfo = negativeButtonInfo;
        mService = IAuthService.Stub.asInterface(
                ServiceManager.getService(Context.AUTH_SERVICE));
        mIsPromptShowing = false;
    }

    /**
@@ -1095,7 +1107,6 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            @NonNull @CallbackExecutor Executor executor,
            @NonNull AuthenticationCallback callback,
            int userId) {

        // Ensure we don't return the wrong crypto object as an auth result.
        if (mCryptoObject != null && mCryptoObject.getOpId() != operationId) {
            Log.w(TAG, "CryptoObject operation ID does not match argument; setting field to null");
@@ -1110,6 +1121,14 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan

            mExecutor = executor;
            mAuthenticationCallback = callback;
            if (mIsPromptShowing) {
                final String stringToSend = mContext.getString(R.string.biometric_error_canceled);
                mExecutor.execute(() -> {
                    mAuthenticationCallback.onAuthenticationError(BIOMETRIC_ERROR_CANCELED,
                            stringToSend);
                });
                return -1;
            }

            final PromptInfo promptInfo;
            if (operationId != 0L) {
@@ -1131,6 +1150,8 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            final long authId = mService.authenticate(mToken, operationId, userId,
                    mBiometricServiceReceiver, mContext.getPackageName(), promptInfo);
            cancel.setOnCancelListener(new OnAuthenticationCancelListener(authId));
            mIsPromptShowing = true;

            return authId;
        } catch (RemoteException e) {
            Log.e(TAG, "Remote exception while authenticating", e);