OSDN Git Service

Merge "Revert "Settings(wifi): Allow mainline wifi stack to use network request dialog""
[android-x86/packages-apps-Settings.git] / src / com / android / settings / biometrics / face / FaceSettingsLockscreenBypassPreferenceController.java
1 /*
2  * Copyright (C) 2019 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.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;
25
26 import androidx.preference.Preference;
27
28 import com.android.internal.annotations.VisibleForTesting;
29
30 public class FaceSettingsLockscreenBypassPreferenceController
31         extends FaceSettingsPreferenceController {
32
33     static final String KEY = "security_lockscreen_bypass";
34
35     @VisibleForTesting
36     protected FaceManager mFaceManager;
37     private UserManager mUserManager;
38
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);
43         }
44
45         mUserManager = context.getSystemService(UserManager.class);
46     }
47
48     @Override
49     public boolean isChecked() {
50         int defaultValue = mContext.getResources().getBoolean(
51                 com.android.internal.R.bool.config_faceAuthDismissesKeyguard) ? 1 : 0;
52         return Settings.Secure.getIntForUser(mContext.getContentResolver(),
53                 Settings.Secure.FACE_UNLOCK_DISMISSES_KEYGUARD, defaultValue, getUserId()) != 0;
54     }
55
56     @Override
57     public boolean setChecked(boolean isChecked) {
58         Settings.Secure.putInt(mContext.getContentResolver(),
59                 Settings.Secure.FACE_UNLOCK_DISMISSES_KEYGUARD, isChecked ? 1 : 0);
60         return true;
61     }
62
63     @Override
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);
72         } else {
73             preference.setEnabled(true);
74         }
75     }
76
77     @Override
78     public int getAvailabilityStatus() {
79         if (mUserManager.isManagedProfile(UserHandle.myUserId())) {
80             return UNSUPPORTED_ON_DEVICE;
81         }
82
83         if (mFaceManager != null && mFaceManager.isHardwareDetected()) {
84             return mFaceManager.hasEnrolledTemplates(getUserId())
85                     ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
86         } else {
87             return UNSUPPORTED_ON_DEVICE;
88         }
89     }
90 }