diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java index 22bff21831deb..308df2f4e9a00 100644 --- a/services/core/java/com/android/server/wm/ActivityRecord.java +++ b/services/core/java/com/android/server/wm/ActivityRecord.java @@ -5033,6 +5033,12 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A void notifyAppStopped() { ProtoLog.v(WM_DEBUG_ADD_REMOVE, "notifyAppStopped: %s", this); mAppStopped = true; + // This is to fix the edge case that auto-enter-pip is finished in Launcher but app calls + // setAutoEnterEnabled(false) and transitions to STOPPED state, see b/191930787. + // Clear any surface transactions and content overlay in this case. + if (task != null && task.mLastRecentsAnimationTransaction != null) { + task.clearLastRecentsAnimationTransaction(true /* forceRemoveOverlay */); + } // Reset the last saved PiP snap fraction on app stop. mDisplayContent.mPinnedTaskController.onActivityHidden(mActivityComponent); mDisplayContent.mUnknownAppVisibilityController.appRemovedOrHidden(this); diff --git a/services/core/java/com/android/server/wm/RootWindowContainer.java b/services/core/java/com/android/server/wm/RootWindowContainer.java index b6e0d8de31f47..719742f727ff0 100644 --- a/services/core/java/com/android/server/wm/RootWindowContainer.java +++ b/services/core/java/com/android/server/wm/RootWindowContainer.java @@ -2151,7 +2151,7 @@ class RootWindowContainer extends WindowContainer rootTask.setLastRecentsAnimationTransaction( task.mLastRecentsAnimationTransaction, task.mLastRecentsAnimationOverlay); - task.clearLastRecentsAnimationTransaction(); + task.clearLastRecentsAnimationTransaction(false /* forceRemoveOverlay */); } // There are multiple activities in the task and moving the top activity should diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java index 382a2b1b5062f..d77c2a6270b6c 100644 --- a/services/core/java/com/android/server/wm/Task.java +++ b/services/core/java/com/android/server/wm/Task.java @@ -7625,7 +7625,10 @@ class Task extends WindowContainer { mLastRecentsAnimationOverlay = overlay; } - void clearLastRecentsAnimationTransaction() { + void clearLastRecentsAnimationTransaction(boolean forceRemoveOverlay) { + if (forceRemoveOverlay && mLastRecentsAnimationOverlay != null) { + getPendingTransaction().remove(mLastRecentsAnimationOverlay); + } mLastRecentsAnimationTransaction = null; mLastRecentsAnimationOverlay = null; // reset also the crop and transform introduced by mLastRecentsAnimationTransaction