Add Biometrics settings inside private space One Lock settings

This includes below changes:
- Add Biometrics preferernce in Private Space One Lock settings page
- Face and Fingerprint enrolment for Private profile
- Feature is behind flag android.multiuser.enable_biometrics_to_unlock_private_space

Screenshots:
go/ss/9cWZRAuvGGW7gMm.png
go/ss/B3NoFbL3KbpSzeN.png
go/ss/7xH3DLi9d6Lu2mR.png
go/ss/8WBEgKychWpduXg.png
go/ss/8pmPGshd9aiPvVC.png
go/ss/AFPBPbiaBBvTj3p.png
go/ss/3fE4XKLLUdP8LmF.png

Bug: 308862923
Test: atest CombinedBiometricStatusUtilsTest, atest FaceFingerprintUnlockControllerTest
Change-Id: I1853107a4df4fc97db53c97524c6d44a4f554e37
diff --git a/src/com/android/settings/Settings.java b/src/com/android/settings/Settings.java
index 86baba4..01ccbb2 100644
--- a/src/com/android/settings/Settings.java
+++ b/src/com/android/settings/Settings.java
@@ -57,7 +57,9 @@
     public static class CombinedBiometricProfileSettingsActivity extends SettingsActivity { /* empty */ }
     public static class TetherSettingsActivity extends SettingsActivity { /* empty */ }
     public static class WifiTetherSettingsActivity extends SettingsActivity { /* empty */ }
-
+    public static class PrivateSpaceBiometricSettingsActivity extends SettingsActivity {
+        /* empty */
+    }
     public static class VpnSettingsActivity extends SettingsActivity { /* empty */ }
     /** Activity for Data saver settings. */
     public static class DataSaverSummaryActivity extends SettingsActivity { /* empty */ }
diff --git a/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtils.java b/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtils.java
index 8cc6bc4..2cd239e 100644
--- a/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtils.java
+++ b/src/com/android/settings/biometrics/combination/CombinedBiometricStatusUtils.java
@@ -159,4 +159,12 @@
     public String getProfileSettingsClassName() {
         return Settings.CombinedBiometricProfileSettingsActivity.class.getName();
     }
+
+    /**
+     * Returns the class name of the Settings page corresponding to combined biometric settings for
+     * Private profile.
+     */
+    public String getPrivateProfileSettingsClassName() {
+        return Settings.PrivateSpaceBiometricSettingsActivity.class.getName();
+    }
 }
diff --git a/src/com/android/settings/core/gateway/SettingsGateway.java b/src/com/android/settings/core/gateway/SettingsGateway.java
index d68f2c8..69a9fb3 100644
--- a/src/com/android/settings/core/gateway/SettingsGateway.java
+++ b/src/com/android/settings/core/gateway/SettingsGateway.java
@@ -165,6 +165,7 @@
 import com.android.settings.print.PrintSettingsFragment;
 import com.android.settings.privacy.PrivacyControlsFragment;
 import com.android.settings.privacy.PrivacyDashboardFragment;
+import com.android.settings.privatespace.onelock.PrivateSpaceBiometricSettings;
 import com.android.settings.regionalpreferences.RegionalPreferencesEntriesFragment;
 import com.android.settings.safetycenter.MoreSecurityPrivacyFragment;
 import com.android.settings.security.LockscreenDashboardFragment;
@@ -264,6 +265,7 @@
             FingerprintSettingsV2Fragment.class.getName(),
             CombinedBiometricSettings.class.getName(),
             CombinedBiometricProfileSettings.class.getName(),
+            PrivateSpaceBiometricSettings.class.getName(),
             SwipeToNotificationSettings.class.getName(),
             DoubleTapPowerSettings.class.getName(),
             DoubleTapScreenSettings.class.getName(),
diff --git a/src/com/android/settings/privatespace/onelock/FaceFingerprintUnlockController.java b/src/com/android/settings/privatespace/onelock/FaceFingerprintUnlockController.java
index e130e4d..271a219 100644
--- a/src/com/android/settings/privatespace/onelock/FaceFingerprintUnlockController.java
+++ b/src/com/android/settings/privatespace/onelock/FaceFingerprintUnlockController.java
@@ -17,25 +17,43 @@
 package com.android.settings.privatespace.onelock;
 
 import android.content.Context;
-import android.text.TextUtils;
+import android.os.UserHandle;
+import android.util.Log;
 
 import androidx.preference.Preference;
 
 import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
-import com.android.settingslib.core.AbstractPreferenceController;
+import com.android.settings.biometrics.combination.CombinedBiometricStatusPreferenceController;
+import com.android.settings.privatespace.PrivateSpaceMaintainer;
+import com.android.settingslib.core.lifecycle.Lifecycle;
 
 /** Represents the preference controller to enroll biometrics for private space lock. */
-public class FaceFingerprintUnlockController extends AbstractPreferenceController {
+public class FaceFingerprintUnlockController extends CombinedBiometricStatusPreferenceController {
+    private static final String TAG = "PSBiometricCtrl";
     private static final String KEY_SET_UNSET_FACE_FINGERPRINT = "private_space_biometrics";
+    private final int mProfileUserId;
 
-    public FaceFingerprintUnlockController(Context context, SettingsPreferenceFragment host) {
-        super(context);
+    public FaceFingerprintUnlockController(Context context, Lifecycle lifecycle) {
+        super(context, KEY_SET_UNSET_FACE_FINGERPRINT, lifecycle);
+        mProfileUserId = getUserId();
+    }
+
+    protected boolean isUserSupported() {
+        return android.os.Flags.allowPrivateProfile()
+                && android.multiuser.Flags.enableBiometricsToUnlockPrivateSpace()
+                && mProfileUserId != UserHandle.USER_NULL;
     }
 
     @Override
-    public boolean isAvailable() {
-        return android.os.Flags.allowPrivateProfile();
+    protected int getUserId() {
+        UserHandle privateProfileHandle =
+                PrivateSpaceMaintainer.getInstance(mContext).getPrivateProfileHandle();
+        if (privateProfileHandle != null) {
+            return privateProfileHandle.getIdentifier();
+        } else {
+            Log.e(TAG, "Private profile user handle is not expected to be null.");
+        }
+        return UserHandle.USER_NULL;
     }
 
     @Override
@@ -44,14 +62,19 @@
     }
 
     @Override
-    public boolean handlePreferenceTreeClick(Preference preference) {
-        return TextUtils.equals(preference.getKey(), getPreferenceKey());
+    protected String getSettingsClassName() {
+        return mCombinedBiometricStatusUtils.getPrivateProfileSettingsClassName();
     }
 
     @Override
     public void updateState(Preference preference) {
-        //TODO(b/308862923) : Add condition to check and enable when separate private lock is set.
-        preference.setSummary(mContext.getString(R.string.lock_settings_profile_unified_summary));
-        preference.setEnabled(false);
+        if (mLockPatternUtils.isSeparateProfileChallengeEnabled(mProfileUserId)) {
+            super.updateState(preference);
+            preference.setEnabled(true);
+        } else {
+            preference.setSummary(
+                    mContext.getString(R.string.lock_settings_profile_unified_summary));
+            preference.setEnabled(false);
+        }
     }
 }
diff --git a/src/com/android/settings/privatespace/onelock/PrivateSpaceBiometricSettings.java b/src/com/android/settings/privatespace/onelock/PrivateSpaceBiometricSettings.java
new file mode 100644
index 0000000..dc00885
--- /dev/null
+++ b/src/com/android/settings/privatespace/onelock/PrivateSpaceBiometricSettings.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.privatespace.onelock;
+
+import android.app.settings.SettingsEnums;
+import android.content.Context;
+import android.os.UserHandle;
+import android.util.Log;
+
+import com.android.settings.R;
+import com.android.settings.biometrics.combination.BiometricsSettingsBase;
+import com.android.settings.privatespace.PrivateSpaceMaintainer;
+
+public class PrivateSpaceBiometricSettings extends BiometricsSettingsBase {
+    private static final String TAG = "PSBiometricSettings";
+    private static final String KEY_FACE_SETTINGS = "private_space_face_unlock_settings";
+    private static final String KEY_FINGERPRINT_SETTINGS =
+            "private_space_fingerprint_unlock_settings";
+
+    @Override
+    public void onAttach(Context context) {
+        if (android.os.Flags.allowPrivateProfile()
+                && android.multiuser.Flags.enableBiometricsToUnlockPrivateSpace()) {
+            super.onAttach(context);
+            UserHandle privateProfileHandle =
+                    PrivateSpaceMaintainer.getInstance(context).getPrivateProfileHandle();
+            if (privateProfileHandle != null) {
+                mUserId = privateProfileHandle.getIdentifier();
+            } else {
+                mUserId = -1;
+                Log.e(TAG, "Private profile user handle is not expected to be null.");
+            }
+        }
+    }
+
+    @Override
+    protected int getPreferenceScreenResId() {
+        return R.xml.private_space_biometric_settings;
+    }
+
+    @Override
+    public String getFacePreferenceKey() {
+        return KEY_FACE_SETTINGS;
+    }
+
+    @Override
+    public String getFingerprintPreferenceKey() {
+        return KEY_FINGERPRINT_SETTINGS;
+    }
+
+    @Override
+    public String getUnlockPhonePreferenceKey() {
+        return "";
+    }
+
+    @Override
+    public String getUseInAppsPreferenceKey() {
+        return "";
+    }
+
+    @Override
+    protected String getLogTag() {
+        return TAG;
+    }
+
+    @Override
+    public int getMetricsCategory() {
+        return SettingsEnums.PRIVATE_SPACE_SETTINGS;
+    }
+}
diff --git a/src/com/android/settings/privatespace/onelock/PrivateSpaceFacePreferenceController.java b/src/com/android/settings/privatespace/onelock/PrivateSpaceFacePreferenceController.java
new file mode 100644
index 0000000..cc22b87
--- /dev/null
+++ b/src/com/android/settings/privatespace/onelock/PrivateSpaceFacePreferenceController.java
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.privatespace.onelock;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.util.Log;
+
+import androidx.lifecycle.Lifecycle;
+
+import com.android.settings.biometrics.combination.BiometricFaceStatusPreferenceController;
+import com.android.settings.privatespace.PrivateSpaceMaintainer;
+
+public class PrivateSpaceFacePreferenceController extends BiometricFaceStatusPreferenceController {
+    private static final String TAG = "PrivateSpaceFaceCtrl";
+
+    public PrivateSpaceFacePreferenceController(Context context, String key) {
+        super(context, key);
+    }
+
+    public PrivateSpaceFacePreferenceController(Context context, String key, Lifecycle lifecycle) {
+        super(context, key, lifecycle);
+    }
+
+    @Override
+    protected boolean isUserSupported() {
+        return android.os.Flags.allowPrivateProfile()
+                && android.multiuser.Flags.enableBiometricsToUnlockPrivateSpace()
+                && getUserId() != UserHandle.USER_NULL;
+    }
+
+    @Override
+    protected int getUserId() {
+        UserHandle privateProfileHandle =
+                PrivateSpaceMaintainer.getInstance(mContext).getPrivateProfileHandle();
+        if (privateProfileHandle != null) {
+            return privateProfileHandle.getIdentifier();
+        } else {
+            Log.e(TAG, "Private profile user handle is not expected to be null.");
+        }
+        return UserHandle.USER_NULL;
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return android.os.Flags.allowPrivateProfile()
+                        && android.multiuser.Flags.enableBiometricsToUnlockPrivateSpace()
+                ? AVAILABLE
+                : UNSUPPORTED_ON_DEVICE;
+    }
+}
diff --git a/src/com/android/settings/privatespace/onelock/PrivateSpaceFingerprintPreferenceController.java b/src/com/android/settings/privatespace/onelock/PrivateSpaceFingerprintPreferenceController.java
new file mode 100644
index 0000000..f2f0801
--- /dev/null
+++ b/src/com/android/settings/privatespace/onelock/PrivateSpaceFingerprintPreferenceController.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.settings.privatespace.onelock;
+
+import android.content.Context;
+import android.os.UserHandle;
+import android.util.Log;
+
+import androidx.lifecycle.Lifecycle;
+
+import com.android.settings.biometrics.combination.BiometricFingerprintStatusPreferenceController;
+import com.android.settings.privatespace.PrivateSpaceMaintainer;
+
+public class PrivateSpaceFingerprintPreferenceController
+        extends BiometricFingerprintStatusPreferenceController {
+    private static final String TAG = "PrivateSpaceFingerCtrl";
+
+    public PrivateSpaceFingerprintPreferenceController(Context context, String key) {
+        super(context, key);
+    }
+
+    public PrivateSpaceFingerprintPreferenceController(
+            Context context, String key, Lifecycle lifecycle) {
+        super(context, key, lifecycle);
+    }
+
+    @Override
+    protected boolean isUserSupported() {
+        return android.os.Flags.allowPrivateProfile()
+                && android.multiuser.Flags.enableBiometricsToUnlockPrivateSpace()
+                && getUserId() != UserHandle.USER_NULL;
+    }
+
+    @Override
+    protected int getUserId() {
+        UserHandle privateProfileHandle =
+                PrivateSpaceMaintainer.getInstance(mContext).getPrivateProfileHandle();
+        if (privateProfileHandle != null) {
+            return privateProfileHandle.getIdentifier();
+        } else {
+            Log.e(TAG, "Private profile user handle is not expected to be null.");
+        }
+        return UserHandle.USER_NULL;
+    }
+
+    @Override
+    public int getAvailabilityStatus() {
+        return android.os.Flags.allowPrivateProfile()
+                        && android.multiuser.Flags.enableBiometricsToUnlockPrivateSpace()
+                ? AVAILABLE
+                : UNSUPPORTED_ON_DEVICE;
+    }
+}
diff --git a/src/com/android/settings/privatespace/onelock/UseOneLockControllerSwitch.java b/src/com/android/settings/privatespace/onelock/UseOneLockControllerSwitch.java
index 54b0374..fd7d02b 100644
--- a/src/com/android/settings/privatespace/onelock/UseOneLockControllerSwitch.java
+++ b/src/com/android/settings/privatespace/onelock/UseOneLockControllerSwitch.java
@@ -31,6 +31,7 @@
 import android.os.UserManager;
 import android.util.Log;
 
+import androidx.annotation.Nullable;
 import androidx.preference.Preference;
 import androidx.preference.PreferenceScreen;
 
@@ -122,15 +123,15 @@
     }
 
     /** Method to handle onActivityResult */
-    public boolean handleActivityResult(int requestCode, int resultCode, Intent data) {
+    public boolean handleActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
         if (requestCode == UNUNIFY_PRIVATE_LOCK_FROM_DEVICE_REQUEST
-                  && resultCode == Activity.RESULT_OK) {
+                  && resultCode == Activity.RESULT_OK && data != null) {
             mCurrentDevicePassword =
                       data.getParcelableExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
             separateLocks();
             return true;
         } else if (requestCode == UNIFY_PRIVATE_LOCK_WITH_DEVICE_REQUEST
-                  && resultCode == Activity.RESULT_OK) {
+                  && resultCode == Activity.RESULT_OK && data != null) {
             mCurrentProfilePassword =
                       data.getParcelableExtra(ChooseLockSettingsHelper.EXTRA_KEY_PASSWORD);
             unifyLocks();
diff --git a/src/com/android/settings/privatespace/onelock/UseOneLockSettingsFragment.java b/src/com/android/settings/privatespace/onelock/UseOneLockSettingsFragment.java
index 181a8d0..6af6c38 100644
--- a/src/com/android/settings/privatespace/onelock/UseOneLockSettingsFragment.java
+++ b/src/com/android/settings/privatespace/onelock/UseOneLockSettingsFragment.java
@@ -71,14 +71,14 @@
         final List<AbstractPreferenceController> controllers = new ArrayList<>();
         controllers.add(new UseOneLockControllerSwitch(context, this));
         controllers.add(new PrivateSpaceLockController(context, this));
-        controllers.add(new FaceFingerprintUnlockController(context, this));
+        controllers.add(new FaceFingerprintUnlockController(context, getSettingsLifecycle()));
         return controllers;
     }
 
     @Override
     public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
         if (use(UseOneLockControllerSwitch.class)
-                  .handleActivityResult(requestCode, resultCode, data)) {
+                .handleActivityResult(requestCode, resultCode, data)) {
             return;
         }
         super.onActivityResult(requestCode, resultCode, data);