blob: 15b3773314bff1083a0e3a91aa4353624d2737ff [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;
22import android.os.IBinder;
23import android.os.RemoteException;
24import android.util.Slog;
25
Kevin Chyn6cf54e82018-09-18 19:13:27 -070026import java.util.ArrayList;
27
Kevin Chyn037c4d52018-06-11 19:17:32 -070028/**
29 * A class to keep track of the remove state for a given client.
30 */
31public abstract class RemovalClient extends ClientMonitor {
Kevin Chyna56dff72018-06-19 18:41:12 -070032 private final int mBiometricId;
33 private final BiometricUtils mBiometricUtils;
Kevin Chyn037c4d52018-06-11 19:17:32 -070034
Kevin Chyn355c6bf2018-09-20 22:14:19 -070035 public RemovalClient(Context context, Metrics metrics,
36 BiometricServiceBase.DaemonWrapper daemon, long halDeviceId, IBinder token,
37 BiometricServiceBase.ServiceListener listener, int biometricId, int groupId, int userId,
38 boolean restricted, String owner, BiometricUtils utils) {
Kevin Chyn037c4d52018-06-11 19:17:32 -070039 super(context, metrics, daemon, halDeviceId, token, listener, userId, groupId, restricted,
40 owner);
Kevin Chyna56dff72018-06-19 18:41:12 -070041 mBiometricId = biometricId;
42 mBiometricUtils = utils;
Kevin Chyn037c4d52018-06-11 19:17:32 -070043 }
44
45 @Override
46 public int start() {
47 // The biometric template ids will be removed when we get confirmation from the HAL
48 try {
Kevin Chyna56dff72018-06-19 18:41:12 -070049 final int result = getDaemonWrapper().remove(getGroupId(), mBiometricId);
Kevin Chyn037c4d52018-06-11 19:17:32 -070050 if (result != 0) {
Kevin Chyna56dff72018-06-19 18:41:12 -070051 Slog.w(getLogTag(), "startRemove with id = " + mBiometricId + " failed, result=" +
Kevin Chyn037c4d52018-06-11 19:17:32 -070052 result);
53 mMetricsLogger.histogram(mMetrics.tagRemoveStartError(), result);
Kevin Chyna56dff72018-06-19 18:41:12 -070054 onError(getHalDeviceId(), BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE,
55 0 /* vendorCode */);
Kevin Chyn037c4d52018-06-11 19:17:32 -070056 return result;
57 }
58 } catch (RemoteException e) {
59 Slog.e(getLogTag(), "startRemove failed", e);
60 }
61 return 0;
62 }
63
64 @Override
65 public int stop(boolean initiatedByClient) {
66 if (mAlreadyCancelled) {
67 Slog.w(getLogTag(), "stopRemove: already cancelled!");
68 return 0;
69 }
70
71 try {
72 final int result = getDaemonWrapper().cancel();
73 if (result != 0) {
74 Slog.w(getLogTag(), "stopRemoval failed, result=" + result);
75 return result;
76 }
77 if (DEBUG) Slog.w(getLogTag(), "client " + getOwnerString() + " is no longer removing");
78 } catch (RemoteException e) {
79 Slog.e(getLogTag(), "stopRemoval failed", e);
80 return ERROR_ESRCH;
81 }
82 mAlreadyCancelled = true;
83 return 0; // success
84 }
85
86 /*
87 * @return true if we're done.
88 */
Kevin Chyna56dff72018-06-19 18:41:12 -070089 private boolean sendRemoved(BiometricAuthenticator.Identifier identifier,
90 int remaining) {
Kevin Chyn037c4d52018-06-11 19:17:32 -070091 try {
Kevin Chyna56dff72018-06-19 18:41:12 -070092 getListener().onRemoved(identifier, remaining);
Kevin Chyn037c4d52018-06-11 19:17:32 -070093 } catch (RemoteException e) {
94 Slog.w(getLogTag(), "Failed to notify Removed:", e);
95 }
96 return remaining == 0;
97 }
98
99 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -0700100 public boolean onRemoved(BiometricAuthenticator.Identifier identifier, int remaining) {
101 if (identifier.getBiometricId() != 0) {
102 mBiometricUtils.removeBiometricForUser(getContext(), getTargetUserId(),
103 identifier.getBiometricId());
Kevin Chyn037c4d52018-06-11 19:17:32 -0700104 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700105 return sendRemoved(identifier, remaining);
Kevin Chyn037c4d52018-06-11 19:17:32 -0700106 }
107
108 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -0700109 public boolean onEnrollResult(BiometricAuthenticator.Identifier identifier, int rem) {
Kevin Chyn037c4d52018-06-11 19:17:32 -0700110 if (DEBUG) Slog.w(getLogTag(), "onEnrollResult() called for remove!");
111 return true; // Invalid for Remove
112 }
113
114 @Override
Kevin Chynb528d692018-07-20 11:53:14 -0700115 public boolean onAuthenticated(BiometricAuthenticator.Identifier identifier,
Kevin Chyn6cf54e82018-09-18 19:13:27 -0700116 boolean authenticated, ArrayList<Byte> token) {
Kevin Chyn037c4d52018-06-11 19:17:32 -0700117 if (DEBUG) Slog.w(getLogTag(), "onAuthenticated() called for remove!");
118 return true; // Invalid for Remove.
119 }
120
121 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -0700122 public boolean onEnumerationResult(BiometricAuthenticator.Identifier identifier,
123 int remaining) {
Kevin Chyn037c4d52018-06-11 19:17:32 -0700124 if (DEBUG) Slog.w(getLogTag(), "onEnumerationResult() called for remove!");
125 return true; // Invalid for Remove.
126 }
127}