blob: fa3a077b7c0b45de0eb187cf823880b00ea367f2 [file] [log] [blame]
Kevin Chyn037c4d52018-06-11 19:17:32 -07001/*
2 * Copyright (C) 2018 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.biometrics.common;
18
19import android.content.Context;
20import android.hardware.biometrics.BiometricConstants;
21import android.os.IBinder;
22import android.os.RemoteException;
23import android.util.Slog;
24
25/**
26 * A class to keep track of the enumeration state for a given client.
27 */
28public abstract class EnumerateClient extends ClientMonitor {
29 public EnumerateClient(Context context, Metrics metrics, BiometricService.DaemonWrapper daemon,
30 long halDeviceId, IBinder token, BiometricService.ServiceListener listener, int groupId,
31 int userId, boolean restricted, String owner) {
32 super(context, metrics, daemon, halDeviceId, token, listener, userId, groupId, restricted,
33 owner);
34 }
35
36 @Override
37 public int start() {
38 // The biometric template ids will be removed when we get confirmation from the HAL
39 try {
40 final int result = getDaemonWrapper().enumerate();
41 if (result != 0) {
42 Slog.w(getLogTag(), "start enumerate for user " + getTargetUserId()
43 + " failed, result=" + result);
44 mMetricsLogger.histogram(mMetrics.tagEnumerateStartError(), result);
45 onError(BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE, 0 /* vendorCode */);
46 return result;
47 }
48 } catch (RemoteException e) {
49 Slog.e(getLogTag(), "startEnumeration failed", e);
50 }
51 return 0;
52 }
53
54 @Override
55 public int stop(boolean initiatedByClient) {
56 if (mAlreadyCancelled) {
57 Slog.w(getLogTag(), "stopEnumerate: already cancelled!");
58 return 0;
59 }
60
61 try {
62 final int result = getDaemonWrapper().cancel();
63 if (result != 0) {
64 Slog.w(getLogTag(), "stop enumeration failed, result=" + result);
65 return result;
66 }
67 } catch (RemoteException e) {
68 Slog.e(getLogTag(), "stopEnumeration failed", e);
69 return ERROR_ESRCH;
70 }
71
72 // We don't actually stop enumerate, but inform the client that the cancel operation
73 // succeeded so we can start the next operation.
74 if (initiatedByClient) {
75 onError(BiometricConstants.BIOMETRIC_ERROR_CANCELED, 0 /* vendorCode */);
76 }
77 mAlreadyCancelled = true;
78 return 0; // success
79 }
80
81 @Override
82 public boolean onEnumerationResult(int fingerId, int groupId, int remaining) {
83 try {
84 getListener().onEnumerated(getHalDeviceId(), fingerId, groupId, remaining);
85 } catch (RemoteException e) {
86 Slog.w(getLogTag(), "Failed to notify enumerated:", e);
87 }
88 return remaining == 0;
89 }
90
91 @Override
92 public boolean onAuthenticated(int fingerId, int groupId) {
93 if (DEBUG) Slog.w(getLogTag(), "onAuthenticated() called for enumerate!");
94 return true; // Invalid for Enumerate.
95 }
96
97 @Override
98 public boolean onEnrollResult(int fingerId, int groupId, int rem) {
99 if (DEBUG) Slog.w(getLogTag(), "onEnrollResult() called for enumerate!");
100 return true; // Invalid for Enumerate.
101 }
102
103 @Override
104 public boolean onRemoved(int fingerId, int groupId, int remaining) {
105 if (DEBUG) Slog.w(getLogTag(), "onRemoved() called for enumerate!");
106 return true; // Invalid for Enumerate.
107 }
108}