• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static android.provider.Settings.Secure.BIOMETRIC_KEYGUARD_ENABLED;
19 
20 import android.app.admin.DevicePolicyManager;
21 import android.content.Context;
22 import android.provider.Settings;
23 
24 import com.android.settings.Utils;
25 import com.android.settings.core.TogglePreferenceController;
26 import com.android.settingslib.RestrictedLockUtils;
27 import com.android.settingslib.RestrictedLockUtilsInternal;
28 
29 /**
30  * Preference controller that controls whether the biometrics authentication to unlock the device.
31  */
32 public class BiometricSettingsKeyguardPreferenceController extends TogglePreferenceController {
33     private static final int ON = 1;
34     private static final int OFF = 0;
35     private static final int DEFAULT = ON;
36 
37     private int mUserId;
38 
BiometricSettingsKeyguardPreferenceController(Context context, String key)39     public BiometricSettingsKeyguardPreferenceController(Context context, String key) {
40         super(context, key);
41     }
42 
getRestrictingAdmin()43     protected RestrictedLockUtils.EnforcedAdmin getRestrictingAdmin() {
44         return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled(mContext,
45                 DevicePolicyManager.KEYGUARD_DISABLE_BIOMETRICS, mUserId);
46     }
47 
setUserId(int userId)48     public void setUserId(int userId) {
49         mUserId = userId;
50     }
51 
52     @Override
isChecked()53     public boolean isChecked() {
54         return Settings.Secure.getIntForUser(mContext.getContentResolver(),
55                 BIOMETRIC_KEYGUARD_ENABLED, DEFAULT, mUserId) == ON;
56     }
57 
58     @Override
setChecked(boolean isChecked)59     public boolean setChecked(boolean isChecked) {
60         return Settings.Secure.putIntForUser(mContext.getContentResolver(),
61                 BIOMETRIC_KEYGUARD_ENABLED, isChecked ? ON : OFF, mUserId);
62     }
63 
64     @Override
getAvailabilityStatus()65     public int getAvailabilityStatus() {
66         if (!Utils.isMultipleBiometricsSupported(mContext)) {
67             return UNSUPPORTED_ON_DEVICE;
68         }
69         return getRestrictingAdmin() != null ? DISABLED_FOR_USER : AVAILABLE;
70     }
71 
72     @Override
isSliceable()73     public final boolean isSliceable() {
74         return false;
75     }
76 
77     @Override
getSliceHighlightMenuRes()78     public int getSliceHighlightMenuRes() {
79         // not needed since it's not sliceable
80         return NO_RES;
81     }
82 }
83