Reset supportsEnterPipOnTaskSwitch when paused

The ActivityRecord#supportsEnterPipOnTaskSwitch flag is to indicate the
Activity can enter PiP while pausing.

This flag is set to true in Transitions#checkEnterPipOnFinish and
wouldn't be reset back in certain scenarios. This can lead to issues
like accidentally enter PiP when do quick switch.

In this change, we make sure the flag is always set to false whenever
the activity is paused. We attempted to do so in makeInvisible if the
internal state is STOPPING/STOPPED, which can be skipped if the
mVisibleRequested flag is set to false first.

Flag: EXEMPT bugfix
Bug: 390872198
Video: http://recall/-/aaaaaabFQoRHlzixHdtY/gvYPNiIVWycrSYPQNZ0J9z
Test: manually make sure legacy enter PiP works
Test: follow the reproduce steps in bug, see also the video
Change-Id: I04ef9435e70f4d1ca41c7c5d7859d3c9462aa2aa
diff --git a/services/core/java/com/android/server/wm/ActivityRecord.java b/services/core/java/com/android/server/wm/ActivityRecord.java
index 57b82c3..d452d76 100644
--- a/services/core/java/com/android/server/wm/ActivityRecord.java
+++ b/services/core/java/com/android/server/wm/ActivityRecord.java
@@ -6005,12 +6005,6 @@
             setVisibility(false);
 
             switch (mState) {
-                case STOPPING:
-                case STOPPED:
-                    // Reset the flag indicating that an app can enter picture-in-picture once the
-                    // activity is hidden
-                    supportsEnterPipOnTaskSwitch = false;
-                    break;
                 case RESUMED:
                 case INITIALIZING:
                 case PAUSING:
diff --git a/services/core/java/com/android/server/wm/TaskFragment.java b/services/core/java/com/android/server/wm/TaskFragment.java
index a8c67f8..f95698a 100644
--- a/services/core/java/com/android/server/wm/TaskFragment.java
+++ b/services/core/java/com/android/server/wm/TaskFragment.java
@@ -2062,6 +2062,7 @@
 
         if (prev != null) {
             prev.setWillCloseOrEnterPip(false);
+            prev.supportsEnterPipOnTaskSwitch = false;
             final boolean wasStopping = prev.isState(STOPPING);
             prev.setState(PAUSED, "completePausedLocked");
             mPausingActivity = null;