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

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

Merge changes from topics "High FRR - notification", "revert-24295111-High FRR...

Merge changes from topics "High FRR - notification", "revert-24295111-High FRR - notification-JTFUNRYWXL" into udc-qpr-dev

* changes:
  [6/n] FRR presubmit annotation
  [5/n] FRR notification strings update
  Fix NPE caused by [4/n] FRR data cleanup
  Revert "Revert "[4/n] FRR data cleanup""
parents 6b7bfa86 d151474d
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -1889,22 +1889,22 @@
    <!-- Content description which should be used for the fingerprint icon. -->
    <string name="fingerprint_icon_content_description">Fingerprint icon</string>

    <!-- Notification name shown when the system requires the user to set up device unlock. [CHAR LIMIT=NONE] -->
    <string name="device_unlock_notification_name">Device unlock</string>
    <!-- Notification title shown when the system suggests the user to set up another way to unlock. [CHAR LIMIT=NONE] -->
    <string name="alternative_unlock_setup_notification_title">Try another way to unlock</string>
    <!-- Notification content shown when the system suggests the user to enroll their face. [CHAR LIMIT=NONE] -->
    <string name="alternative_face_setup_notification_content">Use Face Unlock when your fingerprint isn\'t recognized, like when your fingers are wet</string>
    <!-- Notification content shown when the system suggests the user to enroll their fingerprint. [CHAR LIMIT=NONE] -->
    <string name="alternative_fp_setup_notification_content">Use Fingerprint Unlock when your face isn\'t recognized, like when there\'s not enough light</string>
    <!-- Notification name shown when the system requires the user to re-enroll their face. [CHAR LIMIT=NONE] -->
    <string name="face_recalibrate_notification_name">Face Unlock</string>
    <!-- Notification title shown when the system requires the user to re-enroll their face. [CHAR LIMIT=NONE] -->
    <string name="face_recalibrate_notification_title">Issue with Face Unlock</string>
    <!-- Notification content shown when the system requires the user to re-enroll their face. [CHAR LIMIT=NONE] -->
    <string name="face_recalibrate_notification_content">Tap to delete your face model, then add your face again</string>
    <!-- Title of a notification that directs the user to set up Face Unlock by enrolling their face. [CHAR LIMIT=NONE] -->
    <string name="face_setup_notification_title">Set up Face Unlock</string>
    <!-- Contents of a notification that directs the user to set up face unlock by enrolling their face. [CHAR LIMIT=NONE] -->
    <string name="face_setup_notification_content">Unlock your phone by looking at it</string>
    <!-- Error message indicating that the camera privacy sensor has been turned on [CHAR LIMIT=NONE] -->
    <string name="face_sensor_privacy_enabled">To use Face Unlock, turn on <b>Camera access</b> in Settings > Privacy</string>
    <!-- Title of a notification that directs the user to enroll a fingerprint. [CHAR LIMIT=NONE] -->
    <string name="fingerprint_setup_notification_title">Set up more ways to unlock</string>
    <!-- Contents of a notification that directs the user to enroll a fingerprint. [CHAR LIMIT=NONE] -->
    <string name="fingerprint_setup_notification_content">Tap to add a fingerprint</string>

    <!-- Notification name shown when the system requires the user to re-calibrate their fingerprint. [CHAR LIMIT=NONE] -->
    <string name="fingerprint_recalibrate_notification_name">Fingerprint Unlock</string>
+6 −3
Original line number Diff line number Diff line
@@ -2584,6 +2584,12 @@
  <!-- Biometric FRR config -->
  <java-symbol type="fraction" name="config_biometricNotificationFrrThreshold" />

  <!-- Biometric FRR notification messages -->
  <java-symbol type="string" name="device_unlock_notification_name" />
  <java-symbol type="string" name="alternative_unlock_setup_notification_title" />
  <java-symbol type="string" name="alternative_face_setup_notification_content" />
  <java-symbol type="string" name="alternative_fp_setup_notification_content" />

  <!-- Device credential strings for BiometricManager -->
  <java-symbol type="string" name="screen_lock_app_setting_name" />
  <java-symbol type="string" name="screen_lock_dialog_default_subtitle" />
@@ -2624,8 +2630,6 @@
  <java-symbol type="string" name="fingerprint_recalibrate_notification_name" />
  <java-symbol type="string" name="fingerprint_recalibrate_notification_title" />
  <java-symbol type="string" name="fingerprint_recalibrate_notification_content" />
  <java-symbol type="string" name="fingerprint_setup_notification_title" />
  <java-symbol type="string" name="fingerprint_setup_notification_content" />
  <java-symbol type="string" name="fingerprint_error_power_pressed" />

  <!-- Fingerprint config -->
@@ -2693,7 +2697,6 @@
  <java-symbol type="string" name="face_authenticated_no_confirmation_required" />
  <java-symbol type="string" name="face_authenticated_confirmation_required" />
  <java-symbol type="string" name="face_error_security_update_required" />
  <java-symbol type="string" name="face_setup_notification_title" />

  <java-symbol type="string" name="config_biometric_prompt_ui_package" />
  <java-symbol type="array" name="config_biometric_sensors" />
+30 −3
Original line number Diff line number Diff line
@@ -18,10 +18,14 @@ package com.android.server.biometrics;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import android.os.UserHandle;

import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
@@ -53,9 +57,21 @@ public class AuthenticationStatsCollector {

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

    @NonNull private AuthenticationStatsPersister mAuthenticationStatsPersister;
    // TODO(b/295582896): Find a way to make this NonNull
    @Nullable private AuthenticationStatsPersister mAuthenticationStatsPersister;
    @NonNull private BiometricNotification mBiometricNotification;

    private final BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(@NonNull Context context, @NonNull Intent intent) {
            final int userId = intent.getIntExtra(Intent.EXTRA_USER_HANDLE, UserHandle.USER_NULL);
            if (userId != UserHandle.USER_NULL
                    && intent.getAction().equals(Intent.ACTION_USER_REMOVED)) {
                onUserRemoved(userId);
            }
        }
    };

    public AuthenticationStatsCollector(@NonNull Context context, int modality,
            @NonNull BiometricNotification biometricNotification) {
        mContext = context;
@@ -64,6 +80,8 @@ public class AuthenticationStatsCollector {
        mUserAuthenticationStatsMap = new HashMap<>();
        mModality = modality;
        mBiometricNotification = biometricNotification;

        context.registerReceiver(mBroadcastReceiver, new IntentFilter(Intent.ACTION_USER_REMOVED));
    }

    private void initializeUserAuthenticationStatsMap() {
@@ -75,8 +93,9 @@ public class AuthenticationStatsCollector {

    /** Update total authentication and rejected attempts. */
    public void authenticate(int userId, boolean authenticated) {
        // Initialize mUserAuthenticationStatsMap when authenticate to ensure SharedPreferences
        // are ready for application use and avoid ramdump issue.
        // SharedPreference is not ready when starting system server, initialize
        // mUserAuthenticationStatsMap in authentication to ensure SharedPreference
        // is ready for application use.
        if (mUserAuthenticationStatsMap.isEmpty()) {
            initializeUserAuthenticationStatsMap();
        }
@@ -146,6 +165,14 @@ public class AuthenticationStatsCollector {
        }
    }

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

    /**
     * Only being used in tests. Callers should not make any changes to the returned
     * authentication stats.
+24 −1
Original line number Diff line number Diff line
@@ -93,13 +93,36 @@ public class AuthenticationStatsPersister {
        return authenticationStatsList;
    }

    /**
     * Remove frr data for a specific user.
     */
    public void removeFrrStats(int userId) {
        try {
            // Copy into a new HashSet to allow modification.
            Set<String> frrStatsSet = new HashSet<>(readFrrStats());

            // Remove the old authentication stat for the user if it exists.
            for (Iterator<String> iterator = frrStatsSet.iterator(); iterator.hasNext();) {
                String frrStats = iterator.next();
                JSONObject frrStatJson = new JSONObject(frrStats);
                if (getValue(frrStatJson, USER_ID).equals(String.valueOf(userId))) {
                    iterator.remove();
                    break;
                }
            }

            mSharedPreferences.edit().putStringSet(KEY, frrStatsSet).apply();
        } catch (JSONException ignored) {
        }
    }

    /**
     * Persist frr data for a specific user.
     */
    public void persistFrrStats(int userId, int totalAttempts, int rejectedAttempts,
            int enrollmentNotifications, int modality) {
        try {
            // Copy into a new HashSet to avoid iterator exception.
            // Copy into a new HashSet to allow modification.
            Set<String> frrStatsSet = new HashSet<>(readFrrStats());

            // Remove the old authentication stat for the user if it exists.
+6 −6
Original line number Diff line number Diff line
@@ -87,11 +87,11 @@ public class BiometricNotificationUtils {
    public static void showFaceEnrollNotification(@NonNull Context context) {

        final String name =
                context.getString(R.string.face_recalibrate_notification_name);
                context.getString(R.string.device_unlock_notification_name);
        final String title =
                context.getString(R.string.fingerprint_setup_notification_title);
                context.getString(R.string.alternative_unlock_setup_notification_title);
        final String content =
                context.getString(R.string.face_setup_notification_title);
                context.getString(R.string.alternative_face_setup_notification_content);

        final Intent intent = new Intent(FACE_ENROLL_ACTION);
        intent.setPackage(SETTINGS_PACKAGE);
@@ -112,11 +112,11 @@ public class BiometricNotificationUtils {
    public static void showFingerprintEnrollNotification(@NonNull Context context) {

        final String name =
                context.getString(R.string.fingerprint_recalibrate_notification_name);
                context.getString(R.string.device_unlock_notification_name);
        final String title =
                context.getString(R.string.fingerprint_setup_notification_title);
                context.getString(R.string.alternative_unlock_setup_notification_title);
        final String content =
                context.getString(R.string.fingerprint_setup_notification_content);
                context.getString(R.string.alternative_fp_setup_notification_content);

        final Intent intent = new Intent(FINGERPRINT_ENROLL_ACTION);
        intent.setPackage(SETTINGS_PACKAGE);
Loading