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 static android.provider.Settings.Secure.FACE_UNLOCK_EDUCATION_INFO_DISPLAYED;
20 import static android.security.KeyStore.getApplicationContext;
22 import android.app.settings.SettingsEnums;
23 import android.content.ComponentName;
24 import android.content.Context;
25 import android.content.Intent;
26 import android.hardware.face.FaceManager;
27 import android.os.Bundle;
28 import android.os.Handler;
29 import android.os.UserHandle;
30 import android.provider.Settings;
31 import android.text.TextUtils;
32 import android.view.View;
33 import android.widget.Button;
34 import android.widget.CompoundButton;
36 import com.android.settings.R;
37 import com.android.settings.Utils;
38 import com.android.settings.biometrics.BiometricEnrollBase;
39 import com.android.settings.password.ChooseLockSettingsHelper;
41 import com.google.android.setupcompat.template.FooterBarMixin;
42 import com.google.android.setupcompat.template.FooterButton;
43 import com.google.android.setupcompat.util.WizardManagerHelper;
44 import com.google.android.setupdesign.view.IllustrationVideoView;
46 public class FaceEnrollEducation extends BiometricEnrollBase {
48 private static final String TAG = "FaceEducation";
49 private static final int ON = 1;
50 private static final int OFF = 0;
52 private static final long FACE_ENROLL_EDUCATION_DELAY = 16000;
54 private FaceManager mFaceManager;
55 private FaceEnrollAccessibilityToggle mSwitchDiversity;
57 private IllustrationVideoView mIllustrationNormal;
58 private View mIllustrationAccessibility;
59 private Handler mHandler;
61 private CompoundButton.OnCheckedChangeListener mSwitchDiversityListener =
62 new CompoundButton.OnCheckedChangeListener() {
64 public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
66 mIllustrationNormal.stop();
67 mIllustrationNormal.setVisibility(View.INVISIBLE);
68 mIllustrationAccessibility.setVisibility(View.VISIBLE);
70 mIllustrationNormal.setVisibility(View.VISIBLE);
71 mIllustrationNormal.start();
72 mIllustrationAccessibility.setVisibility(View.INVISIBLE);
78 protected void onCreate(Bundle savedInstanceState) {
79 super.onCreate(savedInstanceState);
80 setContentView(R.layout.face_enroll_education);
81 getLayout().setHeaderText(R.string.security_settings_face_enroll_education_title);
82 setTitle(R.string.security_settings_face_enroll_education_title);
83 mHandler = new Handler();
85 mFaceManager = Utils.getFaceManagerOrNull(this);
87 mIllustrationNormal = findViewById(R.id.illustration_normal);
88 mIllustrationAccessibility = findViewById(R.id.illustration_accessibility);
90 mFooterBarMixin = getLayout().getMixin(FooterBarMixin.class);
91 mFooterBarMixin.setSecondaryButton(
92 new FooterButton.Builder(this)
93 .setText(R.string.security_settings_face_enroll_enrolling_skip)
94 .setListener(this::onSkipButtonClick)
95 .setButtonType(FooterButton.ButtonType.SKIP)
96 .setTheme(R.style.SudGlifButton_Secondary)
100 final FooterButton footerButton = new FooterButton.Builder(this)
101 .setText(R.string.wizard_next)
102 .setListener(this::onNextButtonClick)
103 .setButtonType(FooterButton.ButtonType.NEXT)
104 .setTheme(R.style.SudGlifButton_Primary)
107 mFooterBarMixin.setPrimaryButton(footerButton);
108 final Context context = getApplicationContext();
109 final boolean didDisplayEdu = Settings.Secure.getIntForUser(context.getContentResolver(),
110 FACE_UNLOCK_EDUCATION_INFO_DISPLAYED, OFF, mUserId) == ON;
111 if (!didDisplayEdu) {
112 Settings.Secure.putIntForUser(context.getContentResolver(),
113 FACE_UNLOCK_EDUCATION_INFO_DISPLAYED, ON, mUserId);
114 footerButton.setEnabled(false);
115 mHandler.postDelayed(() -> {
116 footerButton.setEnabled(true);
117 }, FACE_ENROLL_EDUCATION_DELAY);
120 final Button accessibilityButton = findViewById(R.id.accessibility_button);
121 accessibilityButton.setOnClickListener(view -> {
122 footerButton.setEnabled(true);
123 mSwitchDiversity.setChecked(true);
124 accessibilityButton.setVisibility(View.GONE);
125 mSwitchDiversity.setVisibility(View.VISIBLE);
128 mSwitchDiversity = findViewById(R.id.toggle_diversity);
129 mSwitchDiversity.setListener(mSwitchDiversityListener);
133 protected void onResume() {
135 mSwitchDiversityListener.onCheckedChanged(mSwitchDiversity.getSwitch(),
136 mSwitchDiversity.isChecked());
140 protected void onNextButtonClick(View view) {
141 final Intent intent = new Intent();
142 if (mToken != null) {
143 intent.putExtra(ChooseLockSettingsHelper.EXTRA_KEY_CHALLENGE_TOKEN, mToken);
145 if (mUserId != UserHandle.USER_NULL) {
146 intent.putExtra(Intent.EXTRA_USER_ID, mUserId);
148 final String flattenedString = getString(R.string.config_face_enroll);
149 if (!TextUtils.isEmpty(flattenedString)) {
150 ComponentName componentName = ComponentName.unflattenFromString(flattenedString);
151 intent.setComponent(componentName);
153 intent.setClass(this, FaceEnrollEnrolling.class);
155 intent.putExtra(EXTRA_KEY_REQUIRE_DIVERSITY, !mSwitchDiversity.isChecked());
156 WizardManagerHelper.copyWizardManagerExtras(getIntent(), intent);
157 startActivityForResult(intent, BIOMETRIC_FIND_SENSOR_REQUEST);
160 protected void onSkipButtonClick(View view) {
161 setResult(RESULT_SKIP);
166 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
167 if (requestCode == BIOMETRIC_FIND_SENSOR_REQUEST) {
168 setResult(resultCode);
174 public int getMetricsCategory() {
175 return SettingsEnums.FACE_ENROLL_INTRO;