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

Commit 85311755 authored by Wenhui Yang's avatar Wenhui Yang Committed by Android (Google) Code Review
Browse files

Merge "FRR follow-up: make persister non-null" into main

parents b16bd3cc 37dc9ce3
Loading
Loading
Loading
Loading
+12 −25
Original line number Diff line number Diff line
@@ -59,12 +59,9 @@ public class AuthenticationStatsCollector {

    private final float mThreshold;
    private final int mModality;
    private boolean mPersisterInitialized = false;

    @NonNull private final Map<Integer, AuthenticationStats> mUserAuthenticationStatsMap;

    // TODO(b/295582896): Find a way to make this NonNull
    @Nullable private AuthenticationStatsPersister mAuthenticationStatsPersister;
    @NonNull private AuthenticationStatsPersister mAuthenticationStatsPersister;
    @NonNull private BiometricNotification mBiometricNotification;

    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
@@ -93,24 +90,21 @@ public class AuthenticationStatsCollector {
        mFaceManager = mContext.getSystemService(FaceManager.class);
        mFingerprintManager = mContext.getSystemService(FingerprintManager.class);

        mAuthenticationStatsPersister = new AuthenticationStatsPersister(mContext);

        initializeUserAuthenticationStatsMap();
        mAuthenticationStatsPersister.persistFrrThreshold(mThreshold);

        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(Intent.ACTION_USER_REMOVED);
        context.registerReceiver(mBroadcastReceiver, intentFilter);
    }

    private void initializeUserAuthenticationStatsMap() {
        try {
            mAuthenticationStatsPersister = new AuthenticationStatsPersister(mContext);
        for (AuthenticationStats stats :
                mAuthenticationStatsPersister.getAllFrrStats(mModality)) {
            mUserAuthenticationStatsMap.put(stats.getUserId(), stats);
        }
            mAuthenticationStatsPersister.persistFrrThreshold(mThreshold);

            mPersisterInitialized = true;
        } catch (IllegalStateException e) {
            Slog.w(TAG, "Failed to initialize AuthenticationStatsPersister.", e);
        }
    }

    /** Update total authentication and rejected attempts. */
@@ -143,10 +137,8 @@ public class AuthenticationStatsCollector {

        sendNotificationIfNeeded(userId);

        if (mPersisterInitialized) {
        persistDataIfNeeded(userId);
    }
    }

    /** Check if a notification should be sent after a calculation cycle. */
    private void sendNotificationIfNeeded(int userId) {
@@ -188,14 +180,9 @@ public class AuthenticationStatsCollector {
    }

    private void onUserRemoved(final int userId) {
        if (!mPersisterInitialized) {
            initializeUserAuthenticationStatsMap();
        }
        if (mPersisterInitialized) {
        mUserAuthenticationStatsMap.remove(userId);
        mAuthenticationStatsPersister.removeFrrStats(userId);
    }
    }

    private boolean isSingleModalityDevice() {
        return !mPackageManager.hasSystemFeature(PackageManager.FEATURE_FINGERPRINT)
+1 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ public class AuthenticationStatsCollectorTest {
        when(mSharedPreferences.getStringSet(anyString(), anySet())).thenReturn(emptySet());
        when(mSharedPreferences.edit()).thenReturn(mEditor);
        when(mEditor.putFloat(anyString(), anyFloat())).thenReturn(mEditor);
        when(mEditor.putStringSet(anyString(), anySet())).thenReturn(mEditor);

        mAuthenticationStatsCollector = new AuthenticationStatsCollector(mContext,
                0 /* modality */, mBiometricNotification);