1 /* 2 * Copyright (C) 2023 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.privatespace.onelock; 18 19 import android.content.Context; 20 import android.os.UserHandle; 21 import android.util.Log; 22 23 import androidx.preference.Preference; 24 25 import com.android.settings.R; 26 import com.android.settings.Utils; 27 import com.android.settings.biometrics.combination.CombinedBiometricStatusPreferenceController; 28 import com.android.settings.privatespace.PrivateSpaceMaintainer; 29 import com.android.settingslib.core.lifecycle.Lifecycle; 30 31 /** Represents the preference controller to enroll biometrics for private space lock. */ 32 public class FaceFingerprintUnlockController extends CombinedBiometricStatusPreferenceController { 33 private static final String TAG = "PSBiometricCtrl"; 34 private static final String KEY_SET_UNSET_FACE_FINGERPRINT = "private_space_biometrics"; 35 private final int mProfileUserId; 36 FaceFingerprintUnlockController(Context context, Lifecycle lifecycle)37 public FaceFingerprintUnlockController(Context context, Lifecycle lifecycle) { 38 super(context, KEY_SET_UNSET_FACE_FINGERPRINT, lifecycle); 39 mProfileUserId = getUserId(); 40 } 41 isUserSupported()42 protected boolean isUserSupported() { 43 return android.os.Flags.allowPrivateProfile() 44 && android.multiuser.Flags.enableBiometricsToUnlockPrivateSpace() 45 && android.multiuser.Flags.enablePrivateSpaceFeatures() 46 && mProfileUserId != UserHandle.USER_NULL; 47 } 48 49 @Override getUserId()50 protected int getUserId() { 51 UserHandle privateProfileHandle = 52 PrivateSpaceMaintainer.getInstance(mContext).getPrivateProfileHandle(); 53 if (privateProfileHandle != null) { 54 return privateProfileHandle.getIdentifier(); 55 } else { 56 Log.e(TAG, "Private profile user handle is not expected to be null."); 57 } 58 return UserHandle.USER_NULL; 59 } 60 61 @Override getPreferenceKey()62 public String getPreferenceKey() { 63 return KEY_SET_UNSET_FACE_FINGERPRINT; 64 } 65 66 @Override getSettingsClassName()67 protected String getSettingsClassName() { 68 return mCombinedBiometricStatusUtils.getPrivateProfileSettingsClassName(); 69 } 70 71 @Override updateState(Preference preference)72 public void updateState(Preference preference) { 73 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileUserId)) { 74 super.updateState(preference); 75 preference.setEnabled(true); 76 } else { 77 Utils.removeEnrolledFaceForUser(mContext, getUserId()); 78 Utils.removeEnrolledFingerprintForUser(mContext, getUserId()); 79 preference.setSummary( 80 mContext.getString(R.string.lock_settings_profile_unified_summary)); 81 preference.setEnabled(false); 82 } 83 } 84 } 85