blob: 5fbd735d4ac5ebf9053fecd6006f3f58ddec705e [file] [log] [blame]
Jorim Jaggiee77ceb2015-05-12 15:00:12 -07001/**
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.server.fingerprint;
18
19import android.content.Context;
20import android.hardware.fingerprint.Fingerprint;
Selim Cinekd9d53022015-08-13 16:17:13 -070021import android.text.TextUtils;
Jorim Jaggiee77ceb2015-05-12 15:00:12 -070022import android.util.SparseArray;
23
24import com.android.internal.annotations.GuardedBy;
25
26import java.util.List;
27
28/**
29 * Utility class for dealing with fingerprints and fingerprint settings.
30 */
31public class FingerprintUtils {
32
Jorim Jaggiee77ceb2015-05-12 15:00:12 -070033 private static final Object sInstanceLock = new Object();
34 private static FingerprintUtils sInstance;
35
36 @GuardedBy("this")
37 private final SparseArray<FingerprintsUserState> mUsers = new SparseArray<>();
38
39 public static FingerprintUtils getInstance() {
40 synchronized (sInstanceLock) {
41 if (sInstance == null) {
42 sInstance = new FingerprintUtils();
43 }
44 }
45 return sInstance;
46 }
47
48 private FingerprintUtils() {
49 }
50
51 public List<Fingerprint> getFingerprintsForUser(Context ctx, int userId) {
52 return getStateForUser(ctx, userId).getFingerprints();
53 }
54
55 public void addFingerprintForUser(Context ctx, int fingerId, int userId) {
Jim Millered2ab1c2015-07-07 19:12:36 -070056 getStateForUser(ctx, userId).addFingerprint(fingerId, userId);
Jorim Jaggiee77ceb2015-05-12 15:00:12 -070057 }
58
59 public void removeFingerprintIdForUser(Context ctx, int fingerId, int userId) {
60 getStateForUser(ctx, userId).removeFingerprint(fingerId);
61 }
62
63 public void renameFingerprintForUser(Context ctx, int fingerId, int userId, CharSequence name) {
Selim Cinekd9d53022015-08-13 16:17:13 -070064 if (TextUtils.isEmpty(name)) {
65 // Don't do the rename if it's empty
66 return;
67 }
Jorim Jaggiee77ceb2015-05-12 15:00:12 -070068 getStateForUser(ctx, userId).renameFingerprint(fingerId, name);
69 }
70
Jorim Jaggiee77ceb2015-05-12 15:00:12 -070071 private FingerprintsUserState getStateForUser(Context ctx, int userId) {
72 synchronized (this) {
73 FingerprintsUserState state = mUsers.get(userId);
74 if (state == null) {
75 state = new FingerprintsUserState(ctx, userId);
76 mUsers.put(userId, state);
77 }
78 return state;
79 }
80 }
81}
82