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