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.ComponentName;
22 import android.content.Intent;
23 import android.hardware.face.FaceManager;
24 import android.os.Bundle;
25 import android.text.TextUtils;
26 import android.widget.TextView;
28 import com.android.settings.R;
29 import com.android.settings.Utils;
30 import com.android.settings.biometrics.BiometricEnrollIntroduction;
31 import com.android.settings.password.ChooseLockSettingsHelper;
32 import com.android.settingslib.RestrictedLockUtilsInternal;
34 import com.google.android.setupcompat.template.FooterBarMixin;
35 import com.google.android.setupcompat.template.FooterButton;
36 import com.google.android.setupcompat.util.WizardManagerHelper;
37 import com.google.android.setupdesign.span.LinkSpan;
39 public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
41 private static final String TAG = "FaceIntro";
43 private FaceManager mFaceManager;
46 protected void onCreate(Bundle savedInstanceState) {
47 super.onCreate(savedInstanceState);
49 mFaceManager = Utils.getFaceManagerOrNull(this);
51 mFooterBarMixin = getLayout().getMixin(FooterBarMixin.class);
52 if (WizardManagerHelper.isAnySetupWizard(getIntent())) {
53 mFooterBarMixin.setSecondaryButton(
54 new FooterButton.Builder(this)
55 .setText(R.string.skip_label)
56 .setListener(this::onSkipButtonClick)
57 .setButtonType(FooterButton.ButtonType.SKIP)
58 .setTheme(R.style.SudGlifButton_Secondary)
62 mFooterBarMixin.setSecondaryButton(
63 new FooterButton.Builder(this)
64 .setText(R.string.security_settings_face_enroll_introduction_cancel)
65 .setListener(this::onCancelButtonClick)
66 .setButtonType(FooterButton.ButtonType.CANCEL)
67 .setTheme(R.style.SudGlifButton_Secondary)
72 mFooterBarMixin.setPrimaryButton(
73 new FooterButton.Builder(this)
74 .setText(R.string.wizard_next)
75 .setListener(this::onNextButtonClick)
76 .setButtonType(FooterButton.ButtonType.NEXT)
77 .setTheme(R.style.SudGlifButton_Primary)
83 protected boolean isDisabledByAdmin() {
84 return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
85 this, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId) != null;
89 protected int getLayoutResource() {
90 return R.layout.face_enroll_introduction;
94 protected int getHeaderResDisabledByAdmin() {
95 return R.string.security_settings_face_enroll_introduction_title_unlock_disabled;
99 protected int getHeaderResDefault() {
100 return R.string.security_settings_face_enroll_introduction_title;
104 protected int getDescriptionResDisabledByAdmin() {
105 return R.string.security_settings_face_enroll_introduction_message_unlock_disabled;
109 protected FooterButton getCancelButton() {
110 if (mFooterBarMixin != null) {
111 return mFooterBarMixin.getSecondaryButton();
117 protected FooterButton getNextButton() {
118 if (mFooterBarMixin != null) {
119 return mFooterBarMixin.getPrimaryButton();
125 protected TextView getErrorTextView() {
126 return findViewById(R.id.error_text);
130 protected int checkMaxEnrolled() {
131 if (mFaceManager != null) {
132 final int max = getResources().getInteger(
133 com.android.internal.R.integer.config_faceMaxTemplatesPerUser);
134 final int numEnrolledFaces = mFaceManager.getEnrolledFaces(mUserId).size();
135 if (numEnrolledFaces >= max) {
136 return R.string.face_intro_error_max;
139 return R.string.face_intro_error_unknown;
145 protected long getChallenge() {
146 mFaceManager = Utils.getFaceManagerOrNull(this);
147 if (mFaceManager == null) {
150 return mFaceManager.generateChallenge();
154 protected String getExtraKeyForBiometric() {
155 return ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE;
159 protected Intent getEnrollingIntent() {
160 final String flattenedString = getString(R.string.config_face_enroll);
161 final Intent intent = new Intent();
162 if (!TextUtils.isEmpty(flattenedString)) {
163 ComponentName componentName = ComponentName.unflattenFromString(flattenedString);
164 intent.setComponent(componentName);
167 intent.setClass(this, FaceEnrollEnrolling.class);
169 WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
174 protected int getConfirmLockTitleResId() {
175 return R.string.security_settings_face_preference_title;
179 public int getMetricsCategory() {
180 return SettingsEnums.FACE_ENROLL_INTRO;
184 public void onClick(LinkSpan span) {