1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.settings.biometrics.face; 18 19 import android.app.Activity; 20 import android.app.settings.SettingsEnums; 21 import android.hardware.face.FaceManager; 22 import android.os.UserHandle; 23 24 import com.android.settings.Utils; 25 import com.android.settings.biometrics.BiometricEnrollSidecar; 26 27 import java.util.Arrays; 28 29 /** 30 * Sidecar fragment to handle the state around face enrollment 31 */ 32 public class FaceEnrollSidecar extends BiometricEnrollSidecar { 33 34 private final int[] mDisabledFeatures; 35 36 private FaceManager mFaceManager; 37 FaceEnrollSidecar(int[] disabledFeatures)38 public FaceEnrollSidecar(int[] disabledFeatures) { 39 mDisabledFeatures = Arrays.copyOf(disabledFeatures, disabledFeatures.length); 40 } 41 42 @Override onAttach(Activity activity)43 public void onAttach(Activity activity) { 44 super.onAttach(activity); 45 mFaceManager = Utils.getFaceManagerOrNull(activity); 46 } 47 48 @Override startEnrollment()49 public void startEnrollment() { 50 super.startEnrollment(); 51 if (mUserId != UserHandle.USER_NULL) { 52 mFaceManager.setActiveUser(mUserId); 53 } 54 55 mFaceManager.enroll(mUserId, mToken, mEnrollmentCancel, 56 mEnrollmentCallback, mDisabledFeatures); 57 } 58 59 private FaceManager.EnrollmentCallback mEnrollmentCallback 60 = new FaceManager.EnrollmentCallback() { 61 62 @Override 63 public void onEnrollmentProgress(int remaining) { 64 FaceEnrollSidecar.super.onEnrollmentProgress(remaining); 65 } 66 67 @Override 68 public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) { 69 FaceEnrollSidecar.super.onEnrollmentHelp(helpMsgId, helpString); 70 } 71 72 @Override 73 public void onEnrollmentError(int errMsgId, CharSequence errString) { 74 FaceEnrollSidecar.super.onEnrollmentError(errMsgId, errString); 75 } 76 }; 77 78 @Override getMetricsCategory()79 public int getMetricsCategory() { 80 return SettingsEnums.FACE_ENROLL_SIDECAR; 81 } 82 } 83