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

Commit 471879cc authored by Wenhui Yang's avatar Wenhui Yang
Browse files

Catch exception when initializing the persister to avoid crash

Keyguard team has a face_auth_refactor flag to bypass the lockscreen. In
that case, a crash will occurred because SharedPreferences in credential encrypted storage are not available until user is unlocked.

Bug: 296611182
Bug: 295582896
Test: Maunal - enable face_auth_refactor locally.
Change-Id: I6feb155a44ce179cf558562bb663660e16dea355
parent b8ccc196
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