blob: a38abdc1bed0fc641fc05c0a9b7c80b35c42fcfc [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;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020056import android.util.Slog;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020057
Kevin Chyn56e4c3d2019-04-23 11:28:43 -070058import com.android.internal.R;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020059import com.android.internal.annotations.GuardedBy;
60import com.android.internal.logging.MetricsLogger;
61import com.android.internal.util.DumpUtils;
62import com.android.server.SystemServerInitThreadPool;
Kevin Chyna38653c2019-02-11 17:46:21 -080063import com.android.server.biometrics.AuthenticationClient;
Kevin Chyn355c6bf2018-09-20 22:14:19 -070064import com.android.server.biometrics.BiometricServiceBase;
Kevin Chyn836f2cf2018-08-27 11:06:39 -070065import com.android.server.biometrics.BiometricUtils;
Ilya Matyukhin9dac8482019-07-09 11:03:07 -070066import com.android.server.biometrics.ClientMonitor;
Kevin Chyn4cc49f72019-04-24 13:53:35 -070067import com.android.server.biometrics.Constants;
Kevin Chyn0ce70852019-05-10 10:29:18 -070068import com.android.server.biometrics.EnumerateClient;
Kevin Chyn6737c572019-02-08 16:10:54 -080069import com.android.server.biometrics.RemovalClient;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020070
71import org.json.JSONArray;
72import org.json.JSONException;
73import org.json.JSONObject;
74
75import java.io.File;
76import java.io.FileDescriptor;
Joe Onoratodb396002019-04-05 19:49:27 -070077import java.io.FileOutputStream;
78import java.io.IOException;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020079import java.io.PrintWriter;
80import java.util.ArrayList;
Joe Onoratodb396002019-04-05 19:49:27 -070081import java.util.Arrays;
Kevin Chyn9bc1d492019-06-21 15:31:50 -070082import java.util.HashMap;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020083import java.util.List;
Kevin Chyn9bc1d492019-06-21 15:31:50 -070084import java.util.Map;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020085
86/**
87 * A service to manage multiple clients that want to access the face HAL API.
88 * The service is responsible for maintaining a list of clients and dispatching all
Kevin Chyn51676d22018-11-05 18:00:43 -080089 * face-related events.
Gilad Brettercb51b8b2018-03-22 17:04:51 +020090 *
91 * @hide
92 */
Kevin Chyn355c6bf2018-09-20 22:14:19 -070093public class FaceService extends BiometricServiceBase {
Kevin Chyna56dff72018-06-19 18:41:12 -070094
95 protected static final String TAG = "FaceService";
96 private static final boolean DEBUG = true;
Gilad Brettercb51b8b2018-03-22 17:04:51 +020097 private static final String FACE_DATA_DIR = "facedata";
Gilad Brettercb51b8b2018-03-22 17:04:51 +020098 private static final String ACTION_LOCKOUT_RESET =
Kevin Chyn2ffadb32018-06-19 11:29:38 -070099 "com.android.server.biometrics.face.ACTION_LOCKOUT_RESET";
Kevin Chyne46a2162018-09-20 18:43:01 -0700100 private static final int CHALLENGE_TIMEOUT_SEC = 600; // 10 minutes
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200101
Kevin Chyndbfbed42019-06-13 17:01:30 -0700102 private static final String NOTIFICATION_TAG = "FaceService";
103 private static final int NOTIFICATION_ID = 1;
104
Kevin Chyn9bc1d492019-06-21 15:31:50 -0700105 /**
106 * Events for bugreports.
107 */
108 public static final class AuthenticationEvent {
109 private long mStartTime;
110 private long mLatency;
111 // Only valid if mError is 0
112 private boolean mAuthenticated;
113 private int mError;
114 // Only valid if mError is ERROR_VENDOR
115 private int mVendorError;
116
117 AuthenticationEvent(long startTime, long latency, boolean authenticated, int error,
118 int vendorError) {
119 mStartTime = startTime;
120 mLatency = latency;
121 mAuthenticated = authenticated;
122 mError = error;
123 mVendorError = vendorError;
124 }
125
126 public String toString(Context context) {
127 return "Start: " + mStartTime
128 + "\tLatency: " + mLatency
129 + "\tAuthenticated: " + mAuthenticated
130 + "\tError: " + mError
131 + "\tVendorCode: " + mVendorError
132 + "\t" + FaceManager.getErrorString(context, mError, mVendorError);
133 }
134 }
135
136 /**
137 * Keep a short historical buffer of stats, with an aggregated usage time.
138 */
139 private class UsageStats {
140 static final int EVENT_LOG_SIZE = 100;
141
142 Context mContext;
143 List<AuthenticationEvent> mAuthenticationEvents;
144
145 int acceptCount;
146 int rejectCount;
147 Map<Integer, Integer> mErrorCount;
148
149 long acceptLatency;
150 long rejectLatency;
151 Map<Integer, Long> mErrorLatency;
152
153 UsageStats(Context context) {
154 mAuthenticationEvents = new ArrayList<>();
155 mErrorCount = new HashMap<>();
156 mErrorLatency = new HashMap<>();
157 mContext = context;
158 }
159
160 void addEvent(AuthenticationEvent event) {
161 if (mAuthenticationEvents.size() >= EVENT_LOG_SIZE) {
162 mAuthenticationEvents.remove(0);
163 }
164 mAuthenticationEvents.add(event);
165
166 if (event.mAuthenticated) {
167 acceptCount++;
168 acceptLatency += event.mLatency;
169 } else if (event.mError == 0) {
170 rejectCount++;
171 rejectLatency += event.mLatency;
172 } else {
173 mErrorCount.put(event.mError, mErrorCount.getOrDefault(event.mError, 0) + 1);
174 mErrorLatency.put(event.mError,
175 mErrorLatency.getOrDefault(event.mError, 0l) + event.mLatency);
176 }
177 }
178
179 void print(PrintWriter pw) {
180 pw.println("Events since last reboot: " + mAuthenticationEvents.size());
181 for (int i = 0; i < mAuthenticationEvents.size(); i++) {
182 pw.println(mAuthenticationEvents.get(i).toString(mContext));
183 }
184
185 // Dump aggregated usage stats
186 // TODO: Remove or combine with json dump in a future release
187 pw.println("Accept\tCount: " + acceptCount + "\tLatency: " + acceptLatency
188 + "\tAverage: " + (acceptCount > 0 ? acceptLatency / acceptCount : 0));
189 pw.println("Reject\tCount: " + rejectCount + "\tLatency: " + rejectLatency
190 + "\tAverage: " + (rejectCount > 0 ? rejectLatency / rejectCount : 0));
191
192 for (Integer key : mErrorCount.keySet()) {
193 final int count = mErrorCount.get(key);
194 pw.println("Error" + key + "\tCount: " + count
195 + "\tLatency: " + mErrorLatency.getOrDefault(key, 0l)
196 + "\tAverage: " + (count > 0 ? mErrorLatency.getOrDefault(key, 0l) / count
197 : 0)
198 + "\t" + FaceManager.getErrorString(mContext, key, 0 /* vendorCode */));
199 }
200 }
201 }
202
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700203 private final class FaceAuthClient extends AuthenticationClientImpl {
Kevin Chyn0ce70852019-05-10 10:29:18 -0700204 private int mLastAcquire;
205
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700206 public FaceAuthClient(Context context,
207 DaemonWrapper daemon, long halDeviceId, IBinder token,
208 ServiceListener listener, int targetUserId, int groupId, long opId,
Kevin Chyn87f257a2018-11-27 16:26:07 -0800209 boolean restricted, String owner, int cookie, boolean requireConfirmation) {
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700210 super(context, daemon, halDeviceId, token, listener, targetUserId, groupId, opId,
Kevin Chyn87f257a2018-11-27 16:26:07 -0800211 restricted, owner, cookie, requireConfirmation);
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700212 }
Kevin Chyn7782d142019-01-18 12:51:33 -0800213
214 @Override
215 protected int statsModality() {
216 return FaceService.this.statsModality();
217 }
Kevin Chyna38653c2019-02-11 17:46:21 -0800218
219 @Override
220 public boolean shouldFrameworkHandleLockout() {
221 return false;
222 }
Kevin Chyn56d6b072019-02-13 18:39:01 -0800223
224 @Override
Kevin Chyn0ce70852019-05-10 10:29:18 -0700225 public boolean wasUserDetected() {
226 return mLastAcquire != FaceManager.FACE_ACQUIRED_NOT_DETECTED;
227 }
228
229 @Override
Kevin Chyn56d6b072019-02-13 18:39:01 -0800230 public boolean onAuthenticated(BiometricAuthenticator.Identifier identifier,
231 boolean authenticated, ArrayList<Byte> token) {
232 final boolean result = super.onAuthenticated(identifier, authenticated, token);
233
Kevin Chyn9bc1d492019-06-21 15:31:50 -0700234 mUsageStats.addEvent(new AuthenticationEvent(
235 getStartTimeMs(),
236 System.currentTimeMillis() - getStartTimeMs() /* latency */,
237 authenticated,
238 0 /* error */,
239 0 /* vendorError */));
240
Kevin Chyn56d6b072019-02-13 18:39:01 -0800241 // For face, the authentication lifecycle ends either when
242 // 1) Authenticated == true
243 // 2) Error occurred
244 // 3) Authenticated == false
245 // Fingerprint currently does not end when the third condition is met which is a bug,
246 // but let's leave it as-is for now.
247 return result || !authenticated;
248 }
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700249
250 @Override
Kevin Chyn9bc1d492019-06-21 15:31:50 -0700251 public boolean onError(long deviceId, int error, int vendorCode) {
252 mUsageStats.addEvent(new AuthenticationEvent(
253 getStartTimeMs(),
254 System.currentTimeMillis() - getStartTimeMs() /* latency */,
255 false /* authenticated */,
256 error,
257 vendorCode));
258
259 return super.onError(deviceId, error, vendorCode);
260 }
261
262 @Override
Kevin Chyn4cc49f72019-04-24 13:53:35 -0700263 public int[] getAcquireIgnorelist() {
264 if (isBiometricPrompt()) {
265 return mBiometricPromptIgnoreList;
266 } else {
267 // Keyguard
268 return mKeyguardIgnoreList;
269 }
270 }
271
272 @Override
273 public int[] getAcquireVendorIgnorelist() {
274 if (isBiometricPrompt()) {
275 return mBiometricPromptIgnoreListVendor;
276 } else {
277 // Keyguard
278 return mKeyguardIgnoreListVendor;
279 }
280 }
281
282 @Override
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700283 public boolean onAcquired(int acquireInfo, int vendorCode) {
284
Kevin Chyn0ce70852019-05-10 10:29:18 -0700285 mLastAcquire = acquireInfo;
286
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700287 if (acquireInfo == FaceManager.FACE_ACQUIRED_RECALIBRATE) {
288 final String name =
289 getContext().getString(R.string.face_recalibrate_notification_name);
290 final String title =
291 getContext().getString(R.string.face_recalibrate_notification_title);
292 final String content =
293 getContext().getString(R.string.face_recalibrate_notification_content);
294
295 final Intent intent = new Intent("android.settings.FACE_SETTINGS");
296 intent.setPackage("com.android.settings");
297
298 final PendingIntent pendingIntent = PendingIntent.getActivityAsUser(getContext(),
299 0 /* requestCode */, intent, 0 /* flags */, null /* options */,
300 UserHandle.CURRENT);
301
Kevin Chyndbfbed42019-06-13 17:01:30 -0700302 final String channelName = "FaceEnrollNotificationChannel";
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700303
Kevin Chyndbfbed42019-06-13 17:01:30 -0700304 NotificationChannel channel = new NotificationChannel(channelName, name,
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700305 NotificationManager.IMPORTANCE_HIGH);
Kevin Chyndbfbed42019-06-13 17:01:30 -0700306 Notification notification = new Notification.Builder(getContext(), channelName)
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700307 .setSmallIcon(R.drawable.ic_lock)
308 .setContentTitle(title)
309 .setContentText(content)
310 .setSubText(name)
311 .setOnlyAlertOnce(true)
312 .setLocalOnly(true)
313 .setAutoCancel(true)
314 .setCategory(Notification.CATEGORY_SYSTEM)
315 .setContentIntent(pendingIntent)
Kevin Chyn0c3a9982019-06-11 19:09:27 -0700316 .setVisibility(Notification.VISIBILITY_SECRET)
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700317 .build();
318
Kevin Chyndbfbed42019-06-13 17:01:30 -0700319 mNotificationManager.createNotificationChannel(channel);
320 mNotificationManager.notifyAsUser(NOTIFICATION_TAG, NOTIFICATION_ID, notification,
321 UserHandle.CURRENT);
Kevin Chyn56e4c3d2019-04-23 11:28:43 -0700322 }
323
324 return super.onAcquired(acquireInfo, vendorCode);
325 }
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700326 }
327
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200328 /**
Kevin Chyna56dff72018-06-19 18:41:12 -0700329 * Receives the incoming binder calls from FaceManager.
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200330 */
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200331 private final class FaceServiceWrapper extends IFaceService.Stub {
Kevin Chyna56dff72018-06-19 18:41:12 -0700332
333 /**
334 * The following methods contain common code which is shared in biometrics/common.
335 */
Kevin Chyna38653c2019-02-11 17:46:21 -0800336
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200337 @Override // Binder call
Kevin Chynd79e24e2018-09-25 12:06:59 -0700338 public long generateChallenge(IBinder token) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700339 checkPermission(MANAGE_BIOMETRIC);
Kevin Chynd79e24e2018-09-25 12:06:59 -0700340 return startGenerateChallenge(token);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200341 }
342
343 @Override // Binder call
Kevin Chynd79e24e2018-09-25 12:06:59 -0700344 public int revokeChallenge(IBinder token) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700345 checkPermission(MANAGE_BIOMETRIC);
Ilya Matyukhin9dac8482019-07-09 11:03:07 -0700346 // TODO(b/137106905): Schedule binder calls in FaceService to avoid deadlocks.
347 if (getCurrentClient() == null) {
348 // if we aren't handling any other HIDL calls (mCurrentClient == null), revoke the
349 // challenge right away.
350 return startRevokeChallenge(token);
351 } else {
352 // postpone revoking the challenge until we finish processing the current HIDL call.
353 mRevokeChallengePending = true;
354 return Status.OK;
355 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200356 }
357
358 @Override // Binder call
Kevin Chyn593e6262019-06-28 13:24:44 -0700359 public void enroll(int userId, final IBinder token, final byte[] cryptoToken,
Kevin Chyn1f16c2d2018-12-07 13:06:08 -0800360 final IFaceServiceReceiver receiver, final String opPackageName,
361 final int[] disabledFeatures) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700362 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyn593e6262019-06-28 13:24:44 -0700363 updateActiveGroup(userId, opPackageName);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200364
Kevin Chyndbfbed42019-06-13 17:01:30 -0700365 mNotificationManager.cancelAsUser(NOTIFICATION_TAG, NOTIFICATION_ID,
366 UserHandle.CURRENT);
367
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200368 final boolean restricted = isRestricted();
Kevin Chyna56dff72018-06-19 18:41:12 -0700369 final EnrollClientImpl client = new EnrollClientImpl(getContext(), mDaemonWrapper,
370 mHalDeviceId, token, new ServiceListenerImpl(receiver), mCurrentUserId,
Kevin Chyn1429a312019-01-28 16:08:09 -0800371 0 /* groupId */, cryptoToken, restricted, opPackageName, disabledFeatures) {
Kevin Chyn4cc49f72019-04-24 13:53:35 -0700372
373 @Override
374 public int[] getAcquireIgnorelist() {
375 return mEnrollIgnoreList;
376 }
377
378 @Override
379 public int[] getAcquireVendorIgnorelist() {
380 return mEnrollIgnoreListVendor;
381 }
382
Kevin Chyn1429a312019-01-28 16:08:09 -0800383 @Override
384 public boolean shouldVibrate() {
385 return false;
386 }
Kevin Chyn7782d142019-01-18 12:51:33 -0800387
388 @Override
389 protected int statsModality() {
390 return FaceService.this.statsModality();
391 }
Kevin Chyn1429a312019-01-28 16:08:09 -0800392 };
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200393
Kevin Chyn1a878c12019-04-04 15:50:11 -0700394 enrollInternal(client, mCurrentUserId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200395 }
396
397 @Override // Binder call
398 public void cancelEnrollment(final IBinder token) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700399 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700400 cancelEnrollmentInternal(token);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200401 }
402
403 @Override // Binder call
Kevin Chyn747e29b2019-01-11 17:01:53 -0800404 public void authenticate(final IBinder token, final long opId, int userId,
Kevin Chyna56dff72018-06-19 18:41:12 -0700405 final IFaceServiceReceiver receiver, final int flags,
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700406 final String opPackageName) {
407 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyn747e29b2019-01-11 17:01:53 -0800408 updateActiveGroup(userId, opPackageName);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200409 final boolean restricted = isRestricted();
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700410 final AuthenticationClientImpl client = new FaceAuthClient(getContext(),
Kevin Chyna56dff72018-06-19 18:41:12 -0700411 mDaemonWrapper, mHalDeviceId, token, new ServiceListenerImpl(receiver),
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700412 mCurrentUserId, 0 /* groupId */, opId, restricted, opPackageName,
Kevin Chyn87f257a2018-11-27 16:26:07 -0800413 0 /* cookie */, false /* requireConfirmation */);
Kevin Chyna56dff72018-06-19 18:41:12 -0700414 authenticateInternal(client, opId, opPackageName);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200415 }
416
417 @Override // Binder call
Kevin Chyn87f257a2018-11-27 16:26:07 -0800418 public void prepareForAuthentication(boolean requireConfirmation, IBinder token, long opId,
Kevin Chyn23289ef2018-11-28 16:32:36 -0800419 int groupId, IBiometricServiceReceiverInternal wrapperReceiver,
420 String opPackageName, int cookie, int callingUid, int callingPid,
421 int callingUserId) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700422 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyn41a80902019-02-06 08:12:15 -0800423 updateActiveGroup(groupId, opPackageName);
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700424 final boolean restricted = true; // BiometricPrompt is always restricted
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700425 final AuthenticationClientImpl client = new FaceAuthClient(getContext(),
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700426 mDaemonWrapper, mHalDeviceId, token,
Kevin Chyn87f257a2018-11-27 16:26:07 -0800427 new BiometricPromptServiceListenerImpl(wrapperReceiver),
428 mCurrentUserId, 0 /* groupId */, opId, restricted, opPackageName, cookie,
Kevin Chyn158fefb2019-01-03 18:59:05 -0800429 requireConfirmation);
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700430 authenticateInternal(client, opId, opPackageName, callingUid, callingPid,
431 callingUserId);
432 }
433
434 @Override // Binder call
Kevin Chyn87f257a2018-11-27 16:26:07 -0800435 public void startPreparedClient(int cookie) {
436 checkPermission(MANAGE_BIOMETRIC);
437 startCurrentClient(cookie);
438 }
439
440 @Override // Binder call
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200441 public void cancelAuthentication(final IBinder token, final String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700442 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyna56dff72018-06-19 18:41:12 -0700443 cancelAuthenticationInternal(token, opPackageName);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200444 }
445
446 @Override // Binder call
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700447 public void cancelAuthenticationFromService(final IBinder token, final String opPackageName,
Kevin Chyne92cdae2018-11-21 16:35:04 -0800448 int callingUid, int callingPid, int callingUserId, boolean fromClient) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700449 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyne92cdae2018-11-21 16:35:04 -0800450 cancelAuthenticationInternal(token, opPackageName, callingUid, callingPid,
451 callingUserId, fromClient);
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700452 }
453
454 @Override // Binder call
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200455 public void setActiveUser(final int userId) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700456 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700457 setActiveUserInternal(userId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200458 }
459
460 @Override // Binder call
Kevin Chyna56dff72018-06-19 18:41:12 -0700461 public void remove(final IBinder token, final int faceId, final int userId,
Kevin Chyn593e6262019-06-28 13:24:44 -0700462 final IFaceServiceReceiver receiver, final String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700463 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyn593e6262019-06-28 13:24:44 -0700464 updateActiveGroup(userId, opPackageName);
Kevin Chyna56dff72018-06-19 18:41:12 -0700465
466 if (token == null) {
467 Slog.w(TAG, "remove(): token is null");
468 return;
469 }
470
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200471 final boolean restricted = isRestricted();
Kevin Chyn4cc49f72019-04-24 13:53:35 -0700472 final RemovalClient client = new RemovalClient(getContext(), getConstants(),
Kevin Chyn6737c572019-02-08 16:10:54 -0800473 mDaemonWrapper, mHalDeviceId, token, new ServiceListenerImpl(receiver), faceId,
474 0 /* groupId */, userId, restricted, token.toString(), getBiometricUtils()) {
Kevin Chyn7782d142019-01-18 12:51:33 -0800475 @Override
476 protected int statsModality() {
477 return FaceService.this.statsModality();
478 }
479 };
Kevin Chyna56dff72018-06-19 18:41:12 -0700480 removeInternal(client);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200481 }
482
Kevin Chyna56dff72018-06-19 18:41:12 -0700483 @Override
484 public void enumerate(final IBinder token, final int userId,
485 final IFaceServiceReceiver receiver) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700486 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700487
488 final boolean restricted = isRestricted();
Kevin Chyn4cc49f72019-04-24 13:53:35 -0700489 final EnumerateClient client = new EnumerateClient(getContext(), getConstants(),
Kevin Chyn6737c572019-02-08 16:10:54 -0800490 mDaemonWrapper, mHalDeviceId, token, new ServiceListenerImpl(receiver), userId,
491 userId, restricted, getContext().getOpPackageName()) {
Kevin Chyn7782d142019-01-18 12:51:33 -0800492 @Override
493 protected int statsModality() {
494 return FaceService.this.statsModality();
495 }
496 };
Kevin Chyna56dff72018-06-19 18:41:12 -0700497 enumerateInternal(client);
498 }
499
500 @Override
501 public void addLockoutResetCallback(final IBiometricServiceLockoutResetCallback callback)
502 throws RemoteException {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700503 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyna56dff72018-06-19 18:41:12 -0700504 FaceService.super.addLockoutResetCallback(callback);
505 }
506
507 @Override // Binder call
508 protected void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
509 if (!DumpUtils.checkDumpPermission(getContext(), TAG, pw)) {
510 return;
511 }
512
513 final long ident = Binder.clearCallingIdentity();
514 try {
Joe Onoratodb396002019-04-05 19:49:27 -0700515 if (args.length > 1 && "--hal".equals(args[0])) {
516 dumpHal(fd, Arrays.copyOfRange(args, 1, args.length, args.getClass()));
Kevin Chyna56dff72018-06-19 18:41:12 -0700517 } else {
518 dumpInternal(pw);
519 }
520 } finally {
521 Binder.restoreCallingIdentity(ident);
522 }
523 }
524
525 /**
526 * The following methods don't use any common code from BiometricService
527 */
528
529 // TODO: refactor out common code here
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200530 @Override // Binder call
531 public boolean isHardwareDetected(long deviceId, String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700532 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyna56dff72018-06-19 18:41:12 -0700533 if (!canUseBiometric(opPackageName, false /* foregroundOnly */,
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200534 Binder.getCallingUid(), Binder.getCallingPid(),
535 UserHandle.getCallingUserId())) {
536 return false;
537 }
538
539 final long token = Binder.clearCallingIdentity();
540 try {
541 IBiometricsFace daemon = getFaceDaemon();
542 return daemon != null && mHalDeviceId != 0;
543 } finally {
544 Binder.restoreCallingIdentity(token);
545 }
546 }
547
548 @Override // Binder call
Kevin Chyna56dff72018-06-19 18:41:12 -0700549 public void rename(final int faceId, final String name) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700550 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700551 if (!isCurrentUserOrProfile(UserHandle.getCallingUserId())) {
552 return;
553 }
554 mHandler.post(new Runnable() {
555 @Override
556 public void run() {
557 getBiometricUtils().renameBiometricForUser(getContext(), mCurrentUserId,
558 faceId, name);
559 }
560 });
561 }
562
563 @Override // Binder call
564 public List<Face> getEnrolledFaces(int userId, String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700565 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyna56dff72018-06-19 18:41:12 -0700566 if (!canUseBiometric(opPackageName, false /* foregroundOnly */,
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200567 Binder.getCallingUid(), Binder.getCallingPid(),
568 UserHandle.getCallingUserId())) {
569 return null;
570 }
571
Kevin Chyn6737c572019-02-08 16:10:54 -0800572 return FaceService.this.getEnrolledTemplates(userId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200573 }
574
575 @Override // Binder call
Kevin Chyna56dff72018-06-19 18:41:12 -0700576 public boolean hasEnrolledFaces(int userId, String opPackageName) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700577 checkPermission(USE_BIOMETRIC_INTERNAL);
Kevin Chyna56dff72018-06-19 18:41:12 -0700578 if (!canUseBiometric(opPackageName, false /* foregroundOnly */,
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200579 Binder.getCallingUid(), Binder.getCallingPid(),
580 UserHandle.getCallingUserId())) {
581 return false;
582 }
583
Kevin Chyna56dff72018-06-19 18:41:12 -0700584 return FaceService.this.hasEnrolledBiometrics(userId);
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200585 }
586
587 @Override // Binder call
588 public long getAuthenticatorId(String opPackageName) {
589 // In this method, we're not checking whether the caller is permitted to use face
590 // API because current authenticator ID is leaked (in a more contrived way) via Android
591 // Keystore (android.security.keystore package): the user of that API can create a key
592 // which requires face authentication for its use, and then query the key's
593 // characteristics (hidden API) which returns, among other things, face
594 // authenticator ID which was active at key creation time.
595 //
596 // Reason: The part of Android Keystore which runs inside an app's process invokes this
597 // method in certain cases. Those cases are not always where the developer demonstrates
598 // explicit intent to use face functionality. Thus, to avoiding throwing an
599 // unexpected SecurityException this method does not check whether its caller is
600 // permitted to use face API.
601 //
602 // The permission check should be restored once Android Keystore no longer invokes this
603 // method from inside app processes.
604
605 return FaceService.this.getAuthenticatorId(opPackageName);
606 }
607
608 @Override // Binder call
Kevin Chyna38653c2019-02-11 17:46:21 -0800609 public void resetLockout(byte[] token) {
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700610 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyn1d6a2862019-04-02 16:20:21 -0700611
612 if (!FaceService.this.hasEnrolledBiometrics(mCurrentUserId)) {
613 Slog.w(TAG, "Ignoring lockout reset, no templates enrolled");
614 return;
615 }
616
Kevin Chynbe67ce02019-06-10 16:14:22 -0700617 Slog.d(TAG, "Resetting lockout for user: " + mCurrentUserId);
618
Kevin Chyna38653c2019-02-11 17:46:21 -0800619 try {
620 mDaemonWrapper.resetLockout(token);
621 } catch (RemoteException e) {
622 Slog.e(getTag(), "Unable to reset lockout", e);
623 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700624 }
Kevin Chynd79e24e2018-09-25 12:06:59 -0700625
626 @Override
Kevin Chyn593e6262019-06-28 13:24:44 -0700627 public void setFeature(int userId, int feature, boolean enabled, final byte[] token,
628 IFaceServiceReceiver receiver, final String opPackageName) {
Kevin Chynd79e24e2018-09-25 12:06:59 -0700629 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyn593e6262019-06-28 13:24:44 -0700630 updateActiveGroup(userId, opPackageName);
Kevin Chynd79e24e2018-09-25 12:06:59 -0700631
Kevin Chyne62749a2019-04-02 19:33:56 -0700632 mHandler.post(() -> {
633 if (!FaceService.this.hasEnrolledBiometrics(mCurrentUserId)) {
634 Slog.e(TAG, "No enrolled biometrics while setting feature: " + feature);
635 return;
Kevin Chynb95f1522019-03-04 16:45:15 -0800636 }
Kevin Chyne62749a2019-04-02 19:33:56 -0700637
638 final ArrayList<Byte> byteToken = new ArrayList<>();
639 for (int i = 0; i < token.length; i++) {
640 byteToken.add(token[i]);
641 }
642
643 // TODO: Support multiple faces
644 final int faceId = getFirstTemplateForUser(mCurrentUserId);
645
646 if (mDaemon != null) {
647 try {
648 final int result = mDaemon.setFeature(feature, enabled, byteToken, faceId);
649 receiver.onFeatureSet(result == Status.OK, feature);
650 } catch (RemoteException e) {
651 Slog.e(getTag(), "Unable to set feature: " + feature
652 + " to enabled:" + enabled, e);
653 }
654 }
655 });
656
Kevin Chynd79e24e2018-09-25 12:06:59 -0700657 }
658
659 @Override
Kevin Chyn593e6262019-06-28 13:24:44 -0700660 public void getFeature(int userId, int feature, IFaceServiceReceiver receiver,
661 final String opPackageName) {
Kevin Chynd79e24e2018-09-25 12:06:59 -0700662 checkPermission(MANAGE_BIOMETRIC);
Kevin Chyn593e6262019-06-28 13:24:44 -0700663 updateActiveGroup(userId, opPackageName);
Kevin Chynd79e24e2018-09-25 12:06:59 -0700664
Kevin Chyne62749a2019-04-02 19:33:56 -0700665 mHandler.post(() -> {
666 // This should ideally return tri-state, but the user isn't shown settings unless
667 // they are enrolled so it's fine for now.
668 if (!FaceService.this.hasEnrolledBiometrics(mCurrentUserId)) {
669 Slog.e(TAG, "No enrolled biometrics while getting feature: " + feature);
670 return;
Kevin Chynb95f1522019-03-04 16:45:15 -0800671 }
Kevin Chyne62749a2019-04-02 19:33:56 -0700672
673 // TODO: Support multiple faces
674 final int faceId = getFirstTemplateForUser(mCurrentUserId);
675
676 if (mDaemon != null) {
677 try {
678 OptionalBool result = mDaemon.getFeature(feature, faceId);
679 receiver.onFeatureGet(result.status == Status.OK, feature, result.value);
680 } catch (RemoteException e) {
681 Slog.e(getTag(), "Unable to getRequireAttention", e);
682 }
683 }
684 });
685
Kevin Chynd79e24e2018-09-25 12:06:59 -0700686 }
Kevin Chyn57f119b2018-10-25 12:03:41 -0700687
688 @Override
689 public void userActivity() {
690 checkPermission(MANAGE_BIOMETRIC);
691
692 if (mDaemon != null) {
693 try {
694 mDaemon.userActivity();
695 } catch (RemoteException e) {
696 Slog.e(getTag(), "Unable to send userActivity", e);
697 }
698 }
699 }
Kevin Chynb95f1522019-03-04 16:45:15 -0800700
701 // TODO: Support multiple faces
702 private int getFirstTemplateForUser(int user) {
703 final List<Face> faces = FaceService.this.getEnrolledTemplates(user);
704 if (!faces.isEmpty()) {
705 return faces.get(0).getBiometricId();
706 }
707 return 0;
708 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700709 }
710
711 /**
712 * Receives callbacks from the ClientMonitor implementations. The results are forwarded to
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700713 * BiometricPrompt.
714 */
Kevin Chyne92cdae2018-11-21 16:35:04 -0800715 private class BiometricPromptServiceListenerImpl extends BiometricServiceListener {
Kevin Chyn23289ef2018-11-28 16:32:36 -0800716 BiometricPromptServiceListenerImpl(IBiometricServiceReceiverInternal wrapperReceiver) {
Kevin Chyn87f257a2018-11-27 16:26:07 -0800717 super(wrapperReceiver);
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700718 }
719
720 @Override
721 public void onAcquired(long deviceId, int acquiredInfo, int vendorCode)
722 throws RemoteException {
723 /**
724 * Map the acquired codes onto existing {@link BiometricConstants} acquired codes.
725 */
Kevin Chyne92cdae2018-11-21 16:35:04 -0800726 if (getWrapperReceiver() != null) {
727 getWrapperReceiver().onAcquired(
Kevin Chyn8b7a0372018-09-17 15:06:05 -0700728 FaceManager.getMappedAcquiredInfo(acquiredInfo, vendorCode),
729 FaceManager.getAcquiredString(getContext(), acquiredInfo, vendorCode));
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700730 }
731 }
732
733 @Override
Kevin Chyn87f257a2018-11-27 16:26:07 -0800734 public void onError(long deviceId, int error, int vendorCode, int cookie)
735 throws RemoteException {
Kevin Chyne92cdae2018-11-21 16:35:04 -0800736 if (getWrapperReceiver() != null) {
Kevin Chyn23289ef2018-11-28 16:32:36 -0800737 getWrapperReceiver().onError(cookie, error,
738 FaceManager.getErrorString(getContext(), error, vendorCode));
Kevin Chyna24e9fd2018-08-27 12:39:17 -0700739 }
740 }
741 }
742
743 /**
744 * Receives callbacks from the ClientMonitor implementations. The results are forwarded to
Kevin Chyna56dff72018-06-19 18:41:12 -0700745 * the FaceManager.
746 */
747 private class ServiceListenerImpl implements ServiceListener {
Kevin Chyna56dff72018-06-19 18:41:12 -0700748 private IFaceServiceReceiver mFaceServiceReceiver;
749
750 public ServiceListenerImpl(IFaceServiceReceiver receiver) {
751 mFaceServiceReceiver = receiver;
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200752 }
753
754 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -0700755 public void onEnrollResult(BiometricAuthenticator.Identifier identifier, int remaining)
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200756 throws RemoteException {
Kevin Chyna56dff72018-06-19 18:41:12 -0700757 if (mFaceServiceReceiver != null) {
758 mFaceServiceReceiver.onEnrollResult(identifier.getDeviceId(),
759 identifier.getBiometricId(),
760 remaining);
761 }
Gilad Brettercb51b8b2018-03-22 17:04:51 +0200762 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700763
764 @Override
765 public void onAcquired(long deviceId, int acquiredInfo, int vendorCode)
766 throws RemoteException {
767 if (mFaceServiceReceiver != null) {
768 mFaceServiceReceiver.onAcquired(deviceId, acquiredInfo, vendorCode);
769 }
770 }
771
772 @Override
773 public void onAuthenticationSucceeded(long deviceId,
774 BiometricAuthenticator.Identifier biometric, int userId)
775 throws RemoteException {
776 if (mFaceServiceReceiver != null) {
Kevin Chyn628b7182018-11-13 12:00:48 -0800777 if (biometric == null || biometric instanceof Face) {
Kevin Chyn8d2694a2019-04-11 18:30:40 -0700778 mFaceServiceReceiver.onAuthenticationSucceeded(deviceId, (Face) biometric,
779 userId);
Kevin Chyna56dff72018-06-19 18:41:12 -0700780 } else {
781 Slog.e(TAG, "onAuthenticationSucceeded received non-face biometric");
782 }
783 }
784 }
785
786 @Override
787 public void onAuthenticationFailed(long deviceId) throws RemoteException {
788 if (mFaceServiceReceiver != null) {
789 mFaceServiceReceiver.onAuthenticationFailed(deviceId);
790 }
791 }
792
793 @Override
Kevin Chyn87f257a2018-11-27 16:26:07 -0800794 public void onError(long deviceId, int error, int vendorCode, int cookie)
795 throws RemoteException {
Kevin Chyna56dff72018-06-19 18:41:12 -0700796 if (mFaceServiceReceiver != null) {
797 mFaceServiceReceiver.onError(deviceId, error, vendorCode);
798 }
799 }
800
801 @Override
802 public void onRemoved(BiometricAuthenticator.Identifier identifier,
803 int remaining) throws RemoteException {
804 if (mFaceServiceReceiver != null) {
805 mFaceServiceReceiver.onRemoved(identifier.getDeviceId(),
806 identifier.getBiometricId(), remaining);
807 }
808 }
809
810 @Override
811 public void onEnumerated(BiometricAuthenticator.Identifier identifier, int remaining)
812 throws RemoteException {
813 if (mFaceServiceReceiver != null) {
Kevin Chyn6737c572019-02-08 16:10:54 -0800814 mFaceServiceReceiver.onEnumerated(identifier.getDeviceId(),
815 identifier.getBiometricId(), remaining);
Kevin Chyna56dff72018-06-19 18:41:12 -0700816 }
817 }
818 }
819
Kevin Chyn4cc49f72019-04-24 13:53:35 -0700820 private final FaceConstants mFaceConstants = new FaceConstants();
Kevin Chyna56dff72018-06-19 18:41:12 -0700821
822 @GuardedBy("this")
823 private IBiometricsFace mDaemon;
Kevin Chyn9bc1d492019-06-21 15:31:50 -0700824 private UsageStats mUsageStats;
Ilya Matyukhin9dac8482019-07-09 11:03:07 -0700825 private boolean mRevokeChallengePending = false;
Kevin Chyna38653c2019-02-11 17:46:21 -0800826 // One of the AuthenticationClient constants
827 private int mCurrentUserLockoutMode;
Kevin Chyna56dff72018-06-19 18:41:12 -0700828
Kevin Chyndbfbed42019-06-13 17:01:30 -0700829 private NotificationManager mNotificationManager;
830
Kevin Chyn4cc49f72019-04-24 13:53:35 -0700831 private int[] mBiometricPromptIgnoreList;
832 private int[] mBiometricPromptIgnoreListVendor;
833 private int[] mKeyguardIgnoreList;
834 private int[] mKeyguardIgnoreListVendor;
835 private int[] mEnrollIgnoreList;
836 private int[] mEnrollIgnoreListVendor;
837
Kevin Chyna56dff72018-06-19 18:41:12 -0700838 /**
839 * Receives callbacks from the HAL.
840 */
841 private IBiometricsFaceClientCallback mDaemonCallback =
842 new IBiometricsFaceClientCallback.Stub() {
Kevin Chyn6737c572019-02-08 16:10:54 -0800843 @Override
844 public void onEnrollResult(final long deviceId, int faceId, int userId,
845 int remaining) {
846 mHandler.post(() -> {
847 final Face face = new Face(getBiometricUtils()
848 .getUniqueName(getContext(), userId), faceId, deviceId);
849 FaceService.super.handleEnrollResult(face, remaining);
Kevin Chyn576811e2019-06-12 14:50:35 -0700850
851 // Enrollment changes the authenticatorId, so update it here.
852 IBiometricsFace daemon = getFaceDaemon();
853 if (remaining == 0 && daemon != null) {
854 try {
855 mAuthenticatorIds.put(userId,
856 hasEnrolledBiometrics(userId) ? daemon.getAuthenticatorId().value
857 : 0L);
858 } catch (RemoteException e) {
859 Slog.e(TAG, "Unable to get authenticatorId", e);
860 }
861 }
Kevin Chyn6737c572019-02-08 16:10:54 -0800862 });
863 }
864
865 @Override
866 public void onAcquired(final long deviceId, final int userId,
867 final int acquiredInfo,
868 final int vendorCode) {
869 mHandler.post(() -> {
870 FaceService.super.handleAcquired(deviceId, acquiredInfo, vendorCode);
871 });
872 }
873
874 @Override
875 public void onAuthenticated(final long deviceId, final int faceId, final int userId,
876 ArrayList<Byte> token) {
877 mHandler.post(() -> {
878 Face face = new Face("", faceId, deviceId);
879 FaceService.super.handleAuthenticated(face, token);
880 });
881 }
882
883 @Override
884 public void onError(final long deviceId, final int userId, final int error,
885 final int vendorCode) {
886 mHandler.post(() -> {
887 FaceService.super.handleError(deviceId, error, vendorCode);
888
889 // TODO: this chunk of code should be common to all biometric services
890 if (error == BiometricConstants.BIOMETRIC_ERROR_HW_UNAVAILABLE) {
891 // If we get HW_UNAVAILABLE, try to connect again later...
892 Slog.w(TAG, "Got ERROR_HW_UNAVAILABLE; try reconnecting next client.");
893 synchronized (this) {
894 mDaemon = null;
895 mHalDeviceId = 0;
896 mCurrentUserId = UserHandle.USER_NULL;
897 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700898 }
Kevin Chyn6737c572019-02-08 16:10:54 -0800899 });
900 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700901
Kevin Chyn6737c572019-02-08 16:10:54 -0800902 @Override
Kevin Chyn31ae8d22019-03-11 14:12:32 -0700903 public void onRemoved(final long deviceId, ArrayList<Integer> faceIds, final int userId) {
Kevin Chyn6737c572019-02-08 16:10:54 -0800904 mHandler.post(() -> {
Kevin Chyn31ae8d22019-03-11 14:12:32 -0700905 if (!faceIds.isEmpty()) {
906 for (int i = 0; i < faceIds.size(); i++) {
907 final Face face = new Face("", faceIds.get(i), deviceId);
908 // Convert to old behavior
909 FaceService.super.handleRemoved(face, faceIds.size() - i - 1);
910 }
911 } else {
912 final Face face = new Face("", 0 /* identifier */, deviceId);
913 FaceService.super.handleRemoved(face, 0 /* remaining */);
914 }
915
Kevin Chyn6737c572019-02-08 16:10:54 -0800916 });
917 }
918
919 @Override
920 public void onEnumerate(long deviceId, ArrayList<Integer> faceIds, int userId)
921 throws RemoteException {
922 mHandler.post(() -> {
923 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 old behavior
927 FaceService.super.handleEnumerate(face, faceIds.size() - i - 1);
928 }
929 } else {
930 // For face, the HIDL contract is to receive an empty list when there are no
931 // templates enrolled. Send a null identifier since we don't consume them
932 // anywhere, and send remaining == 0 to plumb this with existing common code.
933 FaceService.super.handleEnumerate(null /* identifier */, 0);
Kevin Chyna56dff72018-06-19 18:41:12 -0700934 }
Kevin Chyn6737c572019-02-08 16:10:54 -0800935 });
936 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700937
Kevin Chyn6737c572019-02-08 16:10:54 -0800938 @Override
939 public void onLockoutChanged(long duration) {
Kevin Chyna38653c2019-02-11 17:46:21 -0800940 Slog.d(TAG, "onLockoutChanged: " + duration);
941 if (duration == 0) {
942 mCurrentUserLockoutMode = AuthenticationClient.LOCKOUT_NONE;
943 } else if (duration == Long.MAX_VALUE) {
944 mCurrentUserLockoutMode = AuthenticationClient.LOCKOUT_PERMANENT;
945 } else {
946 mCurrentUserLockoutMode = AuthenticationClient.LOCKOUT_TIMED;
947 }
Kevin Chyna56dff72018-06-19 18:41:12 -0700948
Kevin Chyna38653c2019-02-11 17:46:21 -0800949 mHandler.post(() -> {
950 if (duration == 0) {
951 notifyLockoutResetMonitors();
952 }
953 });
Kevin Chyn6737c572019-02-08 16:10:54 -0800954 }
955 };
Kevin Chyna56dff72018-06-19 18:41:12 -0700956
957 /**
958 * Wraps the HAL-specific code and is passed to the ClientMonitor implementations so that they
959 * can be shared between the multiple biometric services.
960 */
961 private final DaemonWrapper mDaemonWrapper = new DaemonWrapper() {
962 @Override
963 public int authenticate(long operationId, int groupId) throws RemoteException {
964 IBiometricsFace daemon = getFaceDaemon();
965 if (daemon == null) {
966 Slog.w(TAG, "authenticate(): no face HAL!");
967 return ERROR_ESRCH;
968 }
969 return daemon.authenticate(operationId);
970 }
971
972 @Override
973 public int cancel() throws RemoteException {
974 IBiometricsFace daemon = getFaceDaemon();
975 if (daemon == null) {
976 Slog.w(TAG, "cancel(): no face HAL!");
977 return ERROR_ESRCH;
978 }
979 return daemon.cancel();
980 }
981
982 @Override
983 public int remove(int groupId, int biometricId) throws RemoteException {
984 IBiometricsFace daemon = getFaceDaemon();
985 if (daemon == null) {
986 Slog.w(TAG, "remove(): no face HAL!");
987 return ERROR_ESRCH;
988 }
989 return daemon.remove(biometricId);
990 }
991
992 @Override
993 public int enumerate() throws RemoteException {
994 IBiometricsFace daemon = getFaceDaemon();
995 if (daemon == null) {
996 Slog.w(TAG, "enumerate(): no face HAL!");
997 return ERROR_ESRCH;
998 }
999 return daemon.enumerate();
1000 }
1001
1002 @Override
Kevin Chyn1f16c2d2018-12-07 13:06:08 -08001003 public int enroll(byte[] cryptoToken, int groupId, int timeout,
1004 ArrayList<Integer> disabledFeatures) throws RemoteException {
Kevin Chyna56dff72018-06-19 18:41:12 -07001005 IBiometricsFace daemon = getFaceDaemon();
1006 if (daemon == null) {
1007 Slog.w(TAG, "enroll(): no face HAL!");
1008 return ERROR_ESRCH;
1009 }
1010 final ArrayList<Byte> token = new ArrayList<>();
1011 for (int i = 0; i < cryptoToken.length; i++) {
1012 token.add(cryptoToken[i]);
1013 }
Kevin Chyn1f16c2d2018-12-07 13:06:08 -08001014 return daemon.enroll(token, timeout, disabledFeatures);
Kevin Chyna56dff72018-06-19 18:41:12 -07001015 }
Kevin Chyna38653c2019-02-11 17:46:21 -08001016
1017 @Override
1018 public void resetLockout(byte[] cryptoToken) throws RemoteException {
1019 IBiometricsFace daemon = getFaceDaemon();
1020 if (daemon == null) {
1021 Slog.w(TAG, "resetLockout(): no face HAL!");
1022 return;
1023 }
1024 final ArrayList<Byte> token = new ArrayList<>();
1025 for (int i = 0; i < cryptoToken.length; i++) {
1026 token.add(cryptoToken[i]);
1027 }
1028 daemon.resetLockout(token);
1029 }
Kevin Chyna56dff72018-06-19 18:41:12 -07001030 };
1031
1032
1033 public FaceService(Context context) {
1034 super(context);
Kevin Chyn4cc49f72019-04-24 13:53:35 -07001035
Kevin Chyn9bc1d492019-06-21 15:31:50 -07001036 mUsageStats = new UsageStats(context);
1037
Kevin Chyndbfbed42019-06-13 17:01:30 -07001038 mNotificationManager = getContext().getSystemService(NotificationManager.class);
1039
Kevin Chyn4cc49f72019-04-24 13:53:35 -07001040 mBiometricPromptIgnoreList = getContext().getResources()
1041 .getIntArray(R.array.config_face_acquire_biometricprompt_ignorelist);
1042 mBiometricPromptIgnoreListVendor = getContext().getResources()
1043 .getIntArray(R.array.config_face_acquire_vendor_biometricprompt_ignorelist);
1044 mKeyguardIgnoreList = getContext().getResources()
1045 .getIntArray(R.array.config_face_acquire_keyguard_ignorelist);
1046 mKeyguardIgnoreListVendor = getContext().getResources()
1047 .getIntArray(R.array.config_face_acquire_vendor_keyguard_ignorelist);
1048 mEnrollIgnoreList = getContext().getResources()
1049 .getIntArray(R.array.config_face_acquire_enroll_ignorelist);
1050 mEnrollIgnoreListVendor = getContext().getResources()
1051 .getIntArray(R.array.config_face_acquire_vendor_enroll_ignorelist);
Kevin Chyna56dff72018-06-19 18:41:12 -07001052 }
1053
1054 @Override
Ilya Matyukhin9dac8482019-07-09 11:03:07 -07001055 protected void removeClient(ClientMonitor client) {
1056 super.removeClient(client);
1057 if (mRevokeChallengePending) {
1058 startRevokeChallenge(null);
1059 mRevokeChallengePending = false;
1060 }
1061 }
1062
1063 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -07001064 public void onStart() {
Kevin Chyn5a2ff5d2018-08-29 19:07:30 -07001065 super.onStart();
Kevin Chyna56dff72018-06-19 18:41:12 -07001066 publishBinderService(Context.FACE_SERVICE, new FaceServiceWrapper());
Kevin Chyn8398a712019-06-13 16:44:50 -07001067 // Get the face daemon on FaceService's on thread so SystemServerInitThreadPool isn't
1068 // blocked
1069 SystemServerInitThreadPool.get().submit(() -> mHandler.post(this::getFaceDaemon),
1070 TAG + ".onStart");
Kevin Chyna56dff72018-06-19 18:41:12 -07001071 }
1072
1073 @Override
1074 public String getTag() {
1075 return TAG;
1076 }
1077
1078 @Override
Kevin Chyn6737c572019-02-08 16:10:54 -08001079 protected DaemonWrapper getDaemonWrapper() {
1080 return mDaemonWrapper;
1081 }
1082
1083 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -07001084 protected BiometricUtils getBiometricUtils() {
1085 return FaceUtils.getInstance();
1086 }
1087
1088 @Override
Kevin Chyn4cc49f72019-04-24 13:53:35 -07001089 protected Constants getConstants() {
1090 return mFaceConstants;
Kevin Chyna56dff72018-06-19 18:41:12 -07001091 }
1092
1093 @Override
1094 protected boolean hasReachedEnrollmentLimit(int userId) {
1095 final int limit = getContext().getResources().getInteger(
Kevin Chyn017e76e2018-06-27 18:35:06 -07001096 com.android.internal.R.integer.config_faceMaxTemplatesPerUser);
Kevin Chyn6737c572019-02-08 16:10:54 -08001097 final int enrolled = FaceService.this.getEnrolledTemplates(userId).size();
Kevin Chyna56dff72018-06-19 18:41:12 -07001098 if (enrolled >= limit) {
Kevin Chyn1a878c12019-04-04 15:50:11 -07001099 Slog.w(TAG, "Too many faces registered, user: " + userId);
Kevin Chyna56dff72018-06-19 18:41:12 -07001100 return true;
1101 }
1102 return false;
1103 }
1104
1105 @Override
Kevin Chyn9ba99912019-01-16 16:24:36 -08001106 public void serviceDied(long cookie) {
1107 super.serviceDied(cookie);
1108 mDaemon = null;
Jim Miller7b78b222019-02-07 16:47:38 -08001109
1110 mCurrentUserId = UserHandle.USER_NULL; // Force updateActiveGroup() to re-evaluate
Kevin Chyn9ba99912019-01-16 16:24:36 -08001111 }
1112
1113 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -07001114 protected void updateActiveGroup(int userId, String clientPackage) {
1115 IBiometricsFace daemon = getFaceDaemon();
1116
1117 if (daemon != null) {
1118 try {
1119 userId = getUserOrWorkProfileId(clientPackage, userId);
1120 if (userId != mCurrentUserId) {
Kevin Chyn27e33d02019-04-30 01:37:32 +00001121 final File baseDir = Environment.getDataVendorDeDirectory(userId);
Kevin Chyna56dff72018-06-19 18:41:12 -07001122 final File faceDir = new File(baseDir, FACE_DATA_DIR);
1123 if (!faceDir.exists()) {
1124 if (!faceDir.mkdir()) {
1125 Slog.v(TAG, "Cannot make directory: " + faceDir.getAbsolutePath());
1126 return;
1127 }
1128 // Calling mkdir() from this process will create a directory with our
1129 // permissions (inherited from the containing dir). This command fixes
1130 // the label.
1131 if (!SELinux.restorecon(faceDir)) {
1132 Slog.w(TAG, "Restorecons failed. Directory will have wrong label.");
1133 return;
1134 }
1135 }
1136
1137 daemon.setActiveUser(userId, faceDir.getAbsolutePath());
1138 mCurrentUserId = userId;
Kevin Chyn576811e2019-06-12 14:50:35 -07001139 mAuthenticatorIds.put(userId,
1140 hasEnrolledBiometrics(userId) ? daemon.getAuthenticatorId().value : 0L);
Kevin Chyna56dff72018-06-19 18:41:12 -07001141 }
Kevin Chyna56dff72018-06-19 18:41:12 -07001142 } catch (RemoteException e) {
1143 Slog.e(TAG, "Failed to setActiveUser():", e);
1144 }
1145 }
1146 }
1147
1148 @Override
1149 protected String getLockoutResetIntent() {
1150 return ACTION_LOCKOUT_RESET;
1151 }
1152
1153 @Override
1154 protected String getLockoutBroadcastPermission() {
1155 return RESET_FACE_LOCKOUT;
1156 }
1157
1158 @Override
1159 protected long getHalDeviceId() {
1160 return mHalDeviceId;
1161 }
1162
1163 @Override
Kevin Chyna38653c2019-02-11 17:46:21 -08001164 protected void handleUserSwitching(int userId) {
1165 super.handleUserSwitching(userId);
1166 // Will be updated when we get the callback from HAL
1167 mCurrentUserLockoutMode = AuthenticationClient.LOCKOUT_NONE;
1168 }
1169
1170 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -07001171 protected boolean hasEnrolledBiometrics(int userId) {
1172 if (userId != UserHandle.getCallingUserId()) {
1173 checkPermission(INTERACT_ACROSS_USERS);
1174 }
1175 return getBiometricUtils().getBiometricsForUser(getContext(), userId).size() > 0;
1176 }
1177
1178 @Override
1179 protected String getManageBiometricPermission() {
Kevin Chyna24e9fd2018-08-27 12:39:17 -07001180 return MANAGE_BIOMETRIC;
Kevin Chyna56dff72018-06-19 18:41:12 -07001181 }
1182
1183 @Override
1184 protected void checkUseBiometricPermission() {
Kevin Chyna24e9fd2018-08-27 12:39:17 -07001185 // noop for Face. The permission checks are all done on the incoming binder call.
Kevin Chyna56dff72018-06-19 18:41:12 -07001186 }
1187
1188 @Override
Kevin Chynb3c05aa2018-09-21 16:50:32 -07001189 protected boolean checkAppOps(int uid, String opPackageName) {
1190 return mAppOps.noteOp(AppOpsManager.OP_USE_BIOMETRIC, uid, opPackageName)
1191 == AppOpsManager.MODE_ALLOWED;
Kevin Chyna56dff72018-06-19 18:41:12 -07001192 }
1193
1194 @Override
Kevin Chyn6737c572019-02-08 16:10:54 -08001195 protected List<Face> getEnrolledTemplates(int userId) {
1196 return getBiometricUtils().getBiometricsForUser(getContext(), userId);
1197 }
1198
1199 @Override
Kevin Chyna56dff72018-06-19 18:41:12 -07001200 protected void notifyClientActiveCallbacks(boolean isActive) {
1201 // noop for Face.
1202 }
1203
Kevin Chyn7782d142019-01-18 12:51:33 -08001204 @Override
1205 protected int statsModality() {
1206 return BiometricsProtoEnums.MODALITY_FACE;
1207 }
1208
Kevin Chyna38653c2019-02-11 17:46:21 -08001209 @Override
1210 protected int getLockoutMode() {
1211 return mCurrentUserLockoutMode;
1212 }
1213
Kevin Chyna56dff72018-06-19 18:41:12 -07001214 /** Gets the face daemon */
1215 private synchronized IBiometricsFace getFaceDaemon() {
1216 if (mDaemon == null) {
1217 Slog.v(TAG, "mDaemon was null, reconnect to face");
1218 try {
1219 mDaemon = IBiometricsFace.getService();
1220 } catch (java.util.NoSuchElementException e) {
1221 // Service doesn't exist or cannot be opened. Logged below.
1222 } catch (RemoteException e) {
1223 Slog.e(TAG, "Failed to get biometric interface", e);
1224 }
1225 if (mDaemon == null) {
1226 Slog.w(TAG, "face HIDL not available");
1227 return null;
1228 }
1229
1230 mDaemon.asBinder().linkToDeath(this, 0);
1231
1232 try {
1233 mHalDeviceId = mDaemon.setCallback(mDaemonCallback).value;
1234 } catch (RemoteException e) {
1235 Slog.e(TAG, "Failed to open face HAL", e);
1236 mDaemon = null; // try again later!
1237 }
1238
1239 if (DEBUG) Slog.v(TAG, "Face HAL id: " + mHalDeviceId);
1240 if (mHalDeviceId != 0) {
1241 loadAuthenticatorIds();
1242 updateActiveGroup(ActivityManager.getCurrentUser(), null);
Kevin Chyn6737c572019-02-08 16:10:54 -08001243 doTemplateCleanupForUser(ActivityManager.getCurrentUser());
Kevin Chyna56dff72018-06-19 18:41:12 -07001244 } else {
1245 Slog.w(TAG, "Failed to open Face HAL!");
1246 MetricsLogger.count(getContext(), "faced_openhal_error", 1);
1247 mDaemon = null;
1248 }
1249 }
1250 return mDaemon;
1251 }
1252
Kevin Chynd79e24e2018-09-25 12:06:59 -07001253 private long startGenerateChallenge(IBinder token) {
Kevin Chyna56dff72018-06-19 18:41:12 -07001254 IBiometricsFace daemon = getFaceDaemon();
1255 if (daemon == null) {
Kevin Chynd79e24e2018-09-25 12:06:59 -07001256 Slog.w(TAG, "startGenerateChallenge: no face HAL!");
Kevin Chyna56dff72018-06-19 18:41:12 -07001257 return 0;
1258 }
1259 try {
Kevin Chyne46a2162018-09-20 18:43:01 -07001260 return daemon.generateChallenge(CHALLENGE_TIMEOUT_SEC).value;
Kevin Chyna56dff72018-06-19 18:41:12 -07001261 } catch (RemoteException e) {
Kevin Chynd79e24e2018-09-25 12:06:59 -07001262 Slog.e(TAG, "startGenerateChallenge failed", e);
Kevin Chyna56dff72018-06-19 18:41:12 -07001263 }
1264 return 0;
1265 }
1266
Kevin Chynd79e24e2018-09-25 12:06:59 -07001267 private int startRevokeChallenge(IBinder token) {
Kevin Chyna56dff72018-06-19 18:41:12 -07001268 IBiometricsFace daemon = getFaceDaemon();
1269 if (daemon == null) {
Kevin Chynd79e24e2018-09-25 12:06:59 -07001270 Slog.w(TAG, "startRevokeChallenge: no face HAL!");
Kevin Chyna56dff72018-06-19 18:41:12 -07001271 return 0;
1272 }
1273 try {
Ilya Matyukhin9dac8482019-07-09 11:03:07 -07001274 final int res = daemon.revokeChallenge();
1275 if (res != Status.OK) {
1276 Slog.e(TAG, "revokeChallenge returned " + res);
1277 }
1278 return res;
Kevin Chyna56dff72018-06-19 18:41:12 -07001279 } catch (RemoteException e) {
Kevin Chynd79e24e2018-09-25 12:06:59 -07001280 Slog.e(TAG, "startRevokeChallenge failed", e);
Kevin Chyna56dff72018-06-19 18:41:12 -07001281 }
1282 return 0;
1283 }
1284
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001285 private void dumpInternal(PrintWriter pw) {
1286 JSONObject dump = new JSONObject();
1287 try {
1288 dump.put("service", "Face Manager");
1289
1290 JSONArray sets = new JSONArray();
1291 for (UserInfo user : UserManager.get(getContext()).getUsers()) {
1292 final int userId = user.getUserHandle().getIdentifier();
Kevin Chyna56dff72018-06-19 18:41:12 -07001293 final int N = getBiometricUtils().getBiometricsForUser(getContext(), userId).size();
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001294 PerformanceStats stats = mPerformanceMap.get(userId);
1295 PerformanceStats cryptoStats = mCryptoPerformanceMap.get(userId);
1296 JSONObject set = new JSONObject();
1297 set.put("id", userId);
Kevin Chyna56dff72018-06-19 18:41:12 -07001298 set.put("count", N);
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001299 set.put("accept", (stats != null) ? stats.accept : 0);
1300 set.put("reject", (stats != null) ? stats.reject : 0);
1301 set.put("acquire", (stats != null) ? stats.acquire : 0);
1302 set.put("lockout", (stats != null) ? stats.lockout : 0);
1303 set.put("permanentLockout", (stats != null) ? stats.permanentLockout : 0);
1304 // cryptoStats measures statistics about secure face transactions
1305 // (e.g. to unlock password storage, make secure purchases, etc.)
1306 set.put("acceptCrypto", (cryptoStats != null) ? cryptoStats.accept : 0);
1307 set.put("rejectCrypto", (cryptoStats != null) ? cryptoStats.reject : 0);
1308 set.put("acquireCrypto", (cryptoStats != null) ? cryptoStats.acquire : 0);
1309 set.put("lockoutCrypto", (cryptoStats != null) ? cryptoStats.lockout : 0);
Kevin Chyna56dff72018-06-19 18:41:12 -07001310 set.put("permanentLockoutCrypto",
1311 (cryptoStats != null) ? cryptoStats.permanentLockout : 0);
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001312 sets.put(set);
1313 }
1314
1315 dump.put("prints", sets);
1316 } catch (JSONException e) {
1317 Slog.e(TAG, "dump formatting failure", e);
1318 }
1319 pw.println(dump);
Kevin Chyn9bc1d492019-06-21 15:31:50 -07001320 pw.println("HAL deaths since last reboot: " + mHALDeathCount);
1321
1322 mUsageStats.print(pw);
Gilad Brettercb51b8b2018-03-22 17:04:51 +02001323 }
1324
Joe Onoratodb396002019-04-05 19:49:27 -07001325 private void dumpHal(FileDescriptor fd, String[] args) {
Joe Onoratobf955d22019-03-25 00:16:58 -07001326 // WARNING: CDD restricts image data from leaving TEE unencrypted on
1327 // production devices:
1328 // [C-1-10] MUST not allow unencrypted access to identifiable biometric
1329 // data or any data derived from it (such as embeddings) to the
1330 // Application Processor outside the context of the TEE.
1331 // As such, this API should only be enabled for testing purposes on
1332 // engineering and userdebug builds. All modules in the software stack
1333 // MUST enforce final build products do NOT have this functionality.
1334 // Additionally, the following check MUST NOT be removed.
1335 if (!(Build.IS_ENG || Build.IS_USERDEBUG)) {
1336 return;
1337 }
1338
Joe Onorato108413a2019-04-03 18:20:52 -07001339 // Additionally, this flag allows turning off face for a device
1340 // (either permanently through the build or on an individual device).
1341 if (SystemProperties.getBoolean("ro.face.disable_debug_data", false)
1342 || SystemProperties.getBoolean("persist.face.disable_debug_data", false)) {
1343 return;
1344 }
1345
Joe Onoratodb396002019-04-05 19:49:27 -07001346 // The debug method takes two file descriptors. The first is for text
1347 // output, which we will drop. The second is for binary data, which
1348 // will be the protobuf data.
1349 final IBiometricsFace daemon = getFaceDaemon();
1350 if (daemon != null) {
1351 FileOutputStream devnull = null;
1352 try {
1353 devnull = new FileOutputStream("/dev/null");
1354 final NativeHandle handle = new NativeHandle(
1355 new FileDescriptor[] { devnull.getFD(), fd },
1356 new int[0], false);
1357 daemon.debug(handle, new ArrayList<String>(Arrays.asList(args)));
1358 } catch (IOException | RemoteException ex) {
1359 Slog.d(TAG, "error while reading face debugging data", ex);
1360 } finally {
1361 if (devnull != null) {
1362 try {
1363 devnull.close();
1364 } catch (IOException ex) {
1365 }
1366 }
1367 }
Joe Onoratobf955d22019-03-25 00:16:58 -07001368 }
Joe Onoratobf955d22019-03-25 00:16:58 -07001369 }
Kevin Chyn8b7a0372018-09-17 15:06:05 -07001370}