diff options
| author | 2022-08-08 15:14:53 -0700 | |
|---|---|---|
| committer | 2022-08-09 03:39:29 +0000 | |
| commit | a683350eb91780430028da92feab6f129cdfc683 (patch) | |
| tree | 735620eba12d642971adb47a956b6b7a1f80e21c | |
| parent | 36e74d4db8300935d535c77aa760cbc76a6b4437 (diff) | |
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
| -rw-r--r-- | services/core/java/com/android/server/pm/UserManagerService.java | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java index 60f22b032366..5a60da96218e 100644 --- a/services/core/java/com/android/server/pm/UserManagerService.java +++ b/services/core/java/com/android/server/pm/UserManagerService.java @@ -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 |