1 /*
2  * Copyright (C) 2021 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 package com.android.settings.biometrics.combination;
17 
18 import android.app.admin.DevicePolicyManager;
19 import android.content.Context;
20 
21 import androidx.lifecycle.Lifecycle;
22 import androidx.preference.Preference;
23 
24 import com.android.settings.Utils;
25 import com.android.settings.biometrics.face.FaceStatusPreferenceController;
26 import com.android.settingslib.RestrictedLockUtils;
27 import com.android.settingslib.RestrictedLockUtilsInternal;
28 import com.android.settingslib.RestrictedPreference;
29 
30 /**
31  * Preference controller for face settings within the biometrics settings page, that controls the
32  * ability to unlock the phone with face authentication.
33  */
34 public class BiometricFaceStatusPreferenceController extends FaceStatusPreferenceController {
35 
BiometricFaceStatusPreferenceController(Context context, String key)36     public BiometricFaceStatusPreferenceController(Context context, String key) {
37         super(context, key, null /* lifecycle */);
38     }
39 
BiometricFaceStatusPreferenceController( Context context, String key, Lifecycle lifecycle)40     public BiometricFaceStatusPreferenceController(
41             Context context, String key, Lifecycle lifecycle) {
42         super(context, key, lifecycle);
43     }
44 
45     @Override
updateState(Preference preference)46     public void updateState(Preference preference) {
47         super.updateState(preference);
48         final boolean isFaceEnrolled = mFaceStatusUtils.hasEnrolled();
49         final RestrictedLockUtils.EnforcedAdmin admin =
50                 RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(
51                         mContext, DevicePolicyManager.KEYGUARD_DISABLE_FACE, getUserId());
52         if (admin != null && !isFaceEnrolled) {
53             ((RestrictedPreference) preference).setDisabledByAdmin(admin);
54         } else {
55             preference.setEnabled(true);
56         }
57     }
58 
59     @Override
isDeviceSupported()60     protected boolean isDeviceSupported() {
61         return Utils.isMultipleBiometricsSupported(mContext) && isHardwareSupported();
62     }
63 
64     @Override
isHardwareSupported()65     protected boolean isHardwareSupported() {
66         return Utils.hasFaceHardware(mContext);
67     }
68 }
69