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

Commit 2ed6216d authored by Jorge Gil's avatar Jorge Gil Committed by Android (Google) Code Review
Browse files

Merge "Move LaunchAdjacentController logic from Desktop* into FreeformListener." into main

parents f28c6040 e63f933b
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -304,6 +304,7 @@ public abstract class WMShellModule {
            ShellInit shellInit,
            ShellTaskOrganizer shellTaskOrganizer,
            Optional<DesktopModeTaskRepository> desktopModeTaskRepository,
            LaunchAdjacentController launchAdjacentController,
            WindowDecorViewModel windowDecorViewModel) {
        // TODO(b/238217847): Temporarily add this check here until we can remove the dynamic
        //                    override for this controller from the base module
@@ -311,7 +312,7 @@ public abstract class WMShellModule {
                ? shellInit
                : null;
        return new FreeformTaskListener(context, init, shellTaskOrganizer,
                desktopModeTaskRepository, windowDecorViewModel);
                desktopModeTaskRepository, launchAdjacentController, windowDecorViewModel);
    }

    @WMSingleton
+0 −7
Original line number Diff line number Diff line
@@ -150,12 +150,6 @@ class DesktopTasksController(
            visualIndicator?.releaseVisualIndicator(t)
            visualIndicator = null
        }
    private val taskVisibilityListener =
        object : VisibleTasksListener {
            override fun onTasksVisibilityChanged(displayId: Int, visibleTasksCount: Int) {
                launchAdjacentController.launchAdjacentEnabled = visibleTasksCount == 0
            }
        }
    private val dragToDesktopStateListener =
        object : DragToDesktopStateListener {
            override fun onCommitToDesktopAnimationStart(tx: SurfaceControl.Transaction) {
@@ -201,7 +195,6 @@ class DesktopTasksController(
            this
        )
        transitions.addHandler(this)
        taskRepository.addVisibleTasksListener(taskVisibilityListener, mainExecutor)
        dragToDesktopTransitionHandler.dragToDesktopStateListener = dragToDesktopStateListener
        recentsTransitionHandler.addTransitionStateListener(
            object : RecentsTransitionStateListener {
+17 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.view.SurfaceControl;

import com.android.internal.protolog.ProtoLog;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.common.LaunchAdjacentController;
import com.android.wm.shell.desktopmode.DesktopModeTaskRepository;
import com.android.wm.shell.protolog.ShellProtoLogGroup;
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus;
@@ -49,6 +50,7 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
    private final ShellTaskOrganizer mShellTaskOrganizer;
    private final Optional<DesktopModeTaskRepository> mDesktopModeTaskRepository;
    private final WindowDecorViewModel mWindowDecorationViewModel;
    private final LaunchAdjacentController mLaunchAdjacentController;

    private final SparseArray<State> mTasks = new SparseArray<>();

@@ -62,11 +64,13 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
            ShellInit shellInit,
            ShellTaskOrganizer shellTaskOrganizer,
            Optional<DesktopModeTaskRepository> desktopModeTaskRepository,
            LaunchAdjacentController launchAdjacentController,
            WindowDecorViewModel windowDecorationViewModel) {
        mContext = context;
        mShellTaskOrganizer = shellTaskOrganizer;
        mWindowDecorationViewModel = windowDecorationViewModel;
        mDesktopModeTaskRepository = desktopModeTaskRepository;
        mLaunchAdjacentController = launchAdjacentController;
        if (shellInit != null) {
            shellInit.addInitCallback(this::onInit, this);
        }
@@ -106,6 +110,7 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
                }
            });
        }
        updateLaunchAdjacentController();
    }

    @Override
@@ -123,6 +128,7 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
        if (!Transitions.ENABLE_SHELL_TRANSITIONS) {
            mWindowDecorationViewModel.destroyWindowDecoration(taskInfo);
        }
        updateLaunchAdjacentController();
    }

    @Override
@@ -144,6 +150,17 @@ public class FreeformTaskListener implements ShellTaskOrganizer.TaskListener,
                        taskInfo.isVisible);
            });
        }
        updateLaunchAdjacentController();
    }

    private void updateLaunchAdjacentController() {
        for (int i = 0; i < mTasks.size(); i++) {
            if (mTasks.valueAt(i).mTaskInfo.isVisible) {
                mLaunchAdjacentController.setLaunchAdjacentEnabled(false);
                return;
            }
        }
        mLaunchAdjacentController.setLaunchAdjacentEnabled(true);
    }

    @Override
+0 −21
Original line number Diff line number Diff line
@@ -2263,27 +2263,6 @@ class DesktopTasksControllerTest : ShellTestCase() {
    assertNull(result, "Should not handle request")
  }

  @Test
  fun desktopTasksVisibilityChange_visible_setLaunchAdjacentDisabled() {
    val task = setUpFreeformTask()
    clearInvocations(launchAdjacentController)

    markTaskVisible(task)
    shellExecutor.flushAll()
    verify(launchAdjacentController).launchAdjacentEnabled = false
  }

  @Test
  fun desktopTasksVisibilityChange_invisible_setLaunchAdjacentEnabled() {
    val task = setUpFreeformTask()
    markTaskVisible(task)
    clearInvocations(launchAdjacentController)

    markTaskHidden(task)
    shellExecutor.flushAll()
    verify(launchAdjacentController).launchAdjacentEnabled = true
  }

  @Test
  fun moveFocusedTaskToDesktop_fullscreenTaskIsMovedToDesktop() {
    val task1 = setUpFullscreenTask()
+32 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

import android.app.ActivityManager;
import android.view.SurfaceControl;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
@@ -35,6 +36,7 @@ import com.android.dx.mockito.inline.extended.StaticMockitoSession;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.ShellTestCase;
import com.android.wm.shell.TestRunningTaskInfoBuilder;
import com.android.wm.shell.common.LaunchAdjacentController;
import com.android.wm.shell.desktopmode.DesktopModeTaskRepository;
import com.android.wm.shell.shared.desktopmode.DesktopModeStatus;
import com.android.wm.shell.sysui.ShellInit;
@@ -65,7 +67,11 @@ public final class FreeformTaskListenerTests extends ShellTestCase {
    @Mock
    private WindowDecorViewModel mWindowDecorViewModel;
    @Mock
    private SurfaceControl mMockSurfaceControl;
    @Mock
    private DesktopModeTaskRepository mDesktopModeTaskRepository;
    @Mock
    private LaunchAdjacentController mLaunchAdjacentController;
    private FreeformTaskListener mFreeformTaskListener;
    private StaticMockitoSession mMockitoSession;

@@ -80,6 +86,7 @@ public final class FreeformTaskListenerTests extends ShellTestCase {
                mShellInit,
                mTaskOrganizer,
                Optional.of(mDesktopModeTaskRepository),
                mLaunchAdjacentController,
                mWindowDecorViewModel);
    }

@@ -107,6 +114,31 @@ public final class FreeformTaskListenerTests extends ShellTestCase {
                .addOrMoveFreeformTaskToTop(fullscreenTask.displayId, fullscreenTask.taskId);
    }

    @Test
    public void testVisibilityTaskChanged_visible_setLaunchAdjacentDisabled() {
        ActivityManager.RunningTaskInfo task = new TestRunningTaskInfoBuilder()
                .setWindowingMode(WINDOWING_MODE_FREEFORM).build();
        task.isVisible = true;

        mFreeformTaskListener.onTaskAppeared(task, mMockSurfaceControl);

        verify(mLaunchAdjacentController).setLaunchAdjacentEnabled(false);
    }

    @Test
    public void testVisibilityTaskChanged_NotVisible_setLaunchAdjacentEnabled() {
        ActivityManager.RunningTaskInfo task = new TestRunningTaskInfoBuilder()
                .setWindowingMode(WINDOWING_MODE_FREEFORM).build();
        task.isVisible = true;

        mFreeformTaskListener.onTaskAppeared(task, mMockSurfaceControl);

        task.isVisible = false;
        mFreeformTaskListener.onTaskInfoChanged(task);

        verify(mLaunchAdjacentController).setLaunchAdjacentEnabled(true);
    }

    @After
    public void tearDown() {
        mMockitoSession.finishMocking();
Loading