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

Commit 73a6c605 authored by Merissa Mitchell's avatar Merissa Mitchell Committed by Android (Google) Code Review
Browse files

Merge "[PiP on Desktop] Make inset update a Transition if changing app bounds." into main

parents b307eaf5 40e94532
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1845,6 +1845,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel,
                        mMainDispatcher,
                        mBgScope,
                        mBgExecutor,
                        mTransitions,
                        mMainChoreographer,
                        mSyncQueue,
                        mAppHeaderViewHolderFactory,
+23 −5
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.view.InsetsSource.FLAG_FORCE_CONSUMING_OPAQUE_CAPTION_BAR;
import static android.view.MotionEvent.ACTION_CANCEL;
import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_UP;
import static android.view.WindowManager.TRANSIT_CHANGE;
import static android.window.DesktopModeFlags.ENABLE_CAPTION_COMPAT_INSET_FORCE_CONSUMPTION;
import static android.window.DesktopModeFlags.ENABLE_CAPTION_COMPAT_INSET_FORCE_CONSUMPTION_ALWAYS;

@@ -104,6 +105,7 @@ import com.android.wm.shell.shared.desktopmode.DesktopModeTransitionSource;
import com.android.wm.shell.shared.desktopmode.DesktopState;
import com.android.wm.shell.shared.multiinstance.ManageWindowsViewContainer;
import com.android.wm.shell.splitscreen.SplitScreenController;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.windowdecor.common.DecorThemeUtil;
import com.android.wm.shell.windowdecor.common.Theme;
import com.android.wm.shell.windowdecor.common.WindowDecorTaskResourceLoader;
@@ -145,6 +147,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
    private final @ShellMainThread MainCoroutineDispatcher mMainDispatcher;
    private final @ShellBackgroundThread CoroutineScope mBgScope;
    private final @ShellBackgroundThread ShellExecutor mBgExecutor;
    private final Transitions mTransitions;
    private final Choreographer mChoreographer;
    private final SyncTransactionQueue mSyncQueue;
    private final SplitScreenController mSplitScreenController;
@@ -238,6 +241,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            @ShellMainThread MainCoroutineDispatcher mainDispatcher,
            @ShellBackgroundThread CoroutineScope bgScope,
            @ShellBackgroundThread ShellExecutor bgExecutor,
            Transitions transitions,
            Choreographer choreographer,
            SyncTransactionQueue syncQueue,
            AppHeaderViewHolder.Factory appHeaderViewHolderFactory,
@@ -255,8 +259,8 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            DesktopConfig desktopConfig) {
        this (context, userContext, displayController, taskResourceLoader, splitScreenController,
                desktopUserRepositories, taskOrganizer, taskInfo, taskSurface, handler,
                mainExecutor, mainDispatcher, bgScope, bgExecutor, choreographer, syncQueue,
                appHeaderViewHolderFactory, appHandleViewHolderFactory,
                mainExecutor, mainDispatcher, bgScope, bgExecutor, transitions, choreographer,
                syncQueue, appHeaderViewHolderFactory, appHandleViewHolderFactory,
                rootTaskDisplayAreaOrganizer, genericLinksParser, assistContentRequester,
                SurfaceControl.Builder::new, SurfaceControl.Transaction::new,
                WindowContainerTransaction::new, SurfaceControl::new, new WindowManagerWrapper(
@@ -285,6 +289,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
            @ShellMainThread MainCoroutineDispatcher mainDispatcher,
            @ShellBackgroundThread CoroutineScope bgScope,
            @ShellBackgroundThread ShellExecutor bgExecutor,
            Transitions transitions,
            Choreographer choreographer,
            SyncTransactionQueue syncQueue,
            AppHeaderViewHolder.Factory appHeaderViewHolderFactory,
@@ -318,6 +323,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        mMainDispatcher = mainDispatcher;
        mBgScope = bgScope;
        mBgExecutor = bgExecutor;
        mTransitions = transitions;
        mChoreographer = choreographer;
        mSyncQueue = syncQueue;
        mAppHeaderViewHolderFactory = appHeaderViewHolderFactory;
@@ -513,7 +519,6 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        updateDragResizeListenerIfNeeded(mDecorationContainerSurface, inFullImmersive);
    }


    void relayout(ActivityManager.RunningTaskInfo taskInfo,
            SurfaceControl.Transaction startT, SurfaceControl.Transaction finishT,
            boolean applyStartTransactionOnDraw, boolean shouldSetTaskVisibilityPositionAndCrop,
@@ -565,8 +570,19 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
        relayout(mRelayoutParams, startT, finishT, wct, oldRootView, mResult);
        // After this line, mTaskInfo is up-to-date and should be used instead of taskInfo

        if (DesktopExperienceFlags.ENABLE_DESKTOP_WINDOWING_PIP.isTrue()
                && mRelayoutParams.mShouldSetAppBounds) {
            // When expanding from PiP to freeform, we need to start a Transition for applying the
            // inset changes so that PiP receives the insets for the final bounds. This is because
            // |mShouldSetAppBounds| applies the insets by modifying app bounds, which can cause a
            // bounds offset that needs to be reported to transition handlers.
            Trace.beginSection("DesktopModeWindowDecoration#relayout-startTransition");
            mHandler.post(
                    () -> mTransitions.startTransition(TRANSIT_CHANGE, wct, /* handler= */ null));
        } else {
            Trace.beginSection("DesktopModeWindowDecoration#relayout-applyWCT");
            mBgExecutor.execute(() -> mTaskOrganizer.applyTransaction(wct));
        }
        Trace.endSection();

        if (mResult.mRootView == null) {
@@ -2001,6 +2017,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                @ShellMainThread MainCoroutineDispatcher mainDispatcher,
                @ShellBackgroundThread CoroutineScope bgScope,
                @ShellBackgroundThread ShellExecutor bgExecutor,
                Transitions transitions,
                Choreographer choreographer,
                SyncTransactionQueue syncQueue,
                AppHeaderViewHolder.Factory appHeaderViewHolderFactory,
@@ -2032,6 +2049,7 @@ public class DesktopModeWindowDecoration extends WindowDecoration<WindowDecorLin
                    mainDispatcher,
                    bgScope,
                    bgExecutor,
                    transitions,
                    choreographer,
                    syncQueue,
                    appHeaderViewHolderFactory,
+1 −1
Original line number Diff line number Diff line
@@ -355,7 +355,7 @@ open class DesktopModeWindowDecorViewModelTestsBase : ShellTestCase() {
            mockDesktopModeWindowDecorFactory.create(
                any(), any(), any(), any(), any(), any(), any(), eq(task), any(), any(), any(),
                any(), any(), any(), any(), any(), any(), any(), any(), any(), any(), any(),
                any(), any(), any(), any(), any(), any(), any())
                any(), any(), any(), any(), any(), any(), any(), any())
        ).thenReturn(decoration)
        decoration.mTaskInfo = task
        whenever(decoration.user).thenReturn(mockUserHandle)
+50 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import static android.view.InsetsSource.FLAG_FORCE_CONSUMING_OPAQUE_CAPTION_BAR;
import static android.view.WindowInsets.Type.captionBar;
import static android.view.WindowInsets.Type.statusBars;
import static android.view.WindowInsetsController.APPEARANCE_TRANSPARENT_CAPTION_BAR_BACKGROUND;
import static android.view.WindowManager.TRANSIT_CHANGE;

import static com.android.wm.shell.MockSurfaceControlHelper.createMockSurfaceControlTransaction;
import static com.android.wm.shell.shared.split.SplitScreenConstants.SPLIT_POSITION_BOTTOM_OR_RIGHT;
@@ -67,6 +68,7 @@ import android.graphics.Rect;
import android.graphics.Region;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.platform.test.annotations.DisableFlags;
import android.platform.test.annotations.EnableFlags;
import android.testing.AndroidTestingRunner;
@@ -96,6 +98,7 @@ import com.android.window.flags.Flags;
import com.android.wm.shell.RootTaskDisplayAreaOrganizer;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.ShellTestCase;
import com.android.wm.shell.TestHandler;
import com.android.wm.shell.TestRunningTaskInfoBuilder;
import com.android.wm.shell.TestShellExecutor;
import com.android.wm.shell.apptoweb.AppToWebGenericLinksParser;
@@ -115,6 +118,7 @@ import com.android.wm.shell.shared.desktopmode.DesktopModeCompatPolicy;
import com.android.wm.shell.shared.desktopmode.FakeDesktopConfig;
import com.android.wm.shell.shared.desktopmode.FakeDesktopState;
import com.android.wm.shell.splitscreen.SplitScreenController;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.windowdecor.WindowDecoration.RelayoutParams;
import com.android.wm.shell.windowdecor.common.WindowDecorTaskResourceLoader;
import com.android.wm.shell.windowdecor.common.viewhost.WindowDecorViewHost;
@@ -257,6 +261,9 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
    private WindowDecorTaskResourceLoader mMockTaskResourceLoader;
    @Mock
    private DesktopModeCompatPolicy mDesktopModeCompatPolicy;
    @Mock
    private Transitions mTransitions;
    private final TestHandler mTestHandler = new TestHandler(Looper.getMainLooper());
    @Captor
    private ArgumentCaptor<Function1<Boolean, Unit>> mOnMaxMenuHoverChangeListener;
    @Captor
@@ -1225,6 +1232,39 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
        verify(mMockRootSurfaceControl).applyTransactionOnDraw(mMockTransaction);
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_CAPTION_COMPAT_INSET_FORCE_CONSUMPTION_ALWAYS,
            Flags.FLAG_ENABLE_DESKTOP_WINDOWING_PIP})
    public void relayout_shouldSetAppBounds_startsTransition() {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(/* visible= */ true);
        final DesktopModeWindowDecoration spyWindowDecor =
                spy(createWindowDecoration(taskInfo, new FakeMaximizeMenuFactory(), /* relayout= */
                        false, mTestHandler));
        taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);
        when(mDesktopModeCompatPolicy.shouldExcludeCaptionFromAppBounds(taskInfo)).thenReturn(true);

        spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */, mExclusionRegion);

        verify(mTransitions).startTransition(eq(TRANSIT_CHANGE), any(), any());
    }

    @Test
    @EnableFlags({Flags.FLAG_ENABLE_CAPTION_COMPAT_INSET_FORCE_CONSUMPTION_ALWAYS,
            Flags.FLAG_ENABLE_DESKTOP_WINDOWING_PIP})
    public void relayout_shouldNotSetAppBounds_doesNotStartTransition() {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(/* visible= */ true);
        final DesktopModeWindowDecoration spyWindowDecor =
                spy(createWindowDecoration(taskInfo, new FakeMaximizeMenuFactory(), /* relayout= */
                        false, mTestHandler));
        taskInfo.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);
        when(mDesktopModeCompatPolicy.shouldExcludeCaptionFromAppBounds(taskInfo)).thenReturn(
                false);

        spyWindowDecor.relayout(taskInfo, true /* hasGlobalFocus */, mExclusionRegion);

        verify(mTransitions, never()).startTransition(anyInt(), any(), any());
    }

    @Test
    public void createMaximizeMenu_showsMenu() {
        final ActivityManager.RunningTaskInfo taskInfo = createTaskInfo(true /* visible */);
@@ -1883,11 +1923,19 @@ public class DesktopModeWindowDecorationTests extends ShellTestCase {
            ActivityManager.RunningTaskInfo taskInfo,
            MaximizeMenuFactory maximizeMenuFactory,
            boolean relayout) {
        return createWindowDecoration(taskInfo, maximizeMenuFactory, relayout, mMockHandler);
    }

    private DesktopModeWindowDecoration createWindowDecoration(
            ActivityManager.RunningTaskInfo taskInfo,
            MaximizeMenuFactory maximizeMenuFactory,
            boolean relayout,
            Handler handler) {
        final DesktopModeWindowDecoration windowDecor = new DesktopModeWindowDecoration(mContext,
                mContext, mMockDisplayController, mMockTaskResourceLoader,
                mMockSplitScreenController, mMockDesktopUserRepositories, mMockShellTaskOrganizer,
                taskInfo, mMockSurfaceControl, mMockHandler, mMainExecutor,
                mMockMainCoroutineDispatcher, mMockBgCoroutineScope, mBgExecutor,
                taskInfo, mMockSurfaceControl, handler, mMainExecutor,
                mMockMainCoroutineDispatcher, mMockBgCoroutineScope, mBgExecutor, mTransitions,
                mMockChoreographer, mMockSyncQueue, mMockAppHeaderViewHolderFactory,
                mMockAppHandleViewHolderFactory, mMockRootTaskDisplayAreaOrganizer,
                mMockGenericLinksParser, mMockAssistContentRequester, SurfaceControl.Builder::new,