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; 18 19 import android.content.Context; 20 import android.os.UserHandle; 21 import android.os.UserManager; 22 import android.text.TextUtils; 23 24 import androidx.preference.Preference; 25 26 import com.android.internal.widget.LockPatternUtils; 27 import com.android.settings.Utils; 28 import com.android.settings.core.BasePreferenceController; 29 import com.android.settings.overlay.FeatureFactory; 30 31 public abstract class BiometricStatusPreferenceController extends BasePreferenceController { 32 33 protected final UserManager mUm; 34 protected final LockPatternUtils mLockPatternUtils; 35 36 private final int mUserId = UserHandle.myUserId(); 37 protected final int mProfileChallengeUserId; 38 39 private final BiometricNavigationUtils mBiometricNavigationUtils; 40 41 /** 42 * @return true if the manager is not null and the hardware is detected. 43 */ isDeviceSupported()44 protected abstract boolean isDeviceSupported(); 45 46 /** 47 * @return the summary text. 48 */ getSummaryText()49 protected abstract String getSummaryText(); 50 51 /** 52 * @return the class name for the settings page. 53 */ getSettingsClassName()54 protected abstract String getSettingsClassName(); 55 BiometricStatusPreferenceController(Context context, String key)56 public BiometricStatusPreferenceController(Context context, String key) { 57 super(context, key); 58 mUm = (UserManager) context.getSystemService(Context.USER_SERVICE); 59 mLockPatternUtils = FeatureFactory.getFactory(context) 60 .getSecurityFeatureProvider() 61 .getLockPatternUtils(context); 62 mProfileChallengeUserId = Utils.getManagedProfileId(mUm, mUserId); 63 mBiometricNavigationUtils = new BiometricNavigationUtils(getUserId()); 64 } 65 66 @Override getAvailabilityStatus()67 public int getAvailabilityStatus() { 68 if (!isDeviceSupported()) { 69 return UNSUPPORTED_ON_DEVICE; 70 } 71 if (isUserSupported()) { 72 return AVAILABLE; 73 } else { 74 return DISABLED_FOR_USER; 75 } 76 } 77 78 @Override updateState(Preference preference)79 public void updateState(Preference preference) { 80 if (!isAvailable()) { 81 if (preference != null) { 82 preference.setVisible(false); 83 } 84 return; 85 } else { 86 preference.setVisible(true); 87 } 88 preference.setSummary(getSummaryText()); 89 } 90 91 @Override handlePreferenceTreeClick(Preference preference)92 public boolean handlePreferenceTreeClick(Preference preference) { 93 if (!TextUtils.equals(preference.getKey(), getPreferenceKey())) { 94 return super.handlePreferenceTreeClick(preference); 95 } 96 97 return mBiometricNavigationUtils.launchBiometricSettings( 98 preference.getContext(), getSettingsClassName(), preference.getExtras()); 99 } 100 getUserId()101 protected int getUserId() { 102 return mUserId; 103 } 104 isUserSupported()105 protected boolean isUserSupported() { 106 return true; 107 } 108 } 109