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