diff options
Diffstat (limited to 'services')
-rw-r--r-- | services/core/java/com/android/server/fingerprint/FingerprintUtils.java | 2 | ||||
-rw-r--r-- | services/core/java/com/android/server/fingerprint/FingerprintsUserState.java | 30 |
2 files changed, 27 insertions, 5 deletions
diff --git a/services/core/java/com/android/server/fingerprint/FingerprintUtils.java b/services/core/java/com/android/server/fingerprint/FingerprintUtils.java index 1e6e105..d274412 100644 --- a/services/core/java/com/android/server/fingerprint/FingerprintUtils.java +++ b/services/core/java/com/android/server/fingerprint/FingerprintUtils.java @@ -56,7 +56,7 @@ public class FingerprintUtils { } public void addFingerprintForUser(Context ctx, int fingerId, int userId) { - getStateForUser(ctx, userId).addFingerprint(fingerId); + getStateForUser(ctx, userId).addFingerprint(fingerId, userId); } public void removeFingerprintIdForUser(Context ctx, int fingerId, int userId) { diff --git a/services/core/java/com/android/server/fingerprint/FingerprintsUserState.java b/services/core/java/com/android/server/fingerprint/FingerprintsUserState.java index 902d970..0976a22 100644 --- a/services/core/java/com/android/server/fingerprint/FingerprintsUserState.java +++ b/services/core/java/com/android/server/fingerprint/FingerprintsUserState.java @@ -68,9 +68,9 @@ class FingerprintsUserState { } } - public void addFingerprint(int fingerId) { + public void addFingerprint(int fingerId, int groupId) { synchronized (this) { - mFingerprints.add(new Fingerprint(getDefaultFingerprintName(fingerId), 0, fingerId, 0)); + mFingerprints.add(new Fingerprint(getUniqueName(), groupId, fingerId, 0)); scheduleWriteStateLocked(); } } @@ -107,8 +107,30 @@ class FingerprintsUserState { } } - private String getDefaultFingerprintName(int fingerId) { - return mCtx.getString(com.android.internal.R.string.fingerprint_name_template, fingerId); + /** + * Finds a unique name for the given fingerprint + * @return unique name + */ + private String getUniqueName() { + int guess = 1; + while (true) { + // Not the most efficient algorithm in the world, but there shouldn't be more than 10 + String name = mCtx.getString(com.android.internal.R.string.fingerprint_name_template, + guess); + if (isUnique(name)) { + return name; + } + guess++; + } + } + + private boolean isUnique(String name) { + for (Fingerprint fp : mFingerprints) { + if (fp.getName().equals(name)) { + return false; + } + } + return true; } private static File getFileForUser(int userId) { |