From 544007604f1fb2b0d51b9d05120afff587dcdc3d Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Wed, 22 Dec 2021 13:49:35 -0800 Subject: Add Content PiP support with launch-into-pip API Terms - Host activity, the activity that the content-pip is originated from. There should be some UI affordance on Host activity user can tap to enter content-pip - Container activity, the activity that carries the content from Host Activity and transits to PiP mode Workflow in brief - Container activity is defined in the same application as Host activity - A new ActivityOptions#makeLaunchIntoPip API is added, Host activity uses this API to construct ActivityOptions to launch the Container activity directly into pip mode. - ActivityStarter sets a reference on Container activity pointing to Host activity upon creation and moves the activity to pinned task - WMShell transits Container activity to pinned mode - When user taps on `Expand` button in PiP menu, WMShell calls WCT#startTask with the task id to bring the Host task to front Content hand-off - Since Host activity is the one starts Container activity, it can replace its content with some placeholder right after startActivity - This CL also makes the assumption that Host activity can establish a communication channel with the Container activity, such as using the ResultReceiver parcelable. Therefore it's out of scope to provide extra callback to Host activity on lifecycle events of Container activity. See also the design doc go/content-pip-v2 and the end-to-end demo in ApiDemos `App > Activity > Picture in Picture` Bug: 165793661 Video: http://recall/-/aaaaaabFQoRHlzixHdtY/e9Mp5rvxYBrNOdGSUoSXHO Test: manual, see Video Test: atest WmTests:ActivityOptionsTest \ WmTests:ActivityRecordTests \ WmTests:ActivityStarterTests \ PinnedStackTests Change-Id: I2bebfea8d1930b0b7e495d91cfd5ddc7c347da68 --- .../src/com/android/wm/shell/pip/PipTaskOrganizer.java | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'libs/WindowManager/Shell') diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java index 67b39839826c..13d9081bb3ba 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipTaskOrganizer.java @@ -310,6 +310,10 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, return mPipTransitionState.isInPip(); } + private boolean isLaunchIntoPipTask() { + return mPictureInPictureParams != null && mPictureInPictureParams.isLaunchIntoPip(); + } + /** * Returns whether the entry animation is waiting to be started. */ @@ -397,6 +401,10 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, } final WindowContainerTransaction wct = new WindowContainerTransaction(); + if (isLaunchIntoPipTask()) { + exitLaunchIntoPipTask(wct); + return; + } if (ENABLE_SHELL_TRANSITIONS) { if (requestEnterSplit && mSplitScreenOptional.isPresent()) { @@ -468,6 +476,14 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, }); } + private void exitLaunchIntoPipTask(WindowContainerTransaction wct) { + wct.startTask(mTaskInfo.launchIntoPipHostTaskId, null /* ActivityOptions */); + mTaskOrganizer.applyTransaction(wct); + + // Remove the PiP with fade-out animation right after the host Task is brought to front. + removePip(); + } + private void applyWindowingModeChangeOnExit(WindowContainerTransaction wct, int direction) { // Reset the final windowing mode. wct.setWindowingMode(mToken, getOutPipWindowingMode()); @@ -729,7 +745,7 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, } /** - * Note that dismissing PiP is now originated from SystemUI, see {@link #exitPip(int)}. + * Note that dismissing PiP is now originated from SystemUI, see {@link #exitPip(int, boolean)}. * Meanwhile this callback is invoked whenever the task is removed. For instance: * - as a result of removeRootTasksInWindowingModes from WM * - activity itself is died -- cgit v1.2.3-59-g8ed1b