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

Commit 6aa584f9 authored by Diya Bera's avatar Diya Bera
Browse files

Add negative button text when flag is not enabled

Fixes: 420843229
Flag: android.hardware.biometrics.bp_fallback_options
Test: atest PreAuthInfoTest
Change-Id: I990ca554d9f3266b7d1aeebbfdad2077ce68e1b6
parent 8ca800ef
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import android.os.UserManager;
import android.util.Pair;
import android.util.Slog;

import com.android.internal.R;
import com.android.server.biometrics.sensors.LockoutTracker;

import java.lang.annotation.Retention;
@@ -129,6 +130,11 @@ class PreAuthInfo {
                updateAuthenticatorsIfIdentityCheckIsActive(promptInfo, effectiveUserId,
                        trustManager, settingObserver);

        if (!Flags.bpFallbackOptions() && isMandatoryBiometricsAuthentication
                && promptInfo.getNegativeButtonText() == null) {
            promptInfo.setNegativeButtonText(context.getString(R.string.cancel));
        }

        final boolean biometricRequested = Utils.isBiometricRequested(promptInfo);
        final int requestedStrength = Utils.getPublicBiometricStrength(promptInfo);
        final boolean credentialRequested = Utils.isCredentialRequested(promptInfo);
@@ -189,16 +195,14 @@ class PreAuthInfo {
                        effectiveUserId), trustManager)) {
            promptInfo.setAuthenticators(BiometricManager.Authenticators.BIOMETRIC_STRONG);
            promptInfo.setIdentityCheckActive(true);
            return true;
        } else if (Flags.identityCheckTestApi()
                && Utils.shouldApplyIdentityCheck(promptInfo.getAuthenticators())
                && settingObserver.isIdentityCheckActive(effectiveUserId)) {
            promptInfo.setAuthenticators(BiometricManager.Authenticators.BIOMETRIC_STRONG);
            promptInfo.setIdentityCheckActive(true);
            return true;
        }

        return false;
        return promptInfo.isIdentityCheckActive();
    }

    private static boolean dropCredentialFallback(int authenticators,
+21 −2
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@ import android.hardware.biometrics.PromptInfo;
import android.os.RemoteException;
import android.os.UserManager;
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;
@@ -362,9 +363,27 @@ public class PreAuthInfoTest {
        assertThat(promptInfo.getNegativeButtonText()).isEqualTo(TEST_PACKAGE_NAME);
    }

    @Test
    @RequiresFlagsEnabled({Flags.FLAG_IDENTITY_CHECK_TEST_API, Flags.FLAG_BP_FALLBACK_OPTIONS})
    public void testMandatoryBiometricsNegativeButtonText_shouldNotBeSet()
            throws Exception {
        when(mSettingObserver.isIdentityCheckActive(anyInt())).thenReturn(true);

        final BiometricSensor sensor = getFaceSensor();
        final PromptInfo promptInfo = new PromptInfo();
        promptInfo.setAuthenticators(BiometricManager.Authenticators.IDENTITY_CHECK);
        final PreAuthInfo preAuthInfo = PreAuthInfo.create(mTrustManager, mDevicePolicyManager,
                mSettingObserver, List.of(sensor), USER_ID, promptInfo, TEST_PACKAGE_NAME,
                false /* checkDevicePolicyManager */, mContext, mBiometricCameraManager,
                mUserManager);
        assertThat(preAuthInfo.getIsMandatoryBiometricsAuthentication()).isTrue();
        assertThat(promptInfo.getNegativeButtonText()).isNull();
    }

    @Test
    @RequiresFlagsEnabled(Flags.FLAG_IDENTITY_CHECK_TEST_API)
    public void testMandatoryBiometricsNegativeButtonText_whenNotSet()
    @RequiresFlagsDisabled(Flags.FLAG_BP_FALLBACK_OPTIONS)
    public void testMandatoryBiometricsNegativeButtonText_shouldBeSet()
            throws Exception {
        when(mSettingObserver.isIdentityCheckActive(anyInt())).thenReturn(true);

@@ -376,7 +395,7 @@ public class PreAuthInfoTest {
                false /* checkDevicePolicyManager */, mContext, mBiometricCameraManager,
                mUserManager);
        assertThat(preAuthInfo.getIsMandatoryBiometricsAuthentication()).isTrue();
        assertThat(promptInfo.getNegativeButtonText()).isEqualTo(null);
        assertThat(promptInfo.getNegativeButtonText()).isNotNull();
    }

    @Test