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