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

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

Merge "Catch exception when initializing the persister to avoid crash" into udc-qpr-dev

parents 4d1c1d41 471879cc
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.content.pm.PackageManager;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle;
import android.util.Slog;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
@@ -54,6 +55,7 @@ public class AuthenticationStatsCollector {

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

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

@@ -85,10 +87,16 @@ public class AuthenticationStatsCollector {
    }

    private void initializeUserAuthenticationStatsMap() {
        try {
            mAuthenticationStatsPersister = new AuthenticationStatsPersister(mContext);
        for (AuthenticationStats stats : mAuthenticationStatsPersister.getAllFrrStats(mModality)) {
            for (AuthenticationStats stats :
                    mAuthenticationStatsPersister.getAllFrrStats(mModality)) {
                mUserAuthenticationStatsMap.put(stats.getUserId(), stats);
            }
            mPersisterInitialized = true;
        } catch (IllegalStateException e) {
            Slog.w(TAG, "Failed to initialize AuthenticationStatsPersister.", e);
        }
    }

    /** Update total authentication and rejected attempts. */
@@ -108,7 +116,9 @@ public class AuthenticationStatsCollector {

        authenticationStats.authenticate(authenticated);

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

@@ -166,12 +176,14 @@ public class AuthenticationStatsCollector {
    }

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

    /**
     * Only being used in tests. Callers should not make any changes to the returned