diff options
author | Jim Miller <jaggies@google.com> | 2015-07-07 19:12:36 -0700 |
---|---|---|
committer | Jim Miller <jaggies@google.com> | 2015-07-07 19:12:36 -0700 |
commit | ed2ab1cc84cc36f91e501e047889376275db2fef (patch) | |
tree | fb136fab8bcf8ebfa30c7189463c5f2602869f0a /services | |
parent | b5e3eba1665f0a5f42bcfc2630d67011edb70f05 (diff) | |
download | frameworks_base-ed2ab1cc84cc36f91e501e047889376275db2fef.zip frameworks_base-ed2ab1cc84cc36f91e501e047889376275db2fef.tar.gz frameworks_base-ed2ab1cc84cc36f91e501e047889376275db2fef.tar.bz2 |
Don't use fingerId when creating names
Rather than using the fingerprintId, choose a unique name
to show in Settings for newly added fingerprints.
Fixes bug 22009865
Change-Id: I88a92ef95f132321a373bd88f6e1eecaf368f551
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) { |