• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin;
30 import com.android.settingslib.RestrictedSwitchPreference;
31 
32 public class FaceSettingsLockscreenBypassPreferenceController
33         extends FaceSettingsPreferenceController {
34 
35     @VisibleForTesting
36     protected FaceManager mFaceManager;
37     private UserManager mUserManager;
38 
FaceSettingsLockscreenBypassPreferenceController(Context context, String preferenceKey)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
isChecked()49     public boolean isChecked() {
50         if (!FaceSettings.isFaceHardwareDetected(mContext)) {
51             return false;
52         } else if (getRestrictingAdmin() != null) {
53             return false;
54         }
55         int defaultValue = mContext.getResources().getBoolean(
56                 com.android.internal.R.bool.config_faceAuthDismissesKeyguard) ? 1 : 0;
57         return Settings.Secure.getIntForUser(mContext.getContentResolver(),
58                 Settings.Secure.FACE_UNLOCK_DISMISSES_KEYGUARD, defaultValue, getUserId()) != 0;
59     }
60 
61     @Override
setChecked(boolean isChecked)62     public boolean setChecked(boolean isChecked) {
63         Settings.Secure.putInt(mContext.getContentResolver(),
64                 Settings.Secure.FACE_UNLOCK_DISMISSES_KEYGUARD, isChecked ? 1 : 0);
65         return true;
66     }
67 
68     @Override
updateState(Preference preference)69     public void updateState(Preference preference) {
70         EnforcedAdmin admin;
71         super.updateState(preference);
72         if (!FaceSettings.isFaceHardwareDetected(mContext)) {
73             preference.setEnabled(false);
74         } else if ((admin = getRestrictingAdmin()) != null) {
75             ((RestrictedSwitchPreference) preference).setDisabledByAdmin(admin);
76         } else if (!mFaceManager.hasEnrolledTemplates(getUserId())) {
77             preference.setEnabled(false);
78         } else {
79             preference.setEnabled(true);
80         }
81     }
82 
83     @Override
getAvailabilityStatus()84     public int getAvailabilityStatus() {
85         if (mUserManager.isManagedProfile(UserHandle.myUserId())) {
86             return UNSUPPORTED_ON_DEVICE;
87         }
88 
89         if (mFaceManager != null && mFaceManager.isHardwareDetected()) {
90             return mFaceManager.hasEnrolledTemplates(getUserId())
91                     ? AVAILABLE : DISABLED_DEPENDENT_SETTING;
92         } else {
93             return UNSUPPORTED_ON_DEVICE;
94         }
95     }
96 }
97