OSDN Git Service

Updated Face Enroll Introduction
[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.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;
27
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;
33
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;
38
39 public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
40
41     private static final String TAG = "FaceIntro";
42
43     private FaceManager mFaceManager;
44
45     @Override
46     protected void onCreate(Bundle savedInstanceState) {
47         super.onCreate(savedInstanceState);
48
49         mFaceManager = Utils.getFaceManagerOrNull(this);
50
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)
59                             .build()
60             );
61         } else {
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)
68                             .build()
69             );
70         }
71
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)
78                         .build()
79         );
80     }
81
82     @Override
83     protected boolean isDisabledByAdmin() {
84         return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
85                 this, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId) != null;
86     }
87
88     @Override
89     protected int getLayoutResource() {
90         return R.layout.face_enroll_introduction;
91     }
92
93     @Override
94     protected int getHeaderResDisabledByAdmin() {
95         return R.string.security_settings_face_enroll_introduction_title_unlock_disabled;
96     }
97
98     @Override
99     protected int getHeaderResDefault() {
100         return R.string.security_settings_face_enroll_introduction_title;
101     }
102
103     @Override
104     protected int getDescriptionResDisabledByAdmin() {
105         return R.string.security_settings_face_enroll_introduction_message_unlock_disabled;
106     }
107
108     @Override
109     protected FooterButton getCancelButton() {
110         if (mFooterBarMixin != null) {
111             return mFooterBarMixin.getSecondaryButton();
112         }
113         return null;
114     }
115
116     @Override
117     protected FooterButton getNextButton() {
118         if (mFooterBarMixin != null) {
119             return mFooterBarMixin.getPrimaryButton();
120         }
121         return null;
122     }
123
124     @Override
125     protected TextView getErrorTextView() {
126         return findViewById(R.id.error_text);
127     }
128
129     @Override
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;
137             }
138         } else {
139             return R.string.face_intro_error_unknown;
140         }
141         return 0;
142     }
143
144     @Override
145     protected long getChallenge() {
146         mFaceManager = Utils.getFaceManagerOrNull(this);
147         if (mFaceManager == null) {
148             return 0;
149         }
150         return mFaceManager.generateChallenge();
151     }
152
153     @Override
154     protected String getExtraKeyForBiometric() {
155         return ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE;
156     }
157
158     @Override
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);
165
166         } else {
167             intent.setClass(this, FaceEnrollEnrolling.class);
168         }
169         WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
170         return intent;
171     }
172
173     @Override
174     protected int getConfirmLockTitleResId() {
175         return R.string.security_settings_face_preference_title;
176     }
177
178     @Override
179     public int getMetricsCategory() {
180         return SettingsEnums.FACE_ENROLL_INTRO;
181     }
182
183     @Override
184     public void onClick(LinkSpan span) {
185         // TODO(b/110906762)
186     }
187 }