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

Commit f50afe81 authored by Beverly's avatar Beverly
Browse files

CancelAodInterrupt in KeyguardUpdateMonitor

Since keyguard FP listening is started from
KeyguardUpdateMonitor, we rely on the callback in KeyguardUpateMonitor
instead of in AuthController for cancelAodInterrupt. The biometric
callback in AuthController is for biometric auth via
the biometric prompt / BiometricService which doesn't get called on
the keyguard/AOD.

Test: atest KeyguardUpdateMonitorTest AuthControllerTest
Fixes: 183962576
Change-Id: I3a0d8de41b27a3df78e72d401ca70f9d4c3cb166
parent d19254d3
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -1294,16 +1294,17 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab

    private final FingerprintManager.AuthenticationCallback mFingerprintAuthenticationCallback
            = new AuthenticationCallback() {

        @Override
        public void onAuthenticationFailed() {
            handleFingerprintAuthFailed();
            mAuthController.onCancelAodInterrupt();
        }

        @Override
        public void onAuthenticationSucceeded(AuthenticationResult result) {
            Trace.beginSection("KeyguardUpdateMonitor#onAuthenticationSucceeded");
            handleFingerprintAuthenticated(result.getUserId(), result.isStrongBiometric());
            mAuthController.onCancelAodInterrupt();
            Trace.endSection();
        }

@@ -1315,6 +1316,7 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
        @Override
        public void onAuthenticationError(int errMsgId, CharSequence errString) {
            handleFingerprintError(errMsgId, errString.toString());
            mAuthController.onCancelAodInterrupt();
        }

        @Override
+11 −3
Original line number Diff line number Diff line
@@ -290,7 +290,7 @@ public class AuthController extends SystemUI implements CommandQueue.Callbacks,
     * called when authentication either succeeds or fails. Failing to cancel the scan will leave
     * the screen in high brightness mode.
     */
    private void onCancelAodInterrupt() {
    public void onCancelAodInterrupt() {
        if (mUdfpsController == null) {
            return;
        }
@@ -397,10 +397,14 @@ public class AuthController extends SystemUI implements CommandQueue.Callbacks,
        showDialog(args, skipAnimation, null /* savedState */);
    }

    /**
     * Only called via BiometricService for the biometric prompt. Will not be called for
     * authentication directly requested through FingerprintManager. For
     * example, KeyguardUpdateMonitor has its own {@link FingerprintManager.AuthenticationCallback}.
     */
    @Override
    public void onBiometricAuthenticated() {
        mCurrentDialog.onAuthenticationSucceeded();
        onCancelAodInterrupt();
    }

    @Override
@@ -428,6 +432,11 @@ public class AuthController extends SystemUI implements CommandQueue.Callbacks,
        }
    }

    /**
     * Only called via BiometricService for the biometric prompt. Will not be called for
     * authentication directly requested through FingerprintManager. For
     * example, KeyguardUpdateMonitor has its own {@link FingerprintManager.AuthenticationCallback}.
     */
    @Override
    public void onBiometricError(int modality, int error, int vendorCode) {
        if (DEBUG) {
@@ -455,7 +464,6 @@ public class AuthController extends SystemUI implements CommandQueue.Callbacks,
            if (DEBUG) Log.d(TAG, "onBiometricError, hard error: " + errorMessage);
            mCurrentDialog.onError(errorMessage);
        }
        onCancelAodInterrupt();
    }

    @Override
+40 −0
Original line number Diff line number Diff line
@@ -517,6 +517,46 @@ public class KeyguardUpdateMonitorTest extends SysuiTestCase {
        verify(mFaceManager).authenticate(any(), any(), any(), any(), anyInt());
    }

    @Test
    public void testFingerprintCancelAodInterrupt_onAuthenticationFailed() {
        // GIVEN on keyguard and listening for fingerprint authentication
        mKeyguardUpdateMonitor.dispatchStartedGoingToSleep(0 /* why */);
        mTestableLooper.processAllMessages();

        ArgumentCaptor<FingerprintManager.AuthenticationCallback> fingerprintCallbackCaptor =
                ArgumentCaptor.forClass(FingerprintManager.AuthenticationCallback.class);
        verify(mFingerprintManager).authenticate(any(), any(), fingerprintCallbackCaptor.capture(),
                any(), anyInt(), anyInt());
        FingerprintManager.AuthenticationCallback authCallback =
                fingerprintCallbackCaptor.getValue();

        // WHEN authentication fails
        authCallback.onAuthenticationFailed();

        // THEN aod interrupt is cancelled
        verify(mAuthController).onCancelAodInterrupt();
    }

    @Test
    public void testFingerprintCancelAodInterrupt_onAuthenticationError() {
        // GIVEN on keyguard and listening for fingerprint authentication
        mKeyguardUpdateMonitor.dispatchStartedGoingToSleep(0 /* why */);
        mTestableLooper.processAllMessages();

        ArgumentCaptor<FingerprintManager.AuthenticationCallback> fingerprintCallbackCaptor =
                ArgumentCaptor.forClass(FingerprintManager.AuthenticationCallback.class);
        verify(mFingerprintManager).authenticate(any(), any(), fingerprintCallbackCaptor.capture(),
                any(), anyInt(), anyInt());
        FingerprintManager.AuthenticationCallback authCallback =
                fingerprintCallbackCaptor.getValue();

        // WHEN authentication errors
        authCallback.onAuthenticationError(0, "");

        // THEN aod interrupt is cancelled
        verify(mAuthController).onCancelAodInterrupt();
    }

    @Test
    public void skipsAuthentication_whenStatusBarShadeLocked() {
        mStatusBarStateListener.onStateChanged(StatusBarState.SHADE_LOCKED);
+0 −14
Original line number Diff line number Diff line
@@ -509,20 +509,6 @@ public class AuthControllerTest extends SysuiTestCase {
        verify(mUdfpsController).onAodInterrupt(eq(pos), eq(pos), eq(majorMinor), eq(majorMinor));
    }

    @Test
    public void testOnBiometricAuthenticated_OnCancelAodInterrupt() {
        showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */);
        mAuthController.onBiometricAuthenticated();
        verify(mUdfpsController).onCancelAodInterrupt();
    }

    @Test
    public void testOnBiometricError_OnCancelAodInterrupt() {
        showDialog(new int[] {1} /* sensorIds */, false /* credentialAllowed */);
        mAuthController.onBiometricError(0, 0, 0);
        verify(mUdfpsController).onCancelAodInterrupt();
    }

    // Helpers

    private void showDialog(int[] sensorIds, boolean credentialAllowed) {