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; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 26 | import android.content.Context; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 27 | import android.content.pm.UserInfo; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 28 | import android.hardware.biometrics.BiometricAuthenticator; |
| 29 | import android.hardware.biometrics.BiometricConstants; |
| 30 | import android.hardware.biometrics.IBiometricPromptReceiver; |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 31 | import android.hardware.biometrics.IBiometricPromptServiceReceiver; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 32 | import android.hardware.biometrics.IBiometricServiceLockoutResetCallback; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 33 | import android.hardware.biometrics.face.V1_0.IBiometricsFace; |
| 34 | import android.hardware.biometrics.face.V1_0.IBiometricsFaceClientCallback; |
| 35 | import android.hardware.face.Face; |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 36 | import android.hardware.face.FaceManager; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 37 | import android.hardware.face.IFaceService; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 38 | import android.hardware.face.IFaceServiceReceiver; |
| 39 | import android.os.Binder; |
| 40 | import android.os.Bundle; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 41 | import android.os.Environment; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 42 | import android.os.IBinder; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 43 | import android.os.RemoteException; |
| 44 | import android.os.SELinux; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 45 | import android.os.UserHandle; |
| 46 | import android.os.UserManager; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 47 | import android.util.Slog; |
| 48 | import android.util.proto.ProtoOutputStream; |
| 49 | |
| 50 | import com.android.internal.annotations.GuardedBy; |
| 51 | import com.android.internal.logging.MetricsLogger; |
| 52 | import com.android.internal.util.DumpUtils; |
| 53 | import com.android.server.SystemServerInitThreadPool; |
Kevin Chyn | 836f2cf | 2018-08-27 11:06:39 -0700 | [diff] [blame] | 54 | import com.android.server.biometrics.BiometricService; |
| 55 | import com.android.server.biometrics.BiometricUtils; |
| 56 | import com.android.server.biometrics.Metrics; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 57 | |
| 58 | import org.json.JSONArray; |
| 59 | import org.json.JSONException; |
| 60 | import org.json.JSONObject; |
| 61 | |
| 62 | import java.io.File; |
| 63 | import java.io.FileDescriptor; |
| 64 | import java.io.PrintWriter; |
| 65 | import java.util.ArrayList; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 66 | import java.util.List; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 67 | |
| 68 | /** |
| 69 | * A service to manage multiple clients that want to access the face HAL API. |
| 70 | * The service is responsible for maintaining a list of clients and dispatching all |
| 71 | * face -related events. |
| 72 | * |
| 73 | * @hide |
| 74 | */ |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 75 | public class FaceService extends BiometricService { |
| 76 | |
| 77 | protected static final String TAG = "FaceService"; |
| 78 | private static final boolean DEBUG = true; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 79 | private static final String FACE_DATA_DIR = "facedata"; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 80 | private static final String ACTION_LOCKOUT_RESET = |
Kevin Chyn | 2ffadb3 | 2018-06-19 11:29:38 -0700 | [diff] [blame] | 81 | "com.android.server.biometrics.face.ACTION_LOCKOUT_RESET"; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 82 | private static final int MAX_FAILED_ATTEMPTS_LOCKOUT_TIMED = 3; |
| 83 | private static final int MAX_FAILED_ATTEMPTS_LOCKOUT_PERMANENT = 12; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 84 | |
| 85 | /** |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 86 | * Receives the incoming binder calls from FaceManager. |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 87 | */ |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 88 | private final class FaceServiceWrapper extends IFaceService.Stub { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
| 91 | * The following methods contain common code which is shared in biometrics/common. |
| 92 | */ |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 93 | @Override // Binder call |
| 94 | public long preEnroll(IBinder token) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 95 | checkPermission(MANAGE_BIOMETRIC); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 96 | return startPreEnroll(token); |
| 97 | } |
| 98 | |
| 99 | @Override // Binder call |
| 100 | public int postEnroll(IBinder token) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 101 | checkPermission(MANAGE_BIOMETRIC); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 102 | return startPostEnroll(token); |
| 103 | } |
| 104 | |
| 105 | @Override // Binder call |
| 106 | public void enroll(final IBinder token, final byte[] cryptoToken, final int userId, |
| 107 | final IFaceServiceReceiver receiver, final int flags, |
| 108 | final String opPackageName) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 109 | checkPermission(MANAGE_BIOMETRIC); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 110 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 111 | final boolean restricted = isRestricted(); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 112 | final EnrollClientImpl client = new EnrollClientImpl(getContext(), mDaemonWrapper, |
| 113 | mHalDeviceId, token, new ServiceListenerImpl(receiver), mCurrentUserId, |
| 114 | 0 /* groupId */, cryptoToken, restricted, opPackageName); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 115 | |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 116 | enrollInternal(client, userId); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | @Override // Binder call |
| 120 | public void cancelEnrollment(final IBinder token) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 121 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 122 | cancelEnrollmentInternal(token); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | @Override // Binder call |
| 126 | public void authenticate(final IBinder token, final long opId, |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 127 | final IFaceServiceReceiver receiver, final int flags, |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 128 | final String opPackageName) { |
| 129 | checkPermission(USE_BIOMETRIC_INTERNAL); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 130 | final boolean restricted = isRestricted(); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 131 | final AuthenticationClientImpl client = new AuthenticationClientImpl(getContext(), |
| 132 | mDaemonWrapper, mHalDeviceId, token, new ServiceListenerImpl(receiver), |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 133 | mCurrentUserId, 0 /* groupId */, opId, restricted, opPackageName, |
Kevin Chyn | 5a2ff5d | 2018-08-29 19:07:30 -0700 | [diff] [blame] | 134 | null /* bundle */, null /* dialogReceiver */, mStatusBarService, mFaceManager); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 135 | |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 136 | authenticateInternal(client, opId, opPackageName); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | @Override // Binder call |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 140 | public void authenticateFromService(IBinder token, long opId, int groupId, |
| 141 | IBiometricPromptServiceReceiver receiver, int flags, String opPackageName, |
| 142 | Bundle bundle, IBiometricPromptReceiver dialogReceiver, |
| 143 | int callingUid, int callingPid, int callingUserId) { |
| 144 | checkPermission(USE_BIOMETRIC_INTERNAL); |
| 145 | final boolean restricted = true; // BiometricPrompt is always restricted |
| 146 | final AuthenticationClientImpl client = new AuthenticationClientImpl(getContext(), |
| 147 | mDaemonWrapper, mHalDeviceId, token, |
| 148 | new BiometricPromptServiceListenerImpl(receiver), |
| 149 | mCurrentUserId, 0 /* groupId */, opId, restricted, opPackageName, |
Kevin Chyn | 5a2ff5d | 2018-08-29 19:07:30 -0700 | [diff] [blame] | 150 | bundle, dialogReceiver, mStatusBarService, mFaceManager); |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 151 | authenticateInternal(client, opId, opPackageName, callingUid, callingPid, |
| 152 | callingUserId); |
| 153 | } |
| 154 | |
| 155 | @Override // Binder call |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 156 | public void cancelAuthentication(final IBinder token, final String opPackageName) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 157 | checkPermission(USE_BIOMETRIC_INTERNAL); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 158 | cancelAuthenticationInternal(token, opPackageName); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | @Override // Binder call |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 162 | public void cancelAuthenticationFromService(final IBinder token, final String opPackageName, |
| 163 | int callingUid, int callingPid, int callingUserId) { |
| 164 | checkPermission(USE_BIOMETRIC_INTERNAL); |
| 165 | cancelAuthenticationInternal(token, opPackageName, |
| 166 | callingUid, callingPid, callingUserId); |
| 167 | } |
| 168 | |
| 169 | @Override // Binder call |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 170 | public void setActiveUser(final int userId) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 171 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 172 | setActiveUserInternal(userId); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | @Override // Binder call |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 176 | public void remove(final IBinder token, final int faceId, final int userId, |
| 177 | final IFaceServiceReceiver receiver) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 178 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 179 | |
| 180 | if (token == null) { |
| 181 | Slog.w(TAG, "remove(): token is null"); |
| 182 | return; |
| 183 | } |
| 184 | |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 185 | final boolean restricted = isRestricted(); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 186 | final RemovalClientImpl client = new RemovalClientImpl(getContext(), mDaemonWrapper, |
| 187 | mHalDeviceId, token, new ServiceListenerImpl(receiver), faceId, 0 /* groupId */, |
| 188 | userId, restricted, token.toString()); |
| 189 | client.setShouldNotifyUserActivity(true); |
| 190 | removeInternal(client); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 191 | } |
| 192 | |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 193 | @Override |
| 194 | public void enumerate(final IBinder token, final int userId, |
| 195 | final IFaceServiceReceiver receiver) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 196 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 197 | |
| 198 | final boolean restricted = isRestricted(); |
| 199 | final EnumerateClientImpl client = new EnumerateClientImpl(getContext(), mDaemonWrapper, |
| 200 | mHalDeviceId, token, new ServiceListenerImpl(receiver), userId, userId, |
| 201 | restricted, getContext().getOpPackageName()); |
| 202 | enumerateInternal(client); |
| 203 | } |
| 204 | |
| 205 | @Override |
| 206 | public void addLockoutResetCallback(final IBiometricServiceLockoutResetCallback callback) |
| 207 | throws RemoteException { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 208 | checkPermission(USE_BIOMETRIC_INTERNAL); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 209 | FaceService.super.addLockoutResetCallback(callback); |
| 210 | } |
| 211 | |
| 212 | @Override // Binder call |
| 213 | protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 214 | if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) { |
| 215 | return; |
| 216 | } |
| 217 | |
| 218 | final long ident = Binder.clearCallingIdentity(); |
| 219 | try { |
| 220 | if (args.length > 0 && "--proto".equals(args[0])) { |
| 221 | dumpProto(fd); |
| 222 | } else { |
| 223 | dumpInternal(pw); |
| 224 | } |
| 225 | } finally { |
| 226 | Binder.restoreCallingIdentity(ident); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * The following methods don't use any common code from BiometricService |
| 232 | */ |
| 233 | |
| 234 | // TODO: refactor out common code here |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 235 | @Override // Binder call |
| 236 | public boolean isHardwareDetected(long deviceId, String opPackageName) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 237 | checkPermission(USE_BIOMETRIC_INTERNAL); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 238 | if (!canUseBiometric(opPackageName, false /* foregroundOnly */, |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 239 | Binder.getCallingUid(), Binder.getCallingPid(), |
| 240 | UserHandle.getCallingUserId())) { |
| 241 | return false; |
| 242 | } |
| 243 | |
| 244 | final long token = Binder.clearCallingIdentity(); |
| 245 | try { |
| 246 | IBiometricsFace daemon = getFaceDaemon(); |
| 247 | return daemon != null && mHalDeviceId != 0; |
| 248 | } finally { |
| 249 | Binder.restoreCallingIdentity(token); |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | @Override // Binder call |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 254 | public void rename(final int faceId, final String name) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 255 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 256 | if (!isCurrentUserOrProfile(UserHandle.getCallingUserId())) { |
| 257 | return; |
| 258 | } |
| 259 | mHandler.post(new Runnable() { |
| 260 | @Override |
| 261 | public void run() { |
| 262 | getBiometricUtils().renameBiometricForUser(getContext(), mCurrentUserId, |
| 263 | faceId, name); |
| 264 | } |
| 265 | }); |
| 266 | } |
| 267 | |
| 268 | @Override // Binder call |
| 269 | public List<Face> getEnrolledFaces(int userId, String opPackageName) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 270 | checkPermission(MANAGE_BIOMETRIC); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 271 | if (!canUseBiometric(opPackageName, false /* foregroundOnly */, |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 272 | Binder.getCallingUid(), Binder.getCallingPid(), |
| 273 | UserHandle.getCallingUserId())) { |
| 274 | return null; |
| 275 | } |
| 276 | |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 277 | return FaceService.this.getEnrolledFaces(userId); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 278 | } |
| 279 | |
| 280 | @Override // Binder call |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 281 | public boolean hasEnrolledFaces(int userId, String opPackageName) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 282 | checkPermission(USE_BIOMETRIC_INTERNAL); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 283 | if (!canUseBiometric(opPackageName, false /* foregroundOnly */, |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 284 | Binder.getCallingUid(), Binder.getCallingPid(), |
| 285 | UserHandle.getCallingUserId())) { |
| 286 | return false; |
| 287 | } |
| 288 | |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 289 | return FaceService.this.hasEnrolledBiometrics(userId); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | @Override // Binder call |
| 293 | public long getAuthenticatorId(String opPackageName) { |
| 294 | // In this method, we're not checking whether the caller is permitted to use face |
| 295 | // API because current authenticator ID is leaked (in a more contrived way) via Android |
| 296 | // Keystore (android.security.keystore package): the user of that API can create a key |
| 297 | // which requires face authentication for its use, and then query the key's |
| 298 | // characteristics (hidden API) which returns, among other things, face |
| 299 | // authenticator ID which was active at key creation time. |
| 300 | // |
| 301 | // Reason: The part of Android Keystore which runs inside an app's process invokes this |
| 302 | // method in certain cases. Those cases are not always where the developer demonstrates |
| 303 | // explicit intent to use face functionality. Thus, to avoiding throwing an |
| 304 | // unexpected SecurityException this method does not check whether its caller is |
| 305 | // permitted to use face API. |
| 306 | // |
| 307 | // The permission check should be restored once Android Keystore no longer invokes this |
| 308 | // method from inside app processes. |
| 309 | |
| 310 | return FaceService.this.getAuthenticatorId(opPackageName); |
| 311 | } |
| 312 | |
| 313 | @Override // Binder call |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 314 | public void resetTimeout(byte[] token) { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 315 | checkPermission(MANAGE_BIOMETRIC); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 316 | // TODO: confirm security token when we move timeout management into the HAL layer. |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 317 | mHandler.post(mResetFailedAttemptsForCurrentUserRunnable); |
| 318 | } |
| 319 | } |
| 320 | |
| 321 | /** |
| 322 | * Receives callbacks from the ClientMonitor implementations. The results are forwarded to |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 323 | * BiometricPrompt. |
| 324 | */ |
| 325 | private class BiometricPromptServiceListenerImpl implements ServiceListener { |
| 326 | |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 327 | private IBiometricPromptServiceReceiver mBiometricPromptServiceReceiver; |
| 328 | |
| 329 | public BiometricPromptServiceListenerImpl(IBiometricPromptServiceReceiver receiver) { |
| 330 | mBiometricPromptServiceReceiver = receiver; |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | @Override |
| 334 | public void onAcquired(long deviceId, int acquiredInfo, int vendorCode) |
| 335 | throws RemoteException { |
| 336 | /** |
| 337 | * Map the acquired codes onto existing {@link BiometricConstants} acquired codes. |
| 338 | */ |
| 339 | if (mBiometricPromptServiceReceiver != null) { |
| 340 | mBiometricPromptServiceReceiver.onAcquired(deviceId, |
| 341 | mFaceManager.getMappedAcquiredInfo(acquiredInfo, vendorCode), |
| 342 | mFaceManager.getAcquiredString(acquiredInfo, vendorCode)); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | @Override |
| 347 | public void onAuthenticationSucceeded(long deviceId, |
| 348 | BiometricAuthenticator.Identifier biometric, int userId) throws RemoteException { |
| 349 | if (mBiometricPromptServiceReceiver != null) { |
| 350 | mBiometricPromptServiceReceiver.onAuthenticationSucceeded(deviceId); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | @Override |
| 355 | public void onAuthenticationFailed(long deviceId) throws RemoteException { |
| 356 | if (mBiometricPromptServiceReceiver != null) { |
| 357 | mBiometricPromptServiceReceiver.onAuthenticationFailed(deviceId); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | @Override |
| 362 | public void onError(long deviceId, int error, int vendorCode) throws RemoteException { |
| 363 | if (mBiometricPromptServiceReceiver != null) { |
| 364 | mBiometricPromptServiceReceiver.onError(deviceId, error, |
| 365 | mFaceManager.getErrorString(error, vendorCode)); |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * Receives callbacks from the ClientMonitor implementations. The results are forwarded to |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 372 | * the FaceManager. |
| 373 | */ |
| 374 | private class ServiceListenerImpl implements ServiceListener { |
| 375 | |
| 376 | private IFaceServiceReceiver mFaceServiceReceiver; |
| 377 | |
| 378 | public ServiceListenerImpl(IFaceServiceReceiver receiver) { |
| 379 | mFaceServiceReceiver = receiver; |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | @Override |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 383 | public void onEnrollResult(BiometricAuthenticator.Identifier identifier, int remaining) |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 384 | throws RemoteException { |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 385 | if (mFaceServiceReceiver != null) { |
| 386 | mFaceServiceReceiver.onEnrollResult(identifier.getDeviceId(), |
| 387 | identifier.getBiometricId(), |
| 388 | remaining); |
| 389 | } |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 390 | } |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 391 | |
| 392 | @Override |
| 393 | public void onAcquired(long deviceId, int acquiredInfo, int vendorCode) |
| 394 | throws RemoteException { |
| 395 | if (mFaceServiceReceiver != null) { |
| 396 | mFaceServiceReceiver.onAcquired(deviceId, acquiredInfo, vendorCode); |
| 397 | } |
| 398 | } |
| 399 | |
| 400 | @Override |
| 401 | public void onAuthenticationSucceeded(long deviceId, |
| 402 | BiometricAuthenticator.Identifier biometric, int userId) |
| 403 | throws RemoteException { |
| 404 | if (mFaceServiceReceiver != null) { |
| 405 | if (biometric instanceof Face) { |
| 406 | mFaceServiceReceiver.onAuthenticationSucceeded(deviceId, (Face)biometric); |
| 407 | } else { |
| 408 | Slog.e(TAG, "onAuthenticationSucceeded received non-face biometric"); |
| 409 | } |
| 410 | } |
| 411 | } |
| 412 | |
| 413 | @Override |
| 414 | public void onAuthenticationFailed(long deviceId) throws RemoteException { |
| 415 | if (mFaceServiceReceiver != null) { |
| 416 | mFaceServiceReceiver.onAuthenticationFailed(deviceId); |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | @Override |
| 421 | public void onError(long deviceId, int error, int vendorCode) throws RemoteException { |
| 422 | if (mFaceServiceReceiver != null) { |
| 423 | mFaceServiceReceiver.onError(deviceId, error, vendorCode); |
| 424 | } |
| 425 | } |
| 426 | |
| 427 | @Override |
| 428 | public void onRemoved(BiometricAuthenticator.Identifier identifier, |
| 429 | int remaining) throws RemoteException { |
| 430 | if (mFaceServiceReceiver != null) { |
| 431 | mFaceServiceReceiver.onRemoved(identifier.getDeviceId(), |
| 432 | identifier.getBiometricId(), remaining); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | @Override |
| 437 | public void onEnumerated(BiometricAuthenticator.Identifier identifier, int remaining) |
| 438 | throws RemoteException { |
| 439 | if (mFaceServiceReceiver != null) { |
| 440 | |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | private final FaceMetrics mFaceMetrics = new FaceMetrics(); |
| 446 | |
| 447 | @GuardedBy("this") |
| 448 | private IBiometricsFace mDaemon; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 449 | private long mHalDeviceId; |
Kevin Chyn | 5a2ff5d | 2018-08-29 19:07:30 -0700 | [diff] [blame] | 450 | // Use FaceManager to get strings, so BiometricPrompt interface is cleaner |
| 451 | private FaceManager mFaceManager; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 452 | |
| 453 | /** |
| 454 | * Receives callbacks from the HAL. |
| 455 | */ |
| 456 | private IBiometricsFaceClientCallback mDaemonCallback = |
| 457 | new IBiometricsFaceClientCallback.Stub() { |
| 458 | @Override |
| 459 | public void onEnrollResult(final long deviceId, int faceId, int userId, |
| 460 | int remaining) { |
| 461 | mHandler.post(() -> { |
| 462 | final Face face = new Face(getBiometricUtils() |
| 463 | .getUniqueName(getContext(), userId), faceId, deviceId); |
| 464 | FaceService.super.handleEnrollResult(face, remaining); |
| 465 | }); |
| 466 | } |
| 467 | |
| 468 | @Override |
| 469 | public void onAcquired(final long deviceId, final int userId, |
| 470 | final int acquiredInfo, |
| 471 | final int vendorCode) { |
| 472 | mHandler.post(() -> { |
| 473 | FaceService.super.handleAcquired(deviceId, acquiredInfo, vendorCode); |
| 474 | }); |
| 475 | } |
| 476 | |
| 477 | @Override |
| 478 | public void onAuthenticated(final long deviceId, final int faceId, final int userId, |
| 479 | ArrayList<Byte> token) { |
| 480 | mHandler.post(() -> { |
Kevin Chyn | b528d69 | 2018-07-20 11:53:14 -0700 | [diff] [blame] | 481 | Face face = new Face("", faceId, deviceId); |
| 482 | FaceService.super.handleAuthenticated(face, token); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 483 | }); |
| 484 | } |
| 485 | |
| 486 | @Override |
| 487 | public void onError(final long deviceId, final int userId, final int error, |
| 488 | final int vendorCode) { |
| 489 | mHandler.post(() -> { |
| 490 | FaceService.super.handleError(deviceId, error, vendorCode); |
| 491 | |
| 492 | // TODO: this chunk of code should be common to all biometric services |
| 493 | if (error == BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE) { |
| 494 | // If we get HW_UNAVAILABLE, try to connect again later... |
| 495 | Slog.w(TAG, "Got ERROR_HW_UNAVAILABLE; try reconnecting next client."); |
| 496 | synchronized (this) { |
| 497 | mDaemon = null; |
| 498 | mHalDeviceId = 0; |
| 499 | mCurrentUserId = UserHandle.USER_NULL; |
| 500 | } |
| 501 | } |
| 502 | }); |
| 503 | } |
| 504 | |
| 505 | @Override |
| 506 | public void onRemoved(final long deviceId, final int faceId, final int userId, |
| 507 | final int remaining) { |
| 508 | mHandler.post(() -> { |
| 509 | final Face face = new Face("", faceId, deviceId); |
| 510 | FaceService.super.handleRemoved(face, remaining); |
| 511 | }); |
| 512 | } |
| 513 | |
| 514 | @Override |
| 515 | public void onEnumerate(long deviceId, ArrayList<Integer> faceIds, int userId) |
| 516 | throws RemoteException { |
| 517 | // TODO |
| 518 | } |
| 519 | }; |
| 520 | |
| 521 | /** |
| 522 | * Wraps the HAL-specific code and is passed to the ClientMonitor implementations so that they |
| 523 | * can be shared between the multiple biometric services. |
| 524 | */ |
| 525 | private final DaemonWrapper mDaemonWrapper = new DaemonWrapper() { |
| 526 | @Override |
| 527 | public int authenticate(long operationId, int groupId) throws RemoteException { |
| 528 | IBiometricsFace daemon = getFaceDaemon(); |
| 529 | if (daemon == null) { |
| 530 | Slog.w(TAG, "authenticate(): no face HAL!"); |
| 531 | return ERROR_ESRCH; |
| 532 | } |
| 533 | return daemon.authenticate(operationId); |
| 534 | } |
| 535 | |
| 536 | @Override |
| 537 | public int cancel() throws RemoteException { |
| 538 | IBiometricsFace daemon = getFaceDaemon(); |
| 539 | if (daemon == null) { |
| 540 | Slog.w(TAG, "cancel(): no face HAL!"); |
| 541 | return ERROR_ESRCH; |
| 542 | } |
| 543 | return daemon.cancel(); |
| 544 | } |
| 545 | |
| 546 | @Override |
| 547 | public int remove(int groupId, int biometricId) throws RemoteException { |
| 548 | IBiometricsFace daemon = getFaceDaemon(); |
| 549 | if (daemon == null) { |
| 550 | Slog.w(TAG, "remove(): no face HAL!"); |
| 551 | return ERROR_ESRCH; |
| 552 | } |
| 553 | return daemon.remove(biometricId); |
| 554 | } |
| 555 | |
| 556 | @Override |
| 557 | public int enumerate() throws RemoteException { |
| 558 | IBiometricsFace daemon = getFaceDaemon(); |
| 559 | if (daemon == null) { |
| 560 | Slog.w(TAG, "enumerate(): no face HAL!"); |
| 561 | return ERROR_ESRCH; |
| 562 | } |
| 563 | return daemon.enumerate(); |
| 564 | } |
| 565 | |
| 566 | @Override |
| 567 | public int enroll(byte[] cryptoToken, int groupId, int timeout) throws RemoteException { |
| 568 | IBiometricsFace daemon = getFaceDaemon(); |
| 569 | if (daemon == null) { |
| 570 | Slog.w(TAG, "enroll(): no face HAL!"); |
| 571 | return ERROR_ESRCH; |
| 572 | } |
| 573 | final ArrayList<Byte> token = new ArrayList<>(); |
| 574 | for (int i = 0; i < cryptoToken.length; i++) { |
| 575 | token.add(cryptoToken[i]); |
| 576 | } |
Kevin Chyn | a0e920f | 2018-08-31 15:16:55 -0700 | [diff] [blame] | 577 | // TODO: plumb requireAttention down from framework |
| 578 | return daemon.enroll(token, timeout, true /* requireAttention */); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 579 | } |
| 580 | }; |
| 581 | |
| 582 | |
| 583 | public FaceService(Context context) { |
| 584 | super(context); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 585 | } |
| 586 | |
| 587 | @Override |
| 588 | public void onStart() { |
Kevin Chyn | 5a2ff5d | 2018-08-29 19:07:30 -0700 | [diff] [blame] | 589 | super.onStart(); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 590 | publishBinderService(Context.FACE_SERVICE, new FaceServiceWrapper()); |
| 591 | SystemServerInitThreadPool.get().submit(this::getFaceDaemon, TAG + ".onStart"); |
Kevin Chyn | 5a2ff5d | 2018-08-29 19:07:30 -0700 | [diff] [blame] | 592 | mFaceManager = (FaceManager) getContext().getSystemService(Context.FACE_SERVICE); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | @Override |
| 596 | public String getTag() { |
| 597 | return TAG; |
| 598 | } |
| 599 | |
| 600 | @Override |
| 601 | protected BiometricUtils getBiometricUtils() { |
| 602 | return FaceUtils.getInstance(); |
| 603 | } |
| 604 | |
| 605 | @Override |
| 606 | protected int getFailedAttemptsLockoutTimed() { |
| 607 | return MAX_FAILED_ATTEMPTS_LOCKOUT_TIMED; |
| 608 | } |
| 609 | |
| 610 | @Override |
| 611 | protected int getFailedAttemptsLockoutPermanent() { |
| 612 | return MAX_FAILED_ATTEMPTS_LOCKOUT_PERMANENT; |
| 613 | } |
| 614 | |
| 615 | @Override |
| 616 | protected Metrics getMetrics() { |
| 617 | return mFaceMetrics; |
| 618 | } |
| 619 | |
| 620 | @Override |
| 621 | protected boolean hasReachedEnrollmentLimit(int userId) { |
| 622 | final int limit = getContext().getResources().getInteger( |
Kevin Chyn | 017e76e | 2018-06-27 18:35:06 -0700 | [diff] [blame] | 623 | com.android.internal.R.integer.config_faceMaxTemplatesPerUser); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 624 | final int enrolled = FaceService.this.getEnrolledFaces(userId).size(); |
| 625 | if (enrolled >= limit) { |
| 626 | Slog.w(TAG, "Too many faces registered"); |
| 627 | return true; |
| 628 | } |
| 629 | return false; |
| 630 | } |
| 631 | |
| 632 | @Override |
| 633 | protected void updateActiveGroup(int userId, String clientPackage) { |
| 634 | IBiometricsFace daemon = getFaceDaemon(); |
| 635 | |
| 636 | if (daemon != null) { |
| 637 | try { |
| 638 | userId = getUserOrWorkProfileId(clientPackage, userId); |
| 639 | if (userId != mCurrentUserId) { |
| 640 | final File baseDir = Environment.getDataVendorDeDirectory(userId); |
| 641 | final File faceDir = new File(baseDir, FACE_DATA_DIR); |
| 642 | if (!faceDir.exists()) { |
| 643 | if (!faceDir.mkdir()) { |
| 644 | Slog.v(TAG, "Cannot make directory: " + faceDir.getAbsolutePath()); |
| 645 | return; |
| 646 | } |
| 647 | // Calling mkdir() from this process will create a directory with our |
| 648 | // permissions (inherited from the containing dir). This command fixes |
| 649 | // the label. |
| 650 | if (!SELinux.restorecon(faceDir)) { |
| 651 | Slog.w(TAG, "Restorecons failed. Directory will have wrong label."); |
| 652 | return; |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | daemon.setActiveUser(userId, faceDir.getAbsolutePath()); |
| 657 | mCurrentUserId = userId; |
| 658 | } |
| 659 | mAuthenticatorIds.put(userId, |
| 660 | hasEnrolledBiometrics(userId) ? daemon.getAuthenticatorId().value : 0L); |
| 661 | } catch (RemoteException e) { |
| 662 | Slog.e(TAG, "Failed to setActiveUser():", e); |
| 663 | } |
| 664 | } |
| 665 | } |
| 666 | |
| 667 | @Override |
| 668 | protected String getLockoutResetIntent() { |
| 669 | return ACTION_LOCKOUT_RESET; |
| 670 | } |
| 671 | |
| 672 | @Override |
| 673 | protected String getLockoutBroadcastPermission() { |
| 674 | return RESET_FACE_LOCKOUT; |
| 675 | } |
| 676 | |
| 677 | @Override |
| 678 | protected long getHalDeviceId() { |
| 679 | return mHalDeviceId; |
| 680 | } |
| 681 | |
| 682 | @Override |
| 683 | protected void handleUserSwitching(int userId) { |
| 684 | updateActiveGroup(userId, null); |
| 685 | } |
| 686 | |
| 687 | @Override |
| 688 | protected boolean hasEnrolledBiometrics(int userId) { |
| 689 | if (userId != UserHandle.getCallingUserId()) { |
| 690 | checkPermission(INTERACT_ACROSS_USERS); |
| 691 | } |
| 692 | return getBiometricUtils().getBiometricsForUser(getContext(), userId).size() > 0; |
| 693 | } |
| 694 | |
| 695 | @Override |
| 696 | protected String getManageBiometricPermission() { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 697 | return MANAGE_BIOMETRIC; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | @Override |
| 701 | protected void checkUseBiometricPermission() { |
Kevin Chyn | a24e9fd | 2018-08-27 12:39:17 -0700 | [diff] [blame] | 702 | // noop for Face. The permission checks are all done on the incoming binder call. |
| 703 | // TODO: Perhaps do the same in FingerprintService |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 704 | } |
| 705 | |
| 706 | @Override |
| 707 | protected int getAppOp() { |
| 708 | return AppOpsManager.OP_USE_FACE; |
| 709 | } |
| 710 | |
| 711 | @Override |
| 712 | protected void notifyClientActiveCallbacks(boolean isActive) { |
| 713 | // noop for Face. |
| 714 | } |
| 715 | |
| 716 | /** Gets the face daemon */ |
| 717 | private synchronized IBiometricsFace getFaceDaemon() { |
| 718 | if (mDaemon == null) { |
| 719 | Slog.v(TAG, "mDaemon was null, reconnect to face"); |
| 720 | try { |
| 721 | mDaemon = IBiometricsFace.getService(); |
| 722 | } catch (java.util.NoSuchElementException e) { |
| 723 | // Service doesn't exist or cannot be opened. Logged below. |
| 724 | } catch (RemoteException e) { |
| 725 | Slog.e(TAG, "Failed to get biometric interface", e); |
| 726 | } |
| 727 | if (mDaemon == null) { |
| 728 | Slog.w(TAG, "face HIDL not available"); |
| 729 | return null; |
| 730 | } |
| 731 | |
| 732 | mDaemon.asBinder().linkToDeath(this, 0); |
| 733 | |
| 734 | try { |
| 735 | mHalDeviceId = mDaemon.setCallback(mDaemonCallback).value; |
| 736 | } catch (RemoteException e) { |
| 737 | Slog.e(TAG, "Failed to open face HAL", e); |
| 738 | mDaemon = null; // try again later! |
| 739 | } |
| 740 | |
| 741 | if (DEBUG) Slog.v(TAG, "Face HAL id: " + mHalDeviceId); |
| 742 | if (mHalDeviceId != 0) { |
| 743 | loadAuthenticatorIds(); |
| 744 | updateActiveGroup(ActivityManager.getCurrentUser(), null); |
| 745 | } else { |
| 746 | Slog.w(TAG, "Failed to open Face HAL!"); |
| 747 | MetricsLogger.count(getContext(), "faced_openhal_error", 1); |
| 748 | mDaemon = null; |
| 749 | } |
| 750 | } |
| 751 | return mDaemon; |
| 752 | } |
| 753 | |
| 754 | private long startPreEnroll(IBinder token) { |
| 755 | IBiometricsFace daemon = getFaceDaemon(); |
| 756 | if (daemon == null) { |
| 757 | Slog.w(TAG, "startPreEnroll: no face HAL!"); |
| 758 | return 0; |
| 759 | } |
| 760 | try { |
Kevin Chyn | 96c9297 | 2018-08-31 16:09:31 -0700 | [diff] [blame] | 761 | return daemon.generateChallenge().value; |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 762 | } catch (RemoteException e) { |
| 763 | Slog.e(TAG, "startPreEnroll failed", e); |
| 764 | } |
| 765 | return 0; |
| 766 | } |
| 767 | |
| 768 | private int startPostEnroll(IBinder token) { |
| 769 | IBiometricsFace daemon = getFaceDaemon(); |
| 770 | if (daemon == null) { |
| 771 | Slog.w(TAG, "startPostEnroll: no face HAL!"); |
| 772 | return 0; |
| 773 | } |
| 774 | try { |
Kevin Chyn | 96c9297 | 2018-08-31 16:09:31 -0700 | [diff] [blame] | 775 | return daemon.revokeChallenge(); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 776 | } catch (RemoteException e) { |
| 777 | Slog.e(TAG, "startPostEnroll failed", e); |
| 778 | } |
| 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | private List<Face> getEnrolledFaces(int userId) { |
| 783 | return getBiometricUtils().getBiometricsForUser(getContext(), userId); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | private void dumpInternal(PrintWriter pw) { |
| 787 | JSONObject dump = new JSONObject(); |
| 788 | try { |
| 789 | dump.put("service", "Face Manager"); |
| 790 | |
| 791 | JSONArray sets = new JSONArray(); |
| 792 | for (UserInfo user : UserManager.get(getContext()).getUsers()) { |
| 793 | final int userId = user.getUserHandle().getIdentifier(); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 794 | final int N = getBiometricUtils().getBiometricsForUser(getContext(), userId).size(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 795 | PerformanceStats stats = mPerformanceMap.get(userId); |
| 796 | PerformanceStats cryptoStats = mCryptoPerformanceMap.get(userId); |
| 797 | JSONObject set = new JSONObject(); |
| 798 | set.put("id", userId); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 799 | set.put("count", N); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 800 | set.put("accept", (stats != null) ? stats.accept : 0); |
| 801 | set.put("reject", (stats != null) ? stats.reject : 0); |
| 802 | set.put("acquire", (stats != null) ? stats.acquire : 0); |
| 803 | set.put("lockout", (stats != null) ? stats.lockout : 0); |
| 804 | set.put("permanentLockout", (stats != null) ? stats.permanentLockout : 0); |
| 805 | // cryptoStats measures statistics about secure face transactions |
| 806 | // (e.g. to unlock password storage, make secure purchases, etc.) |
| 807 | set.put("acceptCrypto", (cryptoStats != null) ? cryptoStats.accept : 0); |
| 808 | set.put("rejectCrypto", (cryptoStats != null) ? cryptoStats.reject : 0); |
| 809 | set.put("acquireCrypto", (cryptoStats != null) ? cryptoStats.acquire : 0); |
| 810 | set.put("lockoutCrypto", (cryptoStats != null) ? cryptoStats.lockout : 0); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 811 | set.put("permanentLockoutCrypto", |
| 812 | (cryptoStats != null) ? cryptoStats.permanentLockout : 0); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 813 | sets.put(set); |
| 814 | } |
| 815 | |
| 816 | dump.put("prints", sets); |
| 817 | } catch (JSONException e) { |
| 818 | Slog.e(TAG, "dump formatting failure", e); |
| 819 | } |
| 820 | pw.println(dump); |
| 821 | } |
| 822 | |
| 823 | private void dumpProto(FileDescriptor fd) { |
| 824 | final ProtoOutputStream proto = new ProtoOutputStream(fd); |
| 825 | for (UserInfo user : UserManager.get(getContext()).getUsers()) { |
| 826 | final int userId = user.getUserHandle().getIdentifier(); |
| 827 | |
| 828 | final long userToken = proto.start(FaceServiceDumpProto.USERS); |
| 829 | |
| 830 | proto.write(FaceUserStatsProto.USER_ID, userId); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 831 | proto.write(FaceUserStatsProto.NUM_FACES, |
| 832 | getBiometricUtils().getBiometricsForUser(getContext(), userId).size()); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 833 | |
| 834 | // Normal face authentications (e.g. lockscreen) |
| 835 | final PerformanceStats normal = mPerformanceMap.get(userId); |
| 836 | if (normal != null) { |
| 837 | final long countsToken = proto.start(FaceUserStatsProto.NORMAL); |
| 838 | proto.write(FaceActionStatsProto.ACCEPT, normal.accept); |
| 839 | proto.write(FaceActionStatsProto.REJECT, normal.reject); |
| 840 | proto.write(FaceActionStatsProto.ACQUIRE, normal.acquire); |
| 841 | proto.write(FaceActionStatsProto.LOCKOUT, normal.lockout); |
| 842 | proto.write(FaceActionStatsProto.LOCKOUT_PERMANENT, normal.lockout); |
| 843 | proto.end(countsToken); |
| 844 | } |
| 845 | |
| 846 | // Statistics about secure face transactions (e.g. to unlock password |
| 847 | // storage, make secure purchases, etc.) |
| 848 | final PerformanceStats crypto = mCryptoPerformanceMap.get(userId); |
| 849 | if (crypto != null) { |
| 850 | final long countsToken = proto.start(FaceUserStatsProto.CRYPTO); |
| 851 | proto.write(FaceActionStatsProto.ACCEPT, crypto.accept); |
| 852 | proto.write(FaceActionStatsProto.REJECT, crypto.reject); |
| 853 | proto.write(FaceActionStatsProto.ACQUIRE, crypto.acquire); |
| 854 | proto.write(FaceActionStatsProto.LOCKOUT, crypto.lockout); |
| 855 | proto.write(FaceActionStatsProto.LOCKOUT_PERMANENT, crypto.lockout); |
| 856 | proto.end(countsToken); |
| 857 | } |
| 858 | |
| 859 | proto.end(userToken); |
| 860 | } |
| 861 | proto.flush(); |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 862 | mPerformanceMap.clear(); |
| 863 | mCryptoPerformanceMap.clear(); |
Gilad Bretter | cb51b8b | 2018-03-22 17:04:51 +0200 | [diff] [blame] | 864 | } |
Kevin Chyn | a56dff7 | 2018-06-19 18:41:12 -0700 | [diff] [blame] | 865 | } |