blob: 12827d01b34d86a854be10a59f192333a1c531ec [file] [log] [blame]
Jim Millercb2ce6f2016-04-13 20:28:18 -07001/**
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;
Jim Miller40e46452016-12-16 18:38:53 -080020import android.hardware.biometrics.fingerprint.V2_1.IBiometricsFingerprint;
Jim Millercb2ce6f2016-04-13 20:28:18 -070021import android.hardware.fingerprint.FingerprintManager;
Jim Millercb2ce6f2016-04-13 20:28:18 -070022import android.hardware.fingerprint.IFingerprintServiceReceiver;
23import android.os.IBinder;
24import android.os.RemoteException;
25import android.util.Slog;
Jim Millerc57c8d92016-09-30 17:17:59 -070026import com.android.internal.logging.MetricsLogger;
Jim Millercb2ce6f2016-04-13 20:28:18 -070027
28/**
29 * A class to keep track of the enumeration state for a given client.
30 */
31public abstract class EnumerateClient extends ClientMonitor {
32 public EnumerateClient(Context context, long halDeviceId, IBinder token,
Jim Miller40e46452016-12-16 18:38:53 -080033 IFingerprintServiceReceiver receiver, int groupId, int userId,
34 boolean restricted, String owner) {
Jim Millercb2ce6f2016-04-13 20:28:18 -070035 super(context, halDeviceId, token, receiver, userId, groupId, restricted, owner);
36 }
37
38 @Override
39 public int start() {
Jim Miller40e46452016-12-16 18:38:53 -080040 IBiometricsFingerprint daemon = getFingerprintDaemon();
Jim Millercb2ce6f2016-04-13 20:28:18 -070041 // The fingerprint template ids will be removed when we get confirmation from the HAL
42 try {
43 final int result = daemon.enumerate();
44 if (result != 0) {
Jim Miller8f2aca02016-04-20 13:34:11 -070045 Slog.w(TAG, "start enumerate for user " + getTargetUserId()
Jim Millercb2ce6f2016-04-13 20:28:18 -070046 + " failed, result=" + result);
Jim Millerc57c8d92016-09-30 17:17:59 -070047 MetricsLogger.histogram(getContext(), "fingerprintd_enum_start_error", result);
Jim Miller40e46452016-12-16 18:38:53 -080048 onError(FingerprintManager.FINGERPRINT_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */);
Jim Millercb2ce6f2016-04-13 20:28:18 -070049 return result;
50 }
51 } catch (RemoteException e) {
Jim Miller40e46452016-12-16 18:38:53 -080052 Slog.e(TAG, "startEnumeration failed", e);
Jim Millercb2ce6f2016-04-13 20:28:18 -070053 }
54 return 0;
55 }
56
57 @Override
58 public int stop(boolean initiatedByClient) {
Kevin Chyn37368582017-05-19 17:15:38 -070059 if (mAlreadyCancelled) {
60 Slog.w(TAG, "stopEnumerate: already cancelled!");
61 return 0;
62 }
Jim Miller40e46452016-12-16 18:38:53 -080063 IBiometricsFingerprint daemon = getFingerprintDaemon();
Jim Millercb2ce6f2016-04-13 20:28:18 -070064 if (daemon == null) {
Kevin Chynd1f1a0b2017-04-03 13:37:48 -070065 Slog.w(TAG, "stopEnumeration: no fingerprint HAL!");
Jim Millercb2ce6f2016-04-13 20:28:18 -070066 return ERROR_ESRCH;
67 }
68 try {
Jim Miller40e46452016-12-16 18:38:53 -080069 final int result = daemon.cancel();
Jim Millercb2ce6f2016-04-13 20:28:18 -070070 if (result != 0) {
71 Slog.w(TAG, "stop enumeration failed, result=" + result);
72 return result;
73 }
74 } catch (RemoteException e) {
Jim Miller40e46452016-12-16 18:38:53 -080075 Slog.e(TAG, "stopEnumeration failed", e);
Jim Millercb2ce6f2016-04-13 20:28:18 -070076 return ERROR_ESRCH;
77 }
Jim Miller40e46452016-12-16 18:38:53 -080078
Jim Millercb2ce6f2016-04-13 20:28:18 -070079 // We don't actually stop enumerate, but inform the client that the cancel operation
80 // succeeded so we can start the next operation.
81 if (initiatedByClient) {
Jim Miller40e46452016-12-16 18:38:53 -080082 onError(FingerprintManager.FINGERPRINT_ERROR_CANCELED, 0 /* vendorCode */);
Jim Millercb2ce6f2016-04-13 20:28:18 -070083 }
Kevin Chyn37368582017-05-19 17:15:38 -070084 mAlreadyCancelled = true;
Jim Millercb2ce6f2016-04-13 20:28:18 -070085 return 0; // success
86 }
87
88 @Override
Jim Miller40e46452016-12-16 18:38:53 -080089 public boolean onEnumerationResult(int fingerId, int groupId, int remaining) {
Jim Millercb2ce6f2016-04-13 20:28:18 -070090 IFingerprintServiceReceiver receiver = getReceiver();
91 if (receiver == null)
92 return true; // client not listening
93 try {
Jim Miller40e46452016-12-16 18:38:53 -080094 receiver.onEnumerated(getHalDeviceId(), fingerId, groupId, remaining);
Jim Millercb2ce6f2016-04-13 20:28:18 -070095 } catch (RemoteException e) {
96 Slog.w(TAG, "Failed to notify enumerated:", e);
97 }
98 return fingerId == 0; // done when id hits 0
99 }
Jim Miller40e46452016-12-16 18:38:53 -0800100
101 @Override
102 public boolean onAuthenticated(int fingerId, int groupId) {
103 if (DEBUG) Slog.w(TAG, "onAuthenticated() called for enumerate!");
104 return true; // Invalid for Enumerate.
105 }
106
107 @Override
108 public boolean onEnrollResult(int fingerId, int groupId, int rem) {
109 if (DEBUG) Slog.w(TAG, "onEnrollResult() called for enumerate!");
Kevin Chynd1f1a0b2017-04-03 13:37:48 -0700110 return true; // Invalid for Enumerate.
Jim Miller40e46452016-12-16 18:38:53 -0800111 }
112
113 @Override
114 public boolean onRemoved(int fingerId, int groupId, int remaining) {
115 if (DEBUG) Slog.w(TAG, "onRemoved() called for enumerate!");
Kevin Chynd1f1a0b2017-04-03 13:37:48 -0700116 return true; // Invalid for Enumerate.
Jim Miller40e46452016-12-16 18:38:53 -0800117 }
Jim Millercb2ce6f2016-04-13 20:28:18 -0700118}