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

Commit 1862a1ac authored by Joshua Mccloskey's avatar Joshua Mccloskey
Browse files

Added rate limiter for calibration notification

Test: Manually verified notification was only shown once per time period
Fixes: 192105305
Change-Id: I115996ee0ad51ac5bb160a0f6aa3395df49f724f
parent 0954cfe6
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ public interface BiometricFingerprintConstants {
            BIOMETRIC_ERROR_RE_ENROLL,
            BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED,
            FINGERPRINT_ERROR_UNKNOWN,
            FINGERPRINT_ERROR_BAD_CALIBARTION})
            FINGERPRINT_ERROR_BAD_CALIBRATION})
    @Retention(RetentionPolicy.SOURCE)
    @interface FingerprintError {}

@@ -185,7 +185,7 @@ public interface BiometricFingerprintConstants {
     * Error indicating that the fingerprint sensor has bad calibration.
     * @hide
     */
    int FINGERPRINT_ERROR_BAD_CALIBARTION = 18;
    int FINGERPRINT_ERROR_BAD_CALIBRATION = 18;

    /**
     * @hide
+1 −1
Original line number Diff line number Diff line
@@ -1375,7 +1375,7 @@ public class FingerprintManager implements BiometricAuthenticator, BiometricFing
            case BIOMETRIC_ERROR_SECURITY_UPDATE_REQUIRED:
                return context.getString(
                        com.android.internal.R.string.fingerprint_error_security_update_required);
            case FINGERPRINT_ERROR_BAD_CALIBARTION:
            case FINGERPRINT_ERROR_BAD_CALIBRATION:
                return context.getString(
                            com.android.internal.R.string.fingerprint_error_bad_calibration);
            case FINGERPRINT_ERROR_VENDOR: {
+16 −2
Original line number Diff line number Diff line
@@ -23,7 +23,9 @@ import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.os.UserHandle;
import android.util.Slog;

import com.android.internal.R;

@@ -32,9 +34,12 @@ import com.android.internal.R;
 */
public class BiometricNotificationUtils {

    private static final String TAG = "BiometricNotificationUtils";
    private static final String RE_ENROLL_NOTIFICATION_TAG = "FaceService";
    private static final String BAD_CALIBRATION_NOTIFICATION_TAG = "FingerprintService";
    private static final int NOTIFICATION_ID = 1;
    private static final long NOTIFICATION_INTERVAL_MS = 24 * 60 * 60 * 1000;
    private static long sLastAlertTime = 0;

    /**
     * Shows a face re-enrollment notification.
@@ -67,8 +72,17 @@ public class BiometricNotificationUtils {
     * Shows a fingerprint bad calibration notification.
     */
    public static void showBadCalibrationNotification(@NonNull Context context) {
        final NotificationManager notificationManager =
                context.getSystemService(NotificationManager.class);
        final long currentTime = SystemClock.elapsedRealtime();
        final long timeSinceLastAlert = currentTime - sLastAlertTime;

        // Only show the notification if not previously shown or a day has
        // passed since the last notification.
        if (sLastAlertTime != 0 && (timeSinceLastAlert < NOTIFICATION_INTERVAL_MS)) {
            Slog.v(TAG, "Skipping calibration notification : " + timeSinceLastAlert);
            return;
        }

        sLastAlertTime = currentTime;

        final String name =
                context.getString(R.string.fingerprint_recalibrate_notification_name);
+1 −1
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ final class AidlConversionUtils {
        } else if (aidlError == Error.VENDOR) {
            return BiometricFingerprintConstants.FINGERPRINT_ERROR_VENDOR;
        } else if (aidlError == Error.BAD_CALIBRATION) {
            return BiometricFingerprintConstants.FINGERPRINT_ERROR_BAD_CALIBARTION;
            return BiometricFingerprintConstants.FINGERPRINT_ERROR_BAD_CALIBRATION;
        } else {
            return BiometricFingerprintConstants.FINGERPRINT_ERROR_UNKNOWN;
        }
+1 −1
Original line number Diff line number Diff line
@@ -112,7 +112,7 @@ class FingerprintAuthenticationClient extends AuthenticationClient<ISession> imp
    public void onError(int errorCode, int vendorCode) {
        super.onError(errorCode, vendorCode);

        if (errorCode == BiometricFingerprintConstants.FINGERPRINT_ERROR_BAD_CALIBARTION) {
        if (errorCode == BiometricFingerprintConstants.FINGERPRINT_ERROR_BAD_CALIBRATION) {
            BiometricNotificationUtils.showBadCalibrationNotification(getContext());
        }

Loading