Show a separate tab for the Private Space

This covers all the known Settings pages using the tabbed view model.

https://docs.google.com/document/d/1CdjUjAE84-5ZEPRIfw5KYFjLVHtEZxc_sF0w95su8DA/edit?resourcekey=0-dAACT9HRexY1IyoxMmkVlw#heading=h.58jd58rmznte

Screenshots:
all apps
https://screenshot.googleplex.com/3E5Jm7Pi2JfN64r
with work tab:
https://screenshot.googleplex.com/8egk4yHK5jSENjR

PS Apps Special media management apps
https://screenshot.googleplex.com/BHHafqW7bgUwSGg
with work tab:
https://screenshot.googleplex.com/3cocdhruEmCCh5k

PS Location Services tab view
https://screenshot.googleplex.com/3DqJcT2BFTEpvYT
with work tab:
https://screenshot.googleplex.com/6Avpx6hxSrdGJw5

PS on screen keyboard tab view
https://screenshot.googleplex.com/4FzVNnBWwbUeJNw
with work tab:
https://screenshot.googleplex.com/8E8UhpWq8PL5nxU

PS password account tab view
https://screenshot.googleplex.com/6bDR4AKtth2S3EW
with work tab:
https://screenshot.googleplex.com/9msXV2TdHdJapch

PS storage tab view
https://screenshot.googleplex.com/5Nk2FTxwdmpEv3B
with work tab:
https://screenshot.googleplex.com/79tw2EaWZKfMsnC

PS appl_languages_work
https://screenshot.googleplex.com/3qrREeg3RQdHhhH

Bug: 302278487
Test: manual
Change-Id: I8cd39170827fbe251bc4075ef306206020b3a022
diff --git a/tests/robotests/Android.bp b/tests/robotests/Android.bp
index fbfd888..0a7be86 100644
--- a/tests/robotests/Android.bp
+++ b/tests/robotests/Android.bp
@@ -59,6 +59,7 @@
         "androidx.test.rules",
         "androidx.test.runner",
         "flag-junit",
+        "flag-junit-base",
         "aconfig_settings_flags_lib",
         "platform-test-annotations",
         "Settings-testutils2",
diff --git a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectFragmentTest.java
index b595d06..056935c 100644
--- a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectFragmentTest.java
@@ -19,6 +19,7 @@
 import static android.content.Intent.EXTRA_USER_ID;
 
 import static com.android.settings.dashboard.profileselector.ProfileSelectFragment.PERSONAL_TAB;
+import static com.android.settings.dashboard.profileselector.ProfileSelectFragment.PRIVATE_TAB;
 import static com.android.settings.dashboard.profileselector.ProfileSelectFragment.WORK_TAB;
 
 import static com.google.common.truth.Truth.assertThat;
@@ -29,6 +30,9 @@
 import android.content.Context;
 import android.content.Intent;
 import android.os.Bundle;
+import android.os.Flags;
+import android.os.UserHandle;
+import android.platform.test.flag.junit.SetFlagsRule;
 
 import androidx.fragment.app.Fragment;
 import androidx.fragment.app.FragmentActivity;
@@ -38,6 +42,7 @@
 import com.android.settings.testutils.shadow.ShadowUserManager;
 
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.mockito.MockitoAnnotations;
@@ -60,6 +65,7 @@
     private TestProfileSelectFragment mFragment;
     private FragmentActivity mActivity;
     private ShadowUserManager mUserManager;
+    @Rule public final SetFlagsRule mSetFlagsRule = new SetFlagsRule();
 
     @Before
     public void setUp() {
@@ -86,6 +92,14 @@
     }
 
     @Test
+    public void getTabId_setArgumentPrivate_setCorrectTab() {
+        final Bundle bundle = new Bundle();
+        bundle.putInt(SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB, PRIVATE_TAB);
+
+        assertThat(mFragment.getTabId(mActivity, bundle)).isEqualTo(PRIVATE_TAB);
+    }
+
+    @Test
     public void getTabId_setArgumentPersonal_setCorrectTab() {
         final Bundle bundle = new Bundle();
         bundle.putInt(SettingsActivity.EXTRA_SHOW_FRAGMENT_TAB, PERSONAL_TAB);
@@ -105,6 +119,16 @@
     }
 
     @Test
+    public void getTabId_setPrivateId_getCorrectTab() {
+        mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
+        final Bundle bundle = new Bundle();
+        bundle.putInt(EXTRA_USER_ID, 11);
+        mUserManager.setPrivateProfile(11, "private", 0);
+
+        assertThat(mFragment.getTabId(mActivity, bundle)).isEqualTo(PRIVATE_TAB);
+    }
+
+    @Test
     public void getTabId_setPersonalId_getCorrectTab() {
         final Bundle bundle = new Bundle();
         bundle.putInt(EXTRA_USER_ID, 0);
@@ -124,12 +148,120 @@
         assertThat(mFragment.getTabId(mActivity, null)).isEqualTo(WORK_TAB);
     }
 
+    @Test
+    public void testGetFragments_whenOnlyPersonal_returnsOneFragment() {
+        mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
+        Fragment[] fragments = ProfileSelectFragment.getFragments(
+                mContext,
+                null /* bundle */,
+                TestProfileSelectFragment::new,
+                TestProfileSelectFragment::new,
+                TestProfileSelectFragment::new);
+        assertThat(fragments).hasLength(1);
+    }
+
+    @Test
+    public void testGetFragments_whenPrivateDisabled_returnsOneFragment() {
+        Fragment[] fragments = ProfileSelectFragment.getFragments(
+                mContext,
+                null /* bundle */,
+                TestProfileSelectFragment::new,
+                TestProfileSelectFragment::new,
+                TestProfileSelectFragment::new,
+                new ProfileSelectFragment.PrivateSpaceInfoProvider() {
+                    @Override
+                    public boolean isPrivateSpaceLocked(Context context) {
+                        return true;
+                    }
+                },
+                new ProfileSelectFragment.ManagedProfileInfoProvider() {
+                    @Override
+                    public UserHandle getManagedProfile(Context context) {
+                        return null;
+                    }
+                });
+        assertThat(fragments).hasLength(1);
+    }
+
+    @Test
+    public void testGetFragments_whenPrivateEnabled_returnsTwoFragments() {
+        mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
+        Fragment[] fragments = ProfileSelectFragment.getFragments(
+                mContext,
+                null /* bundle */,
+                TestProfileSelectFragment::new,
+                TestProfileSelectFragment::new,
+                TestProfileSelectFragment::new,
+                new ProfileSelectFragment.PrivateSpaceInfoProvider() {
+                    @Override
+                    public boolean isPrivateSpaceLocked(Context context) {
+                        return false;
+                    }
+                },
+                new ProfileSelectFragment.ManagedProfileInfoProvider() {
+                    @Override
+                    public UserHandle getManagedProfile(Context context) {
+                        return null;
+                    }
+                });
+        assertThat(fragments).hasLength(2);
+    }
+
+    @Test
+    public void testGetFragments_whenManagedProfile_returnsTwoFragments() {
+        mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
+        Fragment[] fragments = ProfileSelectFragment.getFragments(
+                mContext,
+                null /* bundle */,
+                TestProfileSelectFragment::new,
+                TestProfileSelectFragment::new,
+                TestProfileSelectFragment::new,
+                new ProfileSelectFragment.PrivateSpaceInfoProvider() {
+                    @Override
+                    public boolean isPrivateSpaceLocked(Context context) {
+                        return false;
+                    }
+                },
+                new ProfileSelectFragment.ManagedProfileInfoProvider() {
+                    @Override
+                    public UserHandle getManagedProfile(Context context) {
+                        return new UserHandle(123);
+                    }
+                });
+        assertThat(fragments).hasLength(2);
+    }
+
+    @Test
+    public void testGetFragments_whenAllProfiles_returnsThreeFragments() {
+        mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
+        Fragment[] fragments = ProfileSelectFragment.getFragments(
+                mContext,
+                null /* bundle */,
+                TestProfileSelectFragment::new,
+                TestProfileSelectFragment::new,
+                TestProfileSelectFragment::new,
+                new ProfileSelectFragment.PrivateSpaceInfoProvider() {
+                    @Override
+                    public boolean isPrivateSpaceLocked(Context context) {
+                        return false;
+                    }
+                },
+                new ProfileSelectFragment.ManagedProfileInfoProvider() {
+                    @Override
+                    public UserHandle getManagedProfile(Context context) {
+                        return new UserHandle(123);
+                    }
+                });
+        assertThat(fragments).hasLength(3);
+    }
+
     public static class TestProfileSelectFragment extends ProfileSelectFragment {
 
         @Override
         public Fragment[] getFragments() {
             return new Fragment[]{
                     new SettingsPreferenceFragmentTest.TestFragment(), //0
+                    new SettingsPreferenceFragmentTest.TestFragment(),
                     new SettingsPreferenceFragmentTest.TestFragment()
             };
         }
diff --git a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragmentTest.java b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragmentTest.java
index f463bec..fa2782f 100644
--- a/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragmentTest.java
+++ b/tests/robotests/src/com/android/settings/dashboard/profileselector/ProfileSelectLocationFragmentTest.java
@@ -39,10 +39,12 @@
 
     @Test
     public void getFragments_containsCorrectBundle() {
-        assertThat(mProfileSelectLocationFragment.getFragments().length).isEqualTo(2);
+        assertThat(mProfileSelectLocationFragment.getFragments().length).isEqualTo(3);
         assertThat(mProfileSelectLocationFragment.getFragments()[0].getArguments().getInt(
                 EXTRA_PROFILE, -1)).isEqualTo(ProfileSelectFragment.ProfileType.PERSONAL);
         assertThat(mProfileSelectLocationFragment.getFragments()[1].getArguments().getInt(
                 EXTRA_PROFILE, -1)).isEqualTo(ProfileSelectFragment.ProfileType.WORK);
+        assertThat(mProfileSelectLocationFragment.getFragments()[1].getArguments().getInt(
+                EXTRA_PROFILE, -1)).isEqualTo(ProfileSelectFragment.ProfileType.PRIVATE);
     }
 }
diff --git a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
index 5db0243..b61f5ab 100644
--- a/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/deviceinfo/storage/StorageItemPreferenceControllerTest.java
@@ -52,6 +52,7 @@
 import com.android.settings.SubSettings;
 import com.android.settings.applications.manageapplications.ManageApplications;
 import com.android.settings.dashboard.profileselector.ProfileSelectFragment;
+import com.android.settings.dashboard.profileselector.ProfileSelectFragment.ProfileType;
 import com.android.settings.deviceinfo.StorageItemPreference;
 import com.android.settings.testutils.shadow.ShadowUserManager;
 import com.android.settingslib.deviceinfo.StorageVolumeProvider;
@@ -99,7 +100,7 @@
         // Note: null is passed as the Lifecycle because we are handling it outside of the normal
         //       Settings fragment lifecycle for test purposes.
         mController = new StorageItemPreferenceController(mContext, mFragment, mVolume, mSvp,
-                false /* isWorkProfile */);
+                ProfileSelectFragment.ProfileType.PERSONAL);
         mPreference = new StorageItemPreference(mContext);
 
         // Inflate the preference and the widget.
@@ -175,7 +176,7 @@
         mPreference.setKey(StorageItemPreferenceController.IMAGES_KEY);
         final Context mockContext = getMockContext();
         mController = new StorageItemPreferenceController(mockContext, mFragment, mVolume,
-                mSvp, false /* isWorkProfile */);
+                mSvp, ProfileSelectFragment.ProfileType.PERSONAL);
         mController.handlePreferenceTreeClick(mPreference);
 
         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
@@ -192,7 +193,7 @@
         mPreference.setKey(StorageItemPreferenceController.AUDIO_KEY);
         final Context mockContext = getMockContext();
         mController = new StorageItemPreferenceController(mockContext, mFragment, mVolume,
-                mSvp, false /* isWorkProfile */);
+                mSvp, ProfileSelectFragment.ProfileType.PERSONAL);
         mController.handlePreferenceTreeClick(mPreference);
 
         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
@@ -242,7 +243,7 @@
     @Test
     public void launchAppsIntent_forWork_settingsIntent() {
         mController = new FakeStorageItemPreferenceController(mContext, mFragment, mVolume, mSvp,
-                true /* isWorkProfile */);
+                ProfileType.WORK);
         mPreference.setKey(StorageItemPreferenceController.APPS_KEY);
         mController.handlePreferenceTreeClick(mPreference);
 
@@ -272,7 +273,7 @@
         mPreference.setKey(StorageItemPreferenceController.DOCUMENTS_AND_OTHER_KEY);
         final Context mockContext = getMockContext();
         mController = new StorageItemPreferenceController(mockContext, mFragment, mVolume,
-                mSvp, false /* isWorkProfile */);
+                mSvp, ProfileSelectFragment.ProfileType.PERSONAL);
         mController.handlePreferenceTreeClick(mPreference);
 
         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
@@ -307,7 +308,7 @@
         mPreference.setKey(StorageItemPreferenceController.VIDEOS_KEY);
         final Context mockContext = getMockContext();
         mController = new StorageItemPreferenceController(mockContext, mFragment, mVolume,
-                mSvp, false /* isWorkProfile */);
+                mSvp, ProfileSelectFragment.ProfileType.PERSONAL);
         mController.handlePreferenceTreeClick(mPreference);
 
         final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
@@ -457,8 +458,8 @@
         private static final int CURRENT_USER_ID = 10;
 
         FakeStorageItemPreferenceController(Context context, Fragment hostFragment,
-                VolumeInfo volume, StorageVolumeProvider svp, boolean isWorkProfile) {
-            super(context, hostFragment, volume, svp, isWorkProfile);
+                VolumeInfo volume, StorageVolumeProvider svp, @ProfileType int profileType) {
+            super(context, hostFragment, volume, svp, profileType);
         }
 
         @Override
diff --git a/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowUserManager.java b/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowUserManager.java
index c8d2866..ce6dc6a 100644
--- a/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowUserManager.java
+++ b/tests/robotests/testutils/com/android/settings/testutils/shadow/ShadowUserManager.java
@@ -17,6 +17,7 @@
 package com.android.settings.testutils.shadow;
 
 import static android.os.Build.VERSION_CODES.LOLLIPOP;
+import static android.os.UserManager.USER_TYPE_PROFILE_PRIVATE;
 
 import android.annotation.UserIdInt;
 import android.content.pm.UserInfo;
@@ -223,6 +224,10 @@
         mManagedProfiles.addAll(profileIds);
     }
 
+    public void setPrivateProfile(int id, String name, int flags) {
+        mUserProfileInfos.add(new UserInfo(id, name, null, flags, USER_TYPE_PROFILE_PRIVATE));
+    }
+
     public void setUserSwitcherEnabled(boolean userSwitchEnabled) {
         mUserSwitchEnabled = userSwitchEnabled;
     }