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; |
Kevin Chyn | 7782d14 | 2019-01-18 12:51:33 -0800 | [diff] [blame] | 22 | import android.hardware.biometrics.BiometricsProtoEnums; |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 23 | import android.os.IBinder; |
| 24 | import android.os.RemoteException; |
| 25 | import android.util.Slog; |
| 26 | |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 27 | import java.util.ArrayList; |
| 28 | |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 29 | /** |
| 30 | * A class to keep track of the enumeration state for a given client. |
| 31 | */ |
| 32 | public abstract class EnumerateClient extends ClientMonitor { |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 33 | public EnumerateClient(Context context, Constants constants, |
Kevin Chyn | 355c6bf | 2018-09-20 22:14:19 -0700 | [diff] [blame] | 34 | BiometricServiceBase.DaemonWrapper daemon, long halDeviceId, IBinder token, |
| 35 | BiometricServiceBase.ServiceListener listener, int groupId, int userId, |
| 36 | boolean restricted, String owner) { |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 37 | super(context, constants, daemon, halDeviceId, token, listener, userId, groupId, restricted, |
Kevin Chyn | 87f257a | 2018-11-27 16:26:07 -0800 | [diff] [blame] | 38 | owner, 0 /* cookie */); |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | @Override |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 42 | public void notifyUserActivity() { |
| 43 | } |
| 44 | |
| 45 | @Override |
Kevin Chyn | 7782d14 | 2019-01-18 12:51:33 -0800 | [diff] [blame] | 46 | protected int statsAction() { |
| 47 | return BiometricsProtoEnums.ACTION_ENUMERATE; |
| 48 | } |
| 49 | |
| 50 | @Override |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 51 | 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 Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 58 | mMetricsLogger.histogram(mConstants.tagEnumerateStartError(), result); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 59 | onError(getHalDeviceId(), BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE, |
| 60 | 0 /* vendorCode */); |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 61 | 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 Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 90 | onError(getHalDeviceId(), BiometricConstants.BIOMETRIC_ERROR_CANCELED, |
| 91 | 0 /* vendorCode */); |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 92 | } |
| 93 | mAlreadyCancelled = true; |
| 94 | return 0; // success |
| 95 | } |
| 96 | |
| 97 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 98 | public boolean onEnumerationResult(BiometricAuthenticator.Identifier identifier, |
| 99 | int remaining) { |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 100 | try { |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 101 | if (getListener() != null) { |
| 102 | getListener().onEnumerated(identifier, remaining); |
| 103 | } |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 104 | } catch (RemoteException e) { |
| 105 | Slog.w(getLogTag(), "Failed to notify enumerated:", e); |
| 106 | } |
| 107 | return remaining == 0; |
| 108 | } |
| 109 | |
| 110 | @Override |
Kevin Chyn | b528d69 | 2018-07-20 11:53:14 -0700 | [diff] [blame] | 111 | public boolean onAuthenticated(BiometricAuthenticator.Identifier identifier, |
Kevin Chyn | 6cf54e8 | 2018-09-18 19:13:27 -0700 | [diff] [blame] | 112 | boolean authenticated, ArrayList<Byte> token) { |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 113 | if (DEBUG) Slog.w(getLogTag(), "onAuthenticated() called for enumerate!"); |
| 114 | return true; // Invalid for Enumerate. |
| 115 | } |
| 116 | |
| 117 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 118 | public boolean onEnrollResult(BiometricAuthenticator.Identifier identifier, int rem) { |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 119 | if (DEBUG) Slog.w(getLogTag(), "onEnrollResult() called for enumerate!"); |
| 120 | return true; // Invalid for Enumerate. |
| 121 | } |
| 122 | |
| 123 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 124 | public boolean onRemoved(BiometricAuthenticator.Identifier identifier, int remaining) { |
Kevin Chyn | 037c4d5 | 2018-06-11 19:17:32 -0700 | [diff] [blame] | 125 | if (DEBUG) Slog.w(getLogTag(), "onRemoved() called for enumerate!"); |
| 126 | return true; // Invalid for Enumerate. |
| 127 | } |
| 128 | } |