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

Commit bf0e973b 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

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



Change-Id: I5e90529ec47752207db4cc89d1f6a3ba92f4b966
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 0f9b9b40 3565eaf8
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