Home | History | Annotate | Download | only in fingerprint
      1 /**
      2  * Copyright (C) 2016 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.FingerprintManager;
     21 import android.hardware.fingerprint.IFingerprintDaemon;
     22 import android.hardware.fingerprint.IFingerprintServiceReceiver;
     23 import android.os.IBinder;
     24 import android.os.RemoteException;
     25 import android.os.UserHandle;
     26 import android.util.Slog;
     27 
     28 /**
     29  * A class to keep track of the remove state for a given client.
     30  */
     31 public abstract class RemovalClient extends ClientMonitor {
     32     private int mFingerId;
     33 
     34     public RemovalClient(Context context, long halDeviceId, IBinder token,
     35             IFingerprintServiceReceiver receiver, int fingerId, int groupId, int userId,
     36             boolean restricted, String owner) {
     37         super(context, halDeviceId, token, receiver, userId, groupId, restricted, owner);
     38         mFingerId = fingerId;
     39     }
     40 
     41     @Override
     42     public int start() {
     43         IFingerprintDaemon daemon = getFingerprintDaemon();
     44         // The fingerprint template ids will be removed when we get confirmation from the HAL
     45         try {
     46             final int result = daemon.remove(mFingerId, getGroupId());
     47             if (result != 0) {
     48                 Slog.w(TAG, "startRemove with id = " + mFingerId + " failed, result=" + result);
     49                 onError(FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE);
     50                 return result;
     51             }
     52         } catch (RemoteException e) {
     53             Slog.e(TAG, "startRemove failed", e);
     54         }
     55         return 0;
     56     }
     57 
     58     @Override
     59     public int stop(boolean initiatedByClient) {
     60         // We don't actually stop remove, but inform the client that the cancel operation succeeded
     61         // so we can start the next operation.
     62         if (initiatedByClient) {
     63             onError(FingerprintManager.FINGERPRINT_ERROR_CANCELED);
     64         }
     65         return 0;
     66     }
     67 
     68     /*
     69      * @return true if we're done.
     70      */
     71     private boolean sendRemoved(int fingerId, int groupId) {
     72         IFingerprintServiceReceiver receiver = getReceiver();
     73         try {
     74             if (receiver != null) {
     75                 receiver.onRemoved(getHalDeviceId(), fingerId, groupId);
     76             }
     77         } catch (RemoteException e) {
     78             Slog.w(TAG, "Failed to notify Removed:", e);
     79         }
     80         return fingerId == 0;
     81     }
     82 
     83     @Override
     84     public boolean onRemoved(int fingerId, int groupId) {
     85         if (fingerId != 0) {
     86             FingerprintUtils.getInstance().removeFingerprintIdForUser(getContext(), fingerId,
     87                     getTargetUserId());
     88         }
     89         return sendRemoved(fingerId, getGroupId());
     90     }
     91 
     92     @Override
     93     public boolean onEnrollResult(int fingerId, int groupId, int rem) {
     94         if (DEBUG) Slog.w(TAG, "onEnrollResult() called for remove!");
     95         return true; // Invalid for Remove
     96     }
     97 
     98     @Override
     99     public boolean onAuthenticated(int fingerId, int groupId) {
    100         if (DEBUG) Slog.w(TAG, "onAuthenticated() called for remove!");
    101         return true; // Invalid for Remove.
    102     }
    103 
    104     @Override
    105     public boolean onEnumerationResult(int fingerId, int groupId) {
    106         if (DEBUG) Slog.w(TAG, "onEnumerationResult() called for remove!");
    107         return false; // Invalid for Remove.
    108     }
    109 
    110 
    111 }
    112