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.face; 18 19 import android.app.admin.DevicePolicyManager; 20 import android.content.Context; 21 import android.hardware.biometrics.BiometricAuthenticator; 22 import android.hardware.face.FaceManager; 23 import android.os.UserManager; 24 25 import com.android.settings.R; 26 import com.android.settings.Settings; 27 import com.android.settings.Utils; 28 import com.android.settings.biometrics.ParentalControlsUtils; 29 import com.android.settings.flags.Flags; 30 import com.android.settingslib.RestrictedLockUtils.EnforcedAdmin; 31 import com.android.settingslib.RestrictedLockUtilsInternal; 32 33 /** Utilities for face details shared between Security Settings and Safety Center. */ 34 public class FaceStatusUtils { 35 36 private final int mUserId; 37 private final Context mContext; 38 private final FaceManager mFaceManager; 39 FaceStatusUtils(Context context, FaceManager faceManager, int userId)40 public FaceStatusUtils(Context context, FaceManager faceManager, int userId) { 41 mContext = context; 42 mFaceManager = faceManager; 43 mUserId = userId; 44 } 45 46 /** Returns whether the face settings entity should be shown. */ isAvailable()47 public boolean isAvailable() { 48 return !Utils.isMultipleBiometricsSupported(mContext) && Utils.hasFaceHardware(mContext); 49 } 50 51 /** 52 * Returns the {@link EnforcedAdmin} if parental consent is required to change face settings. 53 * 54 * @return null if face settings does not require a parental consent. 55 */ getDisablingAdmin()56 public EnforcedAdmin getDisablingAdmin() { 57 return ParentalControlsUtils.parentConsentRequired( 58 mContext, BiometricAuthenticator.TYPE_FACE); 59 } 60 61 /** Returns the title of face settings entity. */ getTitle()62 public String getTitle() { 63 UserManager userManager = mContext.getSystemService(UserManager.class); 64 if (userManager != null && userManager.isProfile()) { 65 return mContext.getString( 66 Utils.isPrivateProfile(mUserId, mContext) 67 ? getPrivateSpaceTitle() 68 : getWorkProfileTitle()); 69 } else { 70 return mContext.getString(getRegularTitle()); 71 } 72 } 73 getPrivateSpaceTitle()74 private int getPrivateSpaceTitle() { 75 if (Flags.biometricsOnboardingEducation()) { 76 return R.string.private_space_face_unlock_title_new; 77 } 78 return R.string.private_space_face_unlock_title; 79 } 80 getWorkProfileTitle()81 private int getWorkProfileTitle() { 82 if (Flags.biometricsOnboardingEducation()) { 83 return R.string.security_settings_face_profile_preference_title_new; 84 } 85 return R.string.security_settings_face_profile_preference_title; 86 } 87 getRegularTitle()88 private int getRegularTitle() { 89 if (Flags.biometricsOnboardingEducation()) { 90 return R.string.security_settings_face_preference_title_new; 91 } 92 return R.string.security_settings_face_preference_title; 93 } 94 95 /** Returns the summary of face settings entity. */ getSummary()96 public String getSummary() { 97 if (shouldShowDisabledByAdminStr()) { 98 return mContext.getString( 99 com.android.settingslib.widget.restricted.R.string.disabled_by_admin); 100 } else { 101 int summaryNoneResId = Flags.biometricsOnboardingEducation() 102 ? R.string.security_settings_face_preference_summary_none_new 103 : R.string.security_settings_face_preference_summary_none; 104 return mContext.getResources() 105 .getString( 106 hasEnrolled() 107 ? R.string.security_settings_face_preference_summary 108 : summaryNoneResId); 109 } 110 } 111 112 /** Returns the class name of the Settings page corresponding to face settings. */ getSettingsClassName()113 public String getSettingsClassName() { 114 return hasEnrolled() 115 ? Settings.FaceSettingsInternalActivity.class.getName() 116 : FaceEnrollIntroductionInternal.class.getName(); 117 } 118 119 /** Returns whether at least one face template has been enrolled. */ hasEnrolled()120 public boolean hasEnrolled() { 121 return mFaceManager.hasEnrolledTemplates(mUserId); 122 } 123 124 /** Indicates if the face feature is enabled or disabled by the Device Admin. */ shouldShowDisabledByAdminStr()125 private boolean shouldShowDisabledByAdminStr() { 126 return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled( 127 mContext, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId) 128 != null; 129 } 130 } 131