Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [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 | 2ffadb3 | 2018-06-19 11:29:38 -0700 | [diff] [blame] | 17 | package com.android.server.biometrics.face; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 18 | |
| 19 | import static android.Manifest.permission.INTERACT_ACROSS_USERS; |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 20 | import static android.Manifest.permission.MANAGE_BIOMETRIC; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 21 | import static android.Manifest.permission.RESET_FACE_LOCKOUT; |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 22 | import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL; |
Ilya Matyukhin | 0f9da35 | 2019-10-03 14:10:01 -0700 | [diff] [blame] | 23 | import static android.hardware.biometrics.BiometricAuthenticator.TYPE_FACE; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 24 | |
| 25 | import android.app.ActivityManager; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 26 | import android.app.AppOpsManager; |
Kevin Chyn | 56e4c3d | 2019-04-23 11:28:43 -0700 | [diff] [blame] | 27 | import android.app.Notification; |
| 28 | import android.app.NotificationChannel; |
| 29 | import android.app.NotificationManager; |
| 30 | import android.app.PendingIntent; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 31 | import android.content.Context; |
Kevin Chyn | 56e4c3d | 2019-04-23 11:28:43 -0700 | [diff] [blame] | 32 | import android.content.Intent; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 33 | import android.content.pm.UserInfo; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 34 | import android.hardware.biometrics.BiometricAuthenticator; |
| 35 | import android.hardware.biometrics.BiometricConstants; |
Kevin Chyn | 7782d14 | 2019-01-18 12:51:33 -0800 | [diff] [blame] | 36 | import android.hardware.biometrics.BiometricsProtoEnums; |
Ilya Matyukhin | ef410e3 | 2020-02-04 13:39:48 -0800 | [diff] [blame] | 37 | import android.hardware.biometrics.IBiometricNativeHandle; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 38 | import android.hardware.biometrics.IBiometricServiceLockoutResetCallback; |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 39 | import android.hardware.biometrics.IBiometricServiceReceiverInternal; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 40 | import android.hardware.biometrics.face.V1_0.IBiometricsFace; |
| 41 | import android.hardware.biometrics.face.V1_0.IBiometricsFaceClientCallback; |
Kevin Chyn | b95f152 | 2019-03-04 16:45:15 -0800 | [diff] [blame] | 42 | import android.hardware.biometrics.face.V1_0.OptionalBool; |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 43 | import android.hardware.biometrics.face.V1_0.Status; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 44 | import android.hardware.face.Face; |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 45 | import android.hardware.face.FaceManager; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 46 | import android.hardware.face.IFaceService; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 47 | import android.hardware.face.IFaceServiceReceiver; |
| 48 | import android.os.Binder; |
Joe Onorato | bf955d2 | 2019-03-25 00:16:58 -0700 | [diff] [blame] | 49 | import android.os.Build; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 50 | import android.os.Environment; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 51 | import android.os.IBinder; |
Joe Onorato | db39600 | 2019-04-05 19:49:27 -0700 | [diff] [blame] | 52 | import android.os.NativeHandle; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 53 | import android.os.RemoteException; |
| 54 | import android.os.SELinux; |
Joe Onorato | 108413a | 2019-04-03 18:20:52 -0700 | [diff] [blame] | 55 | import android.os.SystemProperties; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 56 | import android.os.UserHandle; |
| 57 | import android.os.UserManager; |
joshmccloskey | 4ceaf6b | 2019-08-21 11:26:08 -0700 | [diff] [blame] | 58 | import android.provider.Settings; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 59 | import android.util.Slog; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 60 | |
Kevin Chyn | 56e4c3d | 2019-04-23 11:28:43 -0700 | [diff] [blame] | 61 | import com.android.internal.R; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 62 | import com.android.internal.annotations.GuardedBy; |
| 63 | import com.android.internal.logging.MetricsLogger; |
| 64 | import com.android.internal.util.DumpUtils; |
| 65 | import com.android.server.SystemServerInitThreadPool; |
Kevin Chyn | a38653c | 2019-02-11 17:46:21 -0800 | [diff] [blame] | 66 | import com.android.server.biometrics.AuthenticationClient; |
Kevin Chyn | 355c6bf | 2018-09-20 22:14:19 -0700 | [diff] [blame] | 67 | import com.android.server.biometrics.BiometricServiceBase; |
Kevin Chyn | 836f2cf | 2018-08-27 11:06:39 -0700 | [diff] [blame] | 68 | import com.android.server.biometrics.BiometricUtils; |
Ilya Matyukhin | 9dac848 | 2019-07-09 11:03:07 -0700 | [diff] [blame] | 69 | import com.android.server.biometrics.ClientMonitor; |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 70 | import com.android.server.biometrics.Constants; |
Kevin Chyn | 0ce7085 | 2019-05-10 10:29:18 -0700 | [diff] [blame] | 71 | import com.android.server.biometrics.EnumerateClient; |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 72 | import com.android.server.biometrics.RemovalClient; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 73 | |
| 74 | import org.json.JSONArray; |
| 75 | import org.json.JSONException; |
| 76 | import org.json.JSONObject; |
| 77 | |
| 78 | import java.io.File; |
| 79 | import java.io.FileDescriptor; |
Joe Onorato | db39600 | 2019-04-05 19:49:27 -0700 | [diff] [blame] | 80 | import java.io.FileOutputStream; |
| 81 | import java.io.IOException; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 82 | import java.io.PrintWriter; |
| 83 | import java.util.ArrayList; |
Joe Onorato | db39600 | 2019-04-05 19:49:27 -0700 | [diff] [blame] | 84 | import java.util.Arrays; |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 85 | import java.util.HashMap; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 86 | import java.util.List; |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 87 | import java.util.Map; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * A service to manage multiple clients that want to access the face HAL API. |
| 91 | * The service is responsible for maintaining a list of clients and dispatching all |
Kevin Chyn | 51676d2 | 2018-11-05 18:00:43 -0800 | [diff] [blame] | 92 | * face-related events. |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 93 | * |
| 94 | * @hide |
| 95 | */ |
Kevin Chyn | 355c6bf | 2018-09-20 22:14:19 -0700 | [diff] [blame] | 96 | public class FaceService extends BiometricServiceBase { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 97 | |
| 98 | protected static final String TAG = "FaceService"; |
| 99 | private static final boolean DEBUG = true; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 100 | private static final String FACE_DATA_DIR = "facedata"; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 101 | private static final String ACTION_LOCKOUT_RESET = |
Kevin Chyn | 2ffadb3 | 2018-06-19 11:29:38 -0700 | [diff] [blame] | 102 | "com.android.server.biometrics.face.ACTION_LOCKOUT_RESET"; |
Kevin Chyn | e46a216 | 2018-09-20 18:43:01 -0700 | [diff] [blame] | 103 | private static final int CHALLENGE_TIMEOUT_SEC = 600; // 10 minutes |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 104 | |
Kevin Chyn | dbfbed4 | 2019-06-13 17:01:30 -0700 | [diff] [blame] | 105 | private static final String NOTIFICATION_TAG = "FaceService"; |
| 106 | private static final int NOTIFICATION_ID = 1; |
| 107 | |
joshmccloskey | 4ceaf6b | 2019-08-21 11:26:08 -0700 | [diff] [blame] | 108 | private static final String SKIP_KEYGUARD_ACQUIRE_IGNORE_LIST = |
| 109 | "com.android.server.biometrics.face.skip_keyguard_acquire_ignore_list"; |
| 110 | |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 111 | /** |
| 112 | * Events for bugreports. |
| 113 | */ |
| 114 | public static final class AuthenticationEvent { |
| 115 | private long mStartTime; |
| 116 | private long mLatency; |
| 117 | // Only valid if mError is 0 |
| 118 | private boolean mAuthenticated; |
| 119 | private int mError; |
| 120 | // Only valid if mError is ERROR_VENDOR |
| 121 | private int mVendorError; |
joshmccloskey | 0d75a88 | 2020-01-21 14:59:46 -0800 | [diff] [blame] | 122 | private int mUser; |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 123 | |
| 124 | AuthenticationEvent(long startTime, long latency, boolean authenticated, int error, |
joshmccloskey | 0d75a88 | 2020-01-21 14:59:46 -0800 | [diff] [blame] | 125 | int vendorError, int user) { |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 126 | mStartTime = startTime; |
| 127 | mLatency = latency; |
| 128 | mAuthenticated = authenticated; |
| 129 | mError = error; |
| 130 | mVendorError = vendorError; |
joshmccloskey | 0d75a88 | 2020-01-21 14:59:46 -0800 | [diff] [blame] | 131 | mUser = user; |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | public String toString(Context context) { |
| 135 | return "Start: " + mStartTime |
| 136 | + "\tLatency: " + mLatency |
| 137 | + "\tAuthenticated: " + mAuthenticated |
| 138 | + "\tError: " + mError |
| 139 | + "\tVendorCode: " + mVendorError |
joshmccloskey | 0d75a88 | 2020-01-21 14:59:46 -0800 | [diff] [blame] | 140 | + "\tUser: " + mUser |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 141 | + "\t" + FaceManager.getErrorString(context, mError, mVendorError); |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Keep a short historical buffer of stats, with an aggregated usage time. |
| 147 | */ |
| 148 | private class UsageStats { |
| 149 | static final int EVENT_LOG_SIZE = 100; |
| 150 | |
| 151 | Context mContext; |
| 152 | List<AuthenticationEvent> mAuthenticationEvents; |
| 153 | |
| 154 | int acceptCount; |
| 155 | int rejectCount; |
| 156 | Map<Integer, Integer> mErrorCount; |
| 157 | |
| 158 | long acceptLatency; |
| 159 | long rejectLatency; |
| 160 | Map<Integer, Long> mErrorLatency; |
| 161 | |
| 162 | UsageStats(Context context) { |
| 163 | mAuthenticationEvents = new ArrayList<>(); |
| 164 | mErrorCount = new HashMap<>(); |
| 165 | mErrorLatency = new HashMap<>(); |
| 166 | mContext = context; |
| 167 | } |
| 168 | |
| 169 | void addEvent(AuthenticationEvent event) { |
| 170 | if (mAuthenticationEvents.size() >= EVENT_LOG_SIZE) { |
| 171 | mAuthenticationEvents.remove(0); |
| 172 | } |
| 173 | mAuthenticationEvents.add(event); |
| 174 | |
| 175 | if (event.mAuthenticated) { |
| 176 | acceptCount++; |
| 177 | acceptLatency += event.mLatency; |
| 178 | } else if (event.mError == 0) { |
| 179 | rejectCount++; |
| 180 | rejectLatency += event.mLatency; |
| 181 | } else { |
| 182 | mErrorCount.put(event.mError, mErrorCount.getOrDefault(event.mError, 0) + 1); |
| 183 | mErrorLatency.put(event.mError, |
| 184 | mErrorLatency.getOrDefault(event.mError, 0l) + event.mLatency); |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | void print(PrintWriter pw) { |
| 189 | pw.println("Events since last reboot: " + mAuthenticationEvents.size()); |
| 190 | for (int i = 0; i < mAuthenticationEvents.size(); i++) { |
| 191 | pw.println(mAuthenticationEvents.get(i).toString(mContext)); |
| 192 | } |
| 193 | |
| 194 | // Dump aggregated usage stats |
| 195 | // TODO: Remove or combine with json dump in a future release |
| 196 | pw.println("Accept\tCount: " + acceptCount + "\tLatency: " + acceptLatency |
| 197 | + "\tAverage: " + (acceptCount > 0 ? acceptLatency / acceptCount : 0)); |
| 198 | pw.println("Reject\tCount: " + rejectCount + "\tLatency: " + rejectLatency |
| 199 | + "\tAverage: " + (rejectCount > 0 ? rejectLatency / rejectCount : 0)); |
| 200 | |
| 201 | for (Integer key : mErrorCount.keySet()) { |
| 202 | final int count = mErrorCount.get(key); |
| 203 | pw.println("Error" + key + "\tCount: " + count |
| 204 | + "\tLatency: " + mErrorLatency.getOrDefault(key, 0l) |
| 205 | + "\tAverage: " + (count > 0 ? mErrorLatency.getOrDefault(key, 0l) / count |
| 206 | : 0) |
| 207 | + "\t" + FaceManager.getErrorString(mContext, key, 0 /* vendorCode */)); |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | |
Kevin Chyn | 8b7a037 | 2018-09-17 15:06:05 -0700 | [diff] [blame] | 212 | private final class FaceAuthClient extends AuthenticationClientImpl { |
Kevin Chyn | 0ce7085 | 2019-05-10 10:29:18 -0700 | [diff] [blame] | 213 | private int mLastAcquire; |
| 214 | |
Kevin Chyn | 8b7a037 | 2018-09-17 15:06:05 -0700 | [diff] [blame] | 215 | public FaceAuthClient(Context context, |
| 216 | DaemonWrapper daemon, long halDeviceId, IBinder token, |
| 217 | ServiceListener listener, int targetUserId, int groupId, long opId, |
Ilya Matyukhin | ef410e3 | 2020-02-04 13:39:48 -0800 | [diff] [blame] | 218 | boolean restricted, String owner, int cookie, boolean requireConfirmation, |
| 219 | IBiometricNativeHandle windowId) { |
Kevin Chyn | 8b7a037 | 2018-09-17 15:06:05 -0700 | [diff] [blame] | 220 | super(context, daemon, halDeviceId, token, listener, targetUserId, groupId, opId, |
Ilya Matyukhin | ef410e3 | 2020-02-04 13:39:48 -0800 | [diff] [blame] | 221 | restricted, owner, cookie, requireConfirmation, windowId); |
Kevin Chyn | 8b7a037 | 2018-09-17 15:06:05 -0700 | [diff] [blame] | 222 | } |
Kevin Chyn | 7782d14 | 2019-01-18 12:51:33 -0800 | [diff] [blame] | 223 | |
| 224 | @Override |
| 225 | protected int statsModality() { |
| 226 | return FaceService.this.statsModality(); |
| 227 | } |
Kevin Chyn | a38653c | 2019-02-11 17:46:21 -0800 | [diff] [blame] | 228 | |
| 229 | @Override |
| 230 | public boolean shouldFrameworkHandleLockout() { |
| 231 | return false; |
| 232 | } |
Kevin Chyn | 56d6b07 | 2019-02-13 18:39:01 -0800 | [diff] [blame] | 233 | |
| 234 | @Override |
Kevin Chyn | 0ce7085 | 2019-05-10 10:29:18 -0700 | [diff] [blame] | 235 | public boolean wasUserDetected() { |
Ilya Matyukhin | c90507e | 2019-08-20 15:38:57 -0700 | [diff] [blame] | 236 | return mLastAcquire != FaceManager.FACE_ACQUIRED_NOT_DETECTED |
| 237 | && mLastAcquire != FaceManager.FACE_ACQUIRED_SENSOR_DIRTY; |
Kevin Chyn | 0ce7085 | 2019-05-10 10:29:18 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | @Override |
Kevin Chyn | 56d6b07 | 2019-02-13 18:39:01 -0800 | [diff] [blame] | 241 | public boolean onAuthenticated(BiometricAuthenticator.Identifier identifier, |
| 242 | boolean authenticated, ArrayList<Byte> token) { |
| 243 | final boolean result = super.onAuthenticated(identifier, authenticated, token); |
| 244 | |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 245 | mUsageStats.addEvent(new AuthenticationEvent( |
| 246 | getStartTimeMs(), |
| 247 | System.currentTimeMillis() - getStartTimeMs() /* latency */, |
| 248 | authenticated, |
| 249 | 0 /* error */, |
joshmccloskey | 0d75a88 | 2020-01-21 14:59:46 -0800 | [diff] [blame] | 250 | 0 /* vendorError */, |
| 251 | getTargetUserId())); |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 252 | |
Kevin Chyn | 56d6b07 | 2019-02-13 18:39:01 -0800 | [diff] [blame] | 253 | // For face, the authentication lifecycle ends either when |
| 254 | // 1) Authenticated == true |
| 255 | // 2) Error occurred |
| 256 | // 3) Authenticated == false |
| 257 | // Fingerprint currently does not end when the third condition is met which is a bug, |
| 258 | // but let's leave it as-is for now. |
| 259 | return result || !authenticated; |
| 260 | } |
Kevin Chyn | 56e4c3d | 2019-04-23 11:28:43 -0700 | [diff] [blame] | 261 | |
| 262 | @Override |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 263 | public boolean onError(long deviceId, int error, int vendorCode) { |
| 264 | mUsageStats.addEvent(new AuthenticationEvent( |
| 265 | getStartTimeMs(), |
| 266 | System.currentTimeMillis() - getStartTimeMs() /* latency */, |
| 267 | false /* authenticated */, |
| 268 | error, |
joshmccloskey | 0d75a88 | 2020-01-21 14:59:46 -0800 | [diff] [blame] | 269 | vendorCode, |
| 270 | getTargetUserId())); |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 271 | |
| 272 | return super.onError(deviceId, error, vendorCode); |
| 273 | } |
| 274 | |
| 275 | @Override |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 276 | public int[] getAcquireIgnorelist() { |
| 277 | if (isBiometricPrompt()) { |
| 278 | return mBiometricPromptIgnoreList; |
| 279 | } else { |
| 280 | // Keyguard |
| 281 | return mKeyguardIgnoreList; |
| 282 | } |
| 283 | } |
| 284 | |
| 285 | @Override |
| 286 | public int[] getAcquireVendorIgnorelist() { |
| 287 | if (isBiometricPrompt()) { |
| 288 | return mBiometricPromptIgnoreListVendor; |
| 289 | } else { |
| 290 | // Keyguard |
| 291 | return mKeyguardIgnoreListVendor; |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | @Override |
Kevin Chyn | 56e4c3d | 2019-04-23 11:28:43 -0700 | [diff] [blame] | 296 | public boolean onAcquired(int acquireInfo, int vendorCode) { |
| 297 | |
Kevin Chyn | 0ce7085 | 2019-05-10 10:29:18 -0700 | [diff] [blame] | 298 | mLastAcquire = acquireInfo; |
| 299 | |
Kevin Chyn | 56e4c3d | 2019-04-23 11:28:43 -0700 | [diff] [blame] | 300 | if (acquireInfo == FaceManager.FACE_ACQUIRED_RECALIBRATE) { |
| 301 | final String name = |
| 302 | getContext().getString(R.string.face_recalibrate_notification_name); |
| 303 | final String title = |
| 304 | getContext().getString(R.string.face_recalibrate_notification_title); |
| 305 | final String content = |
| 306 | getContext().getString(R.string.face_recalibrate_notification_content); |
| 307 | |
| 308 | final Intent intent = new Intent("android.settings.FACE_SETTINGS"); |
| 309 | intent.setPackage("com.android.settings"); |
| 310 | |
| 311 | final PendingIntent pendingIntent = PendingIntent.getActivityAsUser(getContext(), |
| 312 | 0 /* requestCode */, intent, 0 /* flags */, null /* options */, |
| 313 | UserHandle.CURRENT); |
| 314 | |
Kevin Chyn | dbfbed4 | 2019-06-13 17:01:30 -0700 | [diff] [blame] | 315 | final String channelName = "FaceEnrollNotificationChannel"; |
Kevin Chyn | 56e4c3d | 2019-04-23 11:28:43 -0700 | [diff] [blame] | 316 | |
Kevin Chyn | dbfbed4 | 2019-06-13 17:01:30 -0700 | [diff] [blame] | 317 | NotificationChannel channel = new NotificationChannel(channelName, name, |
Kevin Chyn | 56e4c3d | 2019-04-23 11:28:43 -0700 | [diff] [blame] | 318 | NotificationManager.IMPORTANCE_HIGH); |
Kevin Chyn | dbfbed4 | 2019-06-13 17:01:30 -0700 | [diff] [blame] | 319 | Notification notification = new Notification.Builder(getContext(), channelName) |
Kevin Chyn | 56e4c3d | 2019-04-23 11:28:43 -0700 | [diff] [blame] | 320 | .setSmallIcon(R.drawable.ic_lock) |
| 321 | .setContentTitle(title) |
| 322 | .setContentText(content) |
| 323 | .setSubText(name) |
| 324 | .setOnlyAlertOnce(true) |
| 325 | .setLocalOnly(true) |
| 326 | .setAutoCancel(true) |
| 327 | .setCategory(Notification.CATEGORY_SYSTEM) |
| 328 | .setContentIntent(pendingIntent) |
Kevin Chyn | 0c3a998 | 2019-06-11 19:09:27 -0700 | [diff] [blame] | 329 | .setVisibility(Notification.VISIBILITY_SECRET) |
Kevin Chyn | 56e4c3d | 2019-04-23 11:28:43 -0700 | [diff] [blame] | 330 | .build(); |
| 331 | |
Kevin Chyn | dbfbed4 | 2019-06-13 17:01:30 -0700 | [diff] [blame] | 332 | mNotificationManager.createNotificationChannel(channel); |
| 333 | mNotificationManager.notifyAsUser(NOTIFICATION_TAG, NOTIFICATION_ID, notification, |
| 334 | UserHandle.CURRENT); |
Kevin Chyn | 56e4c3d | 2019-04-23 11:28:43 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | return super.onAcquired(acquireInfo, vendorCode); |
| 338 | } |
Kevin Chyn | 8b7a037 | 2018-09-17 15:06:05 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 341 | /** |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 342 | * Receives the incoming binder calls from FaceManager. |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 343 | */ |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 344 | private final class FaceServiceWrapper extends IFaceService.Stub { |
Curtis Belmonte | 4578854 | 2019-07-23 11:07:27 -0700 | [diff] [blame] | 345 | private static final int ENROLL_TIMEOUT_SEC = 75; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 346 | |
| 347 | /** |
| 348 | * The following methods contain common code which is shared in biometrics/common. |
| 349 | */ |
Kevin Chyn | a38653c | 2019-02-11 17:46:21 -0800 | [diff] [blame] | 350 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 351 | @Override // Binder call |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 352 | public long generateChallenge(IBinder token) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 353 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 354 | return startGenerateChallenge(token); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | @Override // Binder call |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 358 | public int revokeChallenge(IBinder token) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 359 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | 7a207e4 | 2019-07-27 17:50:33 -0700 | [diff] [blame] | 360 | mHandler.post(() -> { |
| 361 | // TODO(b/137106905): Schedule binder calls in FaceService to avoid deadlocks. |
| 362 | if (getCurrentClient() == null) { |
| 363 | // if we aren't handling any other HIDL calls (mCurrentClient == null), revoke |
| 364 | // the challenge right away. |
| 365 | startRevokeChallenge(token); |
| 366 | } else { |
| 367 | // postpone revoking the challenge until we finish processing the current HIDL |
| 368 | // call. |
| 369 | mRevokeChallengePending = true; |
| 370 | } |
| 371 | }); |
| 372 | return Status.OK; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | @Override // Binder call |
Kevin Chyn | 593e626 | 2019-06-28 13:24:44 -0700 | [diff] [blame] | 376 | public void enroll(int userId, final IBinder token, final byte[] cryptoToken, |
Kevin Chyn | 1f16c2d | 2018-12-07 13:06:08 -0800 | [diff] [blame] | 377 | final IFaceServiceReceiver receiver, final String opPackageName, |
Ilya Matyukhin | ef410e3 | 2020-02-04 13:39:48 -0800 | [diff] [blame] | 378 | final int[] disabledFeatures, IBiometricNativeHandle windowId) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 379 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | 593e626 | 2019-06-28 13:24:44 -0700 | [diff] [blame] | 380 | updateActiveGroup(userId, opPackageName); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 381 | |
Kevin Chyn | dbfbed4 | 2019-06-13 17:01:30 -0700 | [diff] [blame] | 382 | mNotificationManager.cancelAsUser(NOTIFICATION_TAG, NOTIFICATION_ID, |
| 383 | UserHandle.CURRENT); |
| 384 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 385 | final boolean restricted = isRestricted(); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 386 | final EnrollClientImpl client = new EnrollClientImpl(getContext(), mDaemonWrapper, |
| 387 | mHalDeviceId, token, new ServiceListenerImpl(receiver), mCurrentUserId, |
Curtis Belmonte | 4578854 | 2019-07-23 11:07:27 -0700 | [diff] [blame] | 388 | 0 /* groupId */, cryptoToken, restricted, opPackageName, disabledFeatures, |
Ilya Matyukhin | ef410e3 | 2020-02-04 13:39:48 -0800 | [diff] [blame] | 389 | ENROLL_TIMEOUT_SEC, windowId) { |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 390 | |
| 391 | @Override |
| 392 | public int[] getAcquireIgnorelist() { |
| 393 | return mEnrollIgnoreList; |
| 394 | } |
| 395 | |
| 396 | @Override |
| 397 | public int[] getAcquireVendorIgnorelist() { |
| 398 | return mEnrollIgnoreListVendor; |
| 399 | } |
| 400 | |
Kevin Chyn | 1429a31 | 2019-01-28 16:08:09 -0800 | [diff] [blame] | 401 | @Override |
| 402 | public boolean shouldVibrate() { |
| 403 | return false; |
| 404 | } |
Kevin Chyn | 7782d14 | 2019-01-18 12:51:33 -0800 | [diff] [blame] | 405 | |
| 406 | @Override |
| 407 | protected int statsModality() { |
| 408 | return FaceService.this.statsModality(); |
| 409 | } |
Kevin Chyn | 1429a31 | 2019-01-28 16:08:09 -0800 | [diff] [blame] | 410 | }; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 411 | |
Kevin Chyn | 1a878c1 | 2019-04-04 15:50:11 -0700 | [diff] [blame] | 412 | enrollInternal(client, mCurrentUserId); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | @Override // Binder call |
Ilya Matyukhin | ef410e3 | 2020-02-04 13:39:48 -0800 | [diff] [blame] | 416 | public void enrollRemotely(int userId, final IBinder token, final byte[] cryptoToken, |
| 417 | final IFaceServiceReceiver receiver, final String opPackageName, |
| 418 | final int[] disabledFeatures) { |
| 419 | checkPermission(MANAGE_BIOMETRIC); |
| 420 | // TODO(b/145027036): Implement this. |
| 421 | } |
| 422 | |
| 423 | @Override // Binder call |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 424 | public void cancelEnrollment(final IBinder token) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 425 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 426 | cancelEnrollmentInternal(token); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 427 | } |
| 428 | |
| 429 | @Override // Binder call |
Kevin Chyn | 747e29b | 2019-01-11 17:01:53 -0800 | [diff] [blame] | 430 | public void authenticate(final IBinder token, final long opId, int userId, |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 431 | final IFaceServiceReceiver receiver, final int flags, |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 432 | final String opPackageName) { |
| 433 | checkPermission(USE_BIOMETRIC_INTERNAL); |
Kevin Chyn | 747e29b | 2019-01-11 17:01:53 -0800 | [diff] [blame] | 434 | updateActiveGroup(userId, opPackageName); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 435 | final boolean restricted = isRestricted(); |
Kevin Chyn | 8b7a037 | 2018-09-17 15:06:05 -0700 | [diff] [blame] | 436 | final AuthenticationClientImpl client = new FaceAuthClient(getContext(), |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 437 | mDaemonWrapper, mHalDeviceId, token, new ServiceListenerImpl(receiver), |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 438 | mCurrentUserId, 0 /* groupId */, opId, restricted, opPackageName, |
Ilya Matyukhin | ef410e3 | 2020-02-04 13:39:48 -0800 | [diff] [blame] | 439 | 0 /* cookie */, false /* requireConfirmation */, null /* windowId */); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 440 | authenticateInternal(client, opId, opPackageName); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | @Override // Binder call |
Kevin Chyn | 87f257a | 2018-11-27 16:26:07 -0800 | [diff] [blame] | 444 | public void prepareForAuthentication(boolean requireConfirmation, IBinder token, long opId, |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 445 | int groupId, IBiometricServiceReceiverInternal wrapperReceiver, |
| 446 | String opPackageName, int cookie, int callingUid, int callingPid, |
| 447 | int callingUserId) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 448 | checkPermission(USE_BIOMETRIC_INTERNAL); |
Kevin Chyn | 41a8090 | 2019-02-06 08:12:15 -0800 | [diff] [blame] | 449 | updateActiveGroup(groupId, opPackageName); |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 450 | final boolean restricted = true; // BiometricPrompt is always restricted |
Kevin Chyn | 8b7a037 | 2018-09-17 15:06:05 -0700 | [diff] [blame] | 451 | final AuthenticationClientImpl client = new FaceAuthClient(getContext(), |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 452 | mDaemonWrapper, mHalDeviceId, token, |
Kevin Chyn | 87f257a | 2018-11-27 16:26:07 -0800 | [diff] [blame] | 453 | new BiometricPromptServiceListenerImpl(wrapperReceiver), |
| 454 | mCurrentUserId, 0 /* groupId */, opId, restricted, opPackageName, cookie, |
Ilya Matyukhin | ef410e3 | 2020-02-04 13:39:48 -0800 | [diff] [blame] | 455 | requireConfirmation, null /* windowId */); |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 456 | authenticateInternal(client, opId, opPackageName, callingUid, callingPid, |
| 457 | callingUserId); |
| 458 | } |
| 459 | |
| 460 | @Override // Binder call |
Kevin Chyn | 87f257a | 2018-11-27 16:26:07 -0800 | [diff] [blame] | 461 | public void startPreparedClient(int cookie) { |
| 462 | checkPermission(MANAGE_BIOMETRIC); |
| 463 | startCurrentClient(cookie); |
| 464 | } |
| 465 | |
| 466 | @Override // Binder call |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 467 | public void cancelAuthentication(final IBinder token, final String opPackageName) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 468 | checkPermission(USE_BIOMETRIC_INTERNAL); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 469 | cancelAuthenticationInternal(token, opPackageName); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 470 | } |
| 471 | |
| 472 | @Override // Binder call |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 473 | public void cancelAuthenticationFromService(final IBinder token, final String opPackageName, |
Kevin Chyn | e92cdae | 2018-11-21 16:35:04 -0800 | [diff] [blame] | 474 | int callingUid, int callingPid, int callingUserId, boolean fromClient) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 475 | checkPermission(USE_BIOMETRIC_INTERNAL); |
Kevin Chyn | e92cdae | 2018-11-21 16:35:04 -0800 | [diff] [blame] | 476 | cancelAuthenticationInternal(token, opPackageName, callingUid, callingPid, |
| 477 | callingUserId, fromClient); |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | @Override // Binder call |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 481 | public void setActiveUser(final int userId) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 482 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 483 | setActiveUserInternal(userId); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | @Override // Binder call |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 487 | public void remove(final IBinder token, final int faceId, final int userId, |
Kevin Chyn | 593e626 | 2019-06-28 13:24:44 -0700 | [diff] [blame] | 488 | final IFaceServiceReceiver receiver, final String opPackageName) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 489 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | 593e626 | 2019-06-28 13:24:44 -0700 | [diff] [blame] | 490 | updateActiveGroup(userId, opPackageName); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 491 | |
| 492 | if (token == null) { |
| 493 | Slog.w(TAG, "remove(): token is null"); |
| 494 | return; |
| 495 | } |
| 496 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 497 | final boolean restricted = isRestricted(); |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 498 | final RemovalClient client = new RemovalClient(getContext(), getConstants(), |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 499 | mDaemonWrapper, mHalDeviceId, token, new ServiceListenerImpl(receiver), faceId, |
| 500 | 0 /* groupId */, userId, restricted, token.toString(), getBiometricUtils()) { |
Kevin Chyn | 7782d14 | 2019-01-18 12:51:33 -0800 | [diff] [blame] | 501 | @Override |
| 502 | protected int statsModality() { |
| 503 | return FaceService.this.statsModality(); |
| 504 | } |
| 505 | }; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 506 | removeInternal(client); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 507 | } |
| 508 | |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 509 | @Override |
| 510 | public void enumerate(final IBinder token, final int userId, |
| 511 | final IFaceServiceReceiver receiver) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 512 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 513 | |
| 514 | final boolean restricted = isRestricted(); |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 515 | final EnumerateClient client = new EnumerateClient(getContext(), getConstants(), |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 516 | mDaemonWrapper, mHalDeviceId, token, new ServiceListenerImpl(receiver), userId, |
| 517 | userId, restricted, getContext().getOpPackageName()) { |
Kevin Chyn | 7782d14 | 2019-01-18 12:51:33 -0800 | [diff] [blame] | 518 | @Override |
| 519 | protected int statsModality() { |
| 520 | return FaceService.this.statsModality(); |
| 521 | } |
| 522 | }; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 523 | enumerateInternal(client); |
| 524 | } |
| 525 | |
| 526 | @Override |
| 527 | public void addLockoutResetCallback(final IBiometricServiceLockoutResetCallback callback) |
| 528 | throws RemoteException { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 529 | checkPermission(USE_BIOMETRIC_INTERNAL); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 530 | FaceService.super.addLockoutResetCallback(callback); |
| 531 | } |
| 532 | |
| 533 | @Override // Binder call |
| 534 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 535 | if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) { |
| 536 | return; |
| 537 | } |
| 538 | |
| 539 | final long ident = Binder.clearCallingIdentity(); |
| 540 | try { |
Joe Onorato | db39600 | 2019-04-05 19:49:27 -0700 | [diff] [blame] | 541 | if (args.length > 1 && "--hal".equals(args[0])) { |
| 542 | dumpHal(fd, Arrays.copyOfRange(args, 1, args.length, args.getClass())); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 543 | } else { |
| 544 | dumpInternal(pw); |
| 545 | } |
| 546 | } finally { |
| 547 | Binder.restoreCallingIdentity(ident); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | /** |
| 552 | * The following methods don't use any common code from BiometricService |
| 553 | */ |
| 554 | |
| 555 | // TODO: refactor out common code here |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 556 | @Override // Binder call |
Ilya Matyukhin | f2da1a1 | 2019-09-25 15:31:03 -0700 | [diff] [blame] | 557 | public boolean isHardwareDetected(String opPackageName) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 558 | checkPermission(USE_BIOMETRIC_INTERNAL); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 559 | if (!canUseBiometric(opPackageName, false /* foregroundOnly */, |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 560 | Binder.getCallingUid(), Binder.getCallingPid(), |
| 561 | UserHandle.getCallingUserId())) { |
| 562 | return false; |
| 563 | } |
| 564 | |
| 565 | final long token = Binder.clearCallingIdentity(); |
| 566 | try { |
| 567 | IBiometricsFace daemon = getFaceDaemon(); |
| 568 | return daemon != null && mHalDeviceId != 0; |
| 569 | } finally { |
| 570 | Binder.restoreCallingIdentity(token); |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | @Override // Binder call |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 575 | public void rename(final int faceId, final String name) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 576 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 577 | if (!isCurrentUserOrProfile(UserHandle.getCallingUserId())) { |
| 578 | return; |
| 579 | } |
| 580 | mHandler.post(new Runnable() { |
| 581 | @Override |
| 582 | public void run() { |
| 583 | getBiometricUtils().renameBiometricForUser(getContext(), mCurrentUserId, |
| 584 | faceId, name); |
| 585 | } |
| 586 | }); |
| 587 | } |
| 588 | |
| 589 | @Override // Binder call |
| 590 | public List<Face> getEnrolledFaces(int userId, String opPackageName) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 591 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 592 | if (!canUseBiometric(opPackageName, false /* foregroundOnly */, |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 593 | Binder.getCallingUid(), Binder.getCallingPid(), |
| 594 | UserHandle.getCallingUserId())) { |
| 595 | return null; |
| 596 | } |
| 597 | |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 598 | return FaceService.this.getEnrolledTemplates(userId); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | @Override // Binder call |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 602 | public boolean hasEnrolledFaces(int userId, String opPackageName) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 603 | checkPermission(USE_BIOMETRIC_INTERNAL); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 604 | if (!canUseBiometric(opPackageName, false /* foregroundOnly */, |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 605 | Binder.getCallingUid(), Binder.getCallingPid(), |
| 606 | UserHandle.getCallingUserId())) { |
| 607 | return false; |
| 608 | } |
| 609 | |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 610 | return FaceService.this.hasEnrolledBiometrics(userId); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | @Override // Binder call |
| 614 | public long getAuthenticatorId(String opPackageName) { |
| 615 | // In this method, we're not checking whether the caller is permitted to use face |
| 616 | // API because current authenticator ID is leaked (in a more contrived way) via Android |
| 617 | // Keystore (android.security.keystore package): the user of that API can create a key |
| 618 | // which requires face authentication for its use, and then query the key's |
| 619 | // characteristics (hidden API) which returns, among other things, face |
| 620 | // authenticator ID which was active at key creation time. |
| 621 | // |
| 622 | // Reason: The part of Android Keystore which runs inside an app's process invokes this |
| 623 | // method in certain cases. Those cases are not always where the developer demonstrates |
| 624 | // explicit intent to use face functionality. Thus, to avoiding throwing an |
| 625 | // unexpected SecurityException this method does not check whether its caller is |
| 626 | // permitted to use face API. |
| 627 | // |
| 628 | // The permission check should be restored once Android Keystore no longer invokes this |
| 629 | // method from inside app processes. |
| 630 | |
| 631 | return FaceService.this.getAuthenticatorId(opPackageName); |
| 632 | } |
| 633 | |
| 634 | @Override // Binder call |
Kevin Chyn | a38653c | 2019-02-11 17:46:21 -0800 | [diff] [blame] | 635 | public void resetLockout(byte[] token) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 636 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | 1d6a286 | 2019-04-02 16:20:21 -0700 | [diff] [blame] | 637 | |
joshmccloskey | a477206 | 2019-07-24 17:13:16 -0700 | [diff] [blame] | 638 | mHandler.post(() -> { |
| 639 | if (!FaceService.this.hasEnrolledBiometrics(mCurrentUserId)) { |
| 640 | Slog.w(TAG, "Ignoring lockout reset, no templates enrolled"); |
| 641 | return; |
| 642 | } |
Kevin Chyn | 1d6a286 | 2019-04-02 16:20:21 -0700 | [diff] [blame] | 643 | |
joshmccloskey | a477206 | 2019-07-24 17:13:16 -0700 | [diff] [blame] | 644 | Slog.d(TAG, "Resetting lockout for user: " + mCurrentUserId); |
Kevin Chyn | be67ce0 | 2019-06-10 16:14:22 -0700 | [diff] [blame] | 645 | |
joshmccloskey | a477206 | 2019-07-24 17:13:16 -0700 | [diff] [blame] | 646 | try { |
| 647 | mDaemonWrapper.resetLockout(token); |
| 648 | } catch (RemoteException e) { |
| 649 | Slog.e(getTag(), "Unable to reset lockout", e); |
| 650 | } |
| 651 | }); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 652 | } |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 653 | |
| 654 | @Override |
Kevin Chyn | 593e626 | 2019-06-28 13:24:44 -0700 | [diff] [blame] | 655 | public void setFeature(int userId, int feature, boolean enabled, final byte[] token, |
| 656 | IFaceServiceReceiver receiver, final String opPackageName) { |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 657 | checkPermission(MANAGE_BIOMETRIC); |
| 658 | |
Kevin Chyn | e62749a | 2019-04-02 19:33:56 -0700 | [diff] [blame] | 659 | mHandler.post(() -> { |
joshmccloskey | a477206 | 2019-07-24 17:13:16 -0700 | [diff] [blame] | 660 | if (DEBUG) { |
| 661 | Slog.d(TAG, "setFeature for user(" + userId + ")"); |
| 662 | } |
| 663 | updateActiveGroup(userId, opPackageName); |
Kevin Chyn | e62749a | 2019-04-02 19:33:56 -0700 | [diff] [blame] | 664 | if (!FaceService.this.hasEnrolledBiometrics(mCurrentUserId)) { |
| 665 | Slog.e(TAG, "No enrolled biometrics while setting feature: " + feature); |
| 666 | return; |
Kevin Chyn | b95f152 | 2019-03-04 16:45:15 -0800 | [diff] [blame] | 667 | } |
Kevin Chyn | e62749a | 2019-04-02 19:33:56 -0700 | [diff] [blame] | 668 | |
| 669 | final ArrayList<Byte> byteToken = new ArrayList<>(); |
| 670 | for (int i = 0; i < token.length; i++) { |
| 671 | byteToken.add(token[i]); |
| 672 | } |
| 673 | |
| 674 | // TODO: Support multiple faces |
| 675 | final int faceId = getFirstTemplateForUser(mCurrentUserId); |
| 676 | |
| 677 | if (mDaemon != null) { |
| 678 | try { |
| 679 | final int result = mDaemon.setFeature(feature, enabled, byteToken, faceId); |
| 680 | receiver.onFeatureSet(result == Status.OK, feature); |
| 681 | } catch (RemoteException e) { |
| 682 | Slog.e(getTag(), "Unable to set feature: " + feature |
| 683 | + " to enabled:" + enabled, e); |
| 684 | } |
| 685 | } |
| 686 | }); |
| 687 | |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 688 | } |
| 689 | |
| 690 | @Override |
Kevin Chyn | 593e626 | 2019-06-28 13:24:44 -0700 | [diff] [blame] | 691 | public void getFeature(int userId, int feature, IFaceServiceReceiver receiver, |
| 692 | final String opPackageName) { |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 693 | checkPermission(MANAGE_BIOMETRIC); |
| 694 | |
Kevin Chyn | e62749a | 2019-04-02 19:33:56 -0700 | [diff] [blame] | 695 | mHandler.post(() -> { |
joshmccloskey | a477206 | 2019-07-24 17:13:16 -0700 | [diff] [blame] | 696 | if (DEBUG) { |
| 697 | Slog.d(TAG, "getFeature for user(" + userId + ")"); |
| 698 | } |
| 699 | updateActiveGroup(userId, opPackageName); |
Kevin Chyn | e62749a | 2019-04-02 19:33:56 -0700 | [diff] [blame] | 700 | // This should ideally return tri-state, but the user isn't shown settings unless |
| 701 | // they are enrolled so it's fine for now. |
| 702 | if (!FaceService.this.hasEnrolledBiometrics(mCurrentUserId)) { |
| 703 | Slog.e(TAG, "No enrolled biometrics while getting feature: " + feature); |
| 704 | return; |
Kevin Chyn | b95f152 | 2019-03-04 16:45:15 -0800 | [diff] [blame] | 705 | } |
Kevin Chyn | e62749a | 2019-04-02 19:33:56 -0700 | [diff] [blame] | 706 | |
| 707 | // TODO: Support multiple faces |
| 708 | final int faceId = getFirstTemplateForUser(mCurrentUserId); |
| 709 | |
| 710 | if (mDaemon != null) { |
| 711 | try { |
| 712 | OptionalBool result = mDaemon.getFeature(feature, faceId); |
| 713 | receiver.onFeatureGet(result.status == Status.OK, feature, result.value); |
| 714 | } catch (RemoteException e) { |
| 715 | Slog.e(getTag(), "Unable to getRequireAttention", e); |
| 716 | } |
| 717 | } |
| 718 | }); |
| 719 | |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 720 | } |
Kevin Chyn | 57f119b | 2018-10-25 12:03:41 -0700 | [diff] [blame] | 721 | |
| 722 | @Override |
| 723 | public void userActivity() { |
| 724 | checkPermission(MANAGE_BIOMETRIC); |
| 725 | |
| 726 | if (mDaemon != null) { |
| 727 | try { |
| 728 | mDaemon.userActivity(); |
| 729 | } catch (RemoteException e) { |
| 730 | Slog.e(getTag(), "Unable to send userActivity", e); |
| 731 | } |
| 732 | } |
| 733 | } |
Kevin Chyn | b95f152 | 2019-03-04 16:45:15 -0800 | [diff] [blame] | 734 | |
| 735 | // TODO: Support multiple faces |
| 736 | private int getFirstTemplateForUser(int user) { |
| 737 | final List<Face> faces = FaceService.this.getEnrolledTemplates(user); |
| 738 | if (!faces.isEmpty()) { |
| 739 | return faces.get(0).getBiometricId(); |
| 740 | } |
| 741 | return 0; |
| 742 | } |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | /** |
| 746 | * Receives callbacks from the ClientMonitor implementations. The results are forwarded to |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 747 | * BiometricPrompt. |
| 748 | */ |
Kevin Chyn | e92cdae | 2018-11-21 16:35:04 -0800 | [diff] [blame] | 749 | private class BiometricPromptServiceListenerImpl extends BiometricServiceListener { |
Kevin Chyn | 23289ef | 2018-11-28 16:32:36 -0800 | [diff] [blame] | 750 | BiometricPromptServiceListenerImpl(IBiometricServiceReceiverInternal wrapperReceiver) { |
Kevin Chyn | 87f257a | 2018-11-27 16:26:07 -0800 | [diff] [blame] | 751 | super(wrapperReceiver); |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 752 | } |
| 753 | |
| 754 | @Override |
| 755 | public void onAcquired(long deviceId, int acquiredInfo, int vendorCode) |
| 756 | throws RemoteException { |
| 757 | /** |
| 758 | * Map the acquired codes onto existing {@link BiometricConstants} acquired codes. |
| 759 | */ |
Kevin Chyn | e92cdae | 2018-11-21 16:35:04 -0800 | [diff] [blame] | 760 | if (getWrapperReceiver() != null) { |
| 761 | getWrapperReceiver().onAcquired( |
Kevin Chyn | 8b7a037 | 2018-09-17 15:06:05 -0700 | [diff] [blame] | 762 | FaceManager.getMappedAcquiredInfo(acquiredInfo, vendorCode), |
| 763 | FaceManager.getAcquiredString(getContext(), acquiredInfo, vendorCode)); |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
| 767 | @Override |
Kevin Chyn | 87f257a | 2018-11-27 16:26:07 -0800 | [diff] [blame] | 768 | public void onError(long deviceId, int error, int vendorCode, int cookie) |
| 769 | throws RemoteException { |
Kevin Chyn | e92cdae | 2018-11-21 16:35:04 -0800 | [diff] [blame] | 770 | if (getWrapperReceiver() != null) { |
Ilya Matyukhin | 0f9da35 | 2019-10-03 14:10:01 -0700 | [diff] [blame] | 771 | getWrapperReceiver().onError(cookie, TYPE_FACE, error, vendorCode); |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 772 | } |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | /** |
| 777 | * Receives callbacks from the ClientMonitor implementations. The results are forwarded to |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 778 | * the FaceManager. |
| 779 | */ |
| 780 | private class ServiceListenerImpl implements ServiceListener { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 781 | private IFaceServiceReceiver mFaceServiceReceiver; |
| 782 | |
| 783 | public ServiceListenerImpl(IFaceServiceReceiver receiver) { |
| 784 | mFaceServiceReceiver = receiver; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 788 | public void onEnrollResult(BiometricAuthenticator.Identifier identifier, int remaining) |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 789 | throws RemoteException { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 790 | if (mFaceServiceReceiver != null) { |
| 791 | mFaceServiceReceiver.onEnrollResult(identifier.getDeviceId(), |
| 792 | identifier.getBiometricId(), |
| 793 | remaining); |
| 794 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 795 | } |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 796 | |
| 797 | @Override |
| 798 | public void onAcquired(long deviceId, int acquiredInfo, int vendorCode) |
| 799 | throws RemoteException { |
| 800 | if (mFaceServiceReceiver != null) { |
| 801 | mFaceServiceReceiver.onAcquired(deviceId, acquiredInfo, vendorCode); |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | @Override |
| 806 | public void onAuthenticationSucceeded(long deviceId, |
| 807 | BiometricAuthenticator.Identifier biometric, int userId) |
| 808 | throws RemoteException { |
| 809 | if (mFaceServiceReceiver != null) { |
Kevin Chyn | 628b718 | 2018-11-13 12:00:48 -0800 | [diff] [blame] | 810 | if (biometric == null || biometric instanceof Face) { |
Kevin Chyn | 8d2694a | 2019-04-11 18:30:40 -0700 | [diff] [blame] | 811 | mFaceServiceReceiver.onAuthenticationSucceeded(deviceId, (Face) biometric, |
| 812 | userId); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 813 | } else { |
| 814 | Slog.e(TAG, "onAuthenticationSucceeded received non-face biometric"); |
| 815 | } |
| 816 | } |
| 817 | } |
| 818 | |
| 819 | @Override |
| 820 | public void onAuthenticationFailed(long deviceId) throws RemoteException { |
| 821 | if (mFaceServiceReceiver != null) { |
| 822 | mFaceServiceReceiver.onAuthenticationFailed(deviceId); |
| 823 | } |
| 824 | } |
| 825 | |
| 826 | @Override |
Kevin Chyn | 87f257a | 2018-11-27 16:26:07 -0800 | [diff] [blame] | 827 | public void onError(long deviceId, int error, int vendorCode, int cookie) |
| 828 | throws RemoteException { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 829 | if (mFaceServiceReceiver != null) { |
| 830 | mFaceServiceReceiver.onError(deviceId, error, vendorCode); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | @Override |
| 835 | public void onRemoved(BiometricAuthenticator.Identifier identifier, |
| 836 | int remaining) throws RemoteException { |
| 837 | if (mFaceServiceReceiver != null) { |
| 838 | mFaceServiceReceiver.onRemoved(identifier.getDeviceId(), |
| 839 | identifier.getBiometricId(), remaining); |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | @Override |
| 844 | public void onEnumerated(BiometricAuthenticator.Identifier identifier, int remaining) |
| 845 | throws RemoteException { |
| 846 | if (mFaceServiceReceiver != null) { |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 847 | mFaceServiceReceiver.onEnumerated(identifier.getDeviceId(), |
| 848 | identifier.getBiometricId(), remaining); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | } |
| 852 | |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 853 | private final FaceConstants mFaceConstants = new FaceConstants(); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 854 | |
| 855 | @GuardedBy("this") |
| 856 | private IBiometricsFace mDaemon; |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 857 | private UsageStats mUsageStats; |
Ilya Matyukhin | 9dac848 | 2019-07-09 11:03:07 -0700 | [diff] [blame] | 858 | private boolean mRevokeChallengePending = false; |
Kevin Chyn | a38653c | 2019-02-11 17:46:21 -0800 | [diff] [blame] | 859 | // One of the AuthenticationClient constants |
| 860 | private int mCurrentUserLockoutMode; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 861 | |
Kevin Chyn | dbfbed4 | 2019-06-13 17:01:30 -0700 | [diff] [blame] | 862 | private NotificationManager mNotificationManager; |
| 863 | |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 864 | private int[] mBiometricPromptIgnoreList; |
| 865 | private int[] mBiometricPromptIgnoreListVendor; |
| 866 | private int[] mKeyguardIgnoreList; |
| 867 | private int[] mKeyguardIgnoreListVendor; |
| 868 | private int[] mEnrollIgnoreList; |
| 869 | private int[] mEnrollIgnoreListVendor; |
| 870 | |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 871 | /** |
| 872 | * Receives callbacks from the HAL. |
| 873 | */ |
| 874 | private IBiometricsFaceClientCallback mDaemonCallback = |
| 875 | new IBiometricsFaceClientCallback.Stub() { |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 876 | @Override |
| 877 | public void onEnrollResult(final long deviceId, int faceId, int userId, |
| 878 | int remaining) { |
| 879 | mHandler.post(() -> { |
| 880 | final Face face = new Face(getBiometricUtils() |
| 881 | .getUniqueName(getContext(), userId), faceId, deviceId); |
| 882 | FaceService.super.handleEnrollResult(face, remaining); |
Kevin Chyn | 576811e | 2019-06-12 14:50:35 -0700 | [diff] [blame] | 883 | |
| 884 | // Enrollment changes the authenticatorId, so update it here. |
| 885 | IBiometricsFace daemon = getFaceDaemon(); |
| 886 | if (remaining == 0 && daemon != null) { |
| 887 | try { |
| 888 | mAuthenticatorIds.put(userId, |
| 889 | hasEnrolledBiometrics(userId) ? daemon.getAuthenticatorId().value |
| 890 | : 0L); |
| 891 | } catch (RemoteException e) { |
| 892 | Slog.e(TAG, "Unable to get authenticatorId", e); |
| 893 | } |
| 894 | } |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 895 | }); |
| 896 | } |
| 897 | |
| 898 | @Override |
| 899 | public void onAcquired(final long deviceId, final int userId, |
| 900 | final int acquiredInfo, |
| 901 | final int vendorCode) { |
| 902 | mHandler.post(() -> { |
| 903 | FaceService.super.handleAcquired(deviceId, acquiredInfo, vendorCode); |
| 904 | }); |
| 905 | } |
| 906 | |
| 907 | @Override |
| 908 | public void onAuthenticated(final long deviceId, final int faceId, final int userId, |
| 909 | ArrayList<Byte> token) { |
| 910 | mHandler.post(() -> { |
| 911 | Face face = new Face("", faceId, deviceId); |
| 912 | FaceService.super.handleAuthenticated(face, token); |
| 913 | }); |
| 914 | } |
| 915 | |
| 916 | @Override |
| 917 | public void onError(final long deviceId, final int userId, final int error, |
| 918 | final int vendorCode) { |
| 919 | mHandler.post(() -> { |
| 920 | FaceService.super.handleError(deviceId, error, vendorCode); |
| 921 | |
| 922 | // TODO: this chunk of code should be common to all biometric services |
| 923 | if (error == BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE) { |
| 924 | // If we get HW_UNAVAILABLE, try to connect again later... |
| 925 | Slog.w(TAG, "Got ERROR_HW_UNAVAILABLE; try reconnecting next client."); |
| 926 | synchronized (this) { |
| 927 | mDaemon = null; |
| 928 | mHalDeviceId = 0; |
| 929 | mCurrentUserId = UserHandle.USER_NULL; |
| 930 | } |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 931 | } |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 932 | }); |
| 933 | } |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 934 | |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 935 | @Override |
Kevin Chyn | 31ae8d2 | 2019-03-11 14:12:32 -0700 | [diff] [blame] | 936 | public void onRemoved(final long deviceId, ArrayList<Integer> faceIds, final int userId) { |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 937 | mHandler.post(() -> { |
Kevin Chyn | 31ae8d2 | 2019-03-11 14:12:32 -0700 | [diff] [blame] | 938 | if (!faceIds.isEmpty()) { |
| 939 | for (int i = 0; i < faceIds.size(); i++) { |
| 940 | final Face face = new Face("", faceIds.get(i), deviceId); |
| 941 | // Convert to old behavior |
| 942 | FaceService.super.handleRemoved(face, faceIds.size() - i - 1); |
| 943 | } |
| 944 | } else { |
| 945 | final Face face = new Face("", 0 /* identifier */, deviceId); |
| 946 | FaceService.super.handleRemoved(face, 0 /* remaining */); |
| 947 | } |
Curtis Belmonte | 8cfe371 | 2019-09-26 16:02:41 -0700 | [diff] [blame] | 948 | Settings.Secure.putIntForUser(getContext().getContentResolver(), |
| 949 | Settings.Secure.FACE_UNLOCK_RE_ENROLL, 0, UserHandle.USER_CURRENT); |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 950 | }); |
| 951 | } |
| 952 | |
| 953 | @Override |
| 954 | public void onEnumerate(long deviceId, ArrayList<Integer> faceIds, int userId) |
| 955 | throws RemoteException { |
| 956 | mHandler.post(() -> { |
| 957 | if (!faceIds.isEmpty()) { |
| 958 | for (int i = 0; i < faceIds.size(); i++) { |
| 959 | final Face face = new Face("", faceIds.get(i), deviceId); |
| 960 | // Convert to old old behavior |
| 961 | FaceService.super.handleEnumerate(face, faceIds.size() - i - 1); |
| 962 | } |
| 963 | } else { |
| 964 | // For face, the HIDL contract is to receive an empty list when there are no |
| 965 | // templates enrolled. Send a null identifier since we don't consume them |
| 966 | // anywhere, and send remaining == 0 to plumb this with existing common code. |
| 967 | FaceService.super.handleEnumerate(null /* identifier */, 0); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 968 | } |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 969 | }); |
| 970 | } |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 971 | |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 972 | @Override |
| 973 | public void onLockoutChanged(long duration) { |
Kevin Chyn | a38653c | 2019-02-11 17:46:21 -0800 | [diff] [blame] | 974 | Slog.d(TAG, "onLockoutChanged: " + duration); |
Curtis Belmonte | c47df86 | 2020-01-28 16:58:34 -0800 | [diff] [blame] | 975 | |
Kevin Chyn | a38653c | 2019-02-11 17:46:21 -0800 | [diff] [blame] | 976 | if (duration == 0) { |
| 977 | mCurrentUserLockoutMode = AuthenticationClient.LOCKOUT_NONE; |
Curtis Belmonte | c47df86 | 2020-01-28 16:58:34 -0800 | [diff] [blame] | 978 | } else if (duration == -1 || duration == Long.MAX_VALUE) { |
Kevin Chyn | a38653c | 2019-02-11 17:46:21 -0800 | [diff] [blame] | 979 | mCurrentUserLockoutMode = AuthenticationClient.LOCKOUT_PERMANENT; |
| 980 | } else { |
| 981 | mCurrentUserLockoutMode = AuthenticationClient.LOCKOUT_TIMED; |
| 982 | } |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 983 | |
Kevin Chyn | a38653c | 2019-02-11 17:46:21 -0800 | [diff] [blame] | 984 | mHandler.post(() -> { |
| 985 | if (duration == 0) { |
| 986 | notifyLockoutResetMonitors(); |
| 987 | } |
| 988 | }); |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 989 | } |
| 990 | }; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 991 | |
| 992 | /** |
| 993 | * Wraps the HAL-specific code and is passed to the ClientMonitor implementations so that they |
| 994 | * can be shared between the multiple biometric services. |
| 995 | */ |
| 996 | private final DaemonWrapper mDaemonWrapper = new DaemonWrapper() { |
| 997 | @Override |
Ilya Matyukhin | ef410e3 | 2020-02-04 13:39:48 -0800 | [diff] [blame] | 998 | public int authenticate(long operationId, int groupId, NativeHandle windowId) |
| 999 | throws RemoteException { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1000 | IBiometricsFace daemon = getFaceDaemon(); |
| 1001 | if (daemon == null) { |
| 1002 | Slog.w(TAG, "authenticate(): no face HAL!"); |
| 1003 | return ERROR_ESRCH; |
| 1004 | } |
| 1005 | return daemon.authenticate(operationId); |
| 1006 | } |
| 1007 | |
| 1008 | @Override |
| 1009 | public int cancel() throws RemoteException { |
| 1010 | IBiometricsFace daemon = getFaceDaemon(); |
| 1011 | if (daemon == null) { |
| 1012 | Slog.w(TAG, "cancel(): no face HAL!"); |
| 1013 | return ERROR_ESRCH; |
| 1014 | } |
| 1015 | return daemon.cancel(); |
| 1016 | } |
| 1017 | |
| 1018 | @Override |
| 1019 | public int remove(int groupId, int biometricId) throws RemoteException { |
| 1020 | IBiometricsFace daemon = getFaceDaemon(); |
| 1021 | if (daemon == null) { |
| 1022 | Slog.w(TAG, "remove(): no face HAL!"); |
| 1023 | return ERROR_ESRCH; |
| 1024 | } |
| 1025 | return daemon.remove(biometricId); |
| 1026 | } |
| 1027 | |
| 1028 | @Override |
| 1029 | public int enumerate() throws RemoteException { |
| 1030 | IBiometricsFace daemon = getFaceDaemon(); |
| 1031 | if (daemon == null) { |
| 1032 | Slog.w(TAG, "enumerate(): no face HAL!"); |
| 1033 | return ERROR_ESRCH; |
| 1034 | } |
| 1035 | return daemon.enumerate(); |
| 1036 | } |
| 1037 | |
| 1038 | @Override |
Kevin Chyn | 1f16c2d | 2018-12-07 13:06:08 -0800 | [diff] [blame] | 1039 | public int enroll(byte[] cryptoToken, int groupId, int timeout, |
Ilya Matyukhin | ef410e3 | 2020-02-04 13:39:48 -0800 | [diff] [blame] | 1040 | ArrayList<Integer> disabledFeatures, NativeHandle windowId) throws RemoteException { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1041 | IBiometricsFace daemon = getFaceDaemon(); |
| 1042 | if (daemon == null) { |
| 1043 | Slog.w(TAG, "enroll(): no face HAL!"); |
| 1044 | return ERROR_ESRCH; |
| 1045 | } |
| 1046 | final ArrayList<Byte> token = new ArrayList<>(); |
| 1047 | for (int i = 0; i < cryptoToken.length; i++) { |
| 1048 | token.add(cryptoToken[i]); |
| 1049 | } |
Ilya Matyukhin | ef410e3 | 2020-02-04 13:39:48 -0800 | [diff] [blame] | 1050 | android.hardware.biometrics.face.V1_1.IBiometricsFace daemon11 = |
| 1051 | android.hardware.biometrics.face.V1_1.IBiometricsFace.castFrom( |
| 1052 | daemon); |
| 1053 | if (daemon11 != null) { |
| 1054 | return daemon11.enroll_1_1(token, timeout, disabledFeatures, windowId); |
| 1055 | } else if (windowId == null) { |
| 1056 | return daemon.enroll(token, timeout, disabledFeatures); |
| 1057 | } else { |
| 1058 | Slog.e(TAG, "enroll(): windowId is only supported in @1.1 HAL"); |
| 1059 | return ERROR_ESRCH; |
| 1060 | } |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1061 | } |
Kevin Chyn | a38653c | 2019-02-11 17:46:21 -0800 | [diff] [blame] | 1062 | |
| 1063 | @Override |
| 1064 | public void resetLockout(byte[] cryptoToken) throws RemoteException { |
| 1065 | IBiometricsFace daemon = getFaceDaemon(); |
| 1066 | if (daemon == null) { |
| 1067 | Slog.w(TAG, "resetLockout(): no face HAL!"); |
| 1068 | return; |
| 1069 | } |
| 1070 | final ArrayList<Byte> token = new ArrayList<>(); |
| 1071 | for (int i = 0; i < cryptoToken.length; i++) { |
| 1072 | token.add(cryptoToken[i]); |
| 1073 | } |
| 1074 | daemon.resetLockout(token); |
| 1075 | } |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1076 | }; |
| 1077 | |
| 1078 | |
| 1079 | public FaceService(Context context) { |
| 1080 | super(context); |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 1081 | |
joshmccloskey | 4ceaf6b | 2019-08-21 11:26:08 -0700 | [diff] [blame] | 1082 | final boolean ignoreKeyguardBlacklist = Settings.Secure.getInt(context.getContentResolver(), |
| 1083 | SKIP_KEYGUARD_ACQUIRE_IGNORE_LIST, 0) != 0; |
| 1084 | |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 1085 | mUsageStats = new UsageStats(context); |
| 1086 | |
Kevin Chyn | dbfbed4 | 2019-06-13 17:01:30 -0700 | [diff] [blame] | 1087 | mNotificationManager = getContext().getSystemService(NotificationManager.class); |
| 1088 | |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 1089 | mBiometricPromptIgnoreList = getContext().getResources() |
| 1090 | .getIntArray(R.array.config_face_acquire_biometricprompt_ignorelist); |
| 1091 | mBiometricPromptIgnoreListVendor = getContext().getResources() |
| 1092 | .getIntArray(R.array.config_face_acquire_vendor_biometricprompt_ignorelist); |
joshmccloskey | 4ceaf6b | 2019-08-21 11:26:08 -0700 | [diff] [blame] | 1093 | mKeyguardIgnoreList = ignoreKeyguardBlacklist ? new int[0] : getContext().getResources() |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 1094 | .getIntArray(R.array.config_face_acquire_keyguard_ignorelist); |
joshmccloskey | 4ceaf6b | 2019-08-21 11:26:08 -0700 | [diff] [blame] | 1095 | mKeyguardIgnoreListVendor = |
| 1096 | ignoreKeyguardBlacklist ? new int[0] : getContext().getResources() |
| 1097 | .getIntArray(R.array.config_face_acquire_vendor_keyguard_ignorelist); |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 1098 | mEnrollIgnoreList = getContext().getResources() |
| 1099 | .getIntArray(R.array.config_face_acquire_enroll_ignorelist); |
| 1100 | mEnrollIgnoreListVendor = getContext().getResources() |
| 1101 | .getIntArray(R.array.config_face_acquire_vendor_enroll_ignorelist); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | @Override |
Ilya Matyukhin | 9dac848 | 2019-07-09 11:03:07 -0700 | [diff] [blame] | 1105 | protected void removeClient(ClientMonitor client) { |
| 1106 | super.removeClient(client); |
| 1107 | if (mRevokeChallengePending) { |
| 1108 | startRevokeChallenge(null); |
| 1109 | mRevokeChallengePending = false; |
| 1110 | } |
| 1111 | } |
| 1112 | |
| 1113 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1114 | public void onStart() { |
Kevin Chyn | 5a2ff5d | 2018-08-29 19:07:30 -0700 | [diff] [blame] | 1115 | super.onStart(); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1116 | publishBinderService(Context.FACE_SERVICE, new FaceServiceWrapper()); |
Kevin Chyn | 8398a71 | 2019-06-13 16:44:50 -0700 | [diff] [blame] | 1117 | // Get the face daemon on FaceService's on thread so SystemServerInitThreadPool isn't |
| 1118 | // blocked |
Felipe Leme | b68b769 | 2019-10-09 10:43:03 -0700 | [diff] [blame] | 1119 | SystemServerInitThreadPool.submit(() -> mHandler.post(this::getFaceDaemon), |
Kevin Chyn | 8398a71 | 2019-06-13 16:44:50 -0700 | [diff] [blame] | 1120 | TAG + ".onStart"); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | @Override |
| 1124 | public String getTag() { |
| 1125 | return TAG; |
| 1126 | } |
| 1127 | |
| 1128 | @Override |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 1129 | protected DaemonWrapper getDaemonWrapper() { |
| 1130 | return mDaemonWrapper; |
| 1131 | } |
| 1132 | |
| 1133 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1134 | protected BiometricUtils getBiometricUtils() { |
| 1135 | return FaceUtils.getInstance(); |
| 1136 | } |
| 1137 | |
| 1138 | @Override |
Kevin Chyn | 4cc49f7 | 2019-04-24 13:53:35 -0700 | [diff] [blame] | 1139 | protected Constants getConstants() { |
| 1140 | return mFaceConstants; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | @Override |
| 1144 | protected boolean hasReachedEnrollmentLimit(int userId) { |
| 1145 | final int limit = getContext().getResources().getInteger( |
Kevin Chyn | 017e76e | 2018-06-27 18:35:06 -0700 | [diff] [blame] | 1146 | com.android.internal.R.integer.config_faceMaxTemplatesPerUser); |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 1147 | final int enrolled = FaceService.this.getEnrolledTemplates(userId).size(); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1148 | if (enrolled >= limit) { |
Kevin Chyn | 1a878c1 | 2019-04-04 15:50:11 -0700 | [diff] [blame] | 1149 | Slog.w(TAG, "Too many faces registered, user: " + userId); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1150 | return true; |
| 1151 | } |
| 1152 | return false; |
| 1153 | } |
| 1154 | |
| 1155 | @Override |
Kevin Chyn | 9ba9991 | 2019-01-16 16:24:36 -0800 | [diff] [blame] | 1156 | public void serviceDied(long cookie) { |
| 1157 | super.serviceDied(cookie); |
| 1158 | mDaemon = null; |
Jim Miller | 7b78b22 | 2019-02-07 16:47:38 -0800 | [diff] [blame] | 1159 | |
| 1160 | mCurrentUserId = UserHandle.USER_NULL; // Force updateActiveGroup() to re-evaluate |
Kevin Chyn | 9ba9991 | 2019-01-16 16:24:36 -0800 | [diff] [blame] | 1161 | } |
| 1162 | |
| 1163 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1164 | protected void updateActiveGroup(int userId, String clientPackage) { |
| 1165 | IBiometricsFace daemon = getFaceDaemon(); |
| 1166 | |
| 1167 | if (daemon != null) { |
| 1168 | try { |
| 1169 | userId = getUserOrWorkProfileId(clientPackage, userId); |
| 1170 | if (userId != mCurrentUserId) { |
Kevin Chyn | 27e33d0 | 2019-04-30 01:37:32 +0000 | [diff] [blame] | 1171 | final File baseDir = Environment.getDataVendorDeDirectory(userId); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1172 | final File faceDir = new File(baseDir, FACE_DATA_DIR); |
| 1173 | if (!faceDir.exists()) { |
| 1174 | if (!faceDir.mkdir()) { |
| 1175 | Slog.v(TAG, "Cannot make directory: " + faceDir.getAbsolutePath()); |
| 1176 | return; |
| 1177 | } |
| 1178 | // Calling mkdir() from this process will create a directory with our |
| 1179 | // permissions (inherited from the containing dir). This command fixes |
| 1180 | // the label. |
| 1181 | if (!SELinux.restorecon(faceDir)) { |
| 1182 | Slog.w(TAG, "Restorecons failed. Directory will have wrong label."); |
| 1183 | return; |
| 1184 | } |
| 1185 | } |
| 1186 | |
| 1187 | daemon.setActiveUser(userId, faceDir.getAbsolutePath()); |
| 1188 | mCurrentUserId = userId; |
Kevin Chyn | 576811e | 2019-06-12 14:50:35 -0700 | [diff] [blame] | 1189 | mAuthenticatorIds.put(userId, |
| 1190 | hasEnrolledBiometrics(userId) ? daemon.getAuthenticatorId().value : 0L); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1191 | } |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1192 | } catch (RemoteException e) { |
| 1193 | Slog.e(TAG, "Failed to setActiveUser():", e); |
| 1194 | } |
| 1195 | } |
| 1196 | } |
| 1197 | |
| 1198 | @Override |
| 1199 | protected String getLockoutResetIntent() { |
| 1200 | return ACTION_LOCKOUT_RESET; |
| 1201 | } |
| 1202 | |
| 1203 | @Override |
| 1204 | protected String getLockoutBroadcastPermission() { |
| 1205 | return RESET_FACE_LOCKOUT; |
| 1206 | } |
| 1207 | |
| 1208 | @Override |
| 1209 | protected long getHalDeviceId() { |
| 1210 | return mHalDeviceId; |
| 1211 | } |
| 1212 | |
| 1213 | @Override |
Kevin Chyn | a38653c | 2019-02-11 17:46:21 -0800 | [diff] [blame] | 1214 | protected void handleUserSwitching(int userId) { |
| 1215 | super.handleUserSwitching(userId); |
| 1216 | // Will be updated when we get the callback from HAL |
| 1217 | mCurrentUserLockoutMode = AuthenticationClient.LOCKOUT_NONE; |
| 1218 | } |
| 1219 | |
| 1220 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1221 | protected boolean hasEnrolledBiometrics(int userId) { |
| 1222 | if (userId != UserHandle.getCallingUserId()) { |
| 1223 | checkPermission(INTERACT_ACROSS_USERS); |
| 1224 | } |
| 1225 | return getBiometricUtils().getBiometricsForUser(getContext(), userId).size() > 0; |
| 1226 | } |
| 1227 | |
| 1228 | @Override |
| 1229 | protected String getManageBiometricPermission() { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 1230 | return MANAGE_BIOMETRIC; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | @Override |
| 1234 | protected void checkUseBiometricPermission() { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 1235 | // noop for Face. The permission checks are all done on the incoming binder call. |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
| 1238 | @Override |
Kevin Chyn | b3c05aa | 2018-09-21 16:50:32 -0700 | [diff] [blame] | 1239 | protected boolean checkAppOps(int uid, String opPackageName) { |
| 1240 | return mAppOps.noteOp(AppOpsManager.OP_USE_BIOMETRIC, uid, opPackageName) |
| 1241 | == AppOpsManager.MODE_ALLOWED; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | @Override |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 1245 | protected List<Face> getEnrolledTemplates(int userId) { |
| 1246 | return getBiometricUtils().getBiometricsForUser(getContext(), userId); |
| 1247 | } |
| 1248 | |
| 1249 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1250 | protected void notifyClientActiveCallbacks(boolean isActive) { |
| 1251 | // noop for Face. |
| 1252 | } |
| 1253 | |
Kevin Chyn | 7782d14 | 2019-01-18 12:51:33 -0800 | [diff] [blame] | 1254 | @Override |
| 1255 | protected int statsModality() { |
| 1256 | return BiometricsProtoEnums.MODALITY_FACE; |
| 1257 | } |
| 1258 | |
Kevin Chyn | a38653c | 2019-02-11 17:46:21 -0800 | [diff] [blame] | 1259 | @Override |
| 1260 | protected int getLockoutMode() { |
| 1261 | return mCurrentUserLockoutMode; |
| 1262 | } |
| 1263 | |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1264 | /** Gets the face daemon */ |
| 1265 | private synchronized IBiometricsFace getFaceDaemon() { |
| 1266 | if (mDaemon == null) { |
| 1267 | Slog.v(TAG, "mDaemon was null, reconnect to face"); |
| 1268 | try { |
| 1269 | mDaemon = IBiometricsFace.getService(); |
| 1270 | } catch (java.util.NoSuchElementException e) { |
| 1271 | // Service doesn't exist or cannot be opened. Logged below. |
| 1272 | } catch (RemoteException e) { |
| 1273 | Slog.e(TAG, "Failed to get biometric interface", e); |
| 1274 | } |
| 1275 | if (mDaemon == null) { |
| 1276 | Slog.w(TAG, "face HIDL not available"); |
| 1277 | return null; |
| 1278 | } |
| 1279 | |
| 1280 | mDaemon.asBinder().linkToDeath(this, 0); |
| 1281 | |
| 1282 | try { |
| 1283 | mHalDeviceId = mDaemon.setCallback(mDaemonCallback).value; |
| 1284 | } catch (RemoteException e) { |
| 1285 | Slog.e(TAG, "Failed to open face HAL", e); |
| 1286 | mDaemon = null; // try again later! |
| 1287 | } |
| 1288 | |
| 1289 | if (DEBUG) Slog.v(TAG, "Face HAL id: " + mHalDeviceId); |
| 1290 | if (mHalDeviceId != 0) { |
| 1291 | loadAuthenticatorIds(); |
| 1292 | updateActiveGroup(ActivityManager.getCurrentUser(), null); |
Kevin Chyn | 6737c57 | 2019-02-08 16:10:54 -0800 | [diff] [blame] | 1293 | doTemplateCleanupForUser(ActivityManager.getCurrentUser()); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1294 | } else { |
| 1295 | Slog.w(TAG, "Failed to open Face HAL!"); |
| 1296 | MetricsLogger.count(getContext(), "faced_openhal_error", 1); |
| 1297 | mDaemon = null; |
| 1298 | } |
| 1299 | } |
| 1300 | return mDaemon; |
| 1301 | } |
| 1302 | |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 1303 | private long startGenerateChallenge(IBinder token) { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1304 | IBiometricsFace daemon = getFaceDaemon(); |
| 1305 | if (daemon == null) { |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 1306 | Slog.w(TAG, "startGenerateChallenge: no face HAL!"); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1307 | return 0; |
| 1308 | } |
| 1309 | try { |
Kevin Chyn | e46a216 | 2018-09-20 18:43:01 -0700 | [diff] [blame] | 1310 | return daemon.generateChallenge(CHALLENGE_TIMEOUT_SEC).value; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1311 | } catch (RemoteException e) { |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 1312 | Slog.e(TAG, "startGenerateChallenge failed", e); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1313 | } |
| 1314 | return 0; |
| 1315 | } |
| 1316 | |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 1317 | private int startRevokeChallenge(IBinder token) { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1318 | IBiometricsFace daemon = getFaceDaemon(); |
| 1319 | if (daemon == null) { |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 1320 | Slog.w(TAG, "startRevokeChallenge: no face HAL!"); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1321 | return 0; |
| 1322 | } |
| 1323 | try { |
Ilya Matyukhin | 9dac848 | 2019-07-09 11:03:07 -0700 | [diff] [blame] | 1324 | final int res = daemon.revokeChallenge(); |
| 1325 | if (res != Status.OK) { |
| 1326 | Slog.e(TAG, "revokeChallenge returned " + res); |
| 1327 | } |
| 1328 | return res; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1329 | } catch (RemoteException e) { |
Kevin Chyn | d79e24e | 2018-09-25 12:06:59 -0700 | [diff] [blame] | 1330 | Slog.e(TAG, "startRevokeChallenge failed", e); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1331 | } |
| 1332 | return 0; |
| 1333 | } |
| 1334 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1335 | private void dumpInternal(PrintWriter pw) { |
| 1336 | JSONObject dump = new JSONObject(); |
| 1337 | try { |
| 1338 | dump.put("service", "Face Manager"); |
| 1339 | |
| 1340 | JSONArray sets = new JSONArray(); |
| 1341 | for (UserInfo user : UserManager.get(getContext()).getUsers()) { |
| 1342 | final int userId = user.getUserHandle().getIdentifier(); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1343 | final int N = getBiometricUtils().getBiometricsForUser(getContext(), userId).size(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1344 | PerformanceStats stats = mPerformanceMap.get(userId); |
| 1345 | PerformanceStats cryptoStats = mCryptoPerformanceMap.get(userId); |
| 1346 | JSONObject set = new JSONObject(); |
| 1347 | set.put("id", userId); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1348 | set.put("count", N); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1349 | set.put("accept", (stats != null) ? stats.accept : 0); |
| 1350 | set.put("reject", (stats != null) ? stats.reject : 0); |
| 1351 | set.put("acquire", (stats != null) ? stats.acquire : 0); |
| 1352 | set.put("lockout", (stats != null) ? stats.lockout : 0); |
| 1353 | set.put("permanentLockout", (stats != null) ? stats.permanentLockout : 0); |
| 1354 | // cryptoStats measures statistics about secure face transactions |
| 1355 | // (e.g. to unlock password storage, make secure purchases, etc.) |
| 1356 | set.put("acceptCrypto", (cryptoStats != null) ? cryptoStats.accept : 0); |
| 1357 | set.put("rejectCrypto", (cryptoStats != null) ? cryptoStats.reject : 0); |
| 1358 | set.put("acquireCrypto", (cryptoStats != null) ? cryptoStats.acquire : 0); |
| 1359 | set.put("lockoutCrypto", (cryptoStats != null) ? cryptoStats.lockout : 0); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 1360 | set.put("permanentLockoutCrypto", |
| 1361 | (cryptoStats != null) ? cryptoStats.permanentLockout : 0); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1362 | sets.put(set); |
| 1363 | } |
| 1364 | |
| 1365 | dump.put("prints", sets); |
| 1366 | } catch (JSONException e) { |
| 1367 | Slog.e(TAG, "dump formatting failure", e); |
| 1368 | } |
| 1369 | pw.println(dump); |
Kevin Chyn | 9bc1d49 | 2019-06-21 15:31:50 -0700 | [diff] [blame] | 1370 | pw.println("HAL deaths since last reboot: " + mHALDeathCount); |
| 1371 | |
| 1372 | mUsageStats.print(pw); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 1373 | } |
| 1374 | |
Joe Onorato | db39600 | 2019-04-05 19:49:27 -0700 | [diff] [blame] | 1375 | private void dumpHal(FileDescriptor fd, String[] args) { |
Joe Onorato | bf955d2 | 2019-03-25 00:16:58 -0700 | [diff] [blame] | 1376 | // WARNING: CDD restricts image data from leaving TEE unencrypted on |
| 1377 | // production devices: |
| 1378 | // [C-1-10] MUST not allow unencrypted access to identifiable biometric |
| 1379 | // data or any data derived from it (such as embeddings) to the |
| 1380 | // Application Processor outside the context of the TEE. |
| 1381 | // As such, this API should only be enabled for testing purposes on |
| 1382 | // engineering and userdebug builds. All modules in the software stack |
| 1383 | // MUST enforce final build products do NOT have this functionality. |
| 1384 | // Additionally, the following check MUST NOT be removed. |
| 1385 | if (!(Build.IS_ENG || Build.IS_USERDEBUG)) { |
| 1386 | return; |
| 1387 | } |
| 1388 | |
Joe Onorato | 108413a | 2019-04-03 18:20:52 -0700 | [diff] [blame] | 1389 | // Additionally, this flag allows turning off face for a device |
| 1390 | // (either permanently through the build or on an individual device). |
| 1391 | if (SystemProperties.getBoolean("ro.face.disable_debug_data", false) |
| 1392 | || SystemProperties.getBoolean("persist.face.disable_debug_data", false)) { |
| 1393 | return; |
| 1394 | } |
| 1395 | |
Joe Onorato | db39600 | 2019-04-05 19:49:27 -0700 | [diff] [blame] | 1396 | // The debug method takes two file descriptors. The first is for text |
| 1397 | // output, which we will drop. The second is for binary data, which |
| 1398 | // will be the protobuf data. |
| 1399 | final IBiometricsFace daemon = getFaceDaemon(); |
| 1400 | if (daemon != null) { |
| 1401 | FileOutputStream devnull = null; |
| 1402 | try { |
| 1403 | devnull = new FileOutputStream("/dev/null"); |
| 1404 | final NativeHandle handle = new NativeHandle( |
| 1405 | new FileDescriptor[] { devnull.getFD(), fd }, |
| 1406 | new int[0], false); |
| 1407 | daemon.debug(handle, new ArrayList<String>(Arrays.asList(args))); |
| 1408 | } catch (IOException | RemoteException ex) { |
| 1409 | Slog.d(TAG, "error while reading face debugging data", ex); |
| 1410 | } finally { |
| 1411 | if (devnull != null) { |
| 1412 | try { |
| 1413 | devnull.close(); |
| 1414 | } catch (IOException ex) { |
| 1415 | } |
| 1416 | } |
| 1417 | } |
Joe Onorato | bf955d2 | 2019-03-25 00:16:58 -0700 | [diff] [blame] | 1418 | } |
Joe Onorato | bf955d2 | 2019-03-25 00:16:58 -0700 | [diff] [blame] | 1419 | } |
Kevin Chyn | 8b7a037 | 2018-09-17 15:06:05 -0700 | [diff] [blame] | 1420 | } |