From 4ab0f4fe43a31487dcc412764baf8d7226334c6a Mon Sep 17 00:00:00 2001 From: Felipe Leme Date: Fri, 2 Sep 2022 11:49:17 -0700 Subject: [PATCH] Temporary fix on isUserVisibleOnDisplay(userId, displayId). WM will use this API, but the current implementation would break the behavior on non-passenger displays (like cluster, display, or virtual displays). So, this CL is (temporarily) changing the API to always return true for the current user (and its profiles), regardless of the display; the long-term solution would require integrating UserManagerService with DisplayManagerService for displays management. Also added a UserManagerInternal.isUserVisible(userId) method (which will be used by WM during Activity transition). Test: adb shell am start-user --display 42 13 && \ adb shell cmd user is-user-visible --display 42 0 Bug: 244644281 Change-Id: I5330016e0123e85c0f2ab3fc24a4f683994fdfe8 --- .../com/android/server/pm/UserManagerInternal.java | 6 ++++++ .../com/android/server/pm/UserManagerService.java | 12 ++++++++++++ 2 files changed, 18 insertions(+) diff --git a/services/core/java/com/android/server/pm/UserManagerInternal.java b/services/core/java/com/android/server/pm/UserManagerInternal.java index abc0ee4c89f64..a1d5054534839 100644 --- a/services/core/java/com/android/server/pm/UserManagerInternal.java +++ b/services/core/java/com/android/server/pm/UserManagerInternal.java @@ -329,6 +329,12 @@ public abstract class UserManagerInternal { */ public abstract void unassignUserFromDisplay(@UserIdInt int userId); + /** + * Returns {@code true} if the user is visible (as defined by + * {@link UserManager#isUserVisible()}. + */ + public abstract boolean isUserVisible(@UserIdInt int userId); + /** * Returns {@code true} if the user is visible (as defined by * {@link UserManager#isUserVisible()} in the given display. diff --git a/services/core/java/com/android/server/pm/UserManagerService.java b/services/core/java/com/android/server/pm/UserManagerService.java index ab40a4fff1ffd..a3bca4c8976ec 100644 --- a/services/core/java/com/android/server/pm/UserManagerService.java +++ b/services/core/java/com/android/server/pm/UserManagerService.java @@ -1770,6 +1770,13 @@ public class UserManagerService extends IUserManager.Stub { // TODO(b/239982558): try to merge with isUserVisibleUnchecked() (once both are unit tested) boolean isUserVisibleOnDisplay(@UserIdInt int userId, int displayId) { + // TODO(b/244644281): temporary workaround to let WM use this API without breaking current + // behavior (otherwise current user / profiles wouldn't be able to launch activities on + // other non-passenger displays, like cluster, display, or virtual displays) + if (isCurrentUserOrRunningProfileOfCurrentUser(userId)) { + return true; + } + if (displayId == Display.DEFAULT_DISPLAY) { return isCurrentUserOrRunningProfileOfCurrentUser(userId); } @@ -6727,6 +6734,11 @@ public class UserManagerService extends IUserManager.Stub { } } + @Override + public boolean isUserVisible(int userId) { + return isUserVisibleUnchecked(userId); + } + @Override public boolean isUserVisible(int userId, int displayId) { return isUserVisibleOnDisplay(userId, displayId);