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

Commit 3ed961bf authored by Diya Bera's avatar Diya Bera
Browse files

Remove lockout error in BiometricManager

Fixes: 422677001
Test: atest BiometricServiceTest UtilsTest
Flag: android.hardware.biometrics.bp_fallback_options
Change-Id: I8e355f6bbffbe0ffbedeaaf5395ac3a309ca2728
parent f363a0f7
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -345,7 +345,9 @@ public class Utils {
                break;
            case BiometricConstants.BIOMETRIC_ERROR_LOCKOUT:
            case BiometricConstants.BIOMETRIC_ERROR_LOCKOUT_PERMANENT:
                biometricManagerCode = BiometricManager.BIOMETRIC_ERROR_LOCKOUT;
                biometricManagerCode = Flags.bpFallbackOptions()
                        ? BiometricManager.BIOMETRIC_SUCCESS
                        : BiometricManager.BIOMETRIC_ERROR_LOCKOUT;
                break;
            case BiometricConstants.BIOMETRIC_ERROR_SENSOR_PRIVACY_ENABLED:
                biometricManagerCode = BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE;
+26 −0
Original line number Diff line number Diff line
@@ -1661,6 +1661,32 @@ public class BiometricServiceTest {
    }

    @Test
    @EnableFlags(Flags.FLAG_BP_FALLBACK_OPTIONS)
    public void testCanAuthenticate_whenLockoutTimed() throws Exception {
        testCanAuthenticate_whenLockedOut(LockoutTracker.LOCKOUT_TIMED);
    }

    @Test
    @EnableFlags(Flags.FLAG_BP_FALLBACK_OPTIONS)
    public void testCanAuthenticate_whenLockoutPermanent() throws Exception {
        testCanAuthenticate_whenLockedOut(LockoutTracker.LOCKOUT_PERMANENT);
    }

    private void testCanAuthenticate_whenLockedOut(@LockoutTracker.LockoutMode int lockoutMode)
            throws Exception {
        // When only biometric is requested, and sensor is strong enough
        setupAuthForOnly(TYPE_FINGERPRINT, Authenticators.BIOMETRIC_STRONG);

        when(mFingerprintAuthenticator.getLockoutModeForUser(anyInt()))
                .thenReturn(lockoutMode);

        // Lockout is not considered an error for BiometricManager#canAuthenticate
        assertEquals(BiometricManager.BIOMETRIC_SUCCESS,
                invokeCanAuthenticate(mBiometricService, Authenticators.BIOMETRIC_STRONG));
    }

    @Test
    @DisableFlags(Flags.FLAG_BP_FALLBACK_OPTIONS)
    public void testCanAuthenticate_whenLockoutTimed_returnsLockoutError() throws Exception {
        testCanAuthenticate_whenLockedOut_returnLockoutError(LockoutTracker.LOCKOUT_TIMED);
    }
+31 −1
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.hardware.biometrics.BiometricPrompt;
import android.hardware.biometrics.Flags;
import android.hardware.biometrics.PromptInfo;
import android.platform.test.annotations.Presubmit;
import android.platform.test.annotations.RequiresFlagsDisabled;
import android.platform.test.annotations.RequiresFlagsEnabled;
import android.platform.test.flag.junit.CheckFlagsRule;
import android.platform.test.flag.junit.DeviceFlagsValueProvider;
@@ -260,7 +261,8 @@ public class UtilsTest {
    }

    @Test
    public void testBiometricConstantsConversion() {
    @RequiresFlagsDisabled(Flags.FLAG_BP_FALLBACK_OPTIONS)
    public void testBiometricConstantsConversionLegacy() {
        final int[][] testCases = {
                {BiometricConstants.BIOMETRIC_SUCCESS,
                        BiometricManager.BIOMETRIC_SUCCESS},
@@ -286,6 +288,34 @@ public class UtilsTest {
        }
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_BP_FALLBACK_OPTIONS)
    public void testBiometricConstantsConversion() {
        final int[][] testCases = {
                {BiometricConstants.BIOMETRIC_SUCCESS,
                        BiometricManager.BIOMETRIC_SUCCESS},
                {BiometricConstants.BIOMETRIC_ERROR_NO_BIOMETRICS,
                        BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED},
                {BiometricConstants.BIOMETRIC_ERROR_NO_DEVICE_CREDENTIAL,
                        BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED},
                {BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE,
                        BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE},
                {BiometricConstants.BIOMETRIC_ERROR_HW_NOT_PRESENT,
                        BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE},
                {BiometricConstants.BIOMETRIC_ERROR_LOCKOUT,
                        BiometricManager.BIOMETRIC_SUCCESS},
                {BiometricConstants.BIOMETRIC_ERROR_LOCKOUT_PERMANENT,
                        BiometricManager.BIOMETRIC_SUCCESS},
                {BiometricConstants.BIOMETRIC_ERROR_IDENTITY_CHECK_NOT_ACTIVE,
                        BiometricManager.BIOMETRIC_ERROR_IDENTITY_CHECK_NOT_ACTIVE}
        };

        for (int i = 0; i < testCases.length; i++) {
            assertEquals(testCases[i][1],
                    Utils.biometricConstantsToBiometricManager(testCases[i][0]));
        }
    }

    @Test
    public void testGetAuthenticationTypeForResult_getsCorrectType() {
        assertEquals(Utils.getAuthenticationTypeForResult(