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.annotation.NonNull; 24 import androidx.lifecycle.Lifecycle; 25 import androidx.preference.Preference; 26 import androidx.preference.PreferenceScreen; 27 28 import com.android.settings.R; 29 import com.android.settings.Utils; 30 import com.android.settings.biometrics.combination.BiometricFaceStatusPreferenceController; 31 import com.android.settings.privatespace.PrivateSpaceMaintainer; 32 33 public class PrivateSpaceFacePreferenceController extends BiometricFaceStatusPreferenceController { 34 private static final String TAG = "PrivateSpaceFaceCtrl"; 35 PrivateSpaceFacePreferenceController(Context context, String key)36 public PrivateSpaceFacePreferenceController(Context context, String key) { 37 super(context, key); 38 } 39 PrivateSpaceFacePreferenceController(Context context, String key, Lifecycle lifecycle)40 public PrivateSpaceFacePreferenceController(Context context, String key, Lifecycle lifecycle) { 41 super(context, key, lifecycle); 42 } 43 44 @Override isUserSupported()45 protected boolean isUserSupported() { 46 return android.os.Flags.allowPrivateProfile() 47 && android.multiuser.Flags.enableBiometricsToUnlockPrivateSpace() 48 && android.multiuser.Flags.enablePrivateSpaceFeatures() 49 && getUserId() != UserHandle.USER_NULL; 50 } 51 52 @Override getUserId()53 protected int getUserId() { 54 UserHandle privateProfileHandle = 55 PrivateSpaceMaintainer.getInstance(mContext).getPrivateProfileHandle(); 56 if (privateProfileHandle != null) { 57 return privateProfileHandle.getIdentifier(); 58 } else { 59 Log.e(TAG, "Private profile user handle is not expected to be null."); 60 } 61 return UserHandle.USER_NULL; 62 } 63 64 @Override getAvailabilityStatus()65 public int getAvailabilityStatus() { 66 return android.os.Flags.allowPrivateProfile() 67 && android.multiuser.Flags.enableBiometricsToUnlockPrivateSpace() 68 && android.multiuser.Flags.enablePrivateSpaceFeatures() 69 ? AVAILABLE 70 : UNSUPPORTED_ON_DEVICE; 71 } 72 73 @Override updateState(@onNull Preference preference)74 public void updateState(@NonNull Preference preference) { 75 if (mLockPatternUtils.isSeparateProfileChallengeEnabled(getUserId())) { 76 super.updateState(preference); 77 preference.setEnabled(true); 78 } else { 79 Utils.removeEnrolledFaceForUser(mContext, getUserId()); 80 preference.setSummary( 81 mContext.getString(R.string.lock_settings_profile_unified_summary)); 82 preference.setEnabled(false); 83 } 84 } 85 86 @Override displayPreference(@onNull PreferenceScreen screen)87 public void displayPreference(@NonNull PreferenceScreen screen) { 88 super.displayPreference(screen); 89 Preference preference = screen.findPreference(getPreferenceKey()); 90 if (!Utils.isMultipleBiometricsSupported(mContext) 91 && Utils.isFaceNotConvenienceBiometric(mContext)) { 92 preference.setTitle(R.string.private_space_face_title); 93 } 94 } 95 } 96