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

Commit 8c8a073b authored by Hao Dong's avatar Hao Dong
Browse files

Add listeners for PromptContentViewWithMoreOptionsButton.

Flag: ACONFIG android.hardware.biometrics.custom_biometric_prompt DEVELOPMENT
Bug: 328843028
Test: atest BiometricServiceTest
Test: atest AuthControllerTest
Change-Id: I37362304a4779e60befc7d6179996cb4716db72c
parent 6966243b
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -122,6 +122,15 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
     */
    public static final int DISMISSED_REASON_CREDENTIAL_CONFIRMED = 7;

    /**
     * Dialog is done animating away after user clicked on the button set via
     * {@link PromptContentViewWithMoreOptionsButton.Builder#setMoreOptionsButtonListener(Executor,
     * DialogInterface.OnClickListener)} )}.
     *
     * @hide
     */
    public static final int DISMISSED_REASON_CONTENT_VIEW_MORE_OPTIONS = 8;

    /**
     * @hide
     */
@@ -131,7 +140,8 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
            DISMISSED_REASON_BIOMETRIC_CONFIRM_NOT_REQUIRED,
            DISMISSED_REASON_ERROR,
            DISMISSED_REASON_SERVER_REQUESTED,
            DISMISSED_REASON_CREDENTIAL_CONFIRMED})
            DISMISSED_REASON_CREDENTIAL_CONFIRMED,
            DISMISSED_REASON_CONTENT_VIEW_MORE_OPTIONS})
    @Retention(RetentionPolicy.SOURCE)
    public @interface DismissedReason {}

@@ -654,8 +664,6 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
    private final IAuthService mService;
    private final PromptInfo mPromptInfo;
    private final ButtonInfo mNegativeButtonInfo;
    // TODO(b/328843028): add callback onContentViewMoreOptionsButtonClicked() in
    //  IBiometricServiceReceiver.
    private final ButtonInfo mContentViewMoreOptionsButtonInfo;

    private CryptoObject mCryptoObject;
@@ -745,6 +753,13 @@ public class BiometricPrompt implements BiometricAuthenticator, BiometricConstan
                    mNegativeButtonInfo.listener.onClick(null, DialogInterface.BUTTON_NEGATIVE);
                    mIsPromptShowing = false;
                });
            } else if (reason == DISMISSED_REASON_CONTENT_VIEW_MORE_OPTIONS) {
                if (mContentViewMoreOptionsButtonInfo != null) {
                    mContentViewMoreOptionsButtonInfo.executor.execute(() -> {
                        mContentViewMoreOptionsButtonInfo.listener.onClick(null,
                                DialogInterface.BUTTON_NEGATIVE);
                    });
                }
            } else {
                mIsPromptShowing = false;
                Log.e(TAG, "Unknown reason: " + reason);
+11 −0
Original line number Diff line number Diff line
@@ -444,6 +444,17 @@ public class AuthControllerTest extends SysuiTestCase {
                AdditionalMatchers.aryEq(credentialAttestation));
    }

    @Test
    public void testSendsReasonContentViewMoreOptions_whenButtonPressed() throws Exception {
        showDialog(new int[]{1} /* sensorIds */, false /* credentialAllowed */);
        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_BUTTON_CONTENT_VIEW_MORE_OPTIONS,
                null, /* credentialAttestation */
                mAuthController.mCurrentDialog.getRequestId());
        verify(mReceiver).onDialogDismissed(
                eq(BiometricPrompt.DISMISSED_REASON_CONTENT_VIEW_MORE_OPTIONS),
                eq(null) /* credentialAttestation */);
    }

    // Statusbar tests

    @Test
+5 −0
Original line number Diff line number Diff line
@@ -217,6 +217,11 @@ public class AuthContainerView extends LinearLayout
            mConfig.mCallback.onTryAgainPressed(getRequestId());
        }

        @Override
        public void onContentViewMoreOptionsButtonPressed() {
            animateAway(AuthDialogCallback.DISMISSED_BUTTON_CONTENT_VIEW_MORE_OPTIONS);
        }

        @Override
        public void onError() {
            animateAway(AuthDialogCallback.DISMISSED_ERROR);
+8 −3
Original line number Diff line number Diff line
@@ -205,12 +205,12 @@ public class AuthController implements
            if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) {
                String reason = intent.getStringExtra("reason");
                reason = (reason != null) ? reason : "unknown";
                closeDioalog(reason);
                closeDialog(reason);
            }
        }
    };

    private void closeDioalog(String reason) {
    private void closeDialog(String reason) {
        if (isShowing()) {
            Log.i(TAG, "Close BP, reason :" + reason);
            mCurrentDialog.dismissWithoutCallback(true /* animate */);
@@ -571,6 +571,11 @@ public class AuthController implements
                        credentialAttestation);
                break;

            case AuthDialogCallback.DISMISSED_BUTTON_CONTENT_VIEW_MORE_OPTIONS:
                sendResultAndCleanUp(
                        BiometricPrompt.DISMISSED_REASON_CONTENT_VIEW_MORE_OPTIONS,
                        credentialAttestation);
                break;
            default:
                Log.e(TAG, "Unhandled reason: " + reason);
                break;
@@ -579,7 +584,7 @@ public class AuthController implements

    @Override
    public void handleShowGlobalActionsMenu() {
        closeDioalog("PowerMenu shown");
        closeDialog("PowerMenu shown");
    }

    /**
+3 −1
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ public interface AuthDialogCallback {
    int DISMISSED_ERROR = 5;
    int DISMISSED_BY_SYSTEM_SERVER = 6;
    int DISMISSED_CREDENTIAL_AUTHENTICATED = 7;
    int DISMISSED_BUTTON_CONTENT_VIEW_MORE_OPTIONS = 8;

    @IntDef({DISMISSED_USER_CANCELED,
            DISMISSED_BUTTON_NEGATIVE,
@@ -39,7 +40,8 @@ public interface AuthDialogCallback {
            DISMISSED_BIOMETRIC_AUTHENTICATED,
            DISMISSED_ERROR,
            DISMISSED_BY_SYSTEM_SERVER,
            DISMISSED_CREDENTIAL_AUTHENTICATED})
            DISMISSED_CREDENTIAL_AUTHENTICATED,
            DISMISSED_BUTTON_CONTENT_VIEW_MORE_OPTIONS})
    @interface DismissedReason {}

    /**
Loading