1 /* 2 * Copyright (C) 2022 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 import android.os.UserManager; 23 24 import com.android.settings.R; 25 import com.android.settings.Utils; 26 import com.android.settings.biometrics.ParentalControlsUtils; 27 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; 28 import com.android.settingslib.utils.StringUtil; 29 30 /** 31 * Utilities for fingerprint details shared between Security Settings and Safety Center. 32 */ 33 public class FingerprintStatusUtils { 34 35 private final int mUserId; 36 private final Context mContext; 37 private final FingerprintManager mFingerprintManager; 38 FingerprintStatusUtils(Context context, FingerprintManager fingerprintManager, int userId)39 public FingerprintStatusUtils(Context context, FingerprintManager fingerprintManager, 40 int userId) { 41 mContext = context; 42 mFingerprintManager = fingerprintManager; 43 mUserId = userId; 44 } 45 46 /** 47 * Returns whether the fingerprint settings entity should be shown. 48 */ isAvailable()49 public boolean isAvailable() { 50 return !Utils.isMultipleBiometricsSupported(mContext) 51 && Utils.hasFingerprintHardware(mContext); 52 } 53 54 /** 55 * Returns the {@link EnforcedAdmin} if parental consent is required to change face settings. 56 * 57 * @return null if face settings does not require a parental consent. 58 */ getDisablingAdmin()59 public EnforcedAdmin getDisablingAdmin() { 60 return ParentalControlsUtils.parentConsentRequired( 61 mContext, BiometricAuthenticator.TYPE_FINGERPRINT); 62 } 63 /** 64 * Returns the title of fingerprint settings entity. 65 */ getTitle()66 public String getTitle() { 67 UserManager userManager = mContext.getSystemService(UserManager.class); 68 if (userManager != null && userManager.isProfile()) { 69 return mContext.getString(R.string.security_settings_work_fingerprint_preference_title); 70 } else { 71 return mContext.getString(R.string.security_settings_fingerprint_preference_title); 72 } 73 } 74 75 /** 76 * Returns the summary of fingerprint settings entity. 77 */ getSummary()78 public String getSummary() { 79 if (hasEnrolled()) { 80 final int numEnrolled = mFingerprintManager.getEnrolledFingerprints(mUserId).size(); 81 return StringUtil.getIcuPluralsString(mContext, numEnrolled, 82 R.string.security_settings_fingerprint_preference_summary); 83 } else { 84 return mContext.getString( 85 R.string.security_settings_fingerprint_preference_summary_none); 86 } 87 } 88 89 /** 90 * Returns the class name of the Settings page corresponding to fingerprint settings. 91 */ getSettingsClassName()92 public String getSettingsClassName() { 93 return FingerprintSettings.class.getName(); 94 } 95 96 /** 97 * Returns whether at least one fingerprint has been enrolled. 98 */ hasEnrolled()99 public boolean hasEnrolled() { 100 return mFingerprintManager.hasEnrolledFingerprints(mUserId); 101 } 102 } 103