2 * Copyright (C) 2018 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
17 package com.android.settings.biometrics.face;
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;
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;
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;
37 public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
39 private static final String TAG = "FaceIntro";
41 private FaceManager mFaceManager;
44 protected void onCreate(Bundle savedInstanceState) {
45 super.onCreate(savedInstanceState);
47 mFaceManager = Utils.getFaceManagerOrNull(this);
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)
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)
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)
81 protected boolean isDisabledByAdmin() {
82 return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
83 this, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId) != null;
87 protected int getLayoutResource() {
88 return R.layout.face_enroll_introduction;
92 protected int getHeaderResDisabledByAdmin() {
93 return R.string.security_settings_face_enroll_introduction_title_unlock_disabled;
97 protected int getHeaderResDefault() {
98 return R.string.security_settings_face_enroll_introduction_title;
102 protected int getDescriptionResDisabledByAdmin() {
103 return R.string.security_settings_face_enroll_introduction_message_unlock_disabled;
107 protected FooterButton getCancelButton() {
108 if (mFooterBarMixin != null) {
109 return mFooterBarMixin.getSecondaryButton();
115 protected FooterButton getNextButton() {
116 if (mFooterBarMixin != null) {
117 return mFooterBarMixin.getPrimaryButton();
123 protected TextView getErrorTextView() {
124 return findViewById(R.id.error_text);
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;
137 return R.string.face_intro_error_unknown;
143 protected long getChallenge() {
144 mFaceManager = Utils.getFaceManagerOrNull(this);
145 if (mFaceManager == null) {
148 return mFaceManager.generateChallenge();
152 protected String getExtraKeyForBiometric() {
153 return ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE;
157 protected Intent getEnrollingIntent() {
158 Intent intent = new Intent(this, FaceEnrollEducation.class);
159 WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
164 protected int getConfirmLockTitleResId() {
165 return R.string.security_settings_face_preference_title;
169 public int getMetricsCategory() {
170 return SettingsEnums.FACE_ENROLL_INTRO;
174 public void onClick(LinkSpan span) {