Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 1 | /* |
| 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 Chyn | 836f2cf | 2018-08-27 11:06:39 -0700 | [diff] [blame] | 17 | package com.android.server.biometrics; |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 18 | |
| 19 | import android.content.Context; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 20 | import android.hardware.biometrics.BiometricAuthenticator; |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 21 | import android.hardware.biometrics.BiometricConstants; |
| 22 | import android.os.IBinder; |
| 23 | import android.os.RemoteException; |
| 24 | import android.util.Slog; |
| 25 | |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 26 | import java.util.ArrayList; |
| 27 | |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 28 | /** |
| 29 | * A class to keep track of the remove state for a given client. |
| 30 | */ |
| 31 | public abstract class RemovalClient extends ClientMonitor { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 32 | private final int mBiometricId; |
| 33 | private final BiometricUtils mBiometricUtils; |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 34 | |
Kevin Chyn | 355c6bf | 2018-09-20 22:14:19 -0700 | [diff] [blame] | 35 | 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 Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 39 | super(context, metrics, daemon, halDeviceId, token, listener, userId, groupId, restricted, |
| 40 | owner); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 41 | mBiometricId = biometricId; |
| 42 | mBiometricUtils = utils; |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 43 | } |
| 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 Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 49 | final int result = getDaemonWrapper().remove(getGroupId(), mBiometricId); |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 50 | if (result != 0) { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 51 | Slog.w(getLogTag(), "startRemove with id = " + mBiometricId + " failed, result=" + |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 52 | result); |
| 53 | mMetricsLogger.histogram(mMetrics.tagRemoveStartError(), result); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 54 | onError(getHalDeviceId(), BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE, |
| 55 | 0 /* vendorCode */); |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 56 | 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 Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 89 | private boolean sendRemoved(BiometricAuthenticator.Identifier identifier, |
| 90 | int remaining) { |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 91 | try { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 92 | getListener().onRemoved(identifier, remaining); |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 93 | } catch (RemoteException e) { |
| 94 | Slog.w(getLogTag(), "Failed to notify Removed:", e); |
| 95 | } |
| 96 | return remaining == 0; |
| 97 | } |
| 98 | |
| 99 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 100 | public boolean onRemoved(BiometricAuthenticator.Identifier identifier, int remaining) { |
| 101 | if (identifier.getBiometricId() != 0) { |
| 102 | mBiometricUtils.removeBiometricForUser(getContext(), getTargetUserId(), |
| 103 | identifier.getBiometricId()); |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 104 | } |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 105 | return sendRemoved(identifier, remaining); |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 109 | public boolean onEnrollResult(BiometricAuthenticator.Identifier identifier, int rem) { |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 110 | if (DEBUG) Slog.w(getLogTag(), "onEnrollResult() called for remove!"); |
| 111 | return true; // Invalid for Remove |
| 112 | } |
| 113 | |
| 114 | @Override |
Kevin Chyn | b528d69 | 2018-07-20 11:53:14 -0700 | [diff] [blame] | 115 | public boolean onAuthenticated(BiometricAuthenticator.Identifier identifier, |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 116 | boolean authenticated, ArrayList<Byte> token) { |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 117 | if (DEBUG) Slog.w(getLogTag(), "onAuthenticated() called for remove!"); |
| 118 | return true; // Invalid for Remove. |
| 119 | } |
| 120 | |
| 121 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 122 | public boolean onEnumerationResult(BiometricAuthenticator.Identifier identifier, |
| 123 | int remaining) { |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 124 | if (DEBUG) Slog.w(getLogTag(), "onEnumerationResult() called for remove!"); |
| 125 | return true; // Invalid for Remove. |
| 126 | } |
| 127 | } |