OSDN Git Service

Added Face Enroll Education Screen
[android-x86/packages-apps-Settings.git] / src / com / android / settings / biometrics / face / FaceEnrollIntroduction.java
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.admin.DevicePolicyManager;
20 import android.app.settings.SettingsEnums;
21 import android.content.Intent;
22 import android.hardware.face.FaceManager;
23 import android.os.Bundle;
24 import android.widget.TextView;
25
26 import com.android.settings.R;
27 import com.android.settings.Utils;
28 import com.android.settings.biometrics.BiometricEnrollIntroduction;
29 import com.android.settings.password.ChooseLockSettingsHelper;
30 import com.android.settingslib.RestrictedLockUtilsInternal;
31
32 import com.google.android.setupcompat.template.FooterBarMixin;
33 import com.google.android.setupcompat.template.FooterButton;
34 import com.google.android.setupcompat.util.WizardManagerHelper;
35 import com.google.android.setupdesign.span.LinkSpan;
36
37 public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
38
39     private static final String TAG = "FaceIntro";
40
41     private FaceManager mFaceManager;
42
43     @Override
44     protected void onCreate(Bundle savedInstanceState) {
45         super.onCreate(savedInstanceState);
46
47         mFaceManager = Utils.getFaceManagerOrNull(this);
48
49         mFooterBarMixin = getLayout().getMixin(FooterBarMixin.class);
50         if (WizardManagerHelper.isAnySetupWizard(getIntent())) {
51             mFooterBarMixin.setSecondaryButton(
52                     new FooterButton.Builder(this)
53                             .setText(R.string.skip_label)
54                             .setListener(this::onSkipButtonClick)
55                             .setButtonType(FooterButton.ButtonType.SKIP)
56                             .setTheme(R.style.SudGlifButton_Secondary)
57                             .build()
58             );
59         } else {
60             mFooterBarMixin.setSecondaryButton(
61                     new FooterButton.Builder(this)
62                             .setText(R.string.security_settings_face_enroll_introduction_cancel)
63                             .setListener(this::onCancelButtonClick)
64                             .setButtonType(FooterButton.ButtonType.CANCEL)
65                             .setTheme(R.style.SudGlifButton_Secondary)
66                             .build()
67             );
68         }
69
70         mFooterBarMixin.setPrimaryButton(
71                 new FooterButton.Builder(this)
72                         .setText(R.string.wizard_next)
73                         .setListener(this::onNextButtonClick)
74                         .setButtonType(FooterButton.ButtonType.NEXT)
75                         .setTheme(R.style.SudGlifButton_Primary)
76                         .build()
77         );
78     }
79
80     @Override
81     protected boolean isDisabledByAdmin() {
82         return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
83                 this, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId) != null;
84     }
85
86     @Override
87     protected int getLayoutResource() {
88         return R.layout.face_enroll_introduction;
89     }
90
91     @Override
92     protected int getHeaderResDisabledByAdmin() {
93         return R.string.security_settings_face_enroll_introduction_title_unlock_disabled;
94     }
95
96     @Override
97     protected int getHeaderResDefault() {
98         return R.string.security_settings_face_enroll_introduction_title;
99     }
100
101     @Override
102     protected int getDescriptionResDisabledByAdmin() {
103         return R.string.security_settings_face_enroll_introduction_message_unlock_disabled;
104     }
105
106     @Override
107     protected FooterButton getCancelButton() {
108         if (mFooterBarMixin != null) {
109             return mFooterBarMixin.getSecondaryButton();
110         }
111         return null;
112     }
113
114     @Override
115     protected FooterButton getNextButton() {
116         if (mFooterBarMixin != null) {
117             return mFooterBarMixin.getPrimaryButton();
118         }
119         return null;
120     }
121
122     @Override
123     protected TextView getErrorTextView() {
124         return findViewById(R.id.error_text);
125     }
126
127     @Override
128     protected int checkMaxEnrolled() {
129         if (mFaceManager != null) {
130             final int max = getResources().getInteger(
131                     com.android.internal.R.integer.config_faceMaxTemplatesPerUser);
132             final int numEnrolledFaces = mFaceManager.getEnrolledFaces(mUserId).size();
133             if (numEnrolledFaces >= max) {
134                 return R.string.face_intro_error_max;
135             }
136         } else {
137             return R.string.face_intro_error_unknown;
138         }
139         return 0;
140     }
141
142     @Override
143     protected long getChallenge() {
144         mFaceManager = Utils.getFaceManagerOrNull(this);
145         if (mFaceManager == null) {
146             return 0;
147         }
148         return mFaceManager.generateChallenge();
149     }
150
151     @Override
152     protected String getExtraKeyForBiometric() {
153         return ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE;
154     }
155
156     @Override
157     protected Intent getEnrollingIntent() {
158         Intent intent = new Intent(this, FaceEnrollEducation.class);
159         WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
160         return intent;
161     }
162
163     @Override
164     protected int getConfirmLockTitleResId() {
165         return R.string.security_settings_face_preference_title;
166     }
167
168     @Override
169     public int getMetricsCategory() {
170         return SettingsEnums.FACE_ENROLL_INTRO;
171     }
172
173     @Override
174     public void onClick(LinkSpan span) {
175         // TODO(b/110906762)
176     }
177 }