Check client hidden state before resetting draw state.

If there are more than activities switched to foreground very quickly,
imagine like: A->B->A, in previous fix, if we found the resumed activity
is hidden in server side, we will reset the drawing state. However, the
resumed activity may be currently visible at client side, and since the
previous transition may not have finished and we will clear the
AppWindowToken in clearChangeLeash, this AppWindowToken may never receive
onAnimationFinished callback, so the mClientHidden will stay in false.

Since server side doesn't require client side to relayout, the allDraw state
will remain in false, which will cause the second transition cannot start.
Therefore, even when resumed activity idled, the stopping activity cannot be
removed from processStoppingActivitiesLocked because isSelfAnimating remains
true.

Fix: 137898192
Bug: 127741025
Test: atest CtsWindowManagerDeviceTestCases:ActivityStarterTests
Test: Manual testing that b/134561008 didn't reproduce.

Change-Id: Ie76b33ec5f12591c3166612e69b49325d7276216
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index f647fe4..fc350cd 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -548,17 +548,20 @@
                 if (isHidden()) {
                     waitingToShow = true;
 
-                    // Let's reset the draw state in order to prevent the starting window to be
-                    // immediately dismissed when the app still has the surface.
-                    forAllWindows(w -> {
-                        if (w.mWinAnimator.mDrawState == HAS_DRAWN) {
-                            w.mWinAnimator.resetDrawState();
+                    // If the client isn't hidden, we don't need to reset the drawing state.
+                    if (isClientHidden()) {
+                        // Let's reset the draw state in order to prevent the starting window to be
+                        // immediately dismissed when the app still has the surface.
+                        forAllWindows(w -> {
+                            if (w.mWinAnimator.mDrawState == HAS_DRAWN) {
+                                w.mWinAnimator.resetDrawState();
 
-                            // Force add to mResizingWindows, so that we are guaranteed to get
-                            // another reportDrawn callback.
-                            w.resetLastContentInsets();
-                        }
-                    },  true /* traverseTopToBottom */);
+                                // Force add to mResizingWindows, so that we are guaranteed to get
+                                // another reportDrawn callback.
+                                w.resetLastContentInsets();
+                            }
+                        }, true /* traverseTopToBottom */);
+                    }
                 }
             }