Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 94cffad6 authored by Manish Singh's avatar Manish Singh
Browse files

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
parent 6ce9c377
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -25,7 +25,9 @@ import android.content.DialogInterface.OnDismissListener;
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 @@ public class ProfileSelectDialog extends DialogFragment implements UserAdapter.O
        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 @@ public class ProfileSelectDialog extends DialogFragment implements UserAdapter.O
        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 @@ public class ProfileSelectDialog extends DialogFragment implements UserAdapter.O
            }
        }
    }

    private static boolean shouldHideUserInQuietMode(
            UserHandle userHandle, UserManager userManager) {
        UserProperties userProperties = userManager.getUserProperties(userHandle);
        return userProperties.getHideInSettingsInQuietMode()
                && userManager.isQuietModeEnabled(userHandle);
    }
}
+5 −7
Original line number Diff line number Diff line
@@ -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 @@ public class UserAdapter extends BaseAdapter {
    /** 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 @@ public class UserAdapter extends BaseAdapter {
            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);
        }
    }