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

Commit 15045807 authored by Dohyun Lee's avatar Dohyun Lee Committed by bkchoi
Browse files

Refactor isVisibleBackgroundUser into UserManagerService



A visible background user is a full, background user assigned to
secondary displays on the devices that have
config_multiuserVisibleBackgroundUsers enabled. The logic for checking
visible background users was used repeatedly in a couple of classes,
so the logic was moved to UserManagerService to remove redundant codes.

Bug: 342315883
Flag: EXEMPT refactor
Test: m

Signed-off-by: default avatarDohyun Lee <dohyun.lee@lge.com>
(cherry picked from https://partner-android-review.googlesource.com/q/commit:7e2440877925659abbd21d8bc8f213fc4db58f45)

Change-Id: I527bb05f690c6a6c9c98fbd8753890030e8536a3
parent 6b9f4da5
Loading
Loading
Loading
Loading
+2 −22
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ import com.android.internal.logging.nano.MetricsProto;
import com.android.server.LocalServices;
import com.android.server.PackageWatchdog;
import com.android.server.pm.UserManagerInternal;
import com.android.server.pm.UserManagerService;
import com.android.server.usage.AppStandbyInternal;
import com.android.server.wm.WindowProcessController;

@@ -1027,7 +1026,8 @@ class AppErrors {
                isBackground &= (userId != profileId);
            }
            int visibleUserId = getVisibleUserId(userId);
            boolean isVisibleUser = isVisibleBackgroundUser(visibleUserId);
            boolean isVisibleUser = LocalServices.getService(UserManagerInternal.class)
                    .isVisibleBackgroundFullUser(visibleUserId);
            boolean showBackground = Settings.Secure.getIntForUser(mContext.getContentResolver(),
                    Settings.Secure.ANR_SHOW_BACKGROUND, 0, visibleUserId) != 0;
            if (isBackground && !showBackground && !isVisibleUser) {
@@ -1182,26 +1182,6 @@ class AppErrors {
        return appUserId;
    }

    /**
     * Checks if the given user is a visible background user, which is a full, background user
     * assigned to secondary displays on the devices that have
     * {@link UserManager#isVisibleBackgroundUsersEnabled()
     * config_multiuserVisibleBackgroundUsers enabled} (for example, passenger users on
     * automotive builds, using the display associated with their seats).
     *
     * @see UserManager#isUserVisible()
     */
    private boolean isVisibleBackgroundUser(int userId) {
        if (!UserManager.isVisibleBackgroundUsersEnabled()) {
            return false;
        }
        boolean isForeground = mService.mUserController.getCurrentUserId() == userId;
        boolean isProfile = UserManagerService.getInstance().isProfile(userId);
        boolean isVisible = LocalServices.getService(UserManagerInternal.class)
                .isUserVisible(userId);
        return isVisible && !isForeground && !isProfile;
    }

    /**
     * Information about a process that is currently marked as bad.
     */
+11 −0
Original line number Diff line number Diff line
@@ -496,6 +496,17 @@ public abstract class UserManagerInternal {
     */
    public abstract boolean isUserVisible(@UserIdInt int userId, int displayId);

    /**
     * Checks if the given user is a visible background full user, which is a full background user
     * assigned to secondary displays on the devices that have
     * {@link UserManager#isVisibleBackgroundUsersEnabled()
     * config_multiuserVisibleBackgroundUsers enabled} (for example, passenger users on
     * automotive builds, using the display associated with their seats).
     *
     * @see UserManager#isUserVisible()
     */
    public abstract boolean isVisibleBackgroundFullUser(@UserIdInt int userId);

    /**
     * Returns the main display id assigned to the user, or {@code Display.INVALID_DISPLAY} if the
     * user is not assigned to any main display.
+11 −0
Original line number Diff line number Diff line
@@ -7926,6 +7926,17 @@ public class UserManagerService extends IUserManager.Stub {
            return mUserVisibilityMediator.isUserVisible(userId, displayId);
        }

        @Override
        public boolean isVisibleBackgroundFullUser(@UserIdInt int userId) {
            if (!UserManager.isVisibleBackgroundUsersEnabled()) {
                return false;
            }
            boolean isForeground = userId == getCurrentUserId();
            boolean isProfile = isProfileUnchecked(userId);
            boolean isVisible = isUserVisible(userId);
            return isVisible && !isForeground && !isProfile;
        }

        @Override
        public int getMainDisplayAssignedToUser(@UserIdInt int userId) {
            return mUserVisibilityMediator.getMainDisplayAssignedToUser(userId);
+1 −20
Original line number Diff line number Diff line
@@ -7174,25 +7174,6 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
            }
        }

        /**
         * Checks if the given user is a visible background user, which is a full, background user
         * assigned to secondary displays on the devices that have
         * {@link UserManager#isVisibleBackgroundUsersEnabled()
         * config_multiuserVisibleBackgroundUsers enabled} (for example, passenger users on
         * automotive builds, using the display associated with their seats).
         *
         * @see UserManager#isUserVisible()
         */
        private boolean isVisibleBackgroundUser(int userId) {
            if (!UserManager.isVisibleBackgroundUsersEnabled()) {
                return false;
            }
            boolean isForeground = getCurrentUserId() == userId;
            boolean isProfile = getUserManager().isProfile(userId);
            boolean isVisible = mWindowManager.mUmInternal.isUserVisible(userId);
            return isVisible && !isForeground && !isProfile;
        }

        /**
         * In a car environment, {@link ActivityTaskManagerService#mShowDialogs} is always set to
         * {@code false} from {@link ActivityTaskManagerService#updateShouldShowDialogsLocked}
@@ -7208,7 +7189,7 @@ public class ActivityTaskManagerService extends IActivityTaskManager.Stub {
         * @see ActivityTaskManagerService#updateShouldShowDialogsLocked
         */
        private boolean shouldShowDialogsForVisibleBackgroundUserLocked(int userId) {
            if (!isVisibleBackgroundUser(userId)) {
            if (!mWindowManager.mUmInternal.isVisibleBackgroundFullUser(userId)) {
                return false;
            }
            final int displayId = mWindowManager.mUmInternal.getMainDisplayAssignedToUser(userId);