diff options
8 files changed, 41 insertions, 37 deletions
diff --git a/data/etc/services.core.protolog.json b/data/etc/services.core.protolog.json index dfff75b7bf24..8a6dbfba73da 100644 --- a/data/etc/services.core.protolog.json +++ b/data/etc/services.core.protolog.json @@ -373,12 +373,6 @@ "group": "WM_DEBUG_WINDOW_TRANSITIONS", "at": "com\/android\/server\/wm\/TransitionController.java" }, - "-1750384749": { - "message": "Launch on display check: allow launch on public display", - "level": "DEBUG", - "group": "WM_DEBUG_TASKS", - "at": "com\/android\/server\/wm\/ActivityTaskSupervisor.java" - }, "-1750206390": { "message": "Exception thrown when creating surface for client %s (%s). %s", "level": "WARN", @@ -907,6 +901,12 @@ "group": "WM_DEBUG_BOOT", "at": "com\/android\/server\/wm\/WindowManagerService.java" }, + "-1253056469": { + "message": "Launch on display check: %s launch for userId=%d on displayId=%d", + "level": "DEBUG", + "group": "WM_DEBUG_TASKS", + "at": "com\/android\/server\/wm\/ActivityTaskSupervisor.java" + }, "-1248645819": { "message": "\tAdd container=%s", "level": "DEBUG", diff --git a/services/core/java/com/android/server/am/UserController.java b/services/core/java/com/android/server/am/UserController.java index 043da55b55cb..ca90601e7678 100644 --- a/services/core/java/com/android/server/am/UserController.java +++ b/services/core/java/com/android/server/am/UserController.java @@ -1628,7 +1628,7 @@ class UserController implements Handler.Callback { } mInjector.updateUserConfiguration(); updateCurrentProfileIds(); - mInjector.getWindowManager().setCurrentUser(userId, getCurrentProfileIds()); + mInjector.getWindowManager().setCurrentUser(userId); mInjector.reportCurWakefulnessUsageEvent(); // Once the internal notion of the active user has switched, we lock the device // with the option to show the user switcher on the keyguard. @@ -1642,7 +1642,6 @@ class UserController implements Handler.Callback { } else { final Integer currentUserIdInt = mCurrentUserId; updateCurrentProfileIds(); - mInjector.getWindowManager().setCurrentProfileIds(getCurrentProfileIds()); synchronized (mLock) { mUserLru.remove(currentUserIdInt); mUserLru.add(currentUserIdInt); diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index be801182980d..d4c77b66bd47 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -9519,7 +9519,7 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A @Override boolean showToCurrentUser() { - return mShowForAllUsers || mWmService.isCurrentProfile(mUserId); + return mShowForAllUsers || mWmService.isUserVisible(mUserId); } @Override diff --git a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java index dc91c1597128..846caacbd32f 100644 --- a/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java +++ b/services/core/java/com/android/server/wm/ActivityTaskSupervisor.java @@ -1183,10 +1183,14 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks { } if (!displayContent.isPrivate()) { - // Anyone can launch on a public display. - ProtoLog.d(WM_DEBUG_TASKS, "Launch on display check: allow launch on public " - + "display"); - return true; + // Checks if the caller can be shown in the given public display. + int userId = UserHandle.getUserId(callingUid); + int displayId = display.getDisplayId(); + boolean allowed = mWindowManager.mUmInternal.isUserVisible(userId, displayId); + ProtoLog.d(WM_DEBUG_TASKS, + "Launch on display check: %s launch for userId=%d on displayId=%d", + (allowed ? "allow" : "disallow"), userId, displayId); + return allowed; } // Check if the caller is the owner of the display. diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index ec28f34d3a44..6f5ef96c7e87 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -2904,7 +2904,7 @@ class Task extends TaskFragment { @Override boolean showToCurrentUser() { return mForceShowForAllUsers || showForAllUsers() - || mWmService.isCurrentProfile(getTopMostTask().mUserId); + || mWmService.isUserVisible(getTopMostTask().mUserId); } void setForceShowForAllUsers(boolean forceShowForAllUsers) { diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 5ad6fbd69d7e..243bab50bab3 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -155,6 +155,7 @@ import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.RequiresPermission; +import android.annotation.UserIdInt; import android.app.ActivityManager; import android.app.ActivityManagerInternal; import android.app.ActivityThread; @@ -314,6 +315,7 @@ import com.android.server.LocalServices; import com.android.server.UiThread; import com.android.server.Watchdog; import com.android.server.input.InputManagerService; +import com.android.server.pm.UserManagerInternal; import com.android.server.policy.WindowManagerPolicy; import com.android.server.policy.WindowManagerPolicy.ScreenOffListener; import com.android.server.power.ShutdownThread; @@ -503,15 +505,9 @@ public class WindowManagerService extends IWindowManager.Stub }; /** - * Current user when multi-user is enabled. Don't show windows of - * non-current user. Also see mCurrentProfileIds. + * Current user when multi-user is enabled. Don't show windows of non-current user. */ - int mCurrentUserId; - /** - * Users that are profiles of the current user. These are also allowed to show windows - * on the current user. - */ - int[] mCurrentProfileIds = new int[] {}; + @UserIdInt int mCurrentUserId; final Context mContext; @@ -533,6 +529,7 @@ public class WindowManagerService extends IWindowManager.Stub final IActivityManager mActivityManager; final ActivityManagerInternal mAmInternal; + final UserManagerInternal mUmInternal; final AppOpsManager mAppOps; final PackageManagerInternal mPmInternal; @@ -1262,6 +1259,7 @@ public class WindowManagerService extends IWindowManager.Stub mActivityManager = ActivityManager.getService(); mAmInternal = LocalServices.getService(ActivityManagerInternal.class); + mUmInternal = LocalServices.getService(UserManagerInternal.class); mAppOps = (AppOpsManager)context.getSystemService(Context.APP_OPS_SERVICE); AppOpsManager.OnOpChangedInternalListener opListener = new AppOpsManager.OnOpChangedInternalListener() { @@ -3557,16 +3555,9 @@ public class WindowManagerService extends IWindowManager.Stub confirm); } - public void setCurrentProfileIds(final int[] currentProfileIds) { - synchronized (mGlobalLock) { - mCurrentProfileIds = currentProfileIds; - } - } - - public void setCurrentUser(final int newUserId, final int[] currentProfileIds) { + public void setCurrentUser(@UserIdInt int newUserId) { synchronized (mGlobalLock) { mCurrentUserId = newUserId; - mCurrentProfileIds = currentProfileIds; mPolicy.setCurrentUserLw(newUserId); mKeyguardDisableHandler.setCurrentUser(newUserId); @@ -3589,12 +3580,8 @@ public class WindowManagerService extends IWindowManager.Stub } /* Called by WindowState */ - boolean isCurrentProfile(int userId) { - if (userId == mCurrentUserId) return true; - for (int i = 0; i < mCurrentProfileIds.length; i++) { - if (mCurrentProfileIds[i] == userId) return true; - } - return false; + boolean isUserVisible(@UserIdInt int userId) { + return mUmInternal.isUserVisible(userId); } public void enableScreenAfterBoot() { diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java index df7b8bb4ec9b..1d43d18ab917 100644 --- a/services/core/java/com/android/server/wm/WindowState.java +++ b/services/core/java/com/android/server/wm/WindowState.java @@ -3684,7 +3684,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP } return win.showForAllUsers() - || mWmService.isCurrentProfile(win.mShowUserId); + || mWmService.isUserVisible(win.mShowUserId); } private static void applyInsets(Region outRegion, Rect frame, Rect inset) { diff --git a/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java b/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java index 9e6c4c58371b..eda7d910dd42 100644 --- a/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java +++ b/services/tests/wmtests/src/com/android/server/wm/SystemServicesTestRule.java @@ -39,6 +39,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.spy; import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn; import static org.mockito.Mockito.CALLS_REAL_METHODS; +import static org.mockito.Mockito.when; import static org.mockito.Mockito.withSettings; import android.app.ActivityManagerInternal; @@ -81,6 +82,7 @@ import com.android.server.am.ActivityManagerService; import com.android.server.display.color.ColorDisplayService; import com.android.server.firewall.IntentFirewall; import com.android.server.input.InputManagerService; +import com.android.server.pm.UserManagerInternal; import com.android.server.pm.UserManagerService; import com.android.server.policy.PermissionPolicyInternal; import com.android.server.policy.WindowManagerPolicy; @@ -93,6 +95,7 @@ import org.junit.runners.model.Statement; import org.mockito.MockSettings; import org.mockito.Mockito; import org.mockito.quality.Strictness; +import org.mockito.stubbing.Answer; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; @@ -283,6 +286,16 @@ public class SystemServicesTestRule implements TestRule { // StatusBarManagerInternal final StatusBarManagerInternal sbmi = mock(StatusBarManagerInternal.class); doReturn(sbmi).when(() -> LocalServices.getService(eq(StatusBarManagerInternal.class))); + + // UserManagerInternal + final UserManagerInternal umi = mock(UserManagerInternal.class); + doReturn(umi).when(() -> LocalServices.getService(UserManagerInternal.class)); + Answer<Boolean> isUserVisibleAnswer = invocation -> { + int userId = invocation.getArgument(0); + return userId == mWmService.mCurrentUserId; + }; + when(umi.isUserVisible(anyInt())).thenAnswer(isUserVisibleAnswer); + when(umi.isUserVisible(anyInt(), anyInt())).thenAnswer(isUserVisibleAnswer); } private void setUpActivityTaskManagerService() { @@ -403,6 +416,7 @@ public class SystemServicesTestRule implements TestRule { LocalServices.removeServiceForTest(ColorDisplayService.ColorDisplayServiceInternal.class); LocalServices.removeServiceForTest(UsageStatsManagerInternal.class); LocalServices.removeServiceForTest(StatusBarManagerInternal.class); + LocalServices.removeServiceForTest(UserManagerInternal.class); } Description getDescription() { |