2 * Copyright (C) 2019 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.content.Context;
20 import android.content.pm.PackageManager;
21 import android.hardware.face.FaceManager;
22 import android.os.UserHandle;
23 import android.os.UserManager;
24 import android.provider.Settings;
26 import androidx.preference.Preference;
28 import com.android.internal.annotations.VisibleForTesting;
30 public class FaceSettingsLockscreenBypassPreferenceController
31 extends FaceSettingsPreferenceController {
33 static final String KEY = "security_lockscreen_bypass";
36 protected FaceManager mFaceManager;
37 private UserManager mUserManager;
39 public FaceSettingsLockscreenBypassPreferenceController(Context context, String preferenceKey) {
40 super(context, preferenceKey);
41 if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_FACE)) {
42 mFaceManager = context.getSystemService(FaceManager.class);
45 mUserManager = context.getSystemService(UserManager.class);
49 public boolean isChecked() {
50 boolean defaultValue = mContext.getResources().getBoolean(
51 com.android.internal.R.bool.config_faceAuthDismissesKeyguard);
52 return Settings.Secure.getInt(mContext.getContentResolver(),
53 Settings.Secure.FACE_UNLOCK_DISMISSES_KEYGUARD, defaultValue ? 1 : 0) != 0;
57 public boolean setChecked(boolean isChecked) {
58 Settings.Secure.putInt(mContext.getContentResolver(),
59 Settings.Secure.FACE_UNLOCK_DISMISSES_KEYGUARD, isChecked ? 1 : 0);
64 public void updateState(Preference preference) {
65 super.updateState(preference);
66 if (!FaceSettings.isAvailable(mContext)) {
67 preference.setEnabled(false);
68 } else if (adminDisabled()) {
69 preference.setEnabled(false);
70 } else if (!mFaceManager.hasEnrolledTemplates(getUserId())) {
71 preference.setEnabled(false);
73 preference.setEnabled(true);
78 public int getAvailabilityStatus() {
79 if (mUserManager.isManagedProfile(UserHandle.myUserId())) {
80 return UNSUPPORTED_ON_DEVICE;
83 if (mFaceManager != null && mFaceManager.isHardwareDetected()) {
84 return mFaceManager.hasEnrolledTemplates() ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
86 return UNSUPPORTED_ON_DEVICE;