Support Private profile in profile modal selector

Profile selector modal with work profile
https://screenshot.googleplex.com/8ugpsT7nZA75VPa

Modal without work profile
https://screenshot.googleplex.com/9bPFbFG2DKBHhvS

Bug: 309635228
Test: manual
Change-Id: Id7533f101d2b5693c419c9591d59751925a4b7ce
diff --git a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
index 6b50b70..561a51a 100644
--- a/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
+++ b/src/com/android/settings/dashboard/profileselector/ProfileSelectDialog.java
@@ -25,7 +25,9 @@
 import android.content.DialogInterface.OnShowListener;
 import android.content.Intent;
 import android.content.pm.UserInfo;
+import android.content.pm.UserProperties;
 import android.os.Bundle;
+import android.os.Flags;
 import android.os.UserHandle;
 import android.os.UserManager;
 import android.util.Log;
@@ -183,7 +185,10 @@
         final UserManager userManager = UserManager.get(context);
         for (int i = userHandles.size() - 1; i >= 0; i--) {
             UserInfo userInfo = userManager.getUserInfo(userHandles.get(i).getIdentifier());
-            if (userInfo == null || userInfo.isCloneProfile()) {
+            if (userInfo == null
+                    || userInfo.isCloneProfile()
+                    || (Flags.allowPrivateProfile()
+                        && shouldHideUserInQuietMode(userHandles.get(i), userManager))) {
                 if (DEBUG) {
                     Log.d(TAG, "Delete the user: " + userHandles.get(i).getIdentifier());
                 }
@@ -214,7 +219,10 @@
         final UserManager userManager = UserManager.get(context);
         for (UserHandle userHandle : List.copyOf(tile.pendingIntentMap.keySet())) {
             UserInfo userInfo = userManager.getUserInfo(userHandle.getIdentifier());
-            if (userInfo == null || userInfo.isCloneProfile()) {
+            if (userInfo == null
+                    || userInfo.isCloneProfile()
+                    || (Flags.allowPrivateProfile()
+                        && shouldHideUserInQuietMode(userHandle, userManager))) {
                 if (DEBUG) {
                     Log.d(TAG, "Delete the user: " + userHandle.getIdentifier());
                 }
@@ -223,4 +231,11 @@
             }
         }
     }
+
+    private static boolean shouldHideUserInQuietMode(
+            UserHandle userHandle, UserManager userManager) {
+        UserProperties userProperties = userManager.getUserProperties(userHandle);
+        return userProperties.getHideInSettingsInQuietMode()
+                && userManager.isQuietModeEnabled(userHandle);
+    }
 }
diff --git a/src/com/android/settings/dashboard/profileselector/UserAdapter.java b/src/com/android/settings/dashboard/profileselector/UserAdapter.java
index 0552a81..66ba815 100644
--- a/src/com/android/settings/dashboard/profileselector/UserAdapter.java
+++ b/src/com/android/settings/dashboard/profileselector/UserAdapter.java
@@ -17,7 +17,6 @@
 package com.android.settings.dashboard.profileselector;
 
 import static android.app.admin.DevicePolicyResources.Strings.Settings.PERSONAL_CATEGORY_HEADER;
-import static android.app.admin.DevicePolicyResources.Strings.Settings.WORK_CATEGORY_HEADER;
 
 import android.app.ActivityManager;
 import android.app.admin.DevicePolicyManager;
@@ -51,11 +50,13 @@
     /** Holder for user details */
     public static class UserDetails {
         private final UserHandle mUserHandle;
+        private final UserManager mUserManager;
         private final Drawable mIcon;
         private final String mTitle;
 
         public UserDetails(UserHandle userHandle, UserManager um, Context context) {
             mUserHandle = userHandle;
+            mUserManager = um;
             UserInfo userInfo = um.getUserInfo(mUserHandle.getIdentifier());
             int tintColor = Utils.getColorAttrDefaultColor(context,
                     com.android.internal.R.attr.materialColorPrimaryContainer);
@@ -73,16 +74,13 @@
             DevicePolicyManager devicePolicyManager =
                     Objects.requireNonNull(context.getSystemService(DevicePolicyManager.class));
             DevicePolicyResourcesManager resources = devicePolicyManager.getResources();
-            int userHandle = mUserHandle.getIdentifier();
-            if (userHandle == UserHandle.USER_CURRENT
-                    || userHandle == ActivityManager.getCurrentUser()) {
+            int userId = mUserHandle.getIdentifier();
+            if (userId == UserHandle.USER_CURRENT || userId == ActivityManager.getCurrentUser()) {
                 return resources.getString(PERSONAL_CATEGORY_HEADER,
                         () -> context.getString(
                                 com.android.settingslib.R.string.category_personal));
-            } else {
-                return resources.getString(WORK_CATEGORY_HEADER,
-                        () -> context.getString(com.android.settingslib.R.string.category_work));
             }
+            return (String) mUserManager.getBadgedLabelForUser(/* label= */ "", mUserHandle);
         }
     }