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

Commit 39b6c397 authored by Diya Bera's avatar Diya Bera
Browse files

Update mState if try again is successful

Test: atest AuthSessionTest
Fixes: 341443262
Change-Id: I37ae8b5de7af25ee716a2972d389e2f061465c3f
parent 270dc7d7
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -265,6 +265,8 @@ public final class AuthSession implements IBinder.DeathRecipient {
                    && state != BiometricSensor.STATE_CANCELING) {
                Slog.d(TAG, "Skip retry because sensor: " + sensor.id + " is: " + state);
                continue;
            } else if (isTryAgain) {
                mState = STATE_AUTH_PAUSED_RESUMING;
            }

            final int cookie = mRandom.nextInt(Integer.MAX_VALUE - 1) + 1;
@@ -617,7 +619,6 @@ public final class AuthSession implements IBinder.DeathRecipient {

        try {
            setSensorsToStateWaitingForCookie(true /* isTryAgain */);
            mState = STATE_AUTH_PAUSED_RESUMING;
        } catch (RemoteException e) {
            Slog.e(TAG, "RemoteException: " + e);
        }
+63 −0
Original line number Diff line number Diff line
@@ -602,6 +602,69 @@ public class AuthSessionTest {
                eq(0) /* userId */);
    }

    @Test
    public void onErrorReceivedAfterOnTryAgainPressedWhenSensorsAuthenticating() throws Exception {
        setupFingerprint(0 /* id */, FingerprintSensorProperties.TYPE_UDFPS_OPTICAL);
        setupFace(1 /* id */, false, mock(IBiometricAuthenticator.class));
        final long operationId = 123;
        final int userId = 10;
        final AuthSession session = createAuthSession(mSensors,
                false /* checkDevicePolicyManager */,
                Authenticators.BIOMETRIC_STRONG,
                TEST_REQUEST_ID,
                operationId,
                userId);
        session.goToInitialState();
        for (BiometricSensor sensor : session.mPreAuthInfo.eligibleSensors) {
            session.onCookieReceived(
                    session.mPreAuthInfo.eligibleSensors.get(sensor.id).getCookie());
        }
        session.onDialogAnimatedIn(true /* startFingerprintNow */);

        for (BiometricSensor sensor : session.mPreAuthInfo.eligibleSensors) {
            assertEquals(BiometricSensor.STATE_AUTHENTICATING, sensor.getSensorState());
        }
        session.onTryAgainPressed();
        session.onErrorReceived(0 /* sensorId */,
                session.mPreAuthInfo.eligibleSensors.get(0 /* sensorId */).getCookie(),
                BiometricConstants.BIOMETRIC_ERROR_LOCKOUT_PERMANENT, 0);

        verify(mStatusBarService).onBiometricError(anyInt(), anyInt(), anyInt());
    }

    @Test
    public void onErrorReceivedAfterOnTryAgainPressedWhenSensorStopped() throws Exception {
        setupFingerprint(0 /* id */, FingerprintSensorProperties.TYPE_UDFPS_OPTICAL);
        setupFace(1 /* id */, false, mock(IBiometricAuthenticator.class));
        final long operationId = 123;
        final int userId = 10;
        final AuthSession session = createAuthSession(mSensors,
                false /* checkDevicePolicyManager */,
                Authenticators.BIOMETRIC_STRONG,
                TEST_REQUEST_ID,
                operationId,
                userId);
        session.goToInitialState();
        for (BiometricSensor sensor : session.mPreAuthInfo.eligibleSensors) {
            session.onCookieReceived(
                    session.mPreAuthInfo.eligibleSensors.get(sensor.id).getCookie());
        }
        session.onDialogAnimatedIn(true /* startFingerprintNow */);

        for (BiometricSensor sensor : session.mPreAuthInfo.eligibleSensors) {
            sensor.goToStoppedStateIfCookieMatches(sensor.getCookie(),
                    BiometricConstants.BIOMETRIC_ERROR_TIMEOUT);
            assertEquals(BiometricSensor.STATE_STOPPED, sensor.getSensorState());
        }

        session.onTryAgainPressed();
        session.onErrorReceived(0 /* sensorId */,
                session.mPreAuthInfo.eligibleSensors.get(0 /* sensorId */).getCookie(),
                BiometricConstants.BIOMETRIC_ERROR_LOCKOUT_PERMANENT, 0);

        verify(mStatusBarService, never()).onBiometricError(anyInt(), anyInt(), anyInt());
    }

    // TODO (b/208484275) : Enable these tests
    // @Test
    // public void testPreAuth_canAuthAndPrivacyDisabled() throws Exception {