• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.fingerprint;
18 
19 import android.content.Context;
20 import android.hardware.biometrics.BiometricAuthenticator;
21 import android.hardware.fingerprint.FingerprintManager;
22 
23 import androidx.annotation.Nullable;
24 import androidx.lifecycle.Lifecycle;
25 import androidx.lifecycle.LifecycleObserver;
26 import androidx.lifecycle.OnLifecycleEvent;
27 import androidx.preference.Preference;
28 import androidx.preference.PreferenceScreen;
29 
30 import com.android.internal.annotations.VisibleForTesting;
31 import com.android.settings.R;
32 import com.android.settings.Utils;
33 import com.android.settings.biometrics.BiometricStatusPreferenceController;
34 import com.android.settings.biometrics.ParentalControlsUtils;
35 import com.android.settingslib.RestrictedLockUtils;
36 import com.android.settingslib.RestrictedPreference;
37 
38 public class FingerprintStatusPreferenceController extends BiometricStatusPreferenceController
39         implements LifecycleObserver {
40 
41     private static final String KEY_FINGERPRINT_SETTINGS = "fingerprint_settings";
42 
43     protected final FingerprintManager mFingerprintManager;
44     @VisibleForTesting
45     RestrictedPreference mPreference;
46 
FingerprintStatusPreferenceController(Context context)47     public FingerprintStatusPreferenceController(Context context) {
48         this(context, KEY_FINGERPRINT_SETTINGS);
49     }
50 
FingerprintStatusPreferenceController(Context context, String key)51     public FingerprintStatusPreferenceController(Context context, String key) {
52         this(context, key, null /* lifecycle */);
53     }
54 
FingerprintStatusPreferenceController(Context context, Lifecycle lifecycle)55     public FingerprintStatusPreferenceController(Context context, Lifecycle lifecycle) {
56         this(context, KEY_FINGERPRINT_SETTINGS, lifecycle);
57     }
58 
FingerprintStatusPreferenceController(Context context, String key, Lifecycle lifecycle)59     public FingerprintStatusPreferenceController(Context context, String key, Lifecycle lifecycle) {
60         super(context, key);
61         mFingerprintManager = Utils.getFingerprintManagerOrNull(context);
62 
63         if (lifecycle != null) {
64             lifecycle.addObserver(this);
65         }
66     }
67 
68     @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)
onResume()69     public void onResume() {
70         updateStateInternal();
71     }
72 
73     @Override
displayPreference(PreferenceScreen screen)74     public void displayPreference(PreferenceScreen screen) {
75         super.displayPreference(screen);
76         mPreference = screen.findPreference(mPreferenceKey);
77     }
78 
79     @Override
isDeviceSupported()80     protected boolean isDeviceSupported() {
81         return !Utils.isMultipleBiometricsSupported(mContext)
82                 && Utils.hasFingerprintHardware(mContext);
83     }
84 
85     @Override
hasEnrolledBiometrics()86     protected boolean hasEnrolledBiometrics() {
87         return mFingerprintManager.hasEnrolledFingerprints(getUserId());
88     }
89 
90     @Override
updateState(Preference preference)91     public void updateState(Preference preference) {
92         super.updateState(preference);
93         updateStateInternal();
94     }
95 
updateStateInternal()96     private void updateStateInternal() {
97         updateStateInternal(ParentalControlsUtils.parentConsentRequired(
98                 mContext, BiometricAuthenticator.TYPE_FINGERPRINT));
99     }
100 
101     @VisibleForTesting
updateStateInternal(@ullable RestrictedLockUtils.EnforcedAdmin enforcedAdmin)102     void updateStateInternal(@Nullable RestrictedLockUtils.EnforcedAdmin enforcedAdmin) {
103         if (mPreference != null) {
104             mPreference.setDisabledByAdmin(enforcedAdmin);
105         }
106     }
107 
108     @Override
getSummaryTextEnrolled()109     protected String getSummaryTextEnrolled() {
110         final int numEnrolled = mFingerprintManager.getEnrolledFingerprints(getUserId()).size();
111         return mContext.getResources().getQuantityString(
112                 R.plurals.security_settings_fingerprint_preference_summary,
113                 numEnrolled, numEnrolled);
114     }
115 
116     @Override
getSummaryTextNoneEnrolled()117     protected String getSummaryTextNoneEnrolled() {
118         return mContext.getString(R.string.security_settings_fingerprint_preference_summary_none);
119     }
120 
121     @Override
getSettingsClassName()122     protected String getSettingsClassName() {
123         return FingerprintSettings.class.getName();
124     }
125 
126     @Override
getEnrollClassName()127     protected String getEnrollClassName() {
128         return FingerprintEnrollIntroduction.class.getName();
129     }
130 
131 }
132