1 /* 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 17 package com.android.server.fingerprint; 18 19 import android.content.Context; 20 import android.hardware.fingerprint.Fingerprint; 21 import android.hardware.fingerprint.IFingerprintServiceReceiver; 22 import android.os.IBinder; 23 import android.util.Slog; 24 import java.util.ArrayList; 25 import java.util.List; 26 27 /** 28 * An internal class to help clean up unknown fingerprints in the hardware and software 29 */ 30 public abstract class InternalEnumerateClient extends EnumerateClient { 31 32 private List<Fingerprint> mEnrolledList; 33 private List<Fingerprint> mEnumeratedList = new ArrayList<>(); // list of fp to delete 34 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; 50 Slog.e(TAG, "Matched fingerprint fid=" + fingerId); 51 break; 52 } 53 } 54 55 // fingerId 0 means no fingerprints are in hardware 56 if (!matched && fingerId != 0) { 57 Fingerprint fingerprint = new Fingerprint("", groupId, fingerId, getHalDeviceId()); 58 mEnumeratedList.add(fingerprint); 59 } 60 } 61 62 private void doFingerprintCleanup() { 63 64 if (mEnrolledList == null) { 65 return; 66 } 67 68 for (Fingerprint f : mEnrolledList) { 69 Slog.e(TAG, "Internal Enumerate: Removing dangling enrolled fingerprint: " 70 + f.getName() + " " + f.getFingerId() + " " + f.getGroupId() 71 + " " + f.getDeviceId()); 72 73 FingerprintUtils.getInstance().removeFingerprintIdForUser(getContext(), 74 f.getFingerId(), getTargetUserId()); 75 } 76 mEnrolledList.clear(); 77 } 78 79 public List<Fingerprint> getEnumeratedList() { 80 return mEnumeratedList; 81 } 82 83 @Override 84 public boolean onEnumerationResult(int fingerId, int groupId, int remaining) { 85 86 handleEnumeratedFingerprint(fingerId, groupId, remaining); 87 if (remaining == 0) { 88 doFingerprintCleanup(); 89 } 90 91 return remaining == 0; 92 } 93 94 } 95