2 * Copyright (C) 2016 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.server.fingerprint;
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;
29 * A class to keep track of the remove state for a given client.
31 public abstract class RemovalClient extends ClientMonitor {
32 private int mFingerId;
33 private int mUserIdForRemove;
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);
40 mUserIdForRemove = userId;
45 IFingerprintDaemon daemon = getFingerprintDaemon();
46 // The fingerprint template ids will be removed when we get confirmation from the HAL
48 final int result = daemon.remove(mFingerId, getGroupId());
50 Slog.w(TAG, "startRemove with id = " + mFingerId + " failed, result=" + result);
51 onError(FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE);
54 } catch (RemoteException e) {
55 Slog.e(TAG, "startRemove failed", e);
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);
71 * @return true if we're done.
73 private boolean sendRemoved(int fingerId, int groupId) {
74 IFingerprintServiceReceiver receiver = getReceiver();
76 return true; // client not listening
78 receiver.onRemoved(getHalDeviceId(), fingerId, groupId);
80 } catch (RemoteException e) {
81 Slog.w(TAG, "Failed to notify Removed:", e);
87 public boolean onRemoved(int fingerId, int groupId) {
89 if (fingerId != mFingerId)
90 FingerprintUtils.getInstance().removeFingerprintIdForUser(getContext(), fingerId,
93 mUserIdForRemove = UserHandle.USER_NULL;
95 return sendRemoved(fingerId, getGroupId());
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
105 public boolean onAuthenticated(int fingerId, int groupId) {
106 if (DEBUG) Slog.w(TAG, "onAuthenticated() called for remove!");
107 return true; // Invalid for Remove.
111 public boolean onEnumerationResult(int fingerId, int groupId) {
112 if (DEBUG) Slog.w(TAG, "onEnumerationResult() called for remove!");
113 return false; // Invalid for Remove.