summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--services/core/java/com/android/server/biometrics/AuthenticationStatsPersister.java40
1 files changed, 9 insertions, 31 deletions
diff --git a/services/core/java/com/android/server/biometrics/AuthenticationStatsPersister.java b/services/core/java/com/android/server/biometrics/AuthenticationStatsPersister.java
index 21e93a8bc024..74e1410dba00 100644
--- a/services/core/java/com/android/server/biometrics/AuthenticationStatsPersister.java
+++ b/services/core/java/com/android/server/biometrics/AuthenticationStatsPersister.java
@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.biometrics.BiometricsProtoEnums;
import android.os.Environment;
+import android.os.UserHandle;
import android.util.Slog;
import org.json.JSONException;
@@ -72,14 +73,16 @@ public class AuthenticationStatsPersister {
JSONObject frrStatsJson = new JSONObject(frrStats);
if (modality == BiometricsProtoEnums.MODALITY_FACE) {
authenticationStatsList.add(new AuthenticationStats(
- getIntValue(frrStatsJson, USER_ID, -1 /* defaultValue */),
+ getIntValue(frrStatsJson, USER_ID,
+ UserHandle.USER_NULL /* defaultValue */),
getIntValue(frrStatsJson, FACE_ATTEMPTS),
getIntValue(frrStatsJson, FACE_REJECTIONS),
getIntValue(frrStatsJson, ENROLLMENT_NOTIFICATIONS),
modality));
} else if (modality == BiometricsProtoEnums.MODALITY_FINGERPRINT) {
authenticationStatsList.add(new AuthenticationStats(
- getIntValue(frrStatsJson, USER_ID, -1 /* defaultValue */),
+ getIntValue(frrStatsJson, USER_ID,
+ UserHandle.USER_NULL /* defaultValue */),
getIntValue(frrStatsJson, FINGERPRINT_ATTEMPTS),
getIntValue(frrStatsJson, FINGERPRINT_REJECTIONS),
getIntValue(frrStatsJson, ENROLLMENT_NOTIFICATIONS),
@@ -138,13 +141,11 @@ public class AuthenticationStatsPersister {
// If there's existing frr stats in the file, we want to update the stats for the given
// modality and keep the stats for other modalities.
- if (frrStatJson != null) {
- frrStatsSet.add(buildFrrStats(frrStatJson, totalAttempts, rejectedAttempts,
- enrollmentNotifications, modality));
- } else {
- frrStatsSet.add(buildFrrStats(userId, totalAttempts, rejectedAttempts,
- enrollmentNotifications, modality));
+ if (frrStatJson == null) {
+ frrStatJson = new JSONObject().put(USER_ID, userId);
}
+ frrStatsSet.add(buildFrrStats(frrStatJson, totalAttempts, rejectedAttempts,
+ enrollmentNotifications, modality));
mSharedPreferences.edit().putStringSet(KEY, frrStatsSet).apply();
@@ -177,29 +178,6 @@ public class AuthenticationStatsPersister {
}
}
- // Build string for new user and new authentication stats.
- private String buildFrrStats(int userId, int totalAttempts, int rejectedAttempts,
- int enrollmentNotifications, int modality)
- throws JSONException {
- if (modality == BiometricsProtoEnums.MODALITY_FACE) {
- return new JSONObject()
- .put(USER_ID, userId)
- .put(FACE_ATTEMPTS, totalAttempts)
- .put(FACE_REJECTIONS, rejectedAttempts)
- .put(ENROLLMENT_NOTIFICATIONS, enrollmentNotifications)
- .toString();
- } else if (modality == BiometricsProtoEnums.MODALITY_FINGERPRINT) {
- return new JSONObject()
- .put(USER_ID, userId)
- .put(FINGERPRINT_ATTEMPTS, totalAttempts)
- .put(FINGERPRINT_REJECTIONS, rejectedAttempts)
- .put(ENROLLMENT_NOTIFICATIONS, enrollmentNotifications)
- .toString();
- } else {
- return "";
- }
- }
-
private String getValue(JSONObject jsonObject, String key) throws JSONException {
return jsonObject.has(key) ? jsonObject.getString(key) : "";
}