blob: 017503a03816630feb35efcd8b5c43c82e48a20e [file] [log] [blame]
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001/*
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 Chyn2ffadb32018-06-19 11:29:38 -070017package com.android.server.biometrics.face;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020018
19import static android.Manifest.permission.INTERACT_ACROSS_USERS;
Kevin Chyna24e9fd2018-08-27 12:39:17 -070020import static android.Manifest.permission.MANAGE_BIOMETRIC;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020021import static android.Manifest.permission.RESET_FACE_LOCKOUT;
Kevin Chyna24e9fd2018-08-27 12:39:17 -070022import static android.Manifest.permission.USE_BIOMETRIC_INTERNAL;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020023
24import android.app.ActivityManager;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020025import android.app.AppOpsManager;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020026import android.content.Context;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020027import android.content.pm.UserInfo;
Kevin Chyna56dff72018-06-19 18:41:12 -070028import android.hardware.biometrics.BiometricAuthenticator;
29import android.hardware.biometrics.BiometricConstants;
Kevin Chyn7782d142019-01-18 12:51:33 -080030import android.hardware.biometrics.BiometricsProtoEnums;
Kevin Chyna56dff72018-06-19 18:41:12 -070031import android.hardware.biometrics.IBiometricServiceLockoutResetCallback;
Kevin Chyn23289ef2018-11-28 16:32:36 -080032import android.hardware.biometrics.IBiometricServiceReceiverInternal;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020033import android.hardware.biometrics.face.V1_0.IBiometricsFace;
34import android.hardware.biometrics.face.V1_0.IBiometricsFaceClientCallback;
Kevin Chynd79e24e2018-09-25 12:06:59 -070035import android.hardware.biometrics.face.V1_0.Status;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020036import android.hardware.face.Face;
Kevin Chyna24e9fd2018-08-27 12:39:17 -070037import android.hardware.face.FaceManager;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020038import android.hardware.face.IFaceService;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020039import android.hardware.face.IFaceServiceReceiver;
40import android.os.Binder;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020041import android.os.Environment;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020042import android.os.IBinder;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020043import android.os.RemoteException;
44import android.os.SELinux;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020045import android.os.UserHandle;
46import android.os.UserManager;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020047import android.util.Slog;
48import android.util.proto.ProtoOutputStream;
49
50import com.android.internal.annotations.GuardedBy;
51import com.android.internal.logging.MetricsLogger;
52import com.android.internal.util.DumpUtils;
53import com.android.server.SystemServerInitThreadPool;
Kevin Chyn355c6bf2018-09-20 22:14:19 -070054import com.android.server.biometrics.BiometricServiceBase;
Kevin Chyn836f2cf2018-08-27 11:06:39 -070055import com.android.server.biometrics.BiometricUtils;
56import com.android.server.biometrics.Metrics;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020057
58import org.json.JSONArray;
59import org.json.JSONException;
60import org.json.JSONObject;
61
62import java.io.File;
63import java.io.FileDescriptor;
64import java.io.PrintWriter;
65import java.util.ArrayList;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020066import java.util.List;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020067
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
Kevin Chyn51676d22018-11-05 18:00:43 -080071 * face-related events.
Gilad Brettercb51b8b2018-03-22 17:04:51 +020072 *
73 * @hide
74 */
Kevin Chyn355c6bf2018-09-20 22:14:19 -070075public class FaceService extends BiometricServiceBase {
Kevin Chyna56dff72018-06-19 18:41:12 -070076
77 protected static final String TAG = "FaceService";
78 private static final boolean DEBUG = true;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020079 private static final String FACE_DATA_DIR = "facedata";
Gilad Brettercb51b8b2018-03-22 17:04:51 +020080 private static final String ACTION_LOCKOUT_RESET =
Kevin Chyn2ffadb32018-06-19 11:29:38 -070081 "com.android.server.biometrics.face.ACTION_LOCKOUT_RESET";
Kevin Chyna56dff72018-06-19 18:41:12 -070082 private static final int MAX_FAILED_ATTEMPTS_LOCKOUT_TIMED = 3;
83 private static final int MAX_FAILED_ATTEMPTS_LOCKOUT_PERMANENT = 12;
Kevin Chyne46a2162018-09-20 18:43:01 -070084 private static final int CHALLENGE_TIMEOUT_SEC = 600; // 10 minutes
Gilad Brettercb51b8b2018-03-22 17:04:51 +020085
Kevin Chyn8b7a0372018-09-17 15:06:05 -070086 private final class FaceAuthClient extends AuthenticationClientImpl {
87 public FaceAuthClient(Context context,
88 DaemonWrapper daemon, long halDeviceId, IBinder token,
89 ServiceListener listener, int targetUserId, int groupId, long opId,
Kevin Chyn87f257a2018-11-27 16:26:07 -080090 boolean restricted, String owner, int cookie, boolean requireConfirmation) {
Kevin Chyn8b7a0372018-09-17 15:06:05 -070091 super(context, daemon, halDeviceId, token, listener, targetUserId, groupId, opId,
Kevin Chyn87f257a2018-11-27 16:26:07 -080092 restricted, owner, cookie, requireConfirmation);
Kevin Chyn8b7a0372018-09-17 15:06:05 -070093 }
Kevin Chyn7782d142019-01-18 12:51:33 -080094
95 @Override
96 protected int statsModality() {
97 return FaceService.this.statsModality();
98 }
Kevin Chyn8b7a0372018-09-17 15:06:05 -070099 }
100
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200101 /**
Kevin Chyna56dff72018-06-19 18:41:12 -0700102 * Receives the incoming binder calls from FaceManager.
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200103 */
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200104 private final class FaceServiceWrapper extends IFaceService.Stub {
Kevin Chyna56dff72018-06-19 18:41:12 -0700105
106 /**
107 * The following methods contain common code which is shared in biometrics/common.
108 */
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200109 @Override // Binder call
Kevin Chynd79e24e2018-09-25 12:06:59 -0700110 public long generateChallenge(IBinder token) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700111 checkPermission(MANAGE_BIOMETRIC);
Kevin Chynd79e24e2018-09-25 12:06:59 -0700112 return startGenerateChallenge(token);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200113 }
114
115 @Override // Binder call
Kevin Chynd79e24e2018-09-25 12:06:59 -0700116 public int revokeChallenge(IBinder token) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700117 checkPermission(MANAGE_BIOMETRIC);
Kevin Chynd79e24e2018-09-25 12:06:59 -0700118 return startRevokeChallenge(token);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200119 }
120
121 @Override // Binder call
Kevin Chyn1f16c2d2018-12-07 13:06:08 -0800122 public void enroll(final IBinder token, final byte[] cryptoToken,
123 final IFaceServiceReceiver receiver, final String opPackageName,
124 final int[] disabledFeatures) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700125 checkPermission(MANAGE_BIOMETRIC);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200126
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200127 final boolean restricted = isRestricted();
Kevin Chyna56dff72018-06-19 18:41:12 -0700128 final EnrollClientImpl client = new EnrollClientImpl(getContext(), mDaemonWrapper,
129 mHalDeviceId, token, new ServiceListenerImpl(receiver), mCurrentUserId,
Kevin Chyn1429a312019-01-28 16:08:09 -0800130 0 /* groupId */, cryptoToken, restricted, opPackageName, disabledFeatures) {
131 @Override
132 public boolean shouldVibrate() {
133 return false;
134 }
Kevin Chyn7782d142019-01-18 12:51:33 -0800135
136 @Override
137 protected int statsModality() {
138 return FaceService.this.statsModality();
139 }
Kevin Chyn1429a312019-01-28 16:08:09 -0800140 };
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200141
Kevin Chyn1f16c2d2018-12-07 13:06:08 -0800142 enrollInternal(client, UserHandle.getCallingUserId());
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200143 }
144
145 @Override // Binder call
146 public void cancelEnrollment(final IBinder token) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700147 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700148 cancelEnrollmentInternal(token);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200149 }
150
151 @Override // Binder call
Kevin Chyn747e29b2019-01-11 17:01:53 -0800152 public void authenticate(final IBinder token, final long opId, int userId,
Kevin Chyna56dff72018-06-19 18:41:12 -0700153 final IFaceServiceReceiver receiver, final int flags,
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700154 final String opPackageName) {
155 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyn747e29b2019-01-11 17:01:53 -0800156 updateActiveGroup(userId, opPackageName);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200157 final boolean restricted = isRestricted();
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700158 final AuthenticationClientImpl client = new FaceAuthClient(getContext(),
Kevin Chyna56dff72018-06-19 18:41:12 -0700159 mDaemonWrapper, mHalDeviceId, token, new ServiceListenerImpl(receiver),
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700160 mCurrentUserId, 0 /* groupId */, opId, restricted, opPackageName,
Kevin Chyn87f257a2018-11-27 16:26:07 -0800161 0 /* cookie */, false /* requireConfirmation */);
Kevin Chyna56dff72018-06-19 18:41:12 -0700162 authenticateInternal(client, opId, opPackageName);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200163 }
164
165 @Override // Binder call
Kevin Chyn87f257a2018-11-27 16:26:07 -0800166 public void prepareForAuthentication(boolean requireConfirmation, IBinder token, long opId,
Kevin Chyn23289ef2018-11-28 16:32:36 -0800167 int groupId, IBiometricServiceReceiverInternal wrapperReceiver,
168 String opPackageName, int cookie, int callingUid, int callingPid,
169 int callingUserId) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700170 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyn41a80902019-02-06 08:12:15 -0800171 updateActiveGroup(groupId, opPackageName);
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700172 final boolean restricted = true; // BiometricPrompt is always restricted
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700173 final AuthenticationClientImpl client = new FaceAuthClient(getContext(),
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700174 mDaemonWrapper, mHalDeviceId, token,
Kevin Chyn87f257a2018-11-27 16:26:07 -0800175 new BiometricPromptServiceListenerImpl(wrapperReceiver),
176 mCurrentUserId, 0 /* groupId */, opId, restricted, opPackageName, cookie,
Kevin Chyn158fefb2019-01-03 18:59:05 -0800177 requireConfirmation);
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700178 authenticateInternal(client, opId, opPackageName, callingUid, callingPid,
179 callingUserId);
180 }
181
182 @Override // Binder call
Kevin Chyn87f257a2018-11-27 16:26:07 -0800183 public void startPreparedClient(int cookie) {
184 checkPermission(MANAGE_BIOMETRIC);
185 startCurrentClient(cookie);
186 }
187
188 @Override // Binder call
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200189 public void cancelAuthentication(final IBinder token, final String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700190 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyna56dff72018-06-19 18:41:12 -0700191 cancelAuthenticationInternal(token, opPackageName);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200192 }
193
194 @Override // Binder call
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700195 public void cancelAuthenticationFromService(final IBinder token, final String opPackageName,
Kevin Chyne92cdae2018-11-21 16:35:04 -0800196 int callingUid, int callingPid, int callingUserId, boolean fromClient) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700197 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyne92cdae2018-11-21 16:35:04 -0800198 cancelAuthenticationInternal(token, opPackageName, callingUid, callingPid,
199 callingUserId, fromClient);
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700200 }
201
202 @Override // Binder call
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200203 public void setActiveUser(final int userId) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700204 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700205 setActiveUserInternal(userId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200206 }
207
208 @Override // Binder call
Kevin Chyna56dff72018-06-19 18:41:12 -0700209 public void remove(final IBinder token, final int faceId, final int userId,
210 final IFaceServiceReceiver receiver) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700211 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700212
213 if (token == null) {
214 Slog.w(TAG, "remove(): token is null");
215 return;
216 }
217
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200218 final boolean restricted = isRestricted();
Kevin Chyna56dff72018-06-19 18:41:12 -0700219 final RemovalClientImpl client = new RemovalClientImpl(getContext(), mDaemonWrapper,
220 mHalDeviceId, token, new ServiceListenerImpl(receiver), faceId, 0 /* groupId */,
Kevin Chyn7782d142019-01-18 12:51:33 -0800221 userId, restricted, token.toString()) {
222 @Override
223 protected int statsModality() {
224 return FaceService.this.statsModality();
225 }
226 };
Kevin Chyna56dff72018-06-19 18:41:12 -0700227 client.setShouldNotifyUserActivity(true);
228 removeInternal(client);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200229 }
230
Kevin Chyna56dff72018-06-19 18:41:12 -0700231 @Override
232 public void enumerate(final IBinder token, final int userId,
233 final IFaceServiceReceiver receiver) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700234 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700235
236 final boolean restricted = isRestricted();
237 final EnumerateClientImpl client = new EnumerateClientImpl(getContext(), mDaemonWrapper,
238 mHalDeviceId, token, new ServiceListenerImpl(receiver), userId, userId,
Kevin Chyn7782d142019-01-18 12:51:33 -0800239 restricted, getContext().getOpPackageName()) {
240 @Override
241 protected int statsModality() {
242 return FaceService.this.statsModality();
243 }
244 };
Kevin Chyna56dff72018-06-19 18:41:12 -0700245 enumerateInternal(client);
246 }
247
248 @Override
249 public void addLockoutResetCallback(final IBiometricServiceLockoutResetCallback callback)
250 throws RemoteException {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700251 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyna56dff72018-06-19 18:41:12 -0700252 FaceService.super.addLockoutResetCallback(callback);
253 }
254
255 @Override // Binder call
256 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
257 if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) {
258 return;
259 }
260
261 final long ident = Binder.clearCallingIdentity();
262 try {
263 if (args.length > 0 && "--proto".equals(args[0])) {
264 dumpProto(fd);
265 } else {
266 dumpInternal(pw);
267 }
268 } finally {
269 Binder.restoreCallingIdentity(ident);
270 }
271 }
272
273 /**
274 * The following methods don't use any common code from BiometricService
275 */
276
277 // TODO: refactor out common code here
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200278 @Override // Binder call
279 public boolean isHardwareDetected(long deviceId, String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700280 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyna56dff72018-06-19 18:41:12 -0700281 if (!canUseBiometric(opPackageName, false /* foregroundOnly */,
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200282 Binder.getCallingUid(), Binder.getCallingPid(),
283 UserHandle.getCallingUserId())) {
284 return false;
285 }
286
287 final long token = Binder.clearCallingIdentity();
288 try {
289 IBiometricsFace daemon = getFaceDaemon();
290 return daemon != null && mHalDeviceId != 0;
291 } finally {
292 Binder.restoreCallingIdentity(token);
293 }
294 }
295
296 @Override // Binder call
Kevin Chyna56dff72018-06-19 18:41:12 -0700297 public void rename(final int faceId, final String name) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700298 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700299 if (!isCurrentUserOrProfile(UserHandle.getCallingUserId())) {
300 return;
301 }
302 mHandler.post(new Runnable() {
303 @Override
304 public void run() {
305 getBiometricUtils().renameBiometricForUser(getContext(), mCurrentUserId,
306 faceId, name);
307 }
308 });
309 }
310
311 @Override // Binder call
312 public List<Face> getEnrolledFaces(int userId, String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700313 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700314 if (!canUseBiometric(opPackageName, false /* foregroundOnly */,
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200315 Binder.getCallingUid(), Binder.getCallingPid(),
316 UserHandle.getCallingUserId())) {
317 return null;
318 }
319
Kevin Chyna56dff72018-06-19 18:41:12 -0700320 return FaceService.this.getEnrolledFaces(userId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200321 }
322
323 @Override // Binder call
Kevin Chyna56dff72018-06-19 18:41:12 -0700324 public boolean hasEnrolledFaces(int userId, String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700325 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyna56dff72018-06-19 18:41:12 -0700326 if (!canUseBiometric(opPackageName, false /* foregroundOnly */,
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200327 Binder.getCallingUid(), Binder.getCallingPid(),
328 UserHandle.getCallingUserId())) {
329 return false;
330 }
331
Kevin Chyna56dff72018-06-19 18:41:12 -0700332 return FaceService.this.hasEnrolledBiometrics(userId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200333 }
334
335 @Override // Binder call
336 public long getAuthenticatorId(String opPackageName) {
337 // In this method, we're not checking whether the caller is permitted to use face
338 // API because current authenticator ID is leaked (in a more contrived way) via Android
339 // Keystore (android.security.keystore package): the user of that API can create a key
340 // which requires face authentication for its use, and then query the key's
341 // characteristics (hidden API) which returns, among other things, face
342 // authenticator ID which was active at key creation time.
343 //
344 // Reason: The part of Android Keystore which runs inside an app's process invokes this
345 // method in certain cases. Those cases are not always where the developer demonstrates
346 // explicit intent to use face functionality. Thus, to avoiding throwing an
347 // unexpected SecurityException this method does not check whether its caller is
348 // permitted to use face API.
349 //
350 // The permission check should be restored once Android Keystore no longer invokes this
351 // method from inside app processes.
352
353 return FaceService.this.getAuthenticatorId(opPackageName);
354 }
355
356 @Override // Binder call
Kevin Chyna56dff72018-06-19 18:41:12 -0700357 public void resetTimeout(byte[] token) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700358 checkPermission(MANAGE_BIOMETRIC);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200359 // TODO: confirm security token when we move timeout management into the HAL layer.
Kevin Chyna56dff72018-06-19 18:41:12 -0700360 mHandler.post(mResetFailedAttemptsForCurrentUserRunnable);
361 }
Kevin Chynd79e24e2018-09-25 12:06:59 -0700362
363 @Override
Kevin Chyn1f16c2d2018-12-07 13:06:08 -0800364 public int setFeature(int feature, boolean enabled, final byte[] token) {
Kevin Chynd79e24e2018-09-25 12:06:59 -0700365 checkPermission(MANAGE_BIOMETRIC);
366
367 final ArrayList<Byte> byteToken = new ArrayList<>();
368 for (int i = 0; i < token.length; i++) {
369 byteToken.add(token[i]);
370 }
371
372 int result;
373 try {
Kevin Chyn1f16c2d2018-12-07 13:06:08 -0800374 result = mDaemon != null ? mDaemon.setFeature(feature, enabled, byteToken)
Kevin Chynd79e24e2018-09-25 12:06:59 -0700375 : Status.INTERNAL_ERROR;
376 } catch (RemoteException e) {
Kevin Chyn1f16c2d2018-12-07 13:06:08 -0800377 Slog.e(getTag(), "Unable to set feature: " + feature + " to enabled:" + enabled,
378 e);
Kevin Chynd79e24e2018-09-25 12:06:59 -0700379 result = Status.INTERNAL_ERROR;
380 }
381
382 return result;
383 }
384
385 @Override
Kevin Chyn1f16c2d2018-12-07 13:06:08 -0800386 public boolean getFeature(int feature) {
Kevin Chynd79e24e2018-09-25 12:06:59 -0700387 checkPermission(MANAGE_BIOMETRIC);
388
Kevin Chynd79e24e2018-09-25 12:06:59 -0700389 boolean result = true;
390 try {
Kevin Chyn1f16c2d2018-12-07 13:06:08 -0800391 result = mDaemon != null ? mDaemon.getFeature(feature) : true;
Kevin Chynd79e24e2018-09-25 12:06:59 -0700392 } catch (RemoteException e) {
Kevin Chyn57f119b2018-10-25 12:03:41 -0700393 Slog.e(getTag(), "Unable to getRequireAttention", e);
Kevin Chynd79e24e2018-09-25 12:06:59 -0700394 }
395 return result;
396 }
Kevin Chyn57f119b2018-10-25 12:03:41 -0700397
398 @Override
399 public void userActivity() {
400 checkPermission(MANAGE_BIOMETRIC);
401
402 if (mDaemon != null) {
403 try {
404 mDaemon.userActivity();
405 } catch (RemoteException e) {
406 Slog.e(getTag(), "Unable to send userActivity", e);
407 }
408 }
409 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700410 }
411
412 /**
413 * Receives callbacks from the ClientMonitor implementations. The results are forwarded to
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700414 * BiometricPrompt.
415 */
Kevin Chyne92cdae2018-11-21 16:35:04 -0800416 private class BiometricPromptServiceListenerImpl extends BiometricServiceListener {
Kevin Chyn23289ef2018-11-28 16:32:36 -0800417 BiometricPromptServiceListenerImpl(IBiometricServiceReceiverInternal wrapperReceiver) {
Kevin Chyn87f257a2018-11-27 16:26:07 -0800418 super(wrapperReceiver);
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700419 }
420
421 @Override
422 public void onAcquired(long deviceId, int acquiredInfo, int vendorCode)
423 throws RemoteException {
424 /**
425 * Map the acquired codes onto existing {@link BiometricConstants} acquired codes.
426 */
Kevin Chyne92cdae2018-11-21 16:35:04 -0800427 if (getWrapperReceiver() != null) {
428 getWrapperReceiver().onAcquired(
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700429 FaceManager.getMappedAcquiredInfo(acquiredInfo, vendorCode),
430 FaceManager.getAcquiredString(getContext(), acquiredInfo, vendorCode));
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700431 }
432 }
433
434 @Override
Kevin Chyn87f257a2018-11-27 16:26:07 -0800435 public void onError(long deviceId, int error, int vendorCode, int cookie)
436 throws RemoteException {
Kevin Chyne92cdae2018-11-21 16:35:04 -0800437 if (getWrapperReceiver() != null) {
Kevin Chyn23289ef2018-11-28 16:32:36 -0800438 getWrapperReceiver().onError(cookie, error,
439 FaceManager.getErrorString(getContext(), error, vendorCode));
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700440 }
441 }
442 }
443
444 /**
445 * Receives callbacks from the ClientMonitor implementations. The results are forwarded to
Kevin Chyna56dff72018-06-19 18:41:12 -0700446 * the FaceManager.
447 */
448 private class ServiceListenerImpl implements ServiceListener {
Kevin Chyna56dff72018-06-19 18:41:12 -0700449 private IFaceServiceReceiver mFaceServiceReceiver;
450
451 public ServiceListenerImpl(IFaceServiceReceiver receiver) {
452 mFaceServiceReceiver = receiver;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200453 }
454
455 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -0700456 public void onEnrollResult(BiometricAuthenticator.Identifier identifier, int remaining)
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200457 throws RemoteException {
Kevin Chyna56dff72018-06-19 18:41:12 -0700458 if (mFaceServiceReceiver != null) {
459 mFaceServiceReceiver.onEnrollResult(identifier.getDeviceId(),
460 identifier.getBiometricId(),
461 remaining);
462 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200463 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700464
465 @Override
466 public void onAcquired(long deviceId, int acquiredInfo, int vendorCode)
467 throws RemoteException {
468 if (mFaceServiceReceiver != null) {
469 mFaceServiceReceiver.onAcquired(deviceId, acquiredInfo, vendorCode);
470 }
471 }
472
473 @Override
474 public void onAuthenticationSucceeded(long deviceId,
475 BiometricAuthenticator.Identifier biometric, int userId)
476 throws RemoteException {
477 if (mFaceServiceReceiver != null) {
Kevin Chyn628b7182018-11-13 12:00:48 -0800478 if (biometric == null || biometric instanceof Face) {
Kevin Chyna56dff72018-06-19 18:41:12 -0700479 mFaceServiceReceiver.onAuthenticationSucceeded(deviceId, (Face)biometric);
480 } else {
481 Slog.e(TAG, "onAuthenticationSucceeded received non-face biometric");
482 }
483 }
484 }
485
486 @Override
487 public void onAuthenticationFailed(long deviceId) throws RemoteException {
488 if (mFaceServiceReceiver != null) {
489 mFaceServiceReceiver.onAuthenticationFailed(deviceId);
490 }
491 }
492
493 @Override
Kevin Chyn87f257a2018-11-27 16:26:07 -0800494 public void onError(long deviceId, int error, int vendorCode, int cookie)
495 throws RemoteException {
Kevin Chyna56dff72018-06-19 18:41:12 -0700496 if (mFaceServiceReceiver != null) {
497 mFaceServiceReceiver.onError(deviceId, error, vendorCode);
498 }
499 }
500
501 @Override
502 public void onRemoved(BiometricAuthenticator.Identifier identifier,
503 int remaining) throws RemoteException {
504 if (mFaceServiceReceiver != null) {
505 mFaceServiceReceiver.onRemoved(identifier.getDeviceId(),
506 identifier.getBiometricId(), remaining);
507 }
508 }
509
510 @Override
511 public void onEnumerated(BiometricAuthenticator.Identifier identifier, int remaining)
512 throws RemoteException {
513 if (mFaceServiceReceiver != null) {
514
515 }
516 }
517 }
518
519 private final FaceMetrics mFaceMetrics = new FaceMetrics();
520
521 @GuardedBy("this")
522 private IBiometricsFace mDaemon;
Kevin Chyna56dff72018-06-19 18:41:12 -0700523 private long mHalDeviceId;
Kevin Chyna56dff72018-06-19 18:41:12 -0700524
525 /**
526 * Receives callbacks from the HAL.
527 */
528 private IBiometricsFaceClientCallback mDaemonCallback =
529 new IBiometricsFaceClientCallback.Stub() {
530 @Override
531 public void onEnrollResult(final long deviceId, int faceId, int userId,
532 int remaining) {
533 mHandler.post(() -> {
534 final Face face = new Face(getBiometricUtils()
535 .getUniqueName(getContext(), userId), faceId, deviceId);
536 FaceService.super.handleEnrollResult(face, remaining);
537 });
538 }
539
540 @Override
541 public void onAcquired(final long deviceId, final int userId,
542 final int acquiredInfo,
543 final int vendorCode) {
544 mHandler.post(() -> {
545 FaceService.super.handleAcquired(deviceId, acquiredInfo, vendorCode);
546 });
547 }
548
549 @Override
550 public void onAuthenticated(final long deviceId, final int faceId, final int userId,
551 ArrayList<Byte> token) {
552 mHandler.post(() -> {
Kevin Chynb528d692018-07-20 11:53:14 -0700553 Face face = new Face("", faceId, deviceId);
554 FaceService.super.handleAuthenticated(face, token);
Kevin Chyna56dff72018-06-19 18:41:12 -0700555 });
556 }
557
558 @Override
559 public void onError(final long deviceId, final int userId, final int error,
560 final int vendorCode) {
561 mHandler.post(() -> {
562 FaceService.super.handleError(deviceId, error, vendorCode);
563
564 // TODO: this chunk of code should be common to all biometric services
565 if (error == BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE) {
566 // If we get HW_UNAVAILABLE, try to connect again later...
567 Slog.w(TAG, "Got ERROR_HW_UNAVAILABLE; try reconnecting next client.");
568 synchronized (this) {
569 mDaemon = null;
570 mHalDeviceId = 0;
571 mCurrentUserId = UserHandle.USER_NULL;
572 }
573 }
574 });
575 }
576
577 @Override
578 public void onRemoved(final long deviceId, final int faceId, final int userId,
579 final int remaining) {
580 mHandler.post(() -> {
581 final Face face = new Face("", faceId, deviceId);
582 FaceService.super.handleRemoved(face, remaining);
583 });
584 }
585
586 @Override
587 public void onEnumerate(long deviceId, ArrayList<Integer> faceIds, int userId)
588 throws RemoteException {
589 // TODO
590 }
591 };
592
593 /**
594 * Wraps the HAL-specific code and is passed to the ClientMonitor implementations so that they
595 * can be shared between the multiple biometric services.
596 */
597 private final DaemonWrapper mDaemonWrapper = new DaemonWrapper() {
598 @Override
599 public int authenticate(long operationId, int groupId) throws RemoteException {
600 IBiometricsFace daemon = getFaceDaemon();
601 if (daemon == null) {
602 Slog.w(TAG, "authenticate(): no face HAL!");
603 return ERROR_ESRCH;
604 }
605 return daemon.authenticate(operationId);
606 }
607
608 @Override
609 public int cancel() throws RemoteException {
610 IBiometricsFace daemon = getFaceDaemon();
611 if (daemon == null) {
612 Slog.w(TAG, "cancel(): no face HAL!");
613 return ERROR_ESRCH;
614 }
615 return daemon.cancel();
616 }
617
618 @Override
619 public int remove(int groupId, int biometricId) throws RemoteException {
620 IBiometricsFace daemon = getFaceDaemon();
621 if (daemon == null) {
622 Slog.w(TAG, "remove(): no face HAL!");
623 return ERROR_ESRCH;
624 }
625 return daemon.remove(biometricId);
626 }
627
628 @Override
629 public int enumerate() throws RemoteException {
630 IBiometricsFace daemon = getFaceDaemon();
631 if (daemon == null) {
632 Slog.w(TAG, "enumerate(): no face HAL!");
633 return ERROR_ESRCH;
634 }
635 return daemon.enumerate();
636 }
637
638 @Override
Kevin Chyn1f16c2d2018-12-07 13:06:08 -0800639 public int enroll(byte[] cryptoToken, int groupId, int timeout,
640 ArrayList<Integer> disabledFeatures) throws RemoteException {
Kevin Chyna56dff72018-06-19 18:41:12 -0700641 IBiometricsFace daemon = getFaceDaemon();
642 if (daemon == null) {
643 Slog.w(TAG, "enroll(): no face HAL!");
644 return ERROR_ESRCH;
645 }
646 final ArrayList<Byte> token = new ArrayList<>();
647 for (int i = 0; i < cryptoToken.length; i++) {
648 token.add(cryptoToken[i]);
649 }
Kevin Chyna0e920f2018-08-31 15:16:55 -0700650 // TODO: plumb requireAttention down from framework
Kevin Chyn1f16c2d2018-12-07 13:06:08 -0800651 return daemon.enroll(token, timeout, disabledFeatures);
Kevin Chyna56dff72018-06-19 18:41:12 -0700652 }
653 };
654
655
656 public FaceService(Context context) {
657 super(context);
Kevin Chyna56dff72018-06-19 18:41:12 -0700658 }
659
660 @Override
661 public void onStart() {
Kevin Chyn5a2ff5d2018-08-29 19:07:30 -0700662 super.onStart();
Kevin Chyna56dff72018-06-19 18:41:12 -0700663 publishBinderService(Context.FACE_SERVICE, new FaceServiceWrapper());
664 SystemServerInitThreadPool.get().submit(this::getFaceDaemon, TAG + ".onStart");
665 }
666
667 @Override
668 public String getTag() {
669 return TAG;
670 }
671
672 @Override
673 protected BiometricUtils getBiometricUtils() {
674 return FaceUtils.getInstance();
675 }
676
677 @Override
678 protected int getFailedAttemptsLockoutTimed() {
679 return MAX_FAILED_ATTEMPTS_LOCKOUT_TIMED;
680 }
681
682 @Override
683 protected int getFailedAttemptsLockoutPermanent() {
684 return MAX_FAILED_ATTEMPTS_LOCKOUT_PERMANENT;
685 }
686
687 @Override
688 protected Metrics getMetrics() {
689 return mFaceMetrics;
690 }
691
692 @Override
693 protected boolean hasReachedEnrollmentLimit(int userId) {
694 final int limit = getContext().getResources().getInteger(
Kevin Chyn017e76e2018-06-27 18:35:06 -0700695 com.android.internal.R.integer.config_faceMaxTemplatesPerUser);
Kevin Chyna56dff72018-06-19 18:41:12 -0700696 final int enrolled = FaceService.this.getEnrolledFaces(userId).size();
697 if (enrolled >= limit) {
698 Slog.w(TAG, "Too many faces registered");
699 return true;
700 }
701 return false;
702 }
703
704 @Override
Kevin Chyn9ba99912019-01-16 16:24:36 -0800705 public void serviceDied(long cookie) {
706 super.serviceDied(cookie);
707 mDaemon = null;
708 }
709
710 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -0700711 protected void updateActiveGroup(int userId, String clientPackage) {
712 IBiometricsFace daemon = getFaceDaemon();
713
714 if (daemon != null) {
715 try {
716 userId = getUserOrWorkProfileId(clientPackage, userId);
717 if (userId != mCurrentUserId) {
718 final File baseDir = Environment.getDataVendorDeDirectory(userId);
719 final File faceDir = new File(baseDir, FACE_DATA_DIR);
720 if (!faceDir.exists()) {
721 if (!faceDir.mkdir()) {
722 Slog.v(TAG, "Cannot make directory: " + faceDir.getAbsolutePath());
723 return;
724 }
725 // Calling mkdir() from this process will create a directory with our
726 // permissions (inherited from the containing dir). This command fixes
727 // the label.
728 if (!SELinux.restorecon(faceDir)) {
729 Slog.w(TAG, "Restorecons failed. Directory will have wrong label.");
730 return;
731 }
732 }
733
734 daemon.setActiveUser(userId, faceDir.getAbsolutePath());
735 mCurrentUserId = userId;
736 }
737 mAuthenticatorIds.put(userId,
738 hasEnrolledBiometrics(userId) ? daemon.getAuthenticatorId().value : 0L);
739 } catch (RemoteException e) {
740 Slog.e(TAG, "Failed to setActiveUser():", e);
741 }
742 }
743 }
744
745 @Override
746 protected String getLockoutResetIntent() {
747 return ACTION_LOCKOUT_RESET;
748 }
749
750 @Override
751 protected String getLockoutBroadcastPermission() {
752 return RESET_FACE_LOCKOUT;
753 }
754
755 @Override
756 protected long getHalDeviceId() {
757 return mHalDeviceId;
758 }
759
760 @Override
761 protected void handleUserSwitching(int userId) {
762 updateActiveGroup(userId, null);
763 }
764
765 @Override
766 protected boolean hasEnrolledBiometrics(int userId) {
767 if (userId != UserHandle.getCallingUserId()) {
768 checkPermission(INTERACT_ACROSS_USERS);
769 }
770 return getBiometricUtils().getBiometricsForUser(getContext(), userId).size() > 0;
771 }
772
773 @Override
774 protected String getManageBiometricPermission() {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700775 return MANAGE_BIOMETRIC;
Kevin Chyna56dff72018-06-19 18:41:12 -0700776 }
777
778 @Override
779 protected void checkUseBiometricPermission() {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700780 // noop for Face. The permission checks are all done on the incoming binder call.
781 // TODO: Perhaps do the same in FingerprintService
Kevin Chyna56dff72018-06-19 18:41:12 -0700782 }
783
784 @Override
Kevin Chynb3c05aa2018-09-21 16:50:32 -0700785 protected boolean checkAppOps(int uid, String opPackageName) {
786 return mAppOps.noteOp(AppOpsManager.OP_USE_BIOMETRIC, uid, opPackageName)
787 == AppOpsManager.MODE_ALLOWED;
Kevin Chyna56dff72018-06-19 18:41:12 -0700788 }
789
790 @Override
791 protected void notifyClientActiveCallbacks(boolean isActive) {
792 // noop for Face.
793 }
794
Kevin Chyn7782d142019-01-18 12:51:33 -0800795 @Override
796 protected int statsModality() {
797 return BiometricsProtoEnums.MODALITY_FACE;
798 }
799
Kevin Chyna56dff72018-06-19 18:41:12 -0700800 /** Gets the face daemon */
801 private synchronized IBiometricsFace getFaceDaemon() {
802 if (mDaemon == null) {
803 Slog.v(TAG, "mDaemon was null, reconnect to face");
804 try {
805 mDaemon = IBiometricsFace.getService();
806 } catch (java.util.NoSuchElementException e) {
807 // Service doesn't exist or cannot be opened. Logged below.
808 } catch (RemoteException e) {
809 Slog.e(TAG, "Failed to get biometric interface", e);
810 }
811 if (mDaemon == null) {
812 Slog.w(TAG, "face HIDL not available");
813 return null;
814 }
815
816 mDaemon.asBinder().linkToDeath(this, 0);
817
818 try {
819 mHalDeviceId = mDaemon.setCallback(mDaemonCallback).value;
820 } catch (RemoteException e) {
821 Slog.e(TAG, "Failed to open face HAL", e);
822 mDaemon = null; // try again later!
823 }
824
825 if (DEBUG) Slog.v(TAG, "Face HAL id: " + mHalDeviceId);
826 if (mHalDeviceId != 0) {
827 loadAuthenticatorIds();
828 updateActiveGroup(ActivityManager.getCurrentUser(), null);
829 } else {
830 Slog.w(TAG, "Failed to open Face HAL!");
831 MetricsLogger.count(getContext(), "faced_openhal_error", 1);
832 mDaemon = null;
833 }
834 }
835 return mDaemon;
836 }
837
Kevin Chynd79e24e2018-09-25 12:06:59 -0700838 private long startGenerateChallenge(IBinder token) {
Kevin Chyna56dff72018-06-19 18:41:12 -0700839 IBiometricsFace daemon = getFaceDaemon();
840 if (daemon == null) {
Kevin Chynd79e24e2018-09-25 12:06:59 -0700841 Slog.w(TAG, "startGenerateChallenge: no face HAL!");
Kevin Chyna56dff72018-06-19 18:41:12 -0700842 return 0;
843 }
844 try {
Kevin Chyne46a2162018-09-20 18:43:01 -0700845 return daemon.generateChallenge(CHALLENGE_TIMEOUT_SEC).value;
Kevin Chyna56dff72018-06-19 18:41:12 -0700846 } catch (RemoteException e) {
Kevin Chynd79e24e2018-09-25 12:06:59 -0700847 Slog.e(TAG, "startGenerateChallenge failed", e);
Kevin Chyna56dff72018-06-19 18:41:12 -0700848 }
849 return 0;
850 }
851
Kevin Chynd79e24e2018-09-25 12:06:59 -0700852 private int startRevokeChallenge(IBinder token) {
Kevin Chyna56dff72018-06-19 18:41:12 -0700853 IBiometricsFace daemon = getFaceDaemon();
854 if (daemon == null) {
Kevin Chynd79e24e2018-09-25 12:06:59 -0700855 Slog.w(TAG, "startRevokeChallenge: no face HAL!");
Kevin Chyna56dff72018-06-19 18:41:12 -0700856 return 0;
857 }
858 try {
Kevin Chyn96c92972018-08-31 16:09:31 -0700859 return daemon.revokeChallenge();
Kevin Chyna56dff72018-06-19 18:41:12 -0700860 } catch (RemoteException e) {
Kevin Chynd79e24e2018-09-25 12:06:59 -0700861 Slog.e(TAG, "startRevokeChallenge failed", e);
Kevin Chyna56dff72018-06-19 18:41:12 -0700862 }
863 return 0;
864 }
865
866 private List<Face> getEnrolledFaces(int userId) {
867 return getBiometricUtils().getBiometricsForUser(getContext(), userId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200868 }
869
870 private void dumpInternal(PrintWriter pw) {
871 JSONObject dump = new JSONObject();
872 try {
873 dump.put("service", "Face Manager");
874
875 JSONArray sets = new JSONArray();
876 for (UserInfo user : UserManager.get(getContext()).getUsers()) {
877 final int userId = user.getUserHandle().getIdentifier();
Kevin Chyna56dff72018-06-19 18:41:12 -0700878 final int N = getBiometricUtils().getBiometricsForUser(getContext(), userId).size();
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200879 PerformanceStats stats = mPerformanceMap.get(userId);
880 PerformanceStats cryptoStats = mCryptoPerformanceMap.get(userId);
881 JSONObject set = new JSONObject();
882 set.put("id", userId);
Kevin Chyna56dff72018-06-19 18:41:12 -0700883 set.put("count", N);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200884 set.put("accept", (stats != null) ? stats.accept : 0);
885 set.put("reject", (stats != null) ? stats.reject : 0);
886 set.put("acquire", (stats != null) ? stats.acquire : 0);
887 set.put("lockout", (stats != null) ? stats.lockout : 0);
888 set.put("permanentLockout", (stats != null) ? stats.permanentLockout : 0);
889 // cryptoStats measures statistics about secure face transactions
890 // (e.g. to unlock password storage, make secure purchases, etc.)
891 set.put("acceptCrypto", (cryptoStats != null) ? cryptoStats.accept : 0);
892 set.put("rejectCrypto", (cryptoStats != null) ? cryptoStats.reject : 0);
893 set.put("acquireCrypto", (cryptoStats != null) ? cryptoStats.acquire : 0);
894 set.put("lockoutCrypto", (cryptoStats != null) ? cryptoStats.lockout : 0);
Kevin Chyna56dff72018-06-19 18:41:12 -0700895 set.put("permanentLockoutCrypto",
896 (cryptoStats != null) ? cryptoStats.permanentLockout : 0);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200897 sets.put(set);
898 }
899
900 dump.put("prints", sets);
901 } catch (JSONException e) {
902 Slog.e(TAG, "dump formatting failure", e);
903 }
904 pw.println(dump);
Kevin Chyn9ba99912019-01-16 16:24:36 -0800905 pw.println("HAL Deaths: " + mHALDeathCount);
906 mHALDeathCount = 0;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200907 }
908
909 private void dumpProto(FileDescriptor fd) {
910 final ProtoOutputStream proto = new ProtoOutputStream(fd);
911 for (UserInfo user : UserManager.get(getContext()).getUsers()) {
912 final int userId = user.getUserHandle().getIdentifier();
913
914 final long userToken = proto.start(FaceServiceDumpProto.USERS);
915
916 proto.write(FaceUserStatsProto.USER_ID, userId);
Kevin Chyna56dff72018-06-19 18:41:12 -0700917 proto.write(FaceUserStatsProto.NUM_FACES,
918 getBiometricUtils().getBiometricsForUser(getContext(), userId).size());
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200919
920 // Normal face authentications (e.g. lockscreen)
921 final PerformanceStats normal = mPerformanceMap.get(userId);
922 if (normal != null) {
923 final long countsToken = proto.start(FaceUserStatsProto.NORMAL);
924 proto.write(FaceActionStatsProto.ACCEPT, normal.accept);
925 proto.write(FaceActionStatsProto.REJECT, normal.reject);
926 proto.write(FaceActionStatsProto.ACQUIRE, normal.acquire);
927 proto.write(FaceActionStatsProto.LOCKOUT, normal.lockout);
928 proto.write(FaceActionStatsProto.LOCKOUT_PERMANENT, normal.lockout);
929 proto.end(countsToken);
930 }
931
932 // Statistics about secure face transactions (e.g. to unlock password
933 // storage, make secure purchases, etc.)
934 final PerformanceStats crypto = mCryptoPerformanceMap.get(userId);
935 if (crypto != null) {
936 final long countsToken = proto.start(FaceUserStatsProto.CRYPTO);
937 proto.write(FaceActionStatsProto.ACCEPT, crypto.accept);
938 proto.write(FaceActionStatsProto.REJECT, crypto.reject);
939 proto.write(FaceActionStatsProto.ACQUIRE, crypto.acquire);
940 proto.write(FaceActionStatsProto.LOCKOUT, crypto.lockout);
941 proto.write(FaceActionStatsProto.LOCKOUT_PERMANENT, crypto.lockout);
942 proto.end(countsToken);
943 }
944
945 proto.end(userToken);
946 }
947 proto.flush();
Kevin Chyna56dff72018-06-19 18:41:12 -0700948 mPerformanceMap.clear();
949 mCryptoPerformanceMap.clear();
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200950 }
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700951}