From 04f1d4df9d07d027a87d528b0d22986a6251ab5a Mon Sep 17 00:00:00 2001 From: Jerry Chang Date: Tue, 30 Nov 2021 17:07:25 +0800 Subject: [PATCH] Remove stage type from split screen APIs Due to stage type will soon be deprecated, updates to remove stage type param from split screen APIs and leave resolving stage job to split screen controller. Bug: 198438631 Test: atest WMShellUnitTests Test: manul check drop to split and shell command to split behavior Change-Id: Ic543d74ebbee4afba06187e382808fa75ad8a416 --- .../shell/draganddrop/DragAndDropPolicy.java | 38 ++++------ .../wm/shell/splitscreen/ISplitScreen.aidl | 8 +-- .../splitscreen/SplitScreenController.java | 37 +++++----- .../shell/splitscreen/StageCoordinator.java | 11 +-- .../stagesplit/SplitScreenController.java | 31 ++++----- .../draganddrop/DragAndDropPolicyTest.java | 69 ++----------------- .../splitscreen/StageCoordinatorTests.java | 64 ++++++++++++++++- 7 files changed, 124 insertions(+), 134 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java index fbf04d6f3fff0..d2bd28e0f7535 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/draganddrop/DragAndDropPolicy.java @@ -37,8 +37,6 @@ import static com.android.wm.shell.draganddrop.DragAndDropPolicy.Target.TYPE_SPL import static com.android.wm.shell.draganddrop.DragAndDropPolicy.Target.TYPE_SPLIT_LEFT; import static com.android.wm.shell.draganddrop.DragAndDropPolicy.Target.TYPE_SPLIT_RIGHT; import static com.android.wm.shell.draganddrop.DragAndDropPolicy.Target.TYPE_SPLIT_TOP; -import static com.android.wm.shell.splitscreen.SplitScreen.STAGE_TYPE_SIDE; -import static com.android.wm.shell.splitscreen.SplitScreen.STAGE_TYPE_UNDEFINED; import android.app.ActivityManager; import android.app.ActivityTaskManager; @@ -66,7 +64,6 @@ import androidx.annotation.VisibleForTesting; import com.android.internal.logging.InstanceId; import com.android.wm.shell.common.DisplayLayout; import com.android.wm.shell.common.split.SplitLayout.SplitPosition; -import com.android.wm.shell.splitscreen.SplitScreen.StageType; import com.android.wm.shell.splitscreen.SplitScreenController; import java.lang.annotation.Retention; @@ -198,29 +195,23 @@ public class DragAndDropPolicy { return; } - final boolean inSplitScreen = mSplitScreen != null && mSplitScreen.isSplitScreenVisible(); final boolean leftOrTop = target.type == TYPE_SPLIT_TOP || target.type == TYPE_SPLIT_LEFT; - @StageType int stage = STAGE_TYPE_UNDEFINED; @SplitPosition int position = SPLIT_POSITION_UNDEFINED; if (target.type != TYPE_FULLSCREEN && mSplitScreen != null) { // Update launch options for the split side we are targeting. position = leftOrTop ? SPLIT_POSITION_TOP_OR_LEFT : SPLIT_POSITION_BOTTOM_OR_RIGHT; - if (!inSplitScreen) { - // Launch in the side stage if we are not in split-screen already. - stage = STAGE_TYPE_SIDE; - } // Add some data for logging splitscreen once it is invoked mSplitScreen.logOnDroppedToSplit(position, mLoggerSessionId); } final ClipDescription description = data.getDescription(); final Intent dragData = mSession.dragData; - startClipDescription(description, dragData, stage, position); + startClipDescription(description, dragData, position); } private void startClipDescription(ClipDescription description, Intent intent, - @StageType int stage, @SplitPosition int position) { + @SplitPosition int position) { final boolean isTask = description.hasMimeType(MIMETYPE_APPLICATION_TASK); final boolean isShortcut = description.hasMimeType(MIMETYPE_APPLICATION_SHORTCUT); final Bundle opts = intent.hasExtra(EXTRA_ACTIVITY_OPTIONS) @@ -228,15 +219,15 @@ public class DragAndDropPolicy { if (isTask) { final int taskId = intent.getIntExtra(EXTRA_TASK_ID, INVALID_TASK_ID); - mStarter.startTask(taskId, stage, position, opts); + mStarter.startTask(taskId, position, opts); } else if (isShortcut) { final String packageName = intent.getStringExtra(EXTRA_PACKAGE_NAME); final String id = intent.getStringExtra(EXTRA_SHORTCUT_ID); final UserHandle user = intent.getParcelableExtra(EXTRA_USER); - mStarter.startShortcut(packageName, id, stage, position, opts, user); + mStarter.startShortcut(packageName, id, position, opts, user); } else { mStarter.startIntent(intent.getParcelableExtra(EXTRA_PENDING_INTENT), - null, stage, position, opts); + null, position, opts); } } @@ -291,12 +282,10 @@ public class DragAndDropPolicy { * Interface for actually committing the task launches. */ public interface Starter { - void startTask(int taskId, @StageType int stage, @SplitPosition int position, - @Nullable Bundle options); - void startShortcut(String packageName, String shortcutId, @StageType int stage, - @SplitPosition int position, @Nullable Bundle options, UserHandle user); - void startIntent(PendingIntent intent, Intent fillInIntent, - @StageType int stage, @SplitPosition int position, + void startTask(int taskId, @SplitPosition int position, @Nullable Bundle options); + void startShortcut(String packageName, String shortcutId, @SplitPosition int position, + @Nullable Bundle options, UserHandle user); + void startIntent(PendingIntent intent, Intent fillInIntent, @SplitPosition int position, @Nullable Bundle options); void enterSplitScreen(int taskId, boolean leftOrTop); @@ -319,8 +308,7 @@ public class DragAndDropPolicy { } @Override - public void startTask(int taskId, int stage, int position, - @Nullable Bundle options) { + public void startTask(int taskId, int position, @Nullable Bundle options) { try { ActivityTaskManager.getService().startActivityFromRecents(taskId, options); } catch (RemoteException e) { @@ -329,7 +317,7 @@ public class DragAndDropPolicy { } @Override - public void startShortcut(String packageName, String shortcutId, int stage, int position, + public void startShortcut(String packageName, String shortcutId, int position, @Nullable Bundle options, UserHandle user) { try { LauncherApps launcherApps = @@ -342,8 +330,8 @@ public class DragAndDropPolicy { } @Override - public void startIntent(PendingIntent intent, @Nullable Intent fillInIntent, int stage, - int position, @Nullable Bundle options) { + public void startIntent(PendingIntent intent, @Nullable Intent fillInIntent, int position, + @Nullable Bundle options) { try { intent.send(mContext, 0, fillInIntent, null, null, null, options); } catch (PendingIntent.CanceledException e) { diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/ISplitScreen.aidl b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/ISplitScreen.aidl index 4a990975be0d4..3cfa541c1c866 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/ISplitScreen.aidl +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/ISplitScreen.aidl @@ -65,19 +65,19 @@ interface ISplitScreen { /** * Starts a task in a stage. */ - oneway void startTask(int taskId, int stage, int position, in Bundle options) = 7; + oneway void startTask(int taskId, int position, in Bundle options) = 7; /** * Starts a shortcut in a stage. */ - oneway void startShortcut(String packageName, String shortcutId, int stage, int position, + oneway void startShortcut(String packageName, String shortcutId, int position, in Bundle options, in UserHandle user) = 8; /** * Starts an activity in a stage. */ - oneway void startIntent(in PendingIntent intent, in Intent fillInIntent, int stage, - int position, in Bundle options) = 9; + oneway void startIntent(in PendingIntent intent, in Intent fillInIntent, int position, + in Bundle options) = 9; /** * Starts tasks simultaneously in one transition. diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java index 262a9a1ba2bef..47c0f2959e3cc 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/SplitScreenController.java @@ -261,9 +261,9 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, mStageCoordinator.unregisterSplitScreenListener(listener); } - public void startTask(int taskId, @SplitScreen.StageType int stage, - @SplitPosition int position, @Nullable Bundle options) { - options = mStageCoordinator.resolveStartStage(stage, position, options, null /* wct */); + public void startTask(int taskId, @SplitPosition int position, @Nullable Bundle options) { + options = mStageCoordinator.resolveStartStage(STAGE_TYPE_UNDEFINED, position, options, + null /* wct */); try { final WindowContainerTransaction evictWct = new WindowContainerTransaction(); @@ -278,10 +278,10 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, } } - public void startShortcut(String packageName, String shortcutId, - @SplitScreen.StageType int stage, @SplitPosition int position, + public void startShortcut(String packageName, String shortcutId, @SplitPosition int position, @Nullable Bundle options, UserHandle user) { - options = mStageCoordinator.resolveStartStage(stage, position, options, null /* wct */); + options = mStageCoordinator.resolveStartStage(STAGE_TYPE_UNDEFINED, position, options, + null /* wct */); final WindowContainerTransaction evictWct = new WindowContainerTransaction(); mStageCoordinator.prepareEvictChildTasks(position, evictWct); @@ -296,20 +296,18 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, } } - public void startIntent(PendingIntent intent, Intent fillInIntent, - @SplitScreen.StageType int stage, @SplitPosition int position, + public void startIntent(PendingIntent intent, Intent fillInIntent, @SplitPosition int position, @Nullable Bundle options) { if (!Transitions.ENABLE_SHELL_TRANSITIONS) { - startIntentLegacy(intent, fillInIntent, stage, position, options); + startIntentLegacy(intent, fillInIntent, position, options); return; } - mStageCoordinator.startIntent(intent, fillInIntent, stage, position, options, + mStageCoordinator.startIntent(intent, fillInIntent, STAGE_TYPE_UNDEFINED, position, options, null /* remote */); } private void startIntentLegacy(PendingIntent intent, Intent fillInIntent, - @SplitScreen.StageType int stage, @SplitPosition int position, - @Nullable Bundle options) { + @SplitPosition int position, @Nullable Bundle options) { final WindowContainerTransaction evictWct = new WindowContainerTransaction(); mStageCoordinator.prepareEvictChildTasks(position, evictWct); @@ -343,7 +341,7 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, }; final WindowContainerTransaction wct = new WindowContainerTransaction(); - options = mStageCoordinator.resolveStartStage(stage, position, options, wct); + options = mStageCoordinator.resolveStartStage(STAGE_TYPE_UNDEFINED, position, options, wct); wct.sendPendingIntent(intent, fillInIntent, options); mSyncQueue.queue(transition, WindowManager.TRANSIT_OPEN, wct); } @@ -600,10 +598,10 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, } @Override - public void startTask(int taskId, int stage, int position, @Nullable Bundle options) { + public void startTask(int taskId, int position, @Nullable Bundle options) { executeRemoteCallWithTaskPermission(mController, "startTask", (controller) -> { - controller.startTask(taskId, stage, position, options); + controller.startTask(taskId, position, options); }); } @@ -628,21 +626,20 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, } @Override - public void startShortcut(String packageName, String shortcutId, int stage, int position, + public void startShortcut(String packageName, String shortcutId, int position, @Nullable Bundle options, UserHandle user) { executeRemoteCallWithTaskPermission(mController, "startShortcut", (controller) -> { - controller.startShortcut(packageName, shortcutId, stage, position, - options, user); + controller.startShortcut(packageName, shortcutId, position, options, user); }); } @Override - public void startIntent(PendingIntent intent, Intent fillInIntent, int stage, int position, + public void startIntent(PendingIntent intent, Intent fillInIntent, int position, @Nullable Bundle options) { executeRemoteCallWithTaskPermission(mController, "startIntent", (controller) -> { - controller.startIntent(intent, fillInIntent, stage, position, options); + controller.startIntent(intent, fillInIntent, position, options); }); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java index a5579ae7dc256..a698cb9245880 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/splitscreen/StageCoordinator.java @@ -462,12 +462,15 @@ class StageCoordinator implements SplitLayout.SplitLayoutHandler, @androidx.annotation.Nullable WindowContainerTransaction wct) { switch (stage) { case STAGE_TYPE_UNDEFINED: { - // Use the stage of the specified position is valid. if (position != SPLIT_POSITION_UNDEFINED) { - if (position == getSideStagePosition()) { - options = resolveStartStage(STAGE_TYPE_SIDE, position, options, wct); + if (mMainStage.isActive()) { + // Use the stage of the specified position + options = resolveStartStage( + position == mSideStagePosition ? STAGE_TYPE_SIDE : STAGE_TYPE_MAIN, + position, options, wct); } else { - options = resolveStartStage(STAGE_TYPE_MAIN, position, options, wct); + // Use the side stage as default to active split screen + options = resolveStartStage(STAGE_TYPE_SIDE, position, options, wct); } } else { // Exit split-screen and launch fullscreen since stage wasn't specified. diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/stagesplit/SplitScreenController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/stagesplit/SplitScreenController.java index 94db9cd958a35..ad2b988a67ff4 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/stagesplit/SplitScreenController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/stagesplit/SplitScreenController.java @@ -22,6 +22,7 @@ import static android.view.RemoteAnimationTarget.MODE_OPENING; import static com.android.wm.shell.common.ExecutorUtils.executeRemoteCallWithTaskPermission; import static com.android.wm.shell.common.split.SplitLayout.SPLIT_POSITION_BOTTOM_OR_RIGHT; import static com.android.wm.shell.common.split.SplitLayout.SPLIT_POSITION_TOP_OR_LEFT; +import static com.android.wm.shell.splitscreen.SplitScreen.STAGE_TYPE_UNDEFINED; import android.app.ActivityManager; import android.app.ActivityTaskManager; @@ -208,9 +209,9 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, mStageCoordinator.unregisterSplitScreenListener(listener); } - public void startTask(int taskId, @SplitScreen.StageType int stage, - @SplitPosition int position, @Nullable Bundle options) { - options = mStageCoordinator.resolveStartStage(stage, position, options, null /* wct */); + public void startTask(int taskId, @SplitPosition int position, @Nullable Bundle options) { + options = mStageCoordinator.resolveStartStage(STAGE_TYPE_UNDEFINED, position, options, + null /* wct */); try { ActivityTaskManager.getService().startActivityFromRecents(taskId, options); @@ -219,10 +220,10 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, } } - public void startShortcut(String packageName, String shortcutId, - @SplitScreen.StageType int stage, @SplitPosition int position, + public void startShortcut(String packageName, String shortcutId, @SplitPosition int position, @Nullable Bundle options, UserHandle user) { - options = mStageCoordinator.resolveStartStage(stage, position, options, null /* wct */); + options = mStageCoordinator.resolveStartStage(STAGE_TYPE_UNDEFINED, position, options, + null /* wct */); try { LauncherApps launcherApps = @@ -234,20 +235,18 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, } } - public void startIntent(PendingIntent intent, Intent fillInIntent, - @SplitScreen.StageType int stage, @SplitPosition int position, + public void startIntent(PendingIntent intent, Intent fillInIntent, @SplitPosition int position, @Nullable Bundle options) { if (!Transitions.ENABLE_SHELL_TRANSITIONS) { - startIntentLegacy(intent, fillInIntent, stage, position, options); + startIntentLegacy(intent, fillInIntent, position, options); return; } - mStageCoordinator.startIntent(intent, fillInIntent, stage, position, options, + mStageCoordinator.startIntent(intent, fillInIntent, STAGE_TYPE_UNDEFINED, position, options, null /* remote */); } private void startIntentLegacy(PendingIntent intent, Intent fillInIntent, - @SplitScreen.StageType int stage, @SplitPosition int position, - @Nullable Bundle options) { + @SplitPosition int position, @Nullable Bundle options) { LegacyTransitions.ILegacyTransition transition = new LegacyTransitions.ILegacyTransition() { @Override public void onAnimationStart(int transit, RemoteAnimationTarget[] apps, @@ -275,7 +274,7 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, } }; WindowContainerTransaction wct = new WindowContainerTransaction(); - options = mStageCoordinator.resolveStartStage(stage, position, options, wct); + options = mStageCoordinator.resolveStartStage(STAGE_TYPE_UNDEFINED, position, options, wct); wct.sendPendingIntent(intent, fillInIntent, options); mSyncQueue.queue(transition, WindowManager.TRANSIT_OPEN, wct); } @@ -539,7 +538,7 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, public void startTask(int taskId, int stage, int position, @Nullable Bundle options) { executeRemoteCallWithTaskPermission(mController, "startTask", (controller) -> { - controller.startTask(taskId, stage, position, options); + controller.startTask(taskId, position, options); }); } @@ -568,7 +567,7 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, @Nullable Bundle options, UserHandle user) { executeRemoteCallWithTaskPermission(mController, "startShortcut", (controller) -> { - controller.startShortcut(packageName, shortcutId, stage, position, + controller.startShortcut(packageName, shortcutId, position, options, user); }); } @@ -578,7 +577,7 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, @Nullable Bundle options) { executeRemoteCallWithTaskPermission(mController, "startIntent", (controller) -> { - controller.startIntent(intent, fillInIntent, stage, position, options); + controller.startIntent(intent, fillInIntent, position, options); }); } diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/DragAndDropPolicyTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/DragAndDropPolicyTest.java index 734b97b69c874..7fbffc9b4853c 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/DragAndDropPolicyTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/draganddrop/DragAndDropPolicyTest.java @@ -32,8 +32,6 @@ import static com.android.wm.shell.draganddrop.DragAndDropPolicy.Target.TYPE_SPL import static com.android.wm.shell.draganddrop.DragAndDropPolicy.Target.TYPE_SPLIT_LEFT; import static com.android.wm.shell.draganddrop.DragAndDropPolicy.Target.TYPE_SPLIT_RIGHT; import static com.android.wm.shell.draganddrop.DragAndDropPolicy.Target.TYPE_SPLIT_TOP; -import static com.android.wm.shell.splitscreen.SplitScreen.STAGE_TYPE_SIDE; -import static com.android.wm.shell.splitscreen.SplitScreen.STAGE_TYPE_UNDEFINED; import static junit.framework.Assert.assertTrue; import static junit.framework.Assert.fail; @@ -149,7 +147,6 @@ public class DragAndDropPolicyTest { mSplitPrimaryAppTask = createTaskInfo(WINDOWING_MODE_SPLIT_SCREEN_PRIMARY, ACTIVITY_TYPE_STANDARD); - setInSplitScreen(false); setRunningTask(mFullscreenAppTask); } @@ -198,10 +195,6 @@ public class DragAndDropPolicyTest { : ActivityInfo.RESIZE_MODE_UNRESIZEABLE; } - private void setInSplitScreen(boolean inSplitscreen) { - doReturn(inSplitscreen).when(mSplitScreenStarter).isSplitScreenVisible(); - } - @Test public void testDragAppOverFullscreenHome_expectOnlyFullscreenTarget() { setRunningTask(mHomeTask); @@ -211,7 +204,7 @@ public class DragAndDropPolicyTest { mPolicy.handleDrop(filterTargetByType(targets, TYPE_FULLSCREEN), mActivityClipData); verify(mSplitScreenStarter).startIntent(any(), any(), - eq(STAGE_TYPE_UNDEFINED), eq(SPLIT_POSITION_UNDEFINED), any()); + eq(SPLIT_POSITION_UNDEFINED), any()); } @Test @@ -223,12 +216,12 @@ public class DragAndDropPolicyTest { mPolicy.handleDrop(filterTargetByType(targets, TYPE_SPLIT_LEFT), mActivityClipData); verify(mSplitScreenStarter).startIntent(any(), any(), - eq(STAGE_TYPE_SIDE), eq(SPLIT_POSITION_TOP_OR_LEFT), any()); + eq(SPLIT_POSITION_TOP_OR_LEFT), any()); reset(mSplitScreenStarter); mPolicy.handleDrop(filterTargetByType(targets, TYPE_SPLIT_RIGHT), mActivityClipData); verify(mSplitScreenStarter).startIntent(any(), any(), - eq(STAGE_TYPE_SIDE), eq(SPLIT_POSITION_BOTTOM_OR_RIGHT), any()); + eq(SPLIT_POSITION_BOTTOM_OR_RIGHT), any()); } @Test @@ -240,64 +233,12 @@ public class DragAndDropPolicyTest { mPolicy.handleDrop(filterTargetByType(targets, TYPE_SPLIT_TOP), mActivityClipData); verify(mSplitScreenStarter).startIntent(any(), any(), - eq(STAGE_TYPE_SIDE), eq(SPLIT_POSITION_TOP_OR_LEFT), any()); + eq(SPLIT_POSITION_TOP_OR_LEFT), any()); reset(mSplitScreenStarter); mPolicy.handleDrop(filterTargetByType(targets, TYPE_SPLIT_BOTTOM), mActivityClipData); verify(mSplitScreenStarter).startIntent(any(), any(), - eq(STAGE_TYPE_SIDE), eq(SPLIT_POSITION_BOTTOM_OR_RIGHT), any()); - } - - @Test - public void testDragAppOverSplitApp_expectSplitTargets_DropLeft() { - setInSplitScreen(true); - setRunningTask(mSplitPrimaryAppTask); - mPolicy.start(mLandscapeDisplayLayout, mActivityClipData, mLoggerSessionId); - ArrayList targets = assertExactTargetTypes( - mPolicy.getTargets(mInsets), TYPE_SPLIT_LEFT, TYPE_SPLIT_RIGHT); - - mPolicy.handleDrop(filterTargetByType(targets, TYPE_SPLIT_LEFT), mActivityClipData); - verify(mSplitScreenStarter).startIntent(any(), any(), - eq(STAGE_TYPE_UNDEFINED), eq(SPLIT_POSITION_TOP_OR_LEFT), any()); - } - - @Test - public void testDragAppOverSplitApp_expectSplitTargets_DropRight() { - setInSplitScreen(true); - setRunningTask(mSplitPrimaryAppTask); - mPolicy.start(mLandscapeDisplayLayout, mActivityClipData, mLoggerSessionId); - ArrayList targets = assertExactTargetTypes( - mPolicy.getTargets(mInsets), TYPE_SPLIT_LEFT, TYPE_SPLIT_RIGHT); - - mPolicy.handleDrop(filterTargetByType(targets, TYPE_SPLIT_RIGHT), mActivityClipData); - verify(mSplitScreenStarter).startIntent(any(), any(), - eq(STAGE_TYPE_UNDEFINED), eq(SPLIT_POSITION_BOTTOM_OR_RIGHT), any()); - } - - @Test - public void testDragAppOverSplitAppPhone_expectVerticalSplitTargets_DropTop() { - setInSplitScreen(true); - setRunningTask(mSplitPrimaryAppTask); - mPolicy.start(mPortraitDisplayLayout, mActivityClipData, mLoggerSessionId); - ArrayList targets = assertExactTargetTypes( - mPolicy.getTargets(mInsets), TYPE_SPLIT_TOP, TYPE_SPLIT_BOTTOM); - - mPolicy.handleDrop(filterTargetByType(targets, TYPE_SPLIT_TOP), mActivityClipData); - verify(mSplitScreenStarter).startIntent(any(), any(), - eq(STAGE_TYPE_UNDEFINED), eq(SPLIT_POSITION_TOP_OR_LEFT), any()); - } - - @Test - public void testDragAppOverSplitAppPhone_expectVerticalSplitTargets_DropBottom() { - setInSplitScreen(true); - setRunningTask(mSplitPrimaryAppTask); - mPolicy.start(mPortraitDisplayLayout, mActivityClipData, mLoggerSessionId); - ArrayList targets = assertExactTargetTypes( - mPolicy.getTargets(mInsets), TYPE_SPLIT_TOP, TYPE_SPLIT_BOTTOM); - - mPolicy.handleDrop(filterTargetByType(targets, TYPE_SPLIT_BOTTOM), mActivityClipData); - verify(mSplitScreenStarter).startIntent(any(), any(), - eq(STAGE_TYPE_UNDEFINED), eq(SPLIT_POSITION_BOTTOM_OR_RIGHT), any()); + eq(SPLIT_POSITION_BOTTOM_OR_RIGHT), any()); } @Test diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java index ef14d84c6a095..8128bbe3709e8 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/splitscreen/StageCoordinatorTests.java @@ -21,6 +21,7 @@ import static android.view.Display.DEFAULT_DISPLAY; import static com.android.wm.shell.common.split.SplitLayout.SPLIT_POSITION_BOTTOM_OR_RIGHT; import static com.android.wm.shell.common.split.SplitLayout.SPLIT_POSITION_TOP_OR_LEFT; +import static com.android.wm.shell.common.split.SplitLayout.SPLIT_POSITION_UNDEFINED; import static com.android.wm.shell.splitscreen.SplitScreen.STAGE_TYPE_MAIN; import static com.android.wm.shell.splitscreen.SplitScreen.STAGE_TYPE_SIDE; import static com.android.wm.shell.splitscreen.SplitScreen.STAGE_TYPE_UNDEFINED; @@ -28,10 +29,13 @@ import static com.android.wm.shell.splitscreen.SplitScreenController.EXIT_REASON import static org.junit.Assert.assertEquals; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.clearInvocations; +import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -105,7 +109,8 @@ public class StageCoordinatorTests extends ShellTestCase { @Before public void setup() { MockitoAnnotations.initMocks(this); - mStageCoordinator = createStageCoordinator(/* splitLayout */ null); + mStageCoordinator = spy(createStageCoordinator(/* splitLayout */ null)); + doNothing().when(mStageCoordinator).updateActivityOptions(any(), anyInt()); when(mSplitLayout.getBounds1()).thenReturn(mBounds1); when(mSplitLayout.getBounds2()).thenReturn(mBounds2); @@ -224,6 +229,63 @@ public class StageCoordinatorTests extends ShellTestCase { verify(mMainStage).deactivate(any(WindowContainerTransaction.class), eq(false)); } + @Test + public void testResolveStartStage_beforeSplitActivated_setsStagePosition() { + mStageCoordinator.setSideStagePosition(SPLIT_POSITION_TOP_OR_LEFT, null /* wct */); + + mStageCoordinator.resolveStartStage(STAGE_TYPE_UNDEFINED, SPLIT_POSITION_BOTTOM_OR_RIGHT, + null /* options */, null /* wct */); + assertEquals(mStageCoordinator.getSideStagePosition(), SPLIT_POSITION_BOTTOM_OR_RIGHT); + verify(mStageCoordinator).updateActivityOptions(any(), eq(SPLIT_POSITION_BOTTOM_OR_RIGHT)); + + mStageCoordinator.resolveStartStage(STAGE_TYPE_UNDEFINED, SPLIT_POSITION_TOP_OR_LEFT, + null /* options */, null /* wct */); + assertEquals(mStageCoordinator.getSideStagePosition(), SPLIT_POSITION_TOP_OR_LEFT); + verify(mStageCoordinator).updateActivityOptions(any(), eq(SPLIT_POSITION_TOP_OR_LEFT)); + } + + @Test + public void testResolveStartStage_afterSplitActivated_retrievesStagePosition() { + when(mMainStage.isActive()).thenReturn(true); + mStageCoordinator.setSideStagePosition(SPLIT_POSITION_TOP_OR_LEFT, null /* wct */); + + mStageCoordinator.resolveStartStage(STAGE_TYPE_UNDEFINED, SPLIT_POSITION_TOP_OR_LEFT, + null /* options */, null /* wct */); + assertEquals(mStageCoordinator.getSideStagePosition(), SPLIT_POSITION_TOP_OR_LEFT); + verify(mStageCoordinator).updateActivityOptions(any(), eq(SPLIT_POSITION_TOP_OR_LEFT)); + + mStageCoordinator.resolveStartStage(STAGE_TYPE_UNDEFINED, SPLIT_POSITION_BOTTOM_OR_RIGHT, + null /* options */, null /* wct */); + assertEquals(mStageCoordinator.getMainStagePosition(), SPLIT_POSITION_BOTTOM_OR_RIGHT); + verify(mStageCoordinator).updateActivityOptions(any(), eq(SPLIT_POSITION_BOTTOM_OR_RIGHT)); + } + + @Test + public void testResolveStartStage_setsSideStagePosition() { + mStageCoordinator.setSideStagePosition(SPLIT_POSITION_TOP_OR_LEFT, null /* wct */); + + mStageCoordinator.resolveStartStage(STAGE_TYPE_SIDE, SPLIT_POSITION_BOTTOM_OR_RIGHT, + null /* options */, null /* wct */); + assertEquals(mStageCoordinator.getSideStagePosition(), SPLIT_POSITION_BOTTOM_OR_RIGHT); + + mStageCoordinator.resolveStartStage(STAGE_TYPE_MAIN, SPLIT_POSITION_BOTTOM_OR_RIGHT, + null /* options */, null /* wct */); + assertEquals(mStageCoordinator.getMainStagePosition(), SPLIT_POSITION_BOTTOM_OR_RIGHT); + } + + @Test + public void testResolveStartStage_retrievesStagePosition() { + mStageCoordinator.setSideStagePosition(SPLIT_POSITION_TOP_OR_LEFT, null /* wct */); + + mStageCoordinator.resolveStartStage(STAGE_TYPE_SIDE, SPLIT_POSITION_UNDEFINED, + null /* options */, null /* wct */); + assertEquals(mStageCoordinator.getSideStagePosition(), SPLIT_POSITION_TOP_OR_LEFT); + + mStageCoordinator.resolveStartStage(STAGE_TYPE_MAIN, SPLIT_POSITION_UNDEFINED, + null /* options */, null /* wct */); + assertEquals(mStageCoordinator.getMainStagePosition(), SPLIT_POSITION_BOTTOM_OR_RIGHT); + } + private StageCoordinator createStageCoordinator(SplitLayout splitLayout) { return new SplitTestUtils.TestStageCoordinator(mContext, DEFAULT_DISPLAY, mSyncQueue, mRootTDAOrganizer, mTaskOrganizer, mMainStage, mSideStage,