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

Commit 173af827 authored by Wenhui Yang's avatar Wenhui Yang
Browse files

Persist FRR threshold in U-QPR1

Persist FRR threshold in SharedPreferences to prepare for the
implemention of the counter clearance after frr updated through SW
update in the future. This is the min amount of work that would allow us to detect threshold changes in future releases.

Bug: 258872351
Test: AuthenticationStatsPersisterTest
Test: AuthenticationStatsCollectorTest
Change-Id: I798ee3144833cfd3b200f3190b5292c2427be239
parent 071a9f92
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -98,6 +98,8 @@ public class AuthenticationStatsCollector {
                    mAuthenticationStatsPersister.getAllFrrStats(mModality)) {
                mUserAuthenticationStatsMap.put(stats.getUserId(), stats);
            }
            mAuthenticationStatsPersister.persistFrrThreshold(mThreshold);

            mPersisterInitialized = true;
        } catch (IllegalStateException e) {
            Slog.w(TAG, "Failed to initialize AuthenticationStatsPersister.", e);
+8 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ public class AuthenticationStatsPersister {
    private static final String FINGERPRINT_REJECTIONS = "fingerprint_rejections";
    private static final String ENROLLMENT_NOTIFICATIONS = "enrollment_notifications";
    private static final String KEY = "frr_stats";
    private static final String THRESHOLD_KEY = "frr_threshold";

    @NonNull private final SharedPreferences mSharedPreferences;

@@ -157,6 +158,13 @@ public class AuthenticationStatsPersister {
        }
    }

    /**
     * Persist frr threshold.
     */
    public void persistFrrThreshold(float frrThreshold) {
        mSharedPreferences.edit().putFloat(THRESHOLD_KEY, frrThreshold).apply();
    }

    private Set<String> readFrrStats() {
        return mSharedPreferences.getStringSet(KEY, Set.of());
    }
+5 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import static com.android.server.biometrics.AuthenticationStatsCollector.MAXIMUM
import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anySet;
import static org.mockito.ArgumentMatchers.anyString;
@@ -78,6 +79,8 @@ public class AuthenticationStatsCollectorTest {
    @Mock
    private SharedPreferences mSharedPreferences;
    @Mock
    private SharedPreferences.Editor mEditor;
    @Mock
    private BiometricNotification mBiometricNotification;

    @Before
@@ -99,6 +102,8 @@ public class AuthenticationStatsCollectorTest {
        when(mContext.getSharedPreferences(any(File.class), anyInt()))
                .thenReturn(mSharedPreferences);
        when(mSharedPreferences.getStringSet(anyString(), anySet())).thenReturn(emptySet());
        when(mSharedPreferences.edit()).thenReturn(mEditor);
        when(mEditor.putFloat(anyString(), anyFloat())).thenReturn(mEditor);

        mAuthenticationStatsCollector = new AuthenticationStatsCollector(mContext,
                0 /* modality */, mBiometricNotification);
+14 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.server.biometrics;
import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyFloat;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anySet;
import static org.mockito.ArgumentMatchers.anyString;
@@ -63,6 +64,8 @@ public class AuthenticationStatsPersisterTest {
    private static final String FINGERPRINT_REJECTIONS = "fingerprint_rejections";
    private static final String ENROLLMENT_NOTIFICATIONS = "enrollment_notifications";
    private static final String KEY = "frr_stats";
    private static final String THRESHOLD_KEY = "frr_threshold";
    private static final float FRR_THRESHOLD = 0.25f;

    @Mock
    private Context mContext;
@@ -74,6 +77,8 @@ public class AuthenticationStatsPersisterTest {

    @Captor
    private ArgumentCaptor<Set<String>> mStringSetArgumentCaptor;
    @Captor
    private ArgumentCaptor<Float> mFrrThresholdArgumentCaptor;

    @Before
    public void setUp() {
@@ -81,6 +86,7 @@ public class AuthenticationStatsPersisterTest {
                .thenReturn(mSharedPreferences);
        when(mSharedPreferences.edit()).thenReturn(mEditor);
        when(mEditor.putStringSet(anyString(), anySet())).thenReturn(mEditor);
        when(mEditor.putFloat(anyString(), anyFloat())).thenReturn(mEditor);

        mAuthenticationStatsPersister = new AuthenticationStatsPersister(mContext);
    }
@@ -255,6 +261,14 @@ public class AuthenticationStatsPersisterTest {
        assertThat(mStringSetArgumentCaptor.getValue()).doesNotContain(authenticationStats);
    }

    @Test
    public void persistFrrThreshold_shouldUpdateRecord() {
        mAuthenticationStatsPersister.persistFrrThreshold(FRR_THRESHOLD);

        verify(mEditor).putFloat(eq(THRESHOLD_KEY), mFrrThresholdArgumentCaptor.capture());
        assertThat(mFrrThresholdArgumentCaptor.getValue()).isWithin(0f).of(FRR_THRESHOLD);
    }

    private String buildFrrStats(AuthenticationStats authenticationStats)
            throws JSONException {
        if (authenticationStats.getModality() == BiometricsProtoEnums.MODALITY_FACE) {