Fix flicker when transiting activities without animation.

In O, we added the logic surrounding this diff, to handle cases where
stack visibility changes but there is no app transition (e.g. docked
and pinned stack dismissal). We need to be careful to not immediately
hide the Surfaces in the case where there is a transition though. It's possible
there is a transition, even if delayed is false, in the cases where we
have a custom null animation.

Bug: 38031364
Test: Repro from bug. Dismiss docked stack ~10x. Dismiss pinned stack ~10x. go/wm-smoke
Change-Id: I9dac7b9a4794787187c8e9226ab9d8ded282c116
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index b9d02a9..63890bf 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -431,11 +431,18 @@
                 mEnteringAnimation = true;
                 mService.mActivityManagerAppTransitionNotifier.onAppTransitionFinishedLocked(token);
             }
+
             // If we are hidden but there is no delay needed we immediately
             // apply the Surface transaction so that the ActivityManager
-            // can have some guarantee on the Surface state
-            // following setting the visibility.
-            if (hidden && !delayed) {
+            // can have some guarantee on the Surface state following
+            // setting the visibility. This captures cases like dismissing
+            // the docked or pinned stack where there is no app transition.
+            //
+            // In the case of a "Null" animation, there will be
+            // no animation but there will still be a transition set.
+            // We still need to delay hiding the surface such that it
+            // can be synchronized with showing the next surface in the transition.
+            if (hidden && !delayed && !mService.mAppTransition.isTransitionSet()) {
                 SurfaceControl.openTransaction();
                 for (int i = mChildren.size() - 1; i >= 0; i--) {
                     mChildren.get(i).mWinAnimator.hide("immediately hidden");