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.settingslib.RestrictedLockUtils.EnforcedAdmin; 30 import com.android.settingslib.RestrictedLockUtilsInternal; 31 32 /** 33 * Utilities for face details shared between Security Settings and Safety Center. 34 */ 35 public class FaceStatusUtils { 36 37 private final int mUserId; 38 private final Context mContext; 39 private final FaceManager mFaceManager; 40 FaceStatusUtils(Context context, FaceManager faceManager, int userId)41 public FaceStatusUtils(Context context, FaceManager faceManager, int userId) { 42 mContext = context; 43 mFaceManager = faceManager; 44 mUserId = userId; 45 } 46 47 /** 48 * Returns whether the face settings entity should be shown. 49 */ isAvailable()50 public boolean isAvailable() { 51 return !Utils.isMultipleBiometricsSupported(mContext) && Utils.hasFaceHardware(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_FACE); 62 } 63 64 /** 65 * Returns the title of face settings entity. 66 */ getTitle()67 public String getTitle() { 68 UserManager userManager = mContext.getSystemService(UserManager.class); 69 if (userManager != null && userManager.isProfile()) { 70 return mContext.getString( 71 Utils.isPrivateProfile(mUserId, mContext) 72 ? R.string.private_space_face_unlock_title 73 : R.string.security_settings_face_profile_preference_title); 74 } else { 75 return mContext.getString(R.string.security_settings_face_preference_title); 76 } 77 } 78 79 /** 80 * Returns the summary of face settings entity. 81 */ getSummary()82 public String getSummary() { 83 if (shouldShowDisabledByAdminStr()) { 84 return mContext.getString( 85 com.android.settingslib.widget.restricted.R.string.disabled_by_admin); 86 } else { 87 return mContext.getResources().getString(hasEnrolled() 88 ? R.string.security_settings_face_preference_summary 89 : R.string.security_settings_face_preference_summary_none); 90 } 91 } 92 93 /** 94 * Returns the class name of the Settings page corresponding to face settings. 95 */ getSettingsClassName()96 public String getSettingsClassName() { 97 return hasEnrolled() ? Settings.FaceSettingsInternalActivity.class.getName() 98 : FaceEnrollIntroductionInternal.class.getName(); 99 } 100 101 /** 102 * Returns whether at least one face template has been enrolled. 103 */ hasEnrolled()104 public boolean hasEnrolled() { 105 return mFaceManager.hasEnrolledTemplates(mUserId); 106 } 107 108 /** 109 * Indicates if the face feature is enabled or disabled by the Device Admin. 110 */ shouldShowDisabledByAdminStr()111 private boolean shouldShowDisabledByAdminStr() { 112 return RestrictedLockUtilsInternal.checkIfKeyguardFeaturesDisabled( 113 mContext, DevicePolicyManager.KEYGUARD_DISABLE_FACE, mUserId) != null; 114 } 115 } 116