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

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

Updated UserManager.isUserVisible() to check for profiles.

Bug: 239824814

Test: test CtsMultiUserTestCases:android.multiuser.cts.UserManagerTest#testIsUserVisible_startedProfileOfCurrentUser
Test: test CtsMultiUserTestCases:android.multiuser.cts.UserManagerTest#testIsUserVisible_stoppedProfileOfCurrentUser

Change-Id: I4cb109496370e3a910ed0598948fc189f35c3ddd
parent 36e74d4d
Loading
Loading
Loading
Loading
+26 −3
Original line number Diff line number Diff line
@@ -1650,14 +1650,37 @@ public class UserManagerService extends IUserManager.Stub {
        }

        int currentUser = Binder.withCleanCallingIdentity(() -> ActivityManager.getCurrentUser());
        // TODO(b/179163496): should return true for profile users of the current user as well
        return currentUser == userId;
    }

    @Override
    public boolean isUserVisible(@UserIdInt int userId) {
        // TODO(b/239824814): implement other cases like bg user, profile, user on secondary display
        return isUserForeground(userId);
        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 check if another user (" + userId
                    + ") is visible");
        }

        // First check current foreground user (on main display)
        int currentUserId = Binder.withCleanCallingIdentity(() -> ActivityManager.getCurrentUser());

        if (currentUserId == userId) {
            return true;
        }

        // Then profiles of current user
        // TODO(b/239824814): consider using AMInternal.isCurrentProfile() instead
        if (isProfile(userId)) {
            int parentId = Binder.withCleanCallingIdentity(() -> getProfileParentId(userId));
            if (parentId == currentUserId) {
                return isUserRunning(userId);
            }
        }

        // TODO(b/239824814): support background users on secondary display (and their profiles)
        return false;
    }

    @Override