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.content.Intent;
22 import android.hardware.face.FaceManager;
23 
24 import com.android.settings.biometrics.BiometricEnrollSidecar;
25 
26 import java.util.Arrays;
27 
28 /**
29  * Sidecar fragment to handle the state around face enrollment
30  */
31 public class FaceEnrollSidecar extends BiometricEnrollSidecar {
32 
33     private final int[] mDisabledFeatures;
34 
35     private FaceUpdater mFaceUpdater;
36 
37     private Intent mIntent;
38 
FaceEnrollSidecar(int[] disabledFeatures, Intent intent)39     public FaceEnrollSidecar(int[] disabledFeatures, Intent intent) {
40         mDisabledFeatures = Arrays.copyOf(disabledFeatures, disabledFeatures.length);
41         mIntent = intent;
42     }
43 
44     @Override
onAttach(Activity activity)45     public void onAttach(Activity activity) {
46         super.onAttach(activity);
47         mFaceUpdater = new FaceUpdater(activity);
48     }
49 
50     @Override
startEnrollment()51     public void startEnrollment() {
52         super.startEnrollment();
53         mFaceUpdater.enroll(mUserId, mToken, mEnrollmentCancel,
54                 mEnrollmentCallback, mDisabledFeatures, mIntent);
55     }
56 
57     private FaceManager.EnrollmentCallback mEnrollmentCallback
58             = new FaceManager.EnrollmentCallback() {
59 
60         @Override
61         public void onEnrollmentProgress(int remaining) {
62             FaceEnrollSidecar.super.onEnrollmentProgress(remaining);
63         }
64 
65         @Override
66         public void onEnrollmentHelp(int helpMsgId, CharSequence helpString) {
67             FaceEnrollSidecar.super.onEnrollmentHelp(helpMsgId, helpString);
68         }
69 
70         @Override
71         public void onEnrollmentError(int errMsgId, CharSequence errString) {
72             FaceEnrollSidecar.super.onEnrollmentError(errMsgId, errString);
73         }
74     };
75 
76     @Override
getMetricsCategory()77     public int getMetricsCategory() {
78         return SettingsEnums.FACE_ENROLL_SIDECAR;
79     }
80 }
81