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

Commit e4f4315d authored by Wenhui Yang's avatar Wenhui Yang Committed by Automerger Merge Worker
Browse files

Merge "Catch exception when initializing the persister to avoid crash" into...

Merge "Catch exception when initializing the persister to avoid crash" into udc-qpr-dev am: 3565eaf8 am: bf0e973b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/24481871



Change-Id: I5d0c673e055d3dbe1bbcb00564b4332ce17f61cc
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents eba2b6a9 bf0e973b
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