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

Commit da0d26e5 authored by Ats Jenk's avatar Ats Jenk Committed by Android (Google) Code Review
Browse files

Merge "Limit freeform to front for freeform task launches" into tm-qpr-dev

parents eca2762d 40828e97
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -249,11 +249,23 @@ public class DesktopModeController implements RemoteCallable<DesktopModeControll
    @Override
    public WindowContainerTransaction handleRequest(@NonNull IBinder transition,
            @NonNull TransitionRequestInfo request) {

        // Only do anything if we are in desktop mode and opening a task/app
        if (!DesktopModeStatus.isActive(mContext) || request.getType() != TRANSIT_OPEN) {
        // Only do anything if we are in desktop mode and opening a task/app in freeform
        if (!DesktopModeStatus.isActive(mContext)) {
            ProtoLog.d(WM_SHELL_DESKTOP_MODE,
                    "skip shell transition request: desktop mode not active");
            return null;
        }
        if (request.getType() != TRANSIT_OPEN) {
            ProtoLog.d(WM_SHELL_DESKTOP_MODE,
                    "skip shell transition request: only supports TRANSIT_OPEN");
            return null;
        }
        if (request.getTriggerTask() == null
                || request.getTriggerTask().getWindowingMode() != WINDOWING_MODE_FREEFORM) {
            ProtoLog.d(WM_SHELL_DESKTOP_MODE, "skip shell transition request: not freeform task");
            return null;
        }
        ProtoLog.d(WM_SHELL_DESKTOP_MODE, "handle shell transition request: %s", request);

        WindowContainerTransaction wct = mTransitions.dispatchRequest(transition, request, this);
        if (wct == null) {
+42 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.app.WindowConfiguration.WINDOW_CONFIG_BOUNDS;
import static android.view.WindowManager.TRANSIT_OPEN;
import static android.view.WindowManager.TRANSIT_TO_FRONT;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_REORDER;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
@@ -35,10 +37,12 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.app.ActivityManager;
import android.os.Binder;
import android.os.Handler;
import android.os.IBinder;
import android.testing.AndroidTestingRunner;
import android.window.DisplayAreaInfo;
import android.window.TransitionRequestInfo;
import android.window.WindowContainerToken;
import android.window.WindowContainerTransaction;
import android.window.WindowContainerTransaction.Change;
@@ -243,6 +247,44 @@ public class DesktopModeControllerTest extends ShellTestCase {
        assertThat(op2.getContainer()).isEqualTo(token2.binder());
    }

    @Test
    public void testHandleTransitionRequest_desktopModeNotActive_returnsNull() {
        when(DesktopModeStatus.isActive(any())).thenReturn(false);
        WindowContainerTransaction wct = mController.handleRequest(
                new Binder(),
                new TransitionRequestInfo(TRANSIT_OPEN, null /* trigger */, null /* remote */));
        assertThat(wct).isNull();
    }

    @Test
    public void testHandleTransitionRequest_notTransitOpen_returnsNull() {
        WindowContainerTransaction wct = mController.handleRequest(
                new Binder(),
                new TransitionRequestInfo(TRANSIT_TO_FRONT, null /* trigger */, null /* remote */));
        assertThat(wct).isNull();
    }

    @Test
    public void testHandleTransitionRequest_notFreeform_returnsNull() {
        ActivityManager.RunningTaskInfo trigger = new ActivityManager.RunningTaskInfo();
        trigger.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FULLSCREEN);
        WindowContainerTransaction wct = mController.handleRequest(
                new Binder(),
                new TransitionRequestInfo(TRANSIT_TO_FRONT, trigger, null /* remote */));
        assertThat(wct).isNull();
    }

    @Test
    public void testHandleTransitionRequest_returnsWct() {
        ActivityManager.RunningTaskInfo trigger = new ActivityManager.RunningTaskInfo();
        trigger.token = new MockToken().mToken;
        trigger.configuration.windowConfiguration.setWindowingMode(WINDOWING_MODE_FREEFORM);
        WindowContainerTransaction wct = mController.handleRequest(
                mock(IBinder.class),
                new TransitionRequestInfo(TRANSIT_OPEN, trigger, null /* remote */));
        assertThat(wct).isNotNull();
    }

    private static class MockToken {
        private final WindowContainerToken mToken;
        private final IBinder mBinder;