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

Commit e63f933b authored by Ben Lin's avatar Ben Lin
Browse files

Move LaunchAdjacentController logic from Desktop* into FreeformListener.

Currently the controller is set to disable LaunchAdjacent if and only if
Android Desktop Mode is enabled, and there are freeform tasks visible.
Instead of disabling it only when ADM is on, change the callback so that
when there's any >0 freeform tasks appearing in FreeformTaskListener,
diasble LaunchAdjacent.

Bug: 357649930
Test: Manual; In a non-ADM device, open Chrome w/ Freeform window,
then New Window - see that a new freeform window appears
Flag: EXEMPT Bug fix

Change-Id: I615f93a580e8a0b27cbc30b5947815bfcd69c7be
parent 81faef45
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -301,6 +301,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
@@ -308,7 +309,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
@@ -146,12 +146,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) {
@@ -194,7 +188,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
@@ -2223,27 +2223,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