Files
app_Settings/src/com/android/settings/biometrics/face/FaceEnrollIntroduction.java
pastychang 1b1666855e Migrating to new footer button for fingerprint and face enrolling pages.
Bug: 120805516
Test: RunSettingsRoboTests
Change-Id: I89a5e3674b8ba9ec66945c03c9b783664eee214f
2018-12-19 23:24:48 +08:00

180 lines
5.9 KiB
Java

/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.settings.biometrics.face;
import android.app.admin.DevicePolicyManager;
import android.content.Intent;
import android.hardware.face.FaceManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.biometrics.BiometricEnrollIntroduction;
import com.android.settings.password.ChooseLockSettingsHelper;
import com.android.settingslib.RestrictedLockUtilsInternal;
import com.google.android.setupcompat.item.FooterButton;
import com.google.android.setupcompat.template.ButtonFooterMixin;
import com.google.android.setupdesign.span.LinkSpan;
public class FaceEnrollIntroduction extends BiometricEnrollIntroduction {
private static final String TAG = "FaceIntro";
private FaceManager mFaceManager;
private FaceEnrollAccessibilityToggle mSwitchVision;
private FaceEnrollAccessibilityToggle mSwitchDiversity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mFaceManager = Utils.getFaceManagerOrNull(this);
final LinearLayout accessibilityLayout = findViewById(R.id.accessibility_layout);
final Button accessibilityButton = findViewById(R.id.accessibility_button);
accessibilityButton.setOnClickListener(view -> {
accessibilityButton.setVisibility(View.INVISIBLE);
accessibilityLayout.setVisibility(View.VISIBLE);
});
mSwitchVision = findViewById(R.id.toggle_vision);
mSwitchDiversity = findViewById(R.id.toggle_diversity);
mButtonFooterMixin = getLayout().getMixin(ButtonFooterMixin.class);
mButtonFooterMixin.setSecondaryButton(
new FooterButton(
this,
R.string.security_settings_face_enroll_introduction_cancel,
this::onCancelButtonClick,
FooterButton.ButtonType.SKIP,
R.style.SuwGlifButton_Secondary)
);
mButtonFooterMixin.setPrimaryButton(
new FooterButton(
this,
R.string.wizard_next,
this::onNextButtonClick,
FooterButton.ButtonType.NEXT,
R.style.SuwGlifButton_Primary)
);
}
@Override
protected boolean isDisabledByAdmin() {
return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
this, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId) != null;
}
@Override
protected int getLayoutResource() {
return R.layout.face_enroll_introduction;
}
@Override
protected int getHeaderResDisabledByAdmin() {
return R.string.security_settings_face_enroll_introduction_title_unlock_disabled;
}
@Override
protected int getHeaderResDefault() {
return R.string.security_settings_face_enroll_introduction_title;
}
@Override
protected int getDescriptionResDisabledByAdmin() {
return R.string.security_settings_fingerprint_enroll_introduction_message_unlock_disabled;
}
@Override
protected FooterButton getCancelButton() {
if (mButtonFooterMixin != null) {
return mButtonFooterMixin.getSecondaryButton();
}
return null;
}
@Override
protected FooterButton getNextButton() {
if (mButtonFooterMixin != null) {
return mButtonFooterMixin.getPrimaryButton();
}
return null;
}
@Override
protected TextView getErrorTextView() {
return findViewById(R.id.error_text);
}
@Override
protected int checkMaxEnrolled() {
if (mFaceManager != null) {
final int max = getResources().getInteger(
com.android.internal.R.integer.config_faceMaxTemplatesPerUser);
final int numEnrolledFaces = mFaceManager.getEnrolledFaces(mUserId).size();
if (numEnrolledFaces >= max) {
return R.string.face_intro_error_max;
}
} else {
return R.string.face_intro_error_unknown;
}
return 0;
}
@Override
protected long getChallenge() {
mFaceManager = Utils.getFaceManagerOrNull(this);
if (mFaceManager == null) {
return 0;
}
return mFaceManager.generateChallenge();
}
@Override
protected String getExtraKeyForBiometric() {
return ChooseLockSettingsHelper.EXTRA_KEY_FOR_FACE;
}
@Override
protected Intent getEnrollingIntent() {
final Intent intent = new Intent(this, FaceEnrollEnrolling.class);
intent.putExtra(EXTRA_KEY_REQUIRE_VISION, mSwitchVision.isChecked());
intent.putExtra(EXTRA_KEY_REQUIRE_DIVERSITY, mSwitchDiversity.isChecked());
return intent;
}
@Override
protected int getConfirmLockTitleResId() {
return R.string.security_settings_face_preference_title;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.FACE_ENROLL_INTRO;
}
@Override
public void onClick(LinkSpan span) {
// TODO(b/110906762)
}
}