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

Commit 06b61275 authored by Alex Stetson's avatar Alex Stetson
Browse files

Use context id for getMainDisplayIdAssignedToUser

Use the context id rather than the calling user id for the
getMainDisplayIdAssignedToUser UserManager API

Bug: 365853701
Test: manual
Flag: NONE refactor
Change-Id: I08d5ccfa0d95dd074c733cc61372839b289baf5b
parent 203cdd3f
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -139,7 +139,7 @@ interface IUserManager {
    boolean isUserForeground(int userId);
    boolean isUserVisible(int userId);
    int[] getVisibleUsers();
    int getMainDisplayIdAssignedToUser();
    int getMainDisplayIdAssignedToUser(int userId);
    boolean isForegroundUserAdmin();
    boolean isUserNameSet(int userId);
    boolean hasRestrictedProfiles(int userId);
+5 −1
Original line number Diff line number Diff line
@@ -3697,9 +3697,13 @@ public class UserManager {
     * @hide
     */
    @TestApi
    @UserHandleAware(
            requiresAnyOfPermissionsIfNotCaller = {
                    android.Manifest.permission.MANAGE_USERS,
                    android.Manifest.permission.INTERACT_ACROSS_USERS})
    public int getMainDisplayIdAssignedToUser() {
        try {
            return mService.getMainDisplayIdAssignedToUser();
            return mService.getMainDisplayIdAssignedToUser(mUserId);
        } catch (RemoteException re) {
            throw re.rethrowFromSystemServer();
        }
+9 −5
Original line number Diff line number Diff line
@@ -2632,11 +2632,15 @@ public class UserManagerService extends IUserManager.Stub {
    }

    @Override
    public int getMainDisplayIdAssignedToUser() {
        // Not checking for any permission as it returns info about calling user
        int userId = UserHandle.getUserId(Binder.getCallingUid());
        int displayId = mUserVisibilityMediator.getMainDisplayAssignedToUser(userId);
        return displayId;
    public int getMainDisplayIdAssignedToUser(int userId) {
        final int callingUserId = UserHandle.getCallingUserId();
        if (callingUserId != userId
                && !hasManageUsersOrPermission(android.Manifest.permission.INTERACT_ACROSS_USERS)) {
            throw new SecurityException("Caller from user " + callingUserId + " needs MANAGE_USERS "
                    + "or INTERACT_ACROSS_USERS permission to get the main display for (" + userId
                    + ")");
        }
        return mUserVisibilityMediator.getMainDisplayAssignedToUser(userId);
    }

    @Override