blob: 434db98ad37331307c7aae084717b57ecd1306dd [file] [log] [blame]
Kevin Chynd1f1a0b2017-04-03 13:37:48 -07001/*
2 * Copyright (C) 2017 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;
21import android.hardware.fingerprint.IFingerprintServiceReceiver;
22import android.os.IBinder;
23import android.util.Slog;
24import java.util.ArrayList;
25import java.util.List;
26
27/**
28 * An internal class to help clean up unknown fingerprints in the hardware and software
29 */
30public abstract class InternalEnumerateClient extends EnumerateClient {
31
32 private List<Fingerprint> mEnrolledList;
Kevin Chynedd71f92017-09-01 16:09:57 -070033 private List<Fingerprint> mUnknownFingerprints = new ArrayList<>(); // list of fp to delete
Kevin Chynd1f1a0b2017-04-03 13:37:48 -070034
35 public InternalEnumerateClient(Context context, long halDeviceId, IBinder token,
36 IFingerprintServiceReceiver receiver, int groupId, int userId,
37 boolean restricted, String owner, List<Fingerprint> enrolledList) {
38
39 super(context, halDeviceId, token, receiver, userId, groupId, restricted, owner);
40 mEnrolledList = enrolledList;
41 }
42
43 private void handleEnumeratedFingerprint(int fingerId, int groupId, int remaining) {
44
45 boolean matched = false;
46 for (int i=0; i<mEnrolledList.size(); i++) {
47 if (mEnrolledList.get(i).getFingerId() == fingerId) {
48 mEnrolledList.remove(i);
49 matched = true;
Kevin Chynd1f1a0b2017-04-03 13:37:48 -070050 break;
51 }
52 }
53
54 // fingerId 0 means no fingerprints are in hardware
55 if (!matched && fingerId != 0) {
56 Fingerprint fingerprint = new Fingerprint("", groupId, fingerId, getHalDeviceId());
Kevin Chynedd71f92017-09-01 16:09:57 -070057 mUnknownFingerprints.add(fingerprint);
Kevin Chynd1f1a0b2017-04-03 13:37:48 -070058 }
59 }
60
61 private void doFingerprintCleanup() {
62
63 if (mEnrolledList == null) {
64 return;
65 }
66
67 for (Fingerprint f : mEnrolledList) {
68 Slog.e(TAG, "Internal Enumerate: Removing dangling enrolled fingerprint: "
69 + f.getName() + " " + f.getFingerId() + " " + f.getGroupId()
70 + " " + f.getDeviceId());
71
72 FingerprintUtils.getInstance().removeFingerprintIdForUser(getContext(),
73 f.getFingerId(), getTargetUserId());
74 }
75 mEnrolledList.clear();
76 }
77
Kevin Chynedd71f92017-09-01 16:09:57 -070078 public List<Fingerprint> getUnknownFingerprints() {
79 return mUnknownFingerprints;
Kevin Chynd1f1a0b2017-04-03 13:37:48 -070080 }
81
82 @Override
83 public boolean onEnumerationResult(int fingerId, int groupId, int remaining) {
84
85 handleEnumeratedFingerprint(fingerId, groupId, remaining);
86 if (remaining == 0) {
87 doFingerprintCleanup();
88 }
89
Kevin Chyn774ccde2017-08-08 12:24:34 -070090 return remaining == 0;
Kevin Chynd1f1a0b2017-04-03 13:37:48 -070091 }
92
93}