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

Commit 9d52049c authored by Adam Bookatz's avatar Adam Bookatz
Browse files

Auto-stopping users exempt bg visible users

When automatically stopping a user, due to it being scheduled for
stopping or because we have exceeded maxRunningUsers, we already make
sure to exclude alwaysVisible users (such as the communal profile). But
we should actually also exclude users that are visible on background
displays. In short, we should exclude any user that is
UM.isUserVisible(). So we do so.

Bug: 423011998
Flag: EXEMPT bugfix
Test: UserControllerTest
Change-Id: I2c9754b876d4b8c0c5384e608884b469aa3e26fb
parent 8d6d7322
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3798,7 +3798,7 @@ public class UserManager {
     *   <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).
     *   <li>A communal profile, if present.
     *   <li>A user that is always considered visible, such as a communal profile, if present.
     * </ol>
     *
     * @return whether the user is visible at the moment, as defined above.
+10 −7
Original line number Diff line number Diff line
@@ -623,7 +623,7 @@ class UserController implements Handler.Callback {
        final List<UserInfo> users = mInjector.getUserManager().getUsers(true);
        for (int i = 0; i < users.size(); i++) {
            final int userId = users.get(i).id;
            if (isAlwaysVisibleUser(userId)) {
            if (isUserVisible(userId)) {
                exemptedUsers.add(userId);
            } else if (avoidStoppingUserRightNow(userId)) {
                avoidUsers.add(userId);
@@ -2760,14 +2760,15 @@ class UserController implements Handler.Callback {
            return false;
        }
        if (UserManager.isVisibleBackgroundUsersEnabled()) {
            // Feature is not enabled on this device.
            // Feature is not enabled on this device. Consider enabling it after testing it.
            return false;
        }
        if (userId == UserHandle.USER_SYSTEM) {
            // Never stop system user
            return false;
        }
        if (isAlwaysVisibleUser(userId)) {
        if (isUserVisible(userId)) {
            // User is visible, possibly on a background display or as an alwaysVisibleUser.
            return false;
        }
        synchronized(mLock) {
@@ -3598,10 +3599,12 @@ class UserController implements Handler.Callback {
        return userId == getCurrentOrTargetUserIdLU();
    }

    /** Returns whether the user is always-visible (such as a communal profile). */
    private boolean isAlwaysVisibleUser(@UserIdInt int userId) {
        final UserProperties properties = getUserProperties(userId);
        return properties != null && properties.getAlwaysVisible();
    /**
     * Returns whether the user is currently visible, including users visible on a background
     * display and always-visible users (e.g. the communal profile).
     */
    private boolean isUserVisible(@UserIdInt int userId) {
        return mInjector.getUserManagerInternal().isUserVisible(userId);
    }

    int[] getUsers() {