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

Commit a847a03c authored by Kevin Chyn's avatar Kevin Chyn
Browse files

Fix corner case when auth is canceled but credential was already confirmed

Bug: 145991060

Test: atest AuthControllerTest

Change-Id: I94cd579c47b1299c498e0736d7f584e32d903029
parent 9670c9e1
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -338,7 +338,13 @@ public class AuthController extends SystemUI implements CommandQueue.Callbacks,

    @Override
    public void hideAuthenticationDialog() {
        if (DEBUG) Log.d(TAG, "hideAuthenticationDialog");
        if (DEBUG) Log.d(TAG, "hideAuthenticationDialog: " + mCurrentDialog);

        if (mCurrentDialog == null) {
            // Could be possible if the caller canceled authentication after credential success
            // but before the client was notified.
            return;
        }

        mCurrentDialog.dismissFromSystemServer();

+18 −1
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import static android.hardware.biometrics.BiometricManager.Authenticators;

import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static junit.framework.TestCase.assertNotNull;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
@@ -291,6 +290,24 @@ public class AuthControllerTest extends SysuiTestCase {

    // Corner case tests

    @Test
    public void testCancelAuthentication_whenCredentialConfirmed_doesntCrash() throws Exception {
        // It's possible that before the client is notified that credential is confirmed, the client
        // requests to cancel authentication.
        //
        // Test that the following sequence of events does not crash SystemUI:
        // 1) Credential is confirmed
        // 2) Client cancels authentication

        showDialog(Authenticators.DEVICE_CREDENTIAL, BiometricPrompt.TYPE_NONE);
        verify(mDialog1).show(any(), any());

        mAuthController.onDismissed(AuthDialogCallback.DISMISSED_CREDENTIAL_AUTHENTICATED);
        verify(mReceiver).onDialogDismissed(BiometricPrompt.DISMISSED_REASON_CREDENTIAL_CONFIRMED);

        mAuthController.hideAuthenticationDialog();
    }

    @Test
    public void testShowNewDialog_beforeOldDialogDismissed_SkipsAnimations() {
        showDialog(Authenticators.BIOMETRIC_WEAK, BiometricPrompt.TYPE_FACE);