diff options
8 files changed, 46 insertions, 86 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java index 5c230c0a505c..d8dba71c0a4f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecorViewModel.java @@ -33,6 +33,7 @@ import android.graphics.Region; import android.hardware.input.InputManager; import android.os.Handler; import android.os.RemoteException; +import android.os.UserHandle; import android.provider.Settings; import android.util.Log; import android.util.SparseArray; @@ -288,6 +289,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel { final CaptionWindowDecoration windowDecoration = new CaptionWindowDecoration( mContext, + mContext.createContextAsUser(UserHandle.of(taskInfo.userId), 0 /* flags */), mDisplayController, mTaskOrganizer, taskInfo, diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java index cf42a49f7103..de514f661d01 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/CaptionWindowDecoration.java @@ -77,6 +77,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL CaptionWindowDecoration( Context context, + @NonNull Context userContext, DisplayController displayController, ShellTaskOrganizer taskOrganizer, RunningTaskInfo taskInfo, @@ -85,7 +86,7 @@ public class CaptionWindowDecoration extends WindowDecoration<WindowDecorLinearL @ShellBackgroundThread ShellExecutor bgExecutor, Choreographer choreographer, SyncTransactionQueue syncQueue) { - super(context, displayController, taskOrganizer, taskInfo, taskSurface); + super(context, userContext, displayController, taskOrganizer, taskInfo, taskSurface); mHandler = handler; mBgExecutor = bgExecutor; mChoreographer = choreographer; diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java index 0ff35226b77e..7c8f205ce78f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModel.java @@ -59,6 +59,7 @@ import android.net.Uri; import android.os.Handler; import android.os.Looper; import android.os.RemoteException; +import android.os.UserHandle; import android.util.Log; import android.util.SparseArray; import android.view.Choreographer; @@ -1149,6 +1150,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel { final DesktopModeWindowDecoration windowDecoration = mDesktopModeWindowDecorFactory.create( mContext, + mContext.createContextAsUser(UserHandle.of(taskInfo.userId), 0 /* flags */), mDisplayController, mSplitScreenController, mTaskOrganizer, diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java index 41f428b6ca83..e82990f9fe1d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecoration.java @@ -160,6 +160,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin DesktopModeWindowDecoration( Context context, + @NonNull Context userContext, DisplayController displayController, SplitScreenController splitScreenController, ShellTaskOrganizer taskOrganizer, @@ -171,8 +172,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin SyncTransactionQueue syncQueue, RootTaskDisplayAreaOrganizer rootTaskDisplayAreaOrganizer, AppToWebGenericLinksParser genericLinksParser) { - this (context, displayController, splitScreenController, taskOrganizer, taskInfo, - taskSurface, handler, bgExecutor, choreographer, syncQueue, + this (context, userContext, displayController, splitScreenController, taskOrganizer, + taskInfo, taskSurface, handler, bgExecutor, choreographer, syncQueue, rootTaskDisplayAreaOrganizer, genericLinksParser, SurfaceControl.Builder::new, SurfaceControl.Transaction::new, WindowContainerTransaction::new, SurfaceControl::new, new SurfaceControlViewHostFactory() {}, @@ -181,6 +182,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin DesktopModeWindowDecoration( Context context, + @NonNull Context userContext, DisplayController displayController, SplitScreenController splitScreenController, ShellTaskOrganizer taskOrganizer, @@ -199,7 +201,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin SurfaceControlViewHostFactory surfaceControlViewHostFactory, MaximizeMenuFactory maximizeMenuFactory, HandleMenuFactory handleMenuFactory) { - super(context, displayController, taskOrganizer, taskInfo, taskSurface, + super(context, userContext, displayController, taskOrganizer, taskInfo, taskSurface, surfaceControlBuilderSupplier, surfaceControlTransactionSupplier, windowContainerTransactionSupplier, surfaceControlSupplier, surfaceControlViewHostFactory); @@ -737,12 +739,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin Slog.e(TAG, "Base activity component not found in task"); return; } - final PackageManager pm = mContext.getApplicationContext().getPackageManager(); - final ActivityInfo activityInfo = pm.getActivityInfo(baseActivity, - // Include uninstalled apps. Despite its name, adding this flag is a workaround - // to #getActivityInfo throwing a NameNotFoundException for installed packages - // when HSUM is enabled. See b/354884302. - PackageManager.MATCH_UNINSTALLED_PACKAGES); + final PackageManager pm = mUserContext.getPackageManager(); + final ActivityInfo activityInfo = pm.getActivityInfo(baseActivity, 0 /* flags */); final IconProvider provider = new IconProvider(mContext); final Drawable appIconDrawable = provider.getIcon(activityInfo); final BaseIconFactory headerIconFactory = createIconFactory(mContext, @@ -1264,6 +1262,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin DesktopModeWindowDecoration create( Context context, + @NonNull Context userContext, DisplayController displayController, SplitScreenController splitScreenController, ShellTaskOrganizer taskOrganizer, @@ -1277,6 +1276,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin AppToWebGenericLinksParser genericLinksParser) { return new DesktopModeWindowDecoration( context, + userContext, displayController, splitScreenController, taskOrganizer, diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java index 3b8657d4adf5..68285602a26e 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/windowdecor/WindowDecoration.java @@ -106,6 +106,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer> * System-wide context. Only used to create context with overridden configurations. */ final Context mContext; + final @NonNull Context mUserContext; final @NonNull DisplayController mDisplayController; final ShellTaskOrganizer mTaskOrganizer; final Supplier<SurfaceControl.Builder> mSurfaceControlBuilderSupplier; @@ -147,11 +148,12 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer> WindowDecoration( Context context, + @NonNull Context userContext, DisplayController displayController, ShellTaskOrganizer taskOrganizer, RunningTaskInfo taskInfo, SurfaceControl taskSurface) { - this(context, displayController, taskOrganizer, taskInfo, taskSurface, + this(context, userContext, displayController, taskOrganizer, taskInfo, taskSurface, SurfaceControl.Builder::new, SurfaceControl.Transaction::new, WindowContainerTransaction::new, SurfaceControl::new, new SurfaceControlViewHostFactory() {}); @@ -159,6 +161,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer> WindowDecoration( Context context, + @NonNull Context userContext, @NonNull DisplayController displayController, ShellTaskOrganizer taskOrganizer, RunningTaskInfo taskInfo, @@ -169,6 +172,7 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer> Supplier<SurfaceControl> surfaceControlSupplier, SurfaceControlViewHostFactory surfaceControlViewHostFactory) { mContext = context; + mUserContext = userContext; mDisplayController = displayController; mTaskOrganizer = taskOrganizer; mTaskInfo = taskInfo; @@ -177,7 +181,6 @@ public abstract class WindowDecoration<T extends View & TaskFocusStateConsumer> mSurfaceControlTransactionSupplier = surfaceControlTransactionSupplier; mWindowContainerTransactionSupplier = windowContainerTransactionSupplier; mSurfaceControlViewHostFactory = surfaceControlViewHostFactory; - mDisplay = mDisplayController.getDisplay(mTaskInfo.displayId); } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt index 01c4f3ad6870..e26416047c56 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorViewModelTests.kt @@ -103,6 +103,8 @@ import org.mockito.kotlin.whenever import org.mockito.quality.Strictness import java.util.Optional import java.util.function.Supplier +import junit.framework.Assert.assertFalse +import junit.framework.Assert.assertTrue /** * Tests of [DesktopModeWindowDecorViewModel] @@ -206,25 +208,13 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() { val decoration = setUpMockDecorationForTask(task) onTaskOpening(task, taskSurface) + assertTrue(windowDecorByTaskIdSpy.contains(task.taskId)) task.setWindowingMode(WINDOWING_MODE_UNDEFINED) task.setActivityType(ACTIVITY_TYPE_UNDEFINED) onTaskChanging(task, taskSurface) - verify(mockDesktopModeWindowDecorFactory).create( - mContext, - mockDisplayController, - mockSplitScreenController, - mockTaskOrganizer, - task, - taskSurface, - mockMainHandler, - bgExecutor, - mockMainChoreographer, - mockSyncQueue, - mockRootTaskDisplayAreaOrganizer, - mockGenericLinksParser - ) + assertFalse(windowDecorByTaskIdSpy.contains(task.taskId)) verify(decoration).close() } @@ -238,38 +228,12 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() { setUpMockDecorationForTask(task) onTaskChanging(task, taskSurface) - verify(mockDesktopModeWindowDecorFactory, never()).create( - mContext, - mockDisplayController, - mockSplitScreenController, - mockTaskOrganizer, - task, - taskSurface, - mockMainHandler, - bgExecutor, - mockMainChoreographer, - mockSyncQueue, - mockRootTaskDisplayAreaOrganizer, - mockGenericLinksParser - ) + assertFalse(windowDecorByTaskIdSpy.contains(task.taskId)) task.setWindowingMode(WINDOWING_MODE_FREEFORM) task.setActivityType(ACTIVITY_TYPE_STANDARD) onTaskChanging(task, taskSurface) - verify(mockDesktopModeWindowDecorFactory, times(1)).create( - mContext, - mockDisplayController, - mockSplitScreenController, - mockTaskOrganizer, - task, - taskSurface, - mockMainHandler, - bgExecutor, - mockMainChoreographer, - mockSyncQueue, - mockRootTaskDisplayAreaOrganizer, - mockGenericLinksParser - ) + assertTrue(windowDecorByTaskIdSpy.contains(task.taskId)) } @Test @@ -364,9 +328,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() { task.setWindowingMode(ACTIVITY_TYPE_UNDEFINED) onTaskChanging(task) - verify(mockDesktopModeWindowDecorFactory, never()) - .create(any(), any(), any(), any(), eq(task), any(), any(), any(), any(), any(), - any(), any()) + assertFalse(windowDecorByTaskIdSpy.contains(task.taskId)) } @Test @@ -386,9 +348,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() { setUpMockDecorationsForTasks(task) onTaskOpening(task) - verify(mockDesktopModeWindowDecorFactory) - .create(any(), any(), any(), any(), eq(task), any(), any(), any(), any(), - any(), any(), any()) + assertTrue(windowDecorByTaskIdSpy.contains(task.taskId)) } finally { mockitoSession.finishMocking() } @@ -404,9 +364,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() { } onTaskOpening(task) - verify(mockDesktopModeWindowDecorFactory, never()) - .create(any(), any(), any(), any(), eq(task), any(), any(), any(), any(), any(), - any(), any()) + assertFalse(windowDecorByTaskIdSpy.contains(task.taskId)) } @Test @@ -422,9 +380,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() { onTaskOpening(task) - verify(mockDesktopModeWindowDecorFactory, never()) - .create(any(), any(), any(), any(), eq(task), any(), any(), any(), any(), any(), - any(), any()) + assertFalse(windowDecorByTaskIdSpy.contains(task.taskId)) } @Test @@ -520,9 +476,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() { doReturn(false).`when` { DesktopModeStatus.isDesktopModeSupported(any()) } onTaskOpening(task) - verify(mockDesktopModeWindowDecorFactory, never()) - .create(any(), any(), any(), any(), eq(task), any(), any(), any(), any(), any(), - any(), any()) + assertFalse(windowDecorByTaskIdSpy.contains(task.taskId)) } finally { mockitoSession.finishMocking() } @@ -545,9 +499,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() { setUpMockDecorationsForTasks(task) onTaskOpening(task) - verify(mockDesktopModeWindowDecorFactory) - .create(any(), any(), any(), any(), eq(task), any(), any(), any(), any(), any(), - any(), any()) + assertTrue(windowDecorByTaskIdSpy.contains(task.taskId)) } finally { mockitoSession.finishMocking() } @@ -569,9 +521,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() { setUpMockDecorationsForTasks(task) onTaskOpening(task) - verify(mockDesktopModeWindowDecorFactory) - .create(any(), any(), any(), any(), eq(task), any(), any(), any(), any(), any(), - any(), any()) + assertTrue(windowDecorByTaskIdSpy.contains(task.taskId)) } finally { mockitoSession.finishMocking() } @@ -693,7 +643,7 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() { @WindowConfiguration.WindowingMode windowingMode: Int, activityType: Int = ACTIVITY_TYPE_STANDARD, focused: Boolean = true, - activityInfo: ActivityInfo = ActivityInfo() + activityInfo: ActivityInfo = ActivityInfo(), ): RunningTaskInfo { return TestRunningTaskInfoBuilder() .setDisplayId(displayId) @@ -709,8 +659,8 @@ class DesktopModeWindowDecorViewModelTests : ShellTestCase() { private fun setUpMockDecorationForTask(task: RunningTaskInfo): DesktopModeWindowDecoration { val decoration = mock(DesktopModeWindowDecoration::class.java) whenever( - mockDesktopModeWindowDecorFactory.create(any(), any(), any(), any(), eq(task), any(), - any(), any(), any(), any(), any(), any()) + mockDesktopModeWindowDecorFactory.create(any(), any(), any(), any(), any(), eq(task), + any(), any(), any(), any(), any(), any(), any()) ).thenReturn(decoration) decoration.mTaskInfo = task whenever(decoration.isFocused).thenReturn(task.isFocused) diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java index cee9307379ea..04b1eed02950 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/DesktopModeWindowDecorationTests.java @@ -826,10 +826,10 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase { ActivityManager.RunningTaskInfo taskInfo, MaximizeMenuFactory maximizeMenuFactory) { final DesktopModeWindowDecoration windowDecor = new DesktopModeWindowDecoration(mContext, - mMockDisplayController, mMockSplitScreenController, mMockShellTaskOrganizer, - taskInfo, mMockSurfaceControl, mMockHandler, mBgExecutor, mMockChoreographer, - mMockSyncQueue, mMockRootTaskDisplayAreaOrganizer, mMockGenericLinksParser, - SurfaceControl.Builder::new, mMockTransactionSupplier, + mContext, mMockDisplayController, mMockSplitScreenController, + mMockShellTaskOrganizer, taskInfo, mMockSurfaceControl, mMockHandler, mBgExecutor, + mMockChoreographer, mMockSyncQueue, mMockRootTaskDisplayAreaOrganizer, + mMockGenericLinksParser, SurfaceControl.Builder::new, mMockTransactionSupplier, WindowContainerTransaction::new, SurfaceControl::new, mMockSurfaceControlViewHostFactory, maximizeMenuFactory, mMockHandleMenuFactory); windowDecor.setCaptionListeners(mMockTouchEventListener, mMockTouchEventListener, diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java index ca6e03c45e7e..e6e2d0928240 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/windowdecor/WindowDecorationTests.java @@ -51,6 +51,7 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.mockito.quality.Strictness.LENIENT; +import android.annotation.NonNull; import android.app.ActivityManager; import android.content.Context; import android.content.res.Resources; @@ -893,8 +894,8 @@ public class WindowDecorationTests extends ShellTestCase { } private TestWindowDecoration createWindowDecoration(ActivityManager.RunningTaskInfo taskInfo) { - return new TestWindowDecoration(mContext, mMockDisplayController, mMockShellTaskOrganizer, - taskInfo, mMockTaskSurface, + return new TestWindowDecoration(mContext, mContext, mMockDisplayController, + mMockShellTaskOrganizer, taskInfo, mMockTaskSurface, new MockObjectSupplier<>(mMockSurfaceControlBuilders, () -> createMockSurfaceControlBuilder(mock(SurfaceControl.class))), new MockObjectSupplier<>(mMockSurfaceControlTransactions, @@ -932,7 +933,8 @@ public class WindowDecorationTests extends ShellTestCase { } private class TestWindowDecoration extends WindowDecoration<TestView> { - TestWindowDecoration(Context context, DisplayController displayController, + TestWindowDecoration(Context context, @NonNull Context userContext, + DisplayController displayController, ShellTaskOrganizer taskOrganizer, ActivityManager.RunningTaskInfo taskInfo, SurfaceControl taskSurface, Supplier<SurfaceControl.Builder> surfaceControlBuilderSupplier, @@ -940,7 +942,7 @@ public class WindowDecorationTests extends ShellTestCase { Supplier<WindowContainerTransaction> windowContainerTransactionSupplier, Supplier<SurfaceControl> surfaceControlSupplier, SurfaceControlViewHostFactory surfaceControlViewHostFactory) { - super(context, displayController, taskOrganizer, taskInfo, taskSurface, + super(context, userContext, displayController, taskOrganizer, taskInfo, taskSurface, surfaceControlBuilderSupplier, surfaceControlTransactionSupplier, windowContainerTransactionSupplier, surfaceControlSupplier, surfaceControlViewHostFactory); |