blob: b1c7c7685ddf5e907da434e709cd4ac134f79be6 [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;
Kevin Chyn56e4c3d2019-04-23 11:28:43 -070026import android.app.Notification;
27import android.app.NotificationChannel;
28import android.app.NotificationManager;
29import android.app.PendingIntent;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020030import android.content.Context;
Kevin Chyn56e4c3d2019-04-23 11:28:43 -070031import android.content.Intent;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020032import android.content.pm.UserInfo;
Kevin Chyna56dff72018-06-19 18:41:12 -070033import android.hardware.biometrics.BiometricAuthenticator;
34import android.hardware.biometrics.BiometricConstants;
Kevin Chyn7782d142019-01-18 12:51:33 -080035import android.hardware.biometrics.BiometricsProtoEnums;
Kevin Chyna56dff72018-06-19 18:41:12 -070036import android.hardware.biometrics.IBiometricServiceLockoutResetCallback;
Kevin Chyn23289ef2018-11-28 16:32:36 -080037import android.hardware.biometrics.IBiometricServiceReceiverInternal;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020038import android.hardware.biometrics.face.V1_0.IBiometricsFace;
39import android.hardware.biometrics.face.V1_0.IBiometricsFaceClientCallback;
Kevin Chynb95f1522019-03-04 16:45:15 -080040import android.hardware.biometrics.face.V1_0.OptionalBool;
Kevin Chynd79e24e2018-09-25 12:06:59 -070041import android.hardware.biometrics.face.V1_0.Status;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020042import android.hardware.face.Face;
Kevin Chyna24e9fd2018-08-27 12:39:17 -070043import android.hardware.face.FaceManager;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020044import android.hardware.face.IFaceService;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020045import android.hardware.face.IFaceServiceReceiver;
46import android.os.Binder;
Joe Onoratobf955d22019-03-25 00:16:58 -070047import android.os.Build;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020048import android.os.Environment;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020049import android.os.IBinder;
Joe Onoratodb396002019-04-05 19:49:27 -070050import android.os.NativeHandle;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020051import android.os.RemoteException;
52import android.os.SELinux;
Joe Onorato108413a2019-04-03 18:20:52 -070053import android.os.SystemProperties;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020054import android.os.UserHandle;
55import android.os.UserManager;
joshmccloskey4ceaf6b2019-08-21 11:26:08 -070056import android.provider.Settings;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020057import android.util.Slog;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020058
Kevin Chyn56e4c3d2019-04-23 11:28:43 -070059import com.android.internal.R;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020060import com.android.internal.annotations.GuardedBy;
61import com.android.internal.logging.MetricsLogger;
62import com.android.internal.util.DumpUtils;
63import com.android.server.SystemServerInitThreadPool;
Kevin Chyna38653c2019-02-11 17:46:21 -080064import com.android.server.biometrics.AuthenticationClient;
Kevin Chyn355c6bf2018-09-20 22:14:19 -070065import com.android.server.biometrics.BiometricServiceBase;
Kevin Chyn836f2cf2018-08-27 11:06:39 -070066import com.android.server.biometrics.BiometricUtils;
Ilya Matyukhin9dac8482019-07-09 11:03:07 -070067import com.android.server.biometrics.ClientMonitor;
Kevin Chyn4cc49f72019-04-24 13:53:35 -070068import com.android.server.biometrics.Constants;
Kevin Chyn0ce70852019-05-10 10:29:18 -070069import com.android.server.biometrics.EnumerateClient;
Kevin Chyn6737c572019-02-08 16:10:54 -080070import com.android.server.biometrics.RemovalClient;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020071
72import org.json.JSONArray;
73import org.json.JSONException;
74import org.json.JSONObject;
75
76import java.io.File;
77import java.io.FileDescriptor;
Joe Onoratodb396002019-04-05 19:49:27 -070078import java.io.FileOutputStream;
79import java.io.IOException;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020080import java.io.PrintWriter;
81import java.util.ArrayList;
Joe Onoratodb396002019-04-05 19:49:27 -070082import java.util.Arrays;
Kevin Chyn9bc1d492019-06-21 15:31:50 -070083import java.util.HashMap;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020084import java.util.List;
Kevin Chyn9bc1d492019-06-21 15:31:50 -070085import java.util.Map;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020086
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 Chyn51676d22018-11-05 18:00:43 -080090 * face-related events.
Gilad Brettercb51b8b2018-03-22 17:04:51 +020091 *
92 * @hide
93 */
Kevin Chyn355c6bf2018-09-20 22:14:19 -070094public class FaceService extends BiometricServiceBase {
Kevin Chyna56dff72018-06-19 18:41:12 -070095
96 protected static final String TAG = "FaceService";
97 private static final boolean DEBUG = true;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020098 private static final String FACE_DATA_DIR = "facedata";
Gilad Brettercb51b8b2018-03-22 17:04:51 +020099 private static final String ACTION_LOCKOUT_RESET =
Kevin Chyn2ffadb32018-06-19 11:29:38 -0700100 "com.android.server.biometrics.face.ACTION_LOCKOUT_RESET";
Kevin Chyne46a2162018-09-20 18:43:01 -0700101 private static final int CHALLENGE_TIMEOUT_SEC = 600; // 10 minutes
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200102
Kevin Chyndbfbed42019-06-13 17:01:30 -0700103 private static final String NOTIFICATION_TAG = "FaceService";
104 private static final int NOTIFICATION_ID = 1;
105
joshmccloskey4ceaf6b2019-08-21 11:26:08 -0700106 private static final String SKIP_KEYGUARD_ACQUIRE_IGNORE_LIST =
107 "com.android.server.biometrics.face.skip_keyguard_acquire_ignore_list";
108
Kevin Chyn9bc1d492019-06-21 15:31:50 -0700109 /**
110 * Events for bugreports.
111 */
112 public static final class AuthenticationEvent {
113 private long mStartTime;
114 private long mLatency;
115 // Only valid if mError is 0
116 private boolean mAuthenticated;
117 private int mError;
118 // Only valid if mError is ERROR_VENDOR
119 private int mVendorError;
120
121 AuthenticationEvent(long startTime, long latency, boolean authenticated, int error,
122 int vendorError) {
123 mStartTime = startTime;
124 mLatency = latency;
125 mAuthenticated = authenticated;
126 mError = error;
127 mVendorError = vendorError;
128 }
129
130 public String toString(Context context) {
131 return "Start: " + mStartTime
132 + "\tLatency: " + mLatency
133 + "\tAuthenticated: " + mAuthenticated
134 + "\tError: " + mError
135 + "\tVendorCode: " + mVendorError
136 + "\t" + FaceManager.getErrorString(context, mError, mVendorError);
137 }
138 }
139
140 /**
141 * Keep a short historical buffer of stats, with an aggregated usage time.
142 */
143 private class UsageStats {
144 static final int EVENT_LOG_SIZE = 100;
145
146 Context mContext;
147 List<AuthenticationEvent> mAuthenticationEvents;
148
149 int acceptCount;
150 int rejectCount;
151 Map<Integer, Integer> mErrorCount;
152
153 long acceptLatency;
154 long rejectLatency;
155 Map<Integer, Long> mErrorLatency;
156
157 UsageStats(Context context) {
158 mAuthenticationEvents = new ArrayList<>();
159 mErrorCount = new HashMap<>();
160 mErrorLatency = new HashMap<>();
161 mContext = context;
162 }
163
164 void addEvent(AuthenticationEvent event) {
165 if (mAuthenticationEvents.size() >= EVENT_LOG_SIZE) {
166 mAuthenticationEvents.remove(0);
167 }
168 mAuthenticationEvents.add(event);
169
170 if (event.mAuthenticated) {
171 acceptCount++;
172 acceptLatency += event.mLatency;
173 } else if (event.mError == 0) {
174 rejectCount++;
175 rejectLatency += event.mLatency;
176 } else {
177 mErrorCount.put(event.mError, mErrorCount.getOrDefault(event.mError, 0) + 1);
178 mErrorLatency.put(event.mError,
179 mErrorLatency.getOrDefault(event.mError, 0l) + event.mLatency);
180 }
181 }
182
183 void print(PrintWriter pw) {
184 pw.println("Events since last reboot: " + mAuthenticationEvents.size());
185 for (int i = 0; i < mAuthenticationEvents.size(); i++) {
186 pw.println(mAuthenticationEvents.get(i).toString(mContext));
187 }
188
189 // Dump aggregated usage stats
190 // TODO: Remove or combine with json dump in a future release
191 pw.println("Accept\tCount: " + acceptCount + "\tLatency: " + acceptLatency
192 + "\tAverage: " + (acceptCount > 0 ? acceptLatency / acceptCount : 0));
193 pw.println("Reject\tCount: " + rejectCount + "\tLatency: " + rejectLatency
194 + "\tAverage: " + (rejectCount > 0 ? rejectLatency / rejectCount : 0));
195
196 for (Integer key : mErrorCount.keySet()) {
197 final int count = mErrorCount.get(key);
198 pw.println("Error" + key + "\tCount: " + count
199 + "\tLatency: " + mErrorLatency.getOrDefault(key, 0l)
200 + "\tAverage: " + (count > 0 ? mErrorLatency.getOrDefault(key, 0l) / count
201 : 0)
202 + "\t" + FaceManager.getErrorString(mContext, key, 0 /* vendorCode */));
203 }
204 }
205 }
206
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700207 private final class FaceAuthClient extends AuthenticationClientImpl {
Kevin Chyn0ce70852019-05-10 10:29:18 -0700208 private int mLastAcquire;
209
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700210 public FaceAuthClient(Context context,
211 DaemonWrapper daemon, long halDeviceId, IBinder token,
212 ServiceListener listener, int targetUserId, int groupId, long opId,
Kevin Chyn87f257a2018-11-27 16:26:07 -0800213 boolean restricted, String owner, int cookie, boolean requireConfirmation) {
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700214 super(context, daemon, halDeviceId, token, listener, targetUserId, groupId, opId,
Kevin Chyn87f257a2018-11-27 16:26:07 -0800215 restricted, owner, cookie, requireConfirmation);
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700216 }
Kevin Chyn7782d142019-01-18 12:51:33 -0800217
218 @Override
219 protected int statsModality() {
220 return FaceService.this.statsModality();
221 }
Kevin Chyna38653c2019-02-11 17:46:21 -0800222
223 @Override
224 public boolean shouldFrameworkHandleLockout() {
225 return false;
226 }
Kevin Chyn56d6b072019-02-13 18:39:01 -0800227
228 @Override
Kevin Chyn0ce70852019-05-10 10:29:18 -0700229 public boolean wasUserDetected() {
Ilya Matyukhinc90507e2019-08-20 15:38:57 -0700230 return mLastAcquire != FaceManager.FACE_ACQUIRED_NOT_DETECTED
231 && mLastAcquire != FaceManager.FACE_ACQUIRED_SENSOR_DIRTY;
Kevin Chyn0ce70852019-05-10 10:29:18 -0700232 }
233
234 @Override
Kevin Chyn56d6b072019-02-13 18:39:01 -0800235 public boolean onAuthenticated(BiometricAuthenticator.Identifier identifier,
236 boolean authenticated, ArrayList<Byte> token) {
237 final boolean result = super.onAuthenticated(identifier, authenticated, token);
238
Kevin Chyn9bc1d492019-06-21 15:31:50 -0700239 mUsageStats.addEvent(new AuthenticationEvent(
240 getStartTimeMs(),
241 System.currentTimeMillis() - getStartTimeMs() /* latency */,
242 authenticated,
243 0 /* error */,
244 0 /* vendorError */));
245
Kevin Chyn56d6b072019-02-13 18:39:01 -0800246 // For face, the authentication lifecycle ends either when
247 // 1) Authenticated == true
248 // 2) Error occurred
249 // 3) Authenticated == false
250 // Fingerprint currently does not end when the third condition is met which is a bug,
251 // but let's leave it as-is for now.
252 return result || !authenticated;
253 }
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700254
255 @Override
Kevin Chyn9bc1d492019-06-21 15:31:50 -0700256 public boolean onError(long deviceId, int error, int vendorCode) {
257 mUsageStats.addEvent(new AuthenticationEvent(
258 getStartTimeMs(),
259 System.currentTimeMillis() - getStartTimeMs() /* latency */,
260 false /* authenticated */,
261 error,
262 vendorCode));
263
264 return super.onError(deviceId, error, vendorCode);
265 }
266
267 @Override
Kevin Chyn4cc49f72019-04-24 13:53:35 -0700268 public int[] getAcquireIgnorelist() {
269 if (isBiometricPrompt()) {
270 return mBiometricPromptIgnoreList;
271 } else {
272 // Keyguard
273 return mKeyguardIgnoreList;
274 }
275 }
276
277 @Override
278 public int[] getAcquireVendorIgnorelist() {
279 if (isBiometricPrompt()) {
280 return mBiometricPromptIgnoreListVendor;
281 } else {
282 // Keyguard
283 return mKeyguardIgnoreListVendor;
284 }
285 }
286
287 @Override
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700288 public boolean onAcquired(int acquireInfo, int vendorCode) {
289
Kevin Chyn0ce70852019-05-10 10:29:18 -0700290 mLastAcquire = acquireInfo;
291
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700292 if (acquireInfo == FaceManager.FACE_ACQUIRED_RECALIBRATE) {
293 final String name =
294 getContext().getString(R.string.face_recalibrate_notification_name);
295 final String title =
296 getContext().getString(R.string.face_recalibrate_notification_title);
297 final String content =
298 getContext().getString(R.string.face_recalibrate_notification_content);
299
300 final Intent intent = new Intent("android.settings.FACE_SETTINGS");
301 intent.setPackage("com.android.settings");
302
303 final PendingIntent pendingIntent = PendingIntent.getActivityAsUser(getContext(),
304 0 /* requestCode */, intent, 0 /* flags */, null /* options */,
305 UserHandle.CURRENT);
306
Kevin Chyndbfbed42019-06-13 17:01:30 -0700307 final String channelName = "FaceEnrollNotificationChannel";
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700308
Kevin Chyndbfbed42019-06-13 17:01:30 -0700309 NotificationChannel channel = new NotificationChannel(channelName, name,
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700310 NotificationManager.IMPORTANCE_HIGH);
Kevin Chyndbfbed42019-06-13 17:01:30 -0700311 Notification notification = new Notification.Builder(getContext(), channelName)
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700312 .setSmallIcon(R.drawable.ic_lock)
313 .setContentTitle(title)
314 .setContentText(content)
315 .setSubText(name)
316 .setOnlyAlertOnce(true)
317 .setLocalOnly(true)
318 .setAutoCancel(true)
319 .setCategory(Notification.CATEGORY_SYSTEM)
320 .setContentIntent(pendingIntent)
Kevin Chyn0c3a9982019-06-11 19:09:27 -0700321 .setVisibility(Notification.VISIBILITY_SECRET)
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700322 .build();
323
Kevin Chyndbfbed42019-06-13 17:01:30 -0700324 mNotificationManager.createNotificationChannel(channel);
325 mNotificationManager.notifyAsUser(NOTIFICATION_TAG, NOTIFICATION_ID, notification,
326 UserHandle.CURRENT);
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700327 }
328
329 return super.onAcquired(acquireInfo, vendorCode);
330 }
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700331 }
332
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200333 /**
Kevin Chyna56dff72018-06-19 18:41:12 -0700334 * Receives the incoming binder calls from FaceManager.
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200335 */
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200336 private final class FaceServiceWrapper extends IFaceService.Stub {
Curtis Belmonte45788542019-07-23 11:07:27 -0700337 private static final int ENROLL_TIMEOUT_SEC = 75;
Kevin Chyna56dff72018-06-19 18:41:12 -0700338
339 /**
340 * The following methods contain common code which is shared in biometrics/common.
341 */
Kevin Chyna38653c2019-02-11 17:46:21 -0800342
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200343 @Override // Binder call
Kevin Chynd79e24e2018-09-25 12:06:59 -0700344 public long generateChallenge(IBinder token) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700345 checkPermission(MANAGE_BIOMETRIC);
Kevin Chynd79e24e2018-09-25 12:06:59 -0700346 return startGenerateChallenge(token);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200347 }
348
349 @Override // Binder call
Kevin Chynd79e24e2018-09-25 12:06:59 -0700350 public int revokeChallenge(IBinder token) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700351 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyn7a207e42019-07-27 17:50:33 -0700352 mHandler.post(() -> {
353 // TODO(b/137106905): Schedule binder calls in FaceService to avoid deadlocks.
354 if (getCurrentClient() == null) {
355 // if we aren't handling any other HIDL calls (mCurrentClient == null), revoke
356 // the challenge right away.
357 startRevokeChallenge(token);
358 } else {
359 // postpone revoking the challenge until we finish processing the current HIDL
360 // call.
361 mRevokeChallengePending = true;
362 }
363 });
364 return Status.OK;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200365 }
366
367 @Override // Binder call
Kevin Chyn593e6262019-06-28 13:24:44 -0700368 public void enroll(int userId, final IBinder token, final byte[] cryptoToken,
Kevin Chyn1f16c2d2018-12-07 13:06:08 -0800369 final IFaceServiceReceiver receiver, final String opPackageName,
370 final int[] disabledFeatures) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700371 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyn593e6262019-06-28 13:24:44 -0700372 updateActiveGroup(userId, opPackageName);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200373
Kevin Chyndbfbed42019-06-13 17:01:30 -0700374 mNotificationManager.cancelAsUser(NOTIFICATION_TAG, NOTIFICATION_ID,
375 UserHandle.CURRENT);
376
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200377 final boolean restricted = isRestricted();
Kevin Chyna56dff72018-06-19 18:41:12 -0700378 final EnrollClientImpl client = new EnrollClientImpl(getContext(), mDaemonWrapper,
379 mHalDeviceId, token, new ServiceListenerImpl(receiver), mCurrentUserId,
Curtis Belmonte45788542019-07-23 11:07:27 -0700380 0 /* groupId */, cryptoToken, restricted, opPackageName, disabledFeatures,
381 ENROLL_TIMEOUT_SEC) {
Kevin Chyn4cc49f72019-04-24 13:53:35 -0700382
383 @Override
384 public int[] getAcquireIgnorelist() {
385 return mEnrollIgnoreList;
386 }
387
388 @Override
389 public int[] getAcquireVendorIgnorelist() {
390 return mEnrollIgnoreListVendor;
391 }
392
Kevin Chyn1429a312019-01-28 16:08:09 -0800393 @Override
394 public boolean shouldVibrate() {
395 return false;
396 }
Kevin Chyn7782d142019-01-18 12:51:33 -0800397
398 @Override
399 protected int statsModality() {
400 return FaceService.this.statsModality();
401 }
Kevin Chyn1429a312019-01-28 16:08:09 -0800402 };
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200403
Kevin Chyn1a878c12019-04-04 15:50:11 -0700404 enrollInternal(client, mCurrentUserId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200405 }
406
407 @Override // Binder call
408 public void cancelEnrollment(final IBinder token) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700409 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700410 cancelEnrollmentInternal(token);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200411 }
412
413 @Override // Binder call
Kevin Chyn747e29b2019-01-11 17:01:53 -0800414 public void authenticate(final IBinder token, final long opId, int userId,
Kevin Chyna56dff72018-06-19 18:41:12 -0700415 final IFaceServiceReceiver receiver, final int flags,
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700416 final String opPackageName) {
417 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyn747e29b2019-01-11 17:01:53 -0800418 updateActiveGroup(userId, opPackageName);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200419 final boolean restricted = isRestricted();
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700420 final AuthenticationClientImpl client = new FaceAuthClient(getContext(),
Kevin Chyna56dff72018-06-19 18:41:12 -0700421 mDaemonWrapper, mHalDeviceId, token, new ServiceListenerImpl(receiver),
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700422 mCurrentUserId, 0 /* groupId */, opId, restricted, opPackageName,
Kevin Chyn87f257a2018-11-27 16:26:07 -0800423 0 /* cookie */, false /* requireConfirmation */);
Kevin Chyna56dff72018-06-19 18:41:12 -0700424 authenticateInternal(client, opId, opPackageName);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200425 }
426
427 @Override // Binder call
Kevin Chyn87f257a2018-11-27 16:26:07 -0800428 public void prepareForAuthentication(boolean requireConfirmation, IBinder token, long opId,
Kevin Chyn23289ef2018-11-28 16:32:36 -0800429 int groupId, IBiometricServiceReceiverInternal wrapperReceiver,
430 String opPackageName, int cookie, int callingUid, int callingPid,
431 int callingUserId) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700432 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyn41a80902019-02-06 08:12:15 -0800433 updateActiveGroup(groupId, opPackageName);
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700434 final boolean restricted = true; // BiometricPrompt is always restricted
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700435 final AuthenticationClientImpl client = new FaceAuthClient(getContext(),
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700436 mDaemonWrapper, mHalDeviceId, token,
Kevin Chyn87f257a2018-11-27 16:26:07 -0800437 new BiometricPromptServiceListenerImpl(wrapperReceiver),
438 mCurrentUserId, 0 /* groupId */, opId, restricted, opPackageName, cookie,
Kevin Chyn158fefb2019-01-03 18:59:05 -0800439 requireConfirmation);
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700440 authenticateInternal(client, opId, opPackageName, callingUid, callingPid,
441 callingUserId);
442 }
443
444 @Override // Binder call
Kevin Chyn87f257a2018-11-27 16:26:07 -0800445 public void startPreparedClient(int cookie) {
446 checkPermission(MANAGE_BIOMETRIC);
447 startCurrentClient(cookie);
448 }
449
450 @Override // Binder call
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200451 public void cancelAuthentication(final IBinder token, final String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700452 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyna56dff72018-06-19 18:41:12 -0700453 cancelAuthenticationInternal(token, opPackageName);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200454 }
455
456 @Override // Binder call
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700457 public void cancelAuthenticationFromService(final IBinder token, final String opPackageName,
Kevin Chyne92cdae2018-11-21 16:35:04 -0800458 int callingUid, int callingPid, int callingUserId, boolean fromClient) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700459 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyne92cdae2018-11-21 16:35:04 -0800460 cancelAuthenticationInternal(token, opPackageName, callingUid, callingPid,
461 callingUserId, fromClient);
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700462 }
463
464 @Override // Binder call
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200465 public void setActiveUser(final int userId) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700466 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700467 setActiveUserInternal(userId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200468 }
469
470 @Override // Binder call
Kevin Chyna56dff72018-06-19 18:41:12 -0700471 public void remove(final IBinder token, final int faceId, final int userId,
Kevin Chyn593e6262019-06-28 13:24:44 -0700472 final IFaceServiceReceiver receiver, final String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700473 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyn593e6262019-06-28 13:24:44 -0700474 updateActiveGroup(userId, opPackageName);
Kevin Chyna56dff72018-06-19 18:41:12 -0700475
476 if (token == null) {
477 Slog.w(TAG, "remove(): token is null");
478 return;
479 }
480
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200481 final boolean restricted = isRestricted();
Kevin Chyn4cc49f72019-04-24 13:53:35 -0700482 final RemovalClient client = new RemovalClient(getContext(), getConstants(),
Kevin Chyn6737c572019-02-08 16:10:54 -0800483 mDaemonWrapper, mHalDeviceId, token, new ServiceListenerImpl(receiver), faceId,
484 0 /* groupId */, userId, restricted, token.toString(), getBiometricUtils()) {
Kevin Chyn7782d142019-01-18 12:51:33 -0800485 @Override
486 protected int statsModality() {
487 return FaceService.this.statsModality();
488 }
489 };
Kevin Chyna56dff72018-06-19 18:41:12 -0700490 removeInternal(client);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200491 }
492
Kevin Chyna56dff72018-06-19 18:41:12 -0700493 @Override
494 public void enumerate(final IBinder token, final int userId,
495 final IFaceServiceReceiver receiver) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700496 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700497
498 final boolean restricted = isRestricted();
Kevin Chyn4cc49f72019-04-24 13:53:35 -0700499 final EnumerateClient client = new EnumerateClient(getContext(), getConstants(),
Kevin Chyn6737c572019-02-08 16:10:54 -0800500 mDaemonWrapper, mHalDeviceId, token, new ServiceListenerImpl(receiver), userId,
501 userId, restricted, getContext().getOpPackageName()) {
Kevin Chyn7782d142019-01-18 12:51:33 -0800502 @Override
503 protected int statsModality() {
504 return FaceService.this.statsModality();
505 }
506 };
Kevin Chyna56dff72018-06-19 18:41:12 -0700507 enumerateInternal(client);
508 }
509
510 @Override
511 public void addLockoutResetCallback(final IBiometricServiceLockoutResetCallback callback)
512 throws RemoteException {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700513 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyna56dff72018-06-19 18:41:12 -0700514 FaceService.super.addLockoutResetCallback(callback);
515 }
516
517 @Override // Binder call
518 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
519 if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) {
520 return;
521 }
522
523 final long ident = Binder.clearCallingIdentity();
524 try {
Joe Onoratodb396002019-04-05 19:49:27 -0700525 if (args.length > 1 && "--hal".equals(args[0])) {
526 dumpHal(fd, Arrays.copyOfRange(args, 1, args.length, args.getClass()));
Kevin Chyna56dff72018-06-19 18:41:12 -0700527 } else {
528 dumpInternal(pw);
529 }
530 } finally {
531 Binder.restoreCallingIdentity(ident);
532 }
533 }
534
535 /**
536 * The following methods don't use any common code from BiometricService
537 */
538
539 // TODO: refactor out common code here
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200540 @Override // Binder call
541 public boolean isHardwareDetected(long deviceId, String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700542 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyna56dff72018-06-19 18:41:12 -0700543 if (!canUseBiometric(opPackageName, false /* foregroundOnly */,
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200544 Binder.getCallingUid(), Binder.getCallingPid(),
545 UserHandle.getCallingUserId())) {
546 return false;
547 }
548
549 final long token = Binder.clearCallingIdentity();
550 try {
551 IBiometricsFace daemon = getFaceDaemon();
552 return daemon != null && mHalDeviceId != 0;
553 } finally {
554 Binder.restoreCallingIdentity(token);
555 }
556 }
557
558 @Override // Binder call
Kevin Chyna56dff72018-06-19 18:41:12 -0700559 public void rename(final int faceId, final String name) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700560 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700561 if (!isCurrentUserOrProfile(UserHandle.getCallingUserId())) {
562 return;
563 }
564 mHandler.post(new Runnable() {
565 @Override
566 public void run() {
567 getBiometricUtils().renameBiometricForUser(getContext(), mCurrentUserId,
568 faceId, name);
569 }
570 });
571 }
572
573 @Override // Binder call
574 public List<Face> getEnrolledFaces(int userId, String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700575 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700576 if (!canUseBiometric(opPackageName, false /* foregroundOnly */,
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200577 Binder.getCallingUid(), Binder.getCallingPid(),
578 UserHandle.getCallingUserId())) {
579 return null;
580 }
581
Kevin Chyn6737c572019-02-08 16:10:54 -0800582 return FaceService.this.getEnrolledTemplates(userId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200583 }
584
585 @Override // Binder call
Kevin Chyna56dff72018-06-19 18:41:12 -0700586 public boolean hasEnrolledFaces(int userId, String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700587 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyna56dff72018-06-19 18:41:12 -0700588 if (!canUseBiometric(opPackageName, false /* foregroundOnly */,
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200589 Binder.getCallingUid(), Binder.getCallingPid(),
590 UserHandle.getCallingUserId())) {
591 return false;
592 }
593
Kevin Chyna56dff72018-06-19 18:41:12 -0700594 return FaceService.this.hasEnrolledBiometrics(userId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200595 }
596
597 @Override // Binder call
598 public long getAuthenticatorId(String opPackageName) {
599 // In this method, we're not checking whether the caller is permitted to use face
600 // API because current authenticator ID is leaked (in a more contrived way) via Android
601 // Keystore (android.security.keystore package): the user of that API can create a key
602 // which requires face authentication for its use, and then query the key's
603 // characteristics (hidden API) which returns, among other things, face
604 // authenticator ID which was active at key creation time.
605 //
606 // Reason: The part of Android Keystore which runs inside an app's process invokes this
607 // method in certain cases. Those cases are not always where the developer demonstrates
608 // explicit intent to use face functionality. Thus, to avoiding throwing an
609 // unexpected SecurityException this method does not check whether its caller is
610 // permitted to use face API.
611 //
612 // The permission check should be restored once Android Keystore no longer invokes this
613 // method from inside app processes.
614
615 return FaceService.this.getAuthenticatorId(opPackageName);
616 }
617
618 @Override // Binder call
Kevin Chyna38653c2019-02-11 17:46:21 -0800619 public void resetLockout(byte[] token) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700620 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyn1d6a2862019-04-02 16:20:21 -0700621
joshmccloskeya4772062019-07-24 17:13:16 -0700622 mHandler.post(() -> {
623 if (!FaceService.this.hasEnrolledBiometrics(mCurrentUserId)) {
624 Slog.w(TAG, "Ignoring lockout reset, no templates enrolled");
625 return;
626 }
Kevin Chyn1d6a2862019-04-02 16:20:21 -0700627
joshmccloskeya4772062019-07-24 17:13:16 -0700628 Slog.d(TAG, "Resetting lockout for user: " + mCurrentUserId);
Kevin Chynbe67ce02019-06-10 16:14:22 -0700629
joshmccloskeya4772062019-07-24 17:13:16 -0700630 try {
631 mDaemonWrapper.resetLockout(token);
632 } catch (RemoteException e) {
633 Slog.e(getTag(), "Unable to reset lockout", e);
634 }
635 });
Kevin Chyna56dff72018-06-19 18:41:12 -0700636 }
Kevin Chynd79e24e2018-09-25 12:06:59 -0700637
638 @Override
Kevin Chyn593e6262019-06-28 13:24:44 -0700639 public void setFeature(int userId, int feature, boolean enabled, final byte[] token,
640 IFaceServiceReceiver receiver, final String opPackageName) {
Kevin Chynd79e24e2018-09-25 12:06:59 -0700641 checkPermission(MANAGE_BIOMETRIC);
642
Kevin Chyne62749a2019-04-02 19:33:56 -0700643 mHandler.post(() -> {
joshmccloskeya4772062019-07-24 17:13:16 -0700644 if (DEBUG) {
645 Slog.d(TAG, "setFeature for user(" + userId + ")");
646 }
647 updateActiveGroup(userId, opPackageName);
Kevin Chyne62749a2019-04-02 19:33:56 -0700648 if (!FaceService.this.hasEnrolledBiometrics(mCurrentUserId)) {
649 Slog.e(TAG, "No enrolled biometrics while setting feature: " + feature);
650 return;
Kevin Chynb95f1522019-03-04 16:45:15 -0800651 }
Kevin Chyne62749a2019-04-02 19:33:56 -0700652
653 final ArrayList<Byte> byteToken = new ArrayList<>();
654 for (int i = 0; i < token.length; i++) {
655 byteToken.add(token[i]);
656 }
657
658 // TODO: Support multiple faces
659 final int faceId = getFirstTemplateForUser(mCurrentUserId);
660
661 if (mDaemon != null) {
662 try {
663 final int result = mDaemon.setFeature(feature, enabled, byteToken, faceId);
664 receiver.onFeatureSet(result == Status.OK, feature);
665 } catch (RemoteException e) {
666 Slog.e(getTag(), "Unable to set feature: " + feature
667 + " to enabled:" + enabled, e);
668 }
669 }
670 });
671
Kevin Chynd79e24e2018-09-25 12:06:59 -0700672 }
673
674 @Override
Kevin Chyn593e6262019-06-28 13:24:44 -0700675 public void getFeature(int userId, int feature, IFaceServiceReceiver receiver,
676 final String opPackageName) {
Kevin Chynd79e24e2018-09-25 12:06:59 -0700677 checkPermission(MANAGE_BIOMETRIC);
678
Kevin Chyne62749a2019-04-02 19:33:56 -0700679 mHandler.post(() -> {
joshmccloskeya4772062019-07-24 17:13:16 -0700680 if (DEBUG) {
681 Slog.d(TAG, "getFeature for user(" + userId + ")");
682 }
683 updateActiveGroup(userId, opPackageName);
Kevin Chyne62749a2019-04-02 19:33:56 -0700684 // This should ideally return tri-state, but the user isn't shown settings unless
685 // they are enrolled so it's fine for now.
686 if (!FaceService.this.hasEnrolledBiometrics(mCurrentUserId)) {
687 Slog.e(TAG, "No enrolled biometrics while getting feature: " + feature);
688 return;
Kevin Chynb95f1522019-03-04 16:45:15 -0800689 }
Kevin Chyne62749a2019-04-02 19:33:56 -0700690
691 // TODO: Support multiple faces
692 final int faceId = getFirstTemplateForUser(mCurrentUserId);
693
694 if (mDaemon != null) {
695 try {
696 OptionalBool result = mDaemon.getFeature(feature, faceId);
697 receiver.onFeatureGet(result.status == Status.OK, feature, result.value);
698 } catch (RemoteException e) {
699 Slog.e(getTag(), "Unable to getRequireAttention", e);
700 }
701 }
702 });
703
Kevin Chynd79e24e2018-09-25 12:06:59 -0700704 }
Kevin Chyn57f119b2018-10-25 12:03:41 -0700705
706 @Override
707 public void userActivity() {
708 checkPermission(MANAGE_BIOMETRIC);
709
710 if (mDaemon != null) {
711 try {
712 mDaemon.userActivity();
713 } catch (RemoteException e) {
714 Slog.e(getTag(), "Unable to send userActivity", e);
715 }
716 }
717 }
Kevin Chynb95f1522019-03-04 16:45:15 -0800718
719 // TODO: Support multiple faces
720 private int getFirstTemplateForUser(int user) {
721 final List<Face> faces = FaceService.this.getEnrolledTemplates(user);
722 if (!faces.isEmpty()) {
723 return faces.get(0).getBiometricId();
724 }
725 return 0;
726 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700727 }
728
729 /**
730 * Receives callbacks from the ClientMonitor implementations. The results are forwarded to
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700731 * BiometricPrompt.
732 */
Kevin Chyne92cdae2018-11-21 16:35:04 -0800733 private class BiometricPromptServiceListenerImpl extends BiometricServiceListener {
Kevin Chyn23289ef2018-11-28 16:32:36 -0800734 BiometricPromptServiceListenerImpl(IBiometricServiceReceiverInternal wrapperReceiver) {
Kevin Chyn87f257a2018-11-27 16:26:07 -0800735 super(wrapperReceiver);
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700736 }
737
738 @Override
739 public void onAcquired(long deviceId, int acquiredInfo, int vendorCode)
740 throws RemoteException {
741 /**
742 * Map the acquired codes onto existing {@link BiometricConstants} acquired codes.
743 */
Kevin Chyne92cdae2018-11-21 16:35:04 -0800744 if (getWrapperReceiver() != null) {
745 getWrapperReceiver().onAcquired(
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700746 FaceManager.getMappedAcquiredInfo(acquiredInfo, vendorCode),
747 FaceManager.getAcquiredString(getContext(), acquiredInfo, vendorCode));
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700748 }
749 }
750
751 @Override
Kevin Chyn87f257a2018-11-27 16:26:07 -0800752 public void onError(long deviceId, int error, int vendorCode, int cookie)
753 throws RemoteException {
Kevin Chyne92cdae2018-11-21 16:35:04 -0800754 if (getWrapperReceiver() != null) {
Kevin Chyn23289ef2018-11-28 16:32:36 -0800755 getWrapperReceiver().onError(cookie, error,
756 FaceManager.getErrorString(getContext(), error, vendorCode));
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700757 }
758 }
759 }
760
761 /**
762 * Receives callbacks from the ClientMonitor implementations. The results are forwarded to
Kevin Chyna56dff72018-06-19 18:41:12 -0700763 * the FaceManager.
764 */
765 private class ServiceListenerImpl implements ServiceListener {
Kevin Chyna56dff72018-06-19 18:41:12 -0700766 private IFaceServiceReceiver mFaceServiceReceiver;
767
768 public ServiceListenerImpl(IFaceServiceReceiver receiver) {
769 mFaceServiceReceiver = receiver;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200770 }
771
772 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -0700773 public void onEnrollResult(BiometricAuthenticator.Identifier identifier, int remaining)
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200774 throws RemoteException {
Kevin Chyna56dff72018-06-19 18:41:12 -0700775 if (mFaceServiceReceiver != null) {
776 mFaceServiceReceiver.onEnrollResult(identifier.getDeviceId(),
777 identifier.getBiometricId(),
778 remaining);
779 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200780 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700781
782 @Override
783 public void onAcquired(long deviceId, int acquiredInfo, int vendorCode)
784 throws RemoteException {
785 if (mFaceServiceReceiver != null) {
786 mFaceServiceReceiver.onAcquired(deviceId, acquiredInfo, vendorCode);
787 }
788 }
789
790 @Override
791 public void onAuthenticationSucceeded(long deviceId,
792 BiometricAuthenticator.Identifier biometric, int userId)
793 throws RemoteException {
794 if (mFaceServiceReceiver != null) {
Kevin Chyn628b7182018-11-13 12:00:48 -0800795 if (biometric == null || biometric instanceof Face) {
Kevin Chyn8d2694a2019-04-11 18:30:40 -0700796 mFaceServiceReceiver.onAuthenticationSucceeded(deviceId, (Face) biometric,
797 userId);
Kevin Chyna56dff72018-06-19 18:41:12 -0700798 } else {
799 Slog.e(TAG, "onAuthenticationSucceeded received non-face biometric");
800 }
801 }
802 }
803
804 @Override
805 public void onAuthenticationFailed(long deviceId) throws RemoteException {
806 if (mFaceServiceReceiver != null) {
807 mFaceServiceReceiver.onAuthenticationFailed(deviceId);
808 }
809 }
810
811 @Override
Kevin Chyn87f257a2018-11-27 16:26:07 -0800812 public void onError(long deviceId, int error, int vendorCode, int cookie)
813 throws RemoteException {
Kevin Chyna56dff72018-06-19 18:41:12 -0700814 if (mFaceServiceReceiver != null) {
815 mFaceServiceReceiver.onError(deviceId, error, vendorCode);
816 }
817 }
818
819 @Override
820 public void onRemoved(BiometricAuthenticator.Identifier identifier,
821 int remaining) throws RemoteException {
822 if (mFaceServiceReceiver != null) {
823 mFaceServiceReceiver.onRemoved(identifier.getDeviceId(),
824 identifier.getBiometricId(), remaining);
825 }
826 }
827
828 @Override
829 public void onEnumerated(BiometricAuthenticator.Identifier identifier, int remaining)
830 throws RemoteException {
831 if (mFaceServiceReceiver != null) {
Kevin Chyn6737c572019-02-08 16:10:54 -0800832 mFaceServiceReceiver.onEnumerated(identifier.getDeviceId(),
833 identifier.getBiometricId(), remaining);
Kevin Chyna56dff72018-06-19 18:41:12 -0700834 }
835 }
836 }
837
Kevin Chyn4cc49f72019-04-24 13:53:35 -0700838 private final FaceConstants mFaceConstants = new FaceConstants();
Kevin Chyna56dff72018-06-19 18:41:12 -0700839
840 @GuardedBy("this")
841 private IBiometricsFace mDaemon;
Kevin Chyn9bc1d492019-06-21 15:31:50 -0700842 private UsageStats mUsageStats;
Ilya Matyukhin9dac8482019-07-09 11:03:07 -0700843 private boolean mRevokeChallengePending = false;
Kevin Chyna38653c2019-02-11 17:46:21 -0800844 // One of the AuthenticationClient constants
845 private int mCurrentUserLockoutMode;
Kevin Chyna56dff72018-06-19 18:41:12 -0700846
Kevin Chyndbfbed42019-06-13 17:01:30 -0700847 private NotificationManager mNotificationManager;
848
Kevin Chyn4cc49f72019-04-24 13:53:35 -0700849 private int[] mBiometricPromptIgnoreList;
850 private int[] mBiometricPromptIgnoreListVendor;
851 private int[] mKeyguardIgnoreList;
852 private int[] mKeyguardIgnoreListVendor;
853 private int[] mEnrollIgnoreList;
854 private int[] mEnrollIgnoreListVendor;
855
Kevin Chyna56dff72018-06-19 18:41:12 -0700856 /**
857 * Receives callbacks from the HAL.
858 */
859 private IBiometricsFaceClientCallback mDaemonCallback =
860 new IBiometricsFaceClientCallback.Stub() {
Kevin Chyn6737c572019-02-08 16:10:54 -0800861 @Override
862 public void onEnrollResult(final long deviceId, int faceId, int userId,
863 int remaining) {
864 mHandler.post(() -> {
865 final Face face = new Face(getBiometricUtils()
866 .getUniqueName(getContext(), userId), faceId, deviceId);
867 FaceService.super.handleEnrollResult(face, remaining);
Kevin Chyn576811e2019-06-12 14:50:35 -0700868
869 // Enrollment changes the authenticatorId, so update it here.
870 IBiometricsFace daemon = getFaceDaemon();
871 if (remaining == 0 && daemon != null) {
872 try {
873 mAuthenticatorIds.put(userId,
874 hasEnrolledBiometrics(userId) ? daemon.getAuthenticatorId().value
875 : 0L);
876 } catch (RemoteException e) {
877 Slog.e(TAG, "Unable to get authenticatorId", e);
878 }
879 }
Kevin Chyn6737c572019-02-08 16:10:54 -0800880 });
881 }
882
883 @Override
884 public void onAcquired(final long deviceId, final int userId,
885 final int acquiredInfo,
886 final int vendorCode) {
887 mHandler.post(() -> {
888 FaceService.super.handleAcquired(deviceId, acquiredInfo, vendorCode);
889 });
890 }
891
892 @Override
893 public void onAuthenticated(final long deviceId, final int faceId, final int userId,
894 ArrayList<Byte> token) {
895 mHandler.post(() -> {
896 Face face = new Face("", faceId, deviceId);
897 FaceService.super.handleAuthenticated(face, token);
898 });
899 }
900
901 @Override
902 public void onError(final long deviceId, final int userId, final int error,
903 final int vendorCode) {
904 mHandler.post(() -> {
905 FaceService.super.handleError(deviceId, error, vendorCode);
906
907 // TODO: this chunk of code should be common to all biometric services
908 if (error == BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE) {
909 // If we get HW_UNAVAILABLE, try to connect again later...
910 Slog.w(TAG, "Got ERROR_HW_UNAVAILABLE; try reconnecting next client.");
911 synchronized (this) {
912 mDaemon = null;
913 mHalDeviceId = 0;
914 mCurrentUserId = UserHandle.USER_NULL;
915 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700916 }
Kevin Chyn6737c572019-02-08 16:10:54 -0800917 });
918 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700919
Kevin Chyn6737c572019-02-08 16:10:54 -0800920 @Override
Kevin Chyn31ae8d22019-03-11 14:12:32 -0700921 public void onRemoved(final long deviceId, ArrayList<Integer> faceIds, final int userId) {
Kevin Chyn6737c572019-02-08 16:10:54 -0800922 mHandler.post(() -> {
Kevin Chyn31ae8d22019-03-11 14:12:32 -0700923 if (!faceIds.isEmpty()) {
924 for (int i = 0; i < faceIds.size(); i++) {
925 final Face face = new Face("", faceIds.get(i), deviceId);
926 // Convert to old behavior
927 FaceService.super.handleRemoved(face, faceIds.size() - i - 1);
928 }
929 } else {
930 final Face face = new Face("", 0 /* identifier */, deviceId);
931 FaceService.super.handleRemoved(face, 0 /* remaining */);
932 }
933
Kevin Chyn6737c572019-02-08 16:10:54 -0800934 });
935 }
936
937 @Override
938 public void onEnumerate(long deviceId, ArrayList<Integer> faceIds, int userId)
939 throws RemoteException {
940 mHandler.post(() -> {
941 if (!faceIds.isEmpty()) {
942 for (int i = 0; i < faceIds.size(); i++) {
943 final Face face = new Face("", faceIds.get(i), deviceId);
944 // Convert to old old behavior
945 FaceService.super.handleEnumerate(face, faceIds.size() - i - 1);
946 }
947 } else {
948 // For face, the HIDL contract is to receive an empty list when there are no
949 // templates enrolled. Send a null identifier since we don't consume them
950 // anywhere, and send remaining == 0 to plumb this with existing common code.
951 FaceService.super.handleEnumerate(null /* identifier */, 0);
Kevin Chyna56dff72018-06-19 18:41:12 -0700952 }
Kevin Chyn6737c572019-02-08 16:10:54 -0800953 });
954 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700955
Kevin Chyn6737c572019-02-08 16:10:54 -0800956 @Override
957 public void onLockoutChanged(long duration) {
Kevin Chyna38653c2019-02-11 17:46:21 -0800958 Slog.d(TAG, "onLockoutChanged: " + duration);
959 if (duration == 0) {
960 mCurrentUserLockoutMode = AuthenticationClient.LOCKOUT_NONE;
961 } else if (duration == Long.MAX_VALUE) {
962 mCurrentUserLockoutMode = AuthenticationClient.LOCKOUT_PERMANENT;
963 } else {
964 mCurrentUserLockoutMode = AuthenticationClient.LOCKOUT_TIMED;
965 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700966
Kevin Chyna38653c2019-02-11 17:46:21 -0800967 mHandler.post(() -> {
968 if (duration == 0) {
969 notifyLockoutResetMonitors();
970 }
971 });
Kevin Chyn6737c572019-02-08 16:10:54 -0800972 }
973 };
Kevin Chyna56dff72018-06-19 18:41:12 -0700974
975 /**
976 * Wraps the HAL-specific code and is passed to the ClientMonitor implementations so that they
977 * can be shared between the multiple biometric services.
978 */
979 private final DaemonWrapper mDaemonWrapper = new DaemonWrapper() {
980 @Override
981 public int authenticate(long operationId, int groupId) throws RemoteException {
982 IBiometricsFace daemon = getFaceDaemon();
983 if (daemon == null) {
984 Slog.w(TAG, "authenticate(): no face HAL!");
985 return ERROR_ESRCH;
986 }
987 return daemon.authenticate(operationId);
988 }
989
990 @Override
991 public int cancel() throws RemoteException {
992 IBiometricsFace daemon = getFaceDaemon();
993 if (daemon == null) {
994 Slog.w(TAG, "cancel(): no face HAL!");
995 return ERROR_ESRCH;
996 }
997 return daemon.cancel();
998 }
999
1000 @Override
1001 public int remove(int groupId, int biometricId) throws RemoteException {
1002 IBiometricsFace daemon = getFaceDaemon();
1003 if (daemon == null) {
1004 Slog.w(TAG, "remove(): no face HAL!");
1005 return ERROR_ESRCH;
1006 }
1007 return daemon.remove(biometricId);
1008 }
1009
1010 @Override
1011 public int enumerate() throws RemoteException {
1012 IBiometricsFace daemon = getFaceDaemon();
1013 if (daemon == null) {
1014 Slog.w(TAG, "enumerate(): no face HAL!");
1015 return ERROR_ESRCH;
1016 }
1017 return daemon.enumerate();
1018 }
1019
1020 @Override
Kevin Chyn1f16c2d2018-12-07 13:06:08 -08001021 public int enroll(byte[] cryptoToken, int groupId, int timeout,
1022 ArrayList<Integer> disabledFeatures) throws RemoteException {
Kevin Chyna56dff72018-06-19 18:41:12 -07001023 IBiometricsFace daemon = getFaceDaemon();
1024 if (daemon == null) {
1025 Slog.w(TAG, "enroll(): no face HAL!");
1026 return ERROR_ESRCH;
1027 }
1028 final ArrayList<Byte> token = new ArrayList<>();
1029 for (int i = 0; i < cryptoToken.length; i++) {
1030 token.add(cryptoToken[i]);
1031 }
Kevin Chyn1f16c2d2018-12-07 13:06:08 -08001032 return daemon.enroll(token, timeout, disabledFeatures);
Kevin Chyna56dff72018-06-19 18:41:12 -07001033 }
Kevin Chyna38653c2019-02-11 17:46:21 -08001034
1035 @Override
1036 public void resetLockout(byte[] cryptoToken) throws RemoteException {
1037 IBiometricsFace daemon = getFaceDaemon();
1038 if (daemon == null) {
1039 Slog.w(TAG, "resetLockout(): no face HAL!");
1040 return;
1041 }
1042 final ArrayList<Byte> token = new ArrayList<>();
1043 for (int i = 0; i < cryptoToken.length; i++) {
1044 token.add(cryptoToken[i]);
1045 }
1046 daemon.resetLockout(token);
1047 }
Kevin Chyna56dff72018-06-19 18:41:12 -07001048 };
1049
1050
1051 public FaceService(Context context) {
1052 super(context);
Kevin Chyn4cc49f72019-04-24 13:53:35 -07001053
joshmccloskey4ceaf6b2019-08-21 11:26:08 -07001054 final boolean ignoreKeyguardBlacklist = Settings.Secure.getInt(context.getContentResolver(),
1055 SKIP_KEYGUARD_ACQUIRE_IGNORE_LIST, 0) != 0;
1056
Kevin Chyn9bc1d492019-06-21 15:31:50 -07001057 mUsageStats = new UsageStats(context);
1058
Kevin Chyndbfbed42019-06-13 17:01:30 -07001059 mNotificationManager = getContext().getSystemService(NotificationManager.class);
1060
Kevin Chyn4cc49f72019-04-24 13:53:35 -07001061 mBiometricPromptIgnoreList = getContext().getResources()
1062 .getIntArray(R.array.config_face_acquire_biometricprompt_ignorelist);
1063 mBiometricPromptIgnoreListVendor = getContext().getResources()
1064 .getIntArray(R.array.config_face_acquire_vendor_biometricprompt_ignorelist);
joshmccloskey4ceaf6b2019-08-21 11:26:08 -07001065 mKeyguardIgnoreList = ignoreKeyguardBlacklist ? new int[0] : getContext().getResources()
Kevin Chyn4cc49f72019-04-24 13:53:35 -07001066 .getIntArray(R.array.config_face_acquire_keyguard_ignorelist);
joshmccloskey4ceaf6b2019-08-21 11:26:08 -07001067 mKeyguardIgnoreListVendor =
1068 ignoreKeyguardBlacklist ? new int[0] : getContext().getResources()
1069 .getIntArray(R.array.config_face_acquire_vendor_keyguard_ignorelist);
Kevin Chyn4cc49f72019-04-24 13:53:35 -07001070 mEnrollIgnoreList = getContext().getResources()
1071 .getIntArray(R.array.config_face_acquire_enroll_ignorelist);
1072 mEnrollIgnoreListVendor = getContext().getResources()
1073 .getIntArray(R.array.config_face_acquire_vendor_enroll_ignorelist);
Kevin Chyna56dff72018-06-19 18:41:12 -07001074 }
1075
1076 @Override
Ilya Matyukhin9dac8482019-07-09 11:03:07 -07001077 protected void removeClient(ClientMonitor client) {
1078 super.removeClient(client);
1079 if (mRevokeChallengePending) {
1080 startRevokeChallenge(null);
1081 mRevokeChallengePending = false;
1082 }
1083 }
1084
1085 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -07001086 public void onStart() {
Kevin Chyn5a2ff5d2018-08-29 19:07:30 -07001087 super.onStart();
Kevin Chyna56dff72018-06-19 18:41:12 -07001088 publishBinderService(Context.FACE_SERVICE, new FaceServiceWrapper());
Kevin Chyn8398a712019-06-13 16:44:50 -07001089 // Get the face daemon on FaceService's on thread so SystemServerInitThreadPool isn't
1090 // blocked
1091 SystemServerInitThreadPool.get().submit(() -> mHandler.post(this::getFaceDaemon),
1092 TAG + ".onStart");
Kevin Chyna56dff72018-06-19 18:41:12 -07001093 }
1094
1095 @Override
1096 public String getTag() {
1097 return TAG;
1098 }
1099
1100 @Override
Kevin Chyn6737c572019-02-08 16:10:54 -08001101 protected DaemonWrapper getDaemonWrapper() {
1102 return mDaemonWrapper;
1103 }
1104
1105 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -07001106 protected BiometricUtils getBiometricUtils() {
1107 return FaceUtils.getInstance();
1108 }
1109
1110 @Override
Kevin Chyn4cc49f72019-04-24 13:53:35 -07001111 protected Constants getConstants() {
1112 return mFaceConstants;
Kevin Chyna56dff72018-06-19 18:41:12 -07001113 }
1114
1115 @Override
1116 protected boolean hasReachedEnrollmentLimit(int userId) {
1117 final int limit = getContext().getResources().getInteger(
Kevin Chyn017e76e2018-06-27 18:35:06 -07001118 com.android.internal.R.integer.config_faceMaxTemplatesPerUser);
Kevin Chyn6737c572019-02-08 16:10:54 -08001119 final int enrolled = FaceService.this.getEnrolledTemplates(userId).size();
Kevin Chyna56dff72018-06-19 18:41:12 -07001120 if (enrolled >= limit) {
Kevin Chyn1a878c12019-04-04 15:50:11 -07001121 Slog.w(TAG, "Too many faces registered, user: " + userId);
Kevin Chyna56dff72018-06-19 18:41:12 -07001122 return true;
1123 }
1124 return false;
1125 }
1126
1127 @Override
Kevin Chyn9ba99912019-01-16 16:24:36 -08001128 public void serviceDied(long cookie) {
1129 super.serviceDied(cookie);
1130 mDaemon = null;
Jim Miller7b78b222019-02-07 16:47:38 -08001131
1132 mCurrentUserId = UserHandle.USER_NULL; // Force updateActiveGroup() to re-evaluate
Kevin Chyn9ba99912019-01-16 16:24:36 -08001133 }
1134
1135 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -07001136 protected void updateActiveGroup(int userId, String clientPackage) {
1137 IBiometricsFace daemon = getFaceDaemon();
1138
1139 if (daemon != null) {
1140 try {
1141 userId = getUserOrWorkProfileId(clientPackage, userId);
1142 if (userId != mCurrentUserId) {
Kevin Chyn27e33d02019-04-30 01:37:32 +00001143 final File baseDir = Environment.getDataVendorDeDirectory(userId);
Kevin Chyna56dff72018-06-19 18:41:12 -07001144 final File faceDir = new File(baseDir, FACE_DATA_DIR);
1145 if (!faceDir.exists()) {
1146 if (!faceDir.mkdir()) {
1147 Slog.v(TAG, "Cannot make directory: " + faceDir.getAbsolutePath());
1148 return;
1149 }
1150 // Calling mkdir() from this process will create a directory with our
1151 // permissions (inherited from the containing dir). This command fixes
1152 // the label.
1153 if (!SELinux.restorecon(faceDir)) {
1154 Slog.w(TAG, "Restorecons failed. Directory will have wrong label.");
1155 return;
1156 }
1157 }
1158
1159 daemon.setActiveUser(userId, faceDir.getAbsolutePath());
1160 mCurrentUserId = userId;
Kevin Chyn576811e2019-06-12 14:50:35 -07001161 mAuthenticatorIds.put(userId,
1162 hasEnrolledBiometrics(userId) ? daemon.getAuthenticatorId().value : 0L);
Kevin Chyna56dff72018-06-19 18:41:12 -07001163 }
Kevin Chyna56dff72018-06-19 18:41:12 -07001164 } catch (RemoteException e) {
1165 Slog.e(TAG, "Failed to setActiveUser():", e);
1166 }
1167 }
1168 }
1169
1170 @Override
1171 protected String getLockoutResetIntent() {
1172 return ACTION_LOCKOUT_RESET;
1173 }
1174
1175 @Override
1176 protected String getLockoutBroadcastPermission() {
1177 return RESET_FACE_LOCKOUT;
1178 }
1179
1180 @Override
1181 protected long getHalDeviceId() {
1182 return mHalDeviceId;
1183 }
1184
1185 @Override
Kevin Chyna38653c2019-02-11 17:46:21 -08001186 protected void handleUserSwitching(int userId) {
1187 super.handleUserSwitching(userId);
1188 // Will be updated when we get the callback from HAL
1189 mCurrentUserLockoutMode = AuthenticationClient.LOCKOUT_NONE;
1190 }
1191
1192 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -07001193 protected boolean hasEnrolledBiometrics(int userId) {
1194 if (userId != UserHandle.getCallingUserId()) {
1195 checkPermission(INTERACT_ACROSS_USERS);
1196 }
1197 return getBiometricUtils().getBiometricsForUser(getContext(), userId).size() > 0;
1198 }
1199
1200 @Override
1201 protected String getManageBiometricPermission() {
Kevin Chyna24e9fd2018-08-27 12:39:17 -07001202 return MANAGE_BIOMETRIC;
Kevin Chyna56dff72018-06-19 18:41:12 -07001203 }
1204
1205 @Override
1206 protected void checkUseBiometricPermission() {
Kevin Chyna24e9fd2018-08-27 12:39:17 -07001207 // noop for Face. The permission checks are all done on the incoming binder call.
Kevin Chyna56dff72018-06-19 18:41:12 -07001208 }
1209
1210 @Override
Kevin Chynb3c05aa2018-09-21 16:50:32 -07001211 protected boolean checkAppOps(int uid, String opPackageName) {
1212 return mAppOps.noteOp(AppOpsManager.OP_USE_BIOMETRIC, uid, opPackageName)
1213 == AppOpsManager.MODE_ALLOWED;
Kevin Chyna56dff72018-06-19 18:41:12 -07001214 }
1215
1216 @Override
Kevin Chyn6737c572019-02-08 16:10:54 -08001217 protected List<Face> getEnrolledTemplates(int userId) {
1218 return getBiometricUtils().getBiometricsForUser(getContext(), userId);
1219 }
1220
1221 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -07001222 protected void notifyClientActiveCallbacks(boolean isActive) {
1223 // noop for Face.
1224 }
1225
Kevin Chyn7782d142019-01-18 12:51:33 -08001226 @Override
1227 protected int statsModality() {
1228 return BiometricsProtoEnums.MODALITY_FACE;
1229 }
1230
Kevin Chyna38653c2019-02-11 17:46:21 -08001231 @Override
1232 protected int getLockoutMode() {
1233 return mCurrentUserLockoutMode;
1234 }
1235
Kevin Chyna56dff72018-06-19 18:41:12 -07001236 /** Gets the face daemon */
1237 private synchronized IBiometricsFace getFaceDaemon() {
1238 if (mDaemon == null) {
1239 Slog.v(TAG, "mDaemon was null, reconnect to face");
1240 try {
1241 mDaemon = IBiometricsFace.getService();
1242 } catch (java.util.NoSuchElementException e) {
1243 // Service doesn't exist or cannot be opened. Logged below.
1244 } catch (RemoteException e) {
1245 Slog.e(TAG, "Failed to get biometric interface", e);
1246 }
1247 if (mDaemon == null) {
1248 Slog.w(TAG, "face HIDL not available");
1249 return null;
1250 }
1251
1252 mDaemon.asBinder().linkToDeath(this, 0);
1253
1254 try {
1255 mHalDeviceId = mDaemon.setCallback(mDaemonCallback).value;
1256 } catch (RemoteException e) {
1257 Slog.e(TAG, "Failed to open face HAL", e);
1258 mDaemon = null; // try again later!
1259 }
1260
1261 if (DEBUG) Slog.v(TAG, "Face HAL id: " + mHalDeviceId);
1262 if (mHalDeviceId != 0) {
1263 loadAuthenticatorIds();
1264 updateActiveGroup(ActivityManager.getCurrentUser(), null);
Kevin Chyn6737c572019-02-08 16:10:54 -08001265 doTemplateCleanupForUser(ActivityManager.getCurrentUser());
Kevin Chyna56dff72018-06-19 18:41:12 -07001266 } else {
1267 Slog.w(TAG, "Failed to open Face HAL!");
1268 MetricsLogger.count(getContext(), "faced_openhal_error", 1);
1269 mDaemon = null;
1270 }
1271 }
1272 return mDaemon;
1273 }
1274
Kevin Chynd79e24e2018-09-25 12:06:59 -07001275 private long startGenerateChallenge(IBinder token) {
Kevin Chyna56dff72018-06-19 18:41:12 -07001276 IBiometricsFace daemon = getFaceDaemon();
1277 if (daemon == null) {
Kevin Chynd79e24e2018-09-25 12:06:59 -07001278 Slog.w(TAG, "startGenerateChallenge: no face HAL!");
Kevin Chyna56dff72018-06-19 18:41:12 -07001279 return 0;
1280 }
1281 try {
Kevin Chyne46a2162018-09-20 18:43:01 -07001282 return daemon.generateChallenge(CHALLENGE_TIMEOUT_SEC).value;
Kevin Chyna56dff72018-06-19 18:41:12 -07001283 } catch (RemoteException e) {
Kevin Chynd79e24e2018-09-25 12:06:59 -07001284 Slog.e(TAG, "startGenerateChallenge failed", e);
Kevin Chyna56dff72018-06-19 18:41:12 -07001285 }
1286 return 0;
1287 }
1288
Kevin Chynd79e24e2018-09-25 12:06:59 -07001289 private int startRevokeChallenge(IBinder token) {
Kevin Chyna56dff72018-06-19 18:41:12 -07001290 IBiometricsFace daemon = getFaceDaemon();
1291 if (daemon == null) {
Kevin Chynd79e24e2018-09-25 12:06:59 -07001292 Slog.w(TAG, "startRevokeChallenge: no face HAL!");
Kevin Chyna56dff72018-06-19 18:41:12 -07001293 return 0;
1294 }
1295 try {
Ilya Matyukhin9dac8482019-07-09 11:03:07 -07001296 final int res = daemon.revokeChallenge();
1297 if (res != Status.OK) {
1298 Slog.e(TAG, "revokeChallenge returned " + res);
1299 }
1300 return res;
Kevin Chyna56dff72018-06-19 18:41:12 -07001301 } catch (RemoteException e) {
Kevin Chynd79e24e2018-09-25 12:06:59 -07001302 Slog.e(TAG, "startRevokeChallenge failed", e);
Kevin Chyna56dff72018-06-19 18:41:12 -07001303 }
1304 return 0;
1305 }
1306
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001307 private void dumpInternal(PrintWriter pw) {
1308 JSONObject dump = new JSONObject();
1309 try {
1310 dump.put("service", "Face Manager");
1311
1312 JSONArray sets = new JSONArray();
1313 for (UserInfo user : UserManager.get(getContext()).getUsers()) {
1314 final int userId = user.getUserHandle().getIdentifier();
Kevin Chyna56dff72018-06-19 18:41:12 -07001315 final int N = getBiometricUtils().getBiometricsForUser(getContext(), userId).size();
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001316 PerformanceStats stats = mPerformanceMap.get(userId);
1317 PerformanceStats cryptoStats = mCryptoPerformanceMap.get(userId);
1318 JSONObject set = new JSONObject();
1319 set.put("id", userId);
Kevin Chyna56dff72018-06-19 18:41:12 -07001320 set.put("count", N);
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001321 set.put("accept", (stats != null) ? stats.accept : 0);
1322 set.put("reject", (stats != null) ? stats.reject : 0);
1323 set.put("acquire", (stats != null) ? stats.acquire : 0);
1324 set.put("lockout", (stats != null) ? stats.lockout : 0);
1325 set.put("permanentLockout", (stats != null) ? stats.permanentLockout : 0);
1326 // cryptoStats measures statistics about secure face transactions
1327 // (e.g. to unlock password storage, make secure purchases, etc.)
1328 set.put("acceptCrypto", (cryptoStats != null) ? cryptoStats.accept : 0);
1329 set.put("rejectCrypto", (cryptoStats != null) ? cryptoStats.reject : 0);
1330 set.put("acquireCrypto", (cryptoStats != null) ? cryptoStats.acquire : 0);
1331 set.put("lockoutCrypto", (cryptoStats != null) ? cryptoStats.lockout : 0);
Kevin Chyna56dff72018-06-19 18:41:12 -07001332 set.put("permanentLockoutCrypto",
1333 (cryptoStats != null) ? cryptoStats.permanentLockout : 0);
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001334 sets.put(set);
1335 }
1336
1337 dump.put("prints", sets);
1338 } catch (JSONException e) {
1339 Slog.e(TAG, "dump formatting failure", e);
1340 }
1341 pw.println(dump);
Kevin Chyn9bc1d492019-06-21 15:31:50 -07001342 pw.println("HAL deaths since last reboot: " + mHALDeathCount);
1343
1344 mUsageStats.print(pw);
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001345 }
1346
Joe Onoratodb396002019-04-05 19:49:27 -07001347 private void dumpHal(FileDescriptor fd, String[] args) {
Joe Onoratobf955d22019-03-25 00:16:58 -07001348 // WARNING: CDD restricts image data from leaving TEE unencrypted on
1349 // production devices:
1350 // [C-1-10] MUST not allow unencrypted access to identifiable biometric
1351 // data or any data derived from it (such as embeddings) to the
1352 // Application Processor outside the context of the TEE.
1353 // As such, this API should only be enabled for testing purposes on
1354 // engineering and userdebug builds. All modules in the software stack
1355 // MUST enforce final build products do NOT have this functionality.
1356 // Additionally, the following check MUST NOT be removed.
1357 if (!(Build.IS_ENG || Build.IS_USERDEBUG)) {
1358 return;
1359 }
1360
Joe Onorato108413a2019-04-03 18:20:52 -07001361 // Additionally, this flag allows turning off face for a device
1362 // (either permanently through the build or on an individual device).
1363 if (SystemProperties.getBoolean("ro.face.disable_debug_data", false)
1364 || SystemProperties.getBoolean("persist.face.disable_debug_data", false)) {
1365 return;
1366 }
1367
Joe Onoratodb396002019-04-05 19:49:27 -07001368 // The debug method takes two file descriptors. The first is for text
1369 // output, which we will drop. The second is for binary data, which
1370 // will be the protobuf data.
1371 final IBiometricsFace daemon = getFaceDaemon();
1372 if (daemon != null) {
1373 FileOutputStream devnull = null;
1374 try {
1375 devnull = new FileOutputStream("/dev/null");
1376 final NativeHandle handle = new NativeHandle(
1377 new FileDescriptor[] { devnull.getFD(), fd },
1378 new int[0], false);
1379 daemon.debug(handle, new ArrayList<String>(Arrays.asList(args)));
1380 } catch (IOException | RemoteException ex) {
1381 Slog.d(TAG, "error while reading face debugging data", ex);
1382 } finally {
1383 if (devnull != null) {
1384 try {
1385 devnull.close();
1386 } catch (IOException ex) {
1387 }
1388 }
1389 }
Joe Onoratobf955d22019-03-25 00:16:58 -07001390 }
Joe Onoratobf955d22019-03-25 00:16:58 -07001391 }
Kevin Chyn8b7a0372018-09-17 15:06:05 -07001392}