blob: f889d2b41c16cc3c592641263944a90cfbbb6102 [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
Kevin Chyn836f2cf2018-08-27 11:06:39 -070017package com.android.server.biometrics;
Kevin Chyn037c4d52018-06-11 19:17:32 -070018
19import android.content.Context;
Kevin Chyna56dff72018-06-19 18:41:12 -070020import android.hardware.biometrics.BiometricAuthenticator;
Kevin Chyn037c4d52018-06-11 19:17:32 -070021import android.hardware.biometrics.BiometricConstants;
Kevin Chyn7782d142019-01-18 12:51:33 -080022import android.hardware.biometrics.BiometricsProtoEnums;
Kevin Chyn037c4d52018-06-11 19:17:32 -070023import android.os.IBinder;
24import android.os.RemoteException;
25import android.util.Slog;
26
Kevin Chyn6cf54e82018-09-18 19:13:27 -070027import java.util.ArrayList;
28
Kevin Chyn037c4d52018-06-11 19:17:32 -070029/**
30 * A class to keep track of the enumeration state for a given client.
31 */
32public abstract class EnumerateClient extends ClientMonitor {
Kevin Chyn4cc49f72019-04-24 13:53:35 -070033 public EnumerateClient(Context context, Constants constants,
Kevin Chyn355c6bf2018-09-20 22:14:19 -070034 BiometricServiceBase.DaemonWrapper daemon, long halDeviceId, IBinder token,
35 BiometricServiceBase.ServiceListener listener, int groupId, int userId,
36 boolean restricted, String owner) {
Kevin Chyn4cc49f72019-04-24 13:53:35 -070037 super(context, constants, daemon, halDeviceId, token, listener, userId, groupId, restricted,
Kevin Chyn87f257a2018-11-27 16:26:07 -080038 owner, 0 /* cookie */);
Kevin Chyn037c4d52018-06-11 19:17:32 -070039 }
40
41 @Override
Kevin Chyn6737c572019-02-08 16:10:54 -080042 public void notifyUserActivity() {
43 }
44
45 @Override
Kevin Chyn7782d142019-01-18 12:51:33 -080046 protected int statsAction() {
47 return BiometricsProtoEnums.ACTION_ENUMERATE;
48 }
49
50 @Override
Kevin Chyn037c4d52018-06-11 19:17:32 -070051 public int start() {
52 // The biometric template ids will be removed when we get confirmation from the HAL
53 try {
54 final int result = getDaemonWrapper().enumerate();
55 if (result != 0) {
56 Slog.w(getLogTag(), "start enumerate for user " + getTargetUserId()
57 + " failed, result=" + result);
Kevin Chyn4cc49f72019-04-24 13:53:35 -070058 mMetricsLogger.histogram(mConstants.tagEnumerateStartError(), result);
Kevin Chyna56dff72018-06-19 18:41:12 -070059 onError(getHalDeviceId(), BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE,
60 0 /* vendorCode */);
Kevin Chyn037c4d52018-06-11 19:17:32 -070061 return result;
62 }
63 } catch (RemoteException e) {
64 Slog.e(getLogTag(), "startEnumeration failed", e);
65 }
66 return 0;
67 }
68
69 @Override
70 public int stop(boolean initiatedByClient) {
71 if (mAlreadyCancelled) {
72 Slog.w(getLogTag(), "stopEnumerate: already cancelled!");
73 return 0;
74 }
75
76 try {
77 final int result = getDaemonWrapper().cancel();
78 if (result != 0) {
79 Slog.w(getLogTag(), "stop enumeration failed, result=" + result);
80 return result;
81 }
82 } catch (RemoteException e) {
83 Slog.e(getLogTag(), "stopEnumeration failed", e);
84 return ERROR_ESRCH;
85 }
86
87 // We don't actually stop enumerate, but inform the client that the cancel operation
88 // succeeded so we can start the next operation.
89 if (initiatedByClient) {
Kevin Chyna56dff72018-06-19 18:41:12 -070090 onError(getHalDeviceId(), BiometricConstants.BIOMETRIC_ERROR_CANCELED,
91 0 /* vendorCode */);
Kevin Chyn037c4d52018-06-11 19:17:32 -070092 }
93 mAlreadyCancelled = true;
94 return 0; // success
95 }
96
97 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -070098 public boolean onEnumerationResult(BiometricAuthenticator.Identifier identifier,
99 int remaining) {
Kevin Chyn037c4d52018-06-11 19:17:32 -0700100 try {
Kevin Chyn6737c572019-02-08 16:10:54 -0800101 if (getListener() != null) {
102 getListener().onEnumerated(identifier, remaining);
103 }
Kevin Chyn037c4d52018-06-11 19:17:32 -0700104 } catch (RemoteException e) {
105 Slog.w(getLogTag(), "Failed to notify enumerated:", e);
106 }
107 return remaining == 0;
108 }
109
110 @Override
Kevin Chynb528d692018-07-20 11:53:14 -0700111 public boolean onAuthenticated(BiometricAuthenticator.Identifier identifier,
Kevin Chyn6cf54e82018-09-18 19:13:27 -0700112 boolean authenticated, ArrayList<Byte> token) {
Kevin Chyn037c4d52018-06-11 19:17:32 -0700113 if (DEBUG) Slog.w(getLogTag(), "onAuthenticated() called for enumerate!");
114 return true; // Invalid for Enumerate.
115 }
116
117 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -0700118 public boolean onEnrollResult(BiometricAuthenticator.Identifier identifier, int rem) {
Kevin Chyn037c4d52018-06-11 19:17:32 -0700119 if (DEBUG) Slog.w(getLogTag(), "onEnrollResult() called for enumerate!");
120 return true; // Invalid for Enumerate.
121 }
122
123 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -0700124 public boolean onRemoved(BiometricAuthenticator.Identifier identifier, int remaining) {
Kevin Chyn037c4d52018-06-11 19:17:32 -0700125 if (DEBUG) Slog.w(getLogTag(), "onRemoved() called for enumerate!");
126 return true; // Invalid for Enumerate.
127 }
128}