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

Commit b9e759bb authored by Felipe Leme's avatar Felipe Leme Committed by Android (Google) Code Review
Browse files

Merge "Disabled support for profiles on secondary displays."

parents 08b9eefa 39f761d0
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -2869,10 +2869,10 @@ public class UserManager {
     * It includes:
     *
     * <ol>
     *   <li>The current foreground user in the main display.
     *   <li>Current background users in secondary displays (for example, passenger users on
     *   automotive, using the display associated with their seats).
     *   <li>Profile users (in the running / started state) of other visible users.
     *   <li>The current foreground user.
     *   <li>(Running) profiles of the current foreground user.
     *   <li>Background users assigned to secondary displays (for example, passenger users on
     *   automotive builds, using the display associated with their seats).
     * </ol>
     *
     * @return whether the user is visible at the moment, as defined above.
+2 −5
Original line number Diff line number Diff line
@@ -1387,7 +1387,7 @@ class UserController implements Handler.Callback {
        int i = 0;
        for (; i < profilesToStartSize && i < (getMaxRunningUsers() - 1); ++i) {
            // NOTE: this method is setting the profiles of the current user - which is always
            // assigned to the default display - so there's no need to pass PARENT_DISPLAY
            // assigned to the default display
            startUser(profilesToStart.get(i).id, /* foreground= */ false);
        }
        if (i < profilesToStartSize) {
@@ -1430,10 +1430,7 @@ class UserController implements Handler.Callback {
            return false;
        }

        int displayId = mInjector.isUsersOnSecondaryDisplaysEnabled()
                ? UserManagerInternal.PARENT_DISPLAY
                : Display.DEFAULT_DISPLAY;
        return startUserNoChecks(userId, displayId, /* foreground= */ false,
        return startUserNoChecks(userId, Display.DEFAULT_DISPLAY, /* foreground= */ false,
                /* unlockListener= */ null);
    }

+0 −9
Original line number Diff line number Diff line
@@ -46,15 +46,6 @@ public abstract class UserManagerInternal {
    public @interface OwnerType {
    }

    // TODO(b/245963156): move to Display.java (and @hide) if we decide to support profiles on MUMD
    /**
     * Used only when starting a profile (on systems that
     * {@link android.os.UserManager#isUsersOnSecondaryDisplaysSupported() support users running on
     * secondary displays}), to indicate the profile should be started in the same display as its
     * parent user.
     */
    public static final int PARENT_DISPLAY = -2;

    public interface UserRestrictionsListener {
        /**
         * Called when a user restriction changes.
+28 −13
Original line number Diff line number Diff line
@@ -6822,14 +6822,26 @@ public class UserManagerService extends IUserManager.Stub {
                Slogf.d(LOG_TAG, "assignUserToDisplay(%d, %d)", userId, displayId);
            }

            // NOTE: Using Boolean instead of boolean as it will be re-used below
            Boolean isProfile = null;
            if (displayId == Display.DEFAULT_DISPLAY) {
                // Don't need to do anything because methods (such as isUserVisible()) already know
                // that the current user (and their profiles) is assigned to the default display.
                if (mUsersOnSecondaryDisplaysEnabled) {
                    // Profiles are only supported in the default display, but it cannot return yet
                    // as it needs to check if the parent is also assigned to the DEFAULT_DISPLAY
                    // (this is done indirectly below when it checks that the profile parent is the
                    // current user, as the current user is always assigned to the DEFAULT_DISPLAY).
                    isProfile = isProfileUnchecked(userId);
                }
                if (isProfile == null || !isProfile) {
                    // Don't need to do anything because methods (such as isUserVisible()) already
                    // know that the current user (and their profiles) is assigned to the default
                    // display.
                    if (DBG_MUMD) {
                        Slogf.d(LOG_TAG, "ignoring on default display");
                    }
                    return;
                }
            }

            if (!mUsersOnSecondaryDisplaysEnabled) {
                throw new UnsupportedOperationException("assignUserToDisplay(" + userId + ", "
@@ -6846,18 +6858,21 @@ public class UserManagerService extends IUserManager.Stub {
            Preconditions.checkArgument(userId != currentUserId,
                    "Cannot assign current user (%d) to other displays", currentUserId);

            if (isProfile == null) {
                isProfile = isProfileUnchecked(userId);
            }
            synchronized (mUsersOnSecondaryDisplays) {
                if (isProfileUnchecked(userId)) {
                    // Profile can only start in the same display as parent
                    Preconditions.checkArgument(displayId == UserManagerInternal.PARENT_DISPLAY,
                            "Profile user can only be started in the same display as parent");
                if (isProfile) {
                    // Profile can only start in the same display as parent. And for simplicity,
                    // that display must be the DEFAULT_DISPLAY.
                    Preconditions.checkArgument(displayId == Display.DEFAULT_DISPLAY,
                            "Profile user can only be started in the default display");
                    int parentUserId = getProfileParentId(userId);
                    int parentDisplayId = mUsersOnSecondaryDisplays.get(parentUserId);
                    Preconditions.checkArgument(parentUserId == currentUserId,
                            "Only profile of current user can be assigned to a display");
                    if (DBG_MUMD) {
                        Slogf.d(LOG_TAG, "Adding profile user %d -> display %d", userId,
                                parentDisplayId);
                        Slogf.d(LOG_TAG, "Ignoring profile user %d on default display", userId);
                    }
                    mUsersOnSecondaryDisplays.put(userId, parentDisplayId);
                    return;
                }

+18 −6
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ import static android.os.UserHandle.USER_SYSTEM;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;

import static com.android.server.pm.UserManagerInternal.PARENT_DISPLAY;

import static com.google.common.truth.Truth.assertWithMessage;

import static org.junit.Assert.assertThrows;
@@ -185,10 +183,11 @@ public final class UserManagerInternalTest extends UserManagerServiceOrInternalT
        addDefaultProfileAndParent();

        mUmi.assignUserToDisplay(PARENT_USER_ID, SECONDARY_DISPLAY_ID);
        mUmi.assignUserToDisplay(PROFILE_USER_ID, PARENT_DISPLAY);
        IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
                () -> mUmi.assignUserToDisplay(PROFILE_USER_ID, SECONDARY_DISPLAY_ID));

        assertUsersAssignedToDisplays(PARENT_USER_ID, SECONDARY_DISPLAY_ID,
                pair(PROFILE_USER_ID, SECONDARY_DISPLAY_ID));
        Log.v(TAG, "Exception: " + e);
        assertUserAssignedToDisplay(PARENT_USER_ID, SECONDARY_DISPLAY_ID);
    }

    @Test
@@ -198,7 +197,20 @@ public final class UserManagerInternalTest extends UserManagerServiceOrInternalT

        mUmi.assignUserToDisplay(PARENT_USER_ID, SECONDARY_DISPLAY_ID);
        IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
                () -> mUmi.assignUserToDisplay(PROFILE_USER_ID, SECONDARY_DISPLAY_ID));
                () -> mUmi.assignUserToDisplay(PROFILE_USER_ID, OTHER_SECONDARY_DISPLAY_ID));

        Log.v(TAG, "Exception: " + e);
        assertUserAssignedToDisplay(PARENT_USER_ID, SECONDARY_DISPLAY_ID);
    }

    @Test
    public void testAssignUserToDisplay_profileDefaultDisplayParentOnSecondaryDisplay() {
        enableUsersOnSecondaryDisplays();
        addDefaultProfileAndParent();

        mUmi.assignUserToDisplay(PARENT_USER_ID, SECONDARY_DISPLAY_ID);
        IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
                () -> mUmi.assignUserToDisplay(PROFILE_USER_ID, DEFAULT_DISPLAY));

        Log.v(TAG, "Exception: " + e);
        assertUserAssignedToDisplay(PARENT_USER_ID, SECONDARY_DISPLAY_ID);
Loading