From 9ee3fbb5a00eeb1caf93b1ce83950a0aa4e1307f Mon Sep 17 00:00:00 2001 From: Jerry Chang Date: Tue, 4 Oct 2022 11:26:45 +0000 Subject: [PATCH] Support starts a pair of intent/shortcut and task to split Add startIntentAndTask and startShortcutAndTask APIs to support starts a pair of intent/shortcut and task to split with shell-transition. Fix: 250875492 Test: atest WMShellFlickerTests Test: manual check start tasks or start intent/shortcut with task flow with shell-transition enabled Change-Id: Ia79cf5e1990089f2a92895fd09b8f813d9381093 --- .../wm/shell/splitscreen/ISplitScreen.aidl | 29 ++++++--- .../splitscreen/SplitScreenController.java | 22 +++++++ .../shell/splitscreen/StageCoordinator.java | 60 ++++++++++++++++--- 3 files changed, 95 insertions(+), 16 deletions(-) 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 03688b747f766..eb08d0ecbd061 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 @@ -83,6 +83,20 @@ interface ISplitScreen { int splitPosition, float splitRatio, in RemoteTransition remoteTransition, in InstanceId instanceId) = 10; + /** + * Starts a pair of intent and task in one transition. + */ + oneway void startIntentAndTask(in PendingIntent pendingIntent, in Intent fillInIntent, + in Bundle options1, int taskId, in Bundle options2, int sidePosition, float splitRatio, + in RemoteTransition remoteTransition, in InstanceId instanceId) = 16; + + /** + * Starts a pair of shortcut and task in one transition. + */ + oneway void startShortcutAndTask(in ShortcutInfo shortcutInfo, in Bundle options1, int taskId, + in Bundle options2, int splitPosition, float splitRatio, + in RemoteTransition remoteTransition, in InstanceId instanceId) = 17; + /** * Version of startTasks using legacy transition system. */ @@ -98,6 +112,13 @@ interface ISplitScreen { int splitPosition, float splitRatio, in RemoteAnimationAdapter adapter, in InstanceId instanceId) = 12; + /** + * Starts a pair of shortcut and task using legacy transition system. + */ + oneway void startShortcutAndTaskWithLegacyTransition(in ShortcutInfo shortcutInfo, + in Bundle options1, int taskId, in Bundle options2, int splitPosition, float splitRatio, + in RemoteAnimationAdapter adapter, in InstanceId instanceId) = 15; + /** * Blocking call that notifies and gets additional split-screen targets when entering * recents (for example: the dividerBar). @@ -111,11 +132,5 @@ interface ISplitScreen { * does not expect split to currently be running. */ RemoteAnimationTarget[] onStartingSplitLegacy(in RemoteAnimationTarget[] appTargets) = 14; - - /** - * Starts a pair of shortcut and task using legacy transition system. - */ - oneway void startShortcutAndTaskWithLegacyTransition(in ShortcutInfo shortcutInfo, - in Bundle options1, int taskId, in Bundle options2, int splitPosition, float splitRatio, - in RemoteAnimationAdapter adapter, in InstanceId instanceId) = 15; } +// Last id = 17 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 8043b97164ceb..d9c2871a1654d 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 @@ -871,6 +871,28 @@ public class SplitScreenController implements DragAndDropPolicy.Starter, instanceId)); } + @Override + public void startIntentAndTask(PendingIntent pendingIntent, Intent fillInIntent, + @Nullable Bundle options1, int taskId, @Nullable Bundle options2, + @SplitPosition int splitPosition, float splitRatio, + @Nullable RemoteTransition remoteTransition, InstanceId instanceId) { + executeRemoteCallWithTaskPermission(mController, "startIntentAndTask", + (controller) -> controller.mStageCoordinator.startIntentAndTask(pendingIntent, + fillInIntent, options1, taskId, options2, splitPosition, splitRatio, + remoteTransition, instanceId)); + } + + @Override + public void startShortcutAndTask(ShortcutInfo shortcutInfo, @Nullable Bundle options1, + int taskId, @Nullable Bundle options2, @SplitPosition int splitPosition, + float splitRatio, @Nullable RemoteTransition remoteTransition, + InstanceId instanceId) { + executeRemoteCallWithTaskPermission(mController, "startShortcutAndTask", + (controller) -> controller.mStageCoordinator.startShortcutAndTask(shortcutInfo, + options1, taskId, options2, splitPosition, splitRatio, remoteTransition, + instanceId)); + } + @Override public void startShortcut(String packageName, String shortcutId, int position, @Nullable Bundle options, UserHandle user, InstanceId instanceId) { 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 d79e6a1f11d3e..9102bd3a9b6a5 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 @@ -516,14 +516,55 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler, } /** Starts 2 tasks in one transition. */ - void startTasks(int sideTaskId, @Nullable Bundle sideOptions, int mainTaskId, - @Nullable Bundle mainOptions, @SplitPosition int sidePosition, float splitRatio, + void startTasks(int taskId1, @Nullable Bundle options1, int taskId2, + @Nullable Bundle options2, @SplitPosition int splitPosition, float splitRatio, @Nullable RemoteTransition remoteTransition, InstanceId instanceId) { final WindowContainerTransaction wct = new WindowContainerTransaction(); - mainOptions = mainOptions != null ? mainOptions : new Bundle(); - sideOptions = sideOptions != null ? sideOptions : new Bundle(); - setSideStagePosition(sidePosition, wct); + setSideStagePosition(splitPosition, wct); + options1 = options1 != null ? options1 : new Bundle(); + addActivityOptions(options1, mSideStage); + wct.startTask(taskId1, options1); + startWithTask(wct, taskId2, options2, splitRatio, remoteTransition, instanceId); + } + + /** Start an intent and a task to a split pair in one transition. */ + void startIntentAndTask(PendingIntent pendingIntent, Intent fillInIntent, + @Nullable Bundle options1, int taskId, @Nullable Bundle options2, + @SplitPosition int splitPosition, float splitRatio, + @Nullable RemoteTransition remoteTransition, InstanceId instanceId) { + final WindowContainerTransaction wct = new WindowContainerTransaction(); + setSideStagePosition(splitPosition, wct); + options1 = options1 != null ? options1 : new Bundle(); + addActivityOptions(options1, mSideStage); + wct.sendPendingIntent(pendingIntent, fillInIntent, options1); + + startWithTask(wct, taskId, options2, splitRatio, remoteTransition, instanceId); + } + + /** Starts a shortcut and a task to a split pair in one transition. */ + void startShortcutAndTask(ShortcutInfo shortcutInfo, @Nullable Bundle options1, + int taskId, @Nullable Bundle options2, @SplitPosition int splitPosition, + float splitRatio, @Nullable RemoteTransition remoteTransition, InstanceId instanceId) { + final WindowContainerTransaction wct = new WindowContainerTransaction(); + setSideStagePosition(splitPosition, wct); + options1 = options1 != null ? options1 : new Bundle(); + addActivityOptions(options1, mSideStage); + wct.startShortcut(mContext.getPackageName(), shortcutInfo, options1); + + startWithTask(wct, taskId, options2, splitRatio, remoteTransition, instanceId); + } + + /** + * Starts with the second task to a split pair in one transition. + * + * @param wct transaction to start the first task + * @param instanceId if {@code null}, will not log. Otherwise it will be used in + * {@link SplitscreenEventLogger#logEnter(float, int, int, int, int, boolean)} + */ + private void startWithTask(WindowContainerTransaction wct, int mainTaskId, + @Nullable Bundle mainOptions, float splitRatio, + @Nullable RemoteTransition remoteTransition, InstanceId instanceId) { if (mMainStage.isActive()) { mMainStage.evictAllChildren(wct); mSideStage.evictAllChildren(wct); @@ -538,12 +579,11 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler, wct.setForceTranslucent(mRootTaskInfo.token, false); // Make sure the launch options will put tasks in the corresponding split roots + mainOptions = mainOptions != null ? mainOptions : new Bundle(); addActivityOptions(mainOptions, mMainStage); - addActivityOptions(sideOptions, mSideStage); // Add task launch requests wct.startTask(mainTaskId, mainOptions); - wct.startTask(sideTaskId, sideOptions); mSplitTransitions.startEnterTransition( TRANSIT_SPLIT_SCREEN_PAIR_OPEN, wct, remoteTransition, this, null); @@ -593,6 +633,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler, } /** + * @param wct transaction to start the first task * @param instanceId if {@code null}, will not log. Otherwise it will be used in * {@link SplitscreenEventLogger#logEnter(float, int, int, int, int, boolean)} */ @@ -1728,6 +1769,7 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler, @StageType private int getStageType(StageTaskListener stage) { + if (stage == null) return STAGE_TYPE_UNDEFINED; return stage == mMainStage ? STAGE_TYPE_MAIN : STAGE_TYPE_SIDE; } @@ -1982,8 +2024,8 @@ public class StageCoordinator implements SplitLayout.SplitLayoutHandler, } } - // TODO: fallback logic. Probably start a new transition to exit split before applying - // anything here. Ideally consolidate with transition-merging. + // TODO(b/250853925): fallback logic. Probably start a new transition to exit split before + // applying anything here. Ideally consolidate with transition-merging. if (info.getType() == TRANSIT_SPLIT_SCREEN_OPEN_TO_SIDE) { if (mainChild == null && sideChild == null) { throw new IllegalStateException("Launched a task in split, but didn't receive any"