Home | History | Annotate | Download | only in fingerprint
      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> mUnknownFingerprints = 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                 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());
     57             mUnknownFingerprints.add(fingerprint);
     58         }
     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 
     78     public List<Fingerprint> getUnknownFingerprints() {
     79         return mUnknownFingerprints;
     80     }
     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 
     90         return remaining == 0;
     91     }
     92 
     93 }
     94