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