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

Commit a3175792 authored by Felipe Leme's avatar Felipe Leme
Browse files

Added UserManagerInternal.getDisplayAssignedToUser(userId).

Currently, to check if a user is visible, internal services
need to get a context to the user, which is not only more work
(and more expensive), but would not work if the user doesn't exist.

Test: called by Car stack
Bug: 243864134

Change-Id: I25d0915c94ac670cfd126b94ec988d2c4107bc1c
parent 764a223c
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -321,4 +321,15 @@ public abstract class UserManagerInternal {
     * {@link UserManager#isUserVisible()} in the given display.
     */
    public abstract boolean isUserVisible(@UserIdInt int userId, int displayId);

    /**
     * Returns the display id assigned to the user, or {@code Display.INVALID_DISPLAY} if the
     * user is not assigned to any display.
     *
     * <p>The current foreground user is associated with the main display, while other users would
     * only assigned to a display if they were started with
     * {@code ActivityManager.startUserInBackgroundOnSecondaryDisplay()}. If the user is a profile
     * and is running, it's assigned to its parent display.
     */
    public abstract int getDisplayAssignedToUser(@UserIdInt int userId);
}
+17 −0
Original line number Diff line number Diff line
@@ -1731,6 +1731,18 @@ public class UserManagerService extends IUserManager.Stub {
        return false;
    }

    // TODO(b/239982558): add unit test
    private int getDisplayAssignedToUser(@UserIdInt int userId) {
        if (isCurrentUserOrRunningProfileOfCurrentUser(userId)) {
            return Display.DEFAULT_DISPLAY;
        }
        synchronized (mUsersLock) {
            return mUsersOnSecondaryDisplays == null
                    ? Display.INVALID_DISPLAY
                    : mUsersOnSecondaryDisplays.get(userId, Display.INVALID_DISPLAY);
        }
    }

    private boolean isCurrentUserOrRunningProfileOfCurrentUser(@UserIdInt int userId) {
        int currentUserId = Binder.withCleanCallingIdentity(() -> ActivityManager.getCurrentUser());

@@ -6695,6 +6707,11 @@ public class UserManagerService extends IUserManager.Stub {
        public boolean isUserVisible(int userId, int displayId) {
            return isUserVisibleOnDisplay(userId, displayId);
        }

        @Override
        public int getDisplayAssignedToUser(int userId) {
            return UserManagerService.this.getDisplayAssignedToUser(userId);
        }
    } // class LocalService

    /**