From 1c64f9fbade6ff2f18bec16ba8430fd09af44d9a Mon Sep 17 00:00:00 2001 From: Hongwei Wang Date: Thu, 18 May 2023 11:27:12 -0700 Subject: [PATCH] Cleanup on aborting auto-enter-pip Note that this change does not fix the bug listed here. This is to ensure WMShell can cleanup its internal state when the bug happens to avoid further confusions in WMShell. Bug: 283177443 Test: adb shell dumpsys activity service SystemUIService WMShell Test: go/winscope and check the SF/WM dump Change-Id: I3804d57458a20f6a1c41963a704fae8bb28f0392 --- .../src/com/android/wm/shell/pip/IPip.aidl | 18 +++++++++++++----- .../android/wm/shell/pip/PipTaskOrganizer.java | 18 +++++++++++++++++- .../wm/shell/pip/phone/PipController.java | 10 ++++++++++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/IPip.aidl b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/IPip.aidl index 78de5f3e7a1f3..3906599b75811 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/IPip.aidl +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/IPip.aidl @@ -56,28 +56,36 @@ interface IPip { oneway void stopSwipePipToHome(int taskId, in ComponentName componentName, in Rect destinationBounds, in SurfaceControl overlay) = 2; + /** + * Notifies the swiping Activity to PiP onto home transition is aborted + * + * @param taskId the Task id that the Activity and overlay are currently in. + * @param componentName ComponentName represents the Activity + */ + oneway void abortSwipePipToHome(int taskId, in ComponentName componentName) = 3; + /** * Sets listener to get pinned stack animation callbacks. */ - oneway void setPipAnimationListener(IPipAnimationListener listener) = 3; + oneway void setPipAnimationListener(IPipAnimationListener listener) = 4; /** * Sets the shelf height and visibility. */ - oneway void setShelfHeight(boolean visible, int shelfHeight) = 4; + oneway void setShelfHeight(boolean visible, int shelfHeight) = 5; /** * Sets the next pip animation type to be the alpha animation. */ - oneway void setPipAnimationTypeToAlpha() = 5; + oneway void setPipAnimationTypeToAlpha() = 6; /** * Sets the height and visibility of the Launcher keep clear area. */ - oneway void setLauncherKeepClearAreaHeight(boolean visible, int height) = 6; + oneway void setLauncherKeepClearAreaHeight(boolean visible, int height) = 7; /** * Sets the app icon size in pixel used by Launcher */ - oneway void setLauncherAppIconSize(int iconSizePx) = 7; + oneway void setLauncherAppIconSize(int iconSizePx) = 8; } 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 58bc81dd3007e..db7c3fc9c9ec9 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 @@ -462,13 +462,29 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener, // to the actual Task surface now. // PipTransition is responsible to fade it out and cleanup when finishing the enter PIP // transition. - final SurfaceControl.Transaction t = new SurfaceControl.Transaction(); + final SurfaceControl.Transaction t = mSurfaceControlTransactionFactory.getTransaction(); mTaskOrganizer.reparentChildSurfaceToTask(taskId, overlay, t); t.setLayer(overlay, Integer.MAX_VALUE); t.apply(); } } + /** + * Callback when launcher aborts swipe-pip-to-home operation. + */ + public void abortSwipePipToHome(int taskId, ComponentName componentName) { + if (!mPipTransitionState.getInSwipePipToHomeTransition()) { + return; + } + ProtoLog.d(ShellProtoLogGroup.WM_SHELL_PICTURE_IN_PICTURE, + "Abort swipe-pip-to-home for %s", componentName); + sendOnPipTransitionCancelled(TRANSITION_DIRECTION_TO_PIP); + // Cleanup internal states + mPipTransitionState.setInSwipePipToHomeTransition(false); + mPictureInPictureParams = null; + mPipTransitionState.setTransitionState(PipTransitionState.UNDEFINED); + } + public ActivityManager.RunningTaskInfo getTaskInfo() { return mTaskInfo; } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java index 9e6bd47609005..63181da46b027 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java @@ -1017,6 +1017,10 @@ public class PipController implements PipTransitionController.PipTransitionCallb mPipTaskOrganizer.stopSwipePipToHome(taskId, componentName, destinationBounds, overlay); } + private void abortSwipePipToHome(int taskId, ComponentName componentName) { + mPipTaskOrganizer.abortSwipePipToHome(taskId, componentName); + } + private String getTransitionTag(int direction) { switch (direction) { case TRANSITION_DIRECTION_TO_PIP: @@ -1312,6 +1316,12 @@ public class PipController implements PipTransitionController.PipTransitionCallb taskId, componentName, destinationBounds, overlay)); } + @Override + public void abortSwipePipToHome(int taskId, ComponentName componentName) { + executeRemoteCallWithTaskPermission(mController, "abortSwipePipToHome", + (controller) -> controller.abortSwipePipToHome(taskId, componentName)); + } + @Override public void setShelfHeight(boolean visible, int height) { executeRemoteCallWithTaskPermission(mController, "setShelfHeight",