Defer hiding clients until animation is done

This is a preparation for remote animations: We used to set app
visibility state immediately after we started the animation.
However, with remote animations, we'd like to allow them drawing
until the transition is done. For that, we defer hiding the client
until the animation is done.

Instead of special-casing remote animations, we do it for all
apps, as there is no harm in doing so.

Test: Open YouTube, make sure it enters Auto-PIP when pressing
home.
Test: go/wm-smoke
Test: Open trace with open/closing a couple of apps. Make sure
app visibility gets dispatched at the correct time.
Test: WindowStateTests

Bug: 64674361
Change-Id: I8deb6a97ca1c3d8f4a70a6e045f45a6bc16604bb
diff --git a/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java b/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java
index 7be203a..6a4710b 100644
--- a/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java
+++ b/services/tests/servicestests/src/com/android/server/wm/WindowStateTests.java
@@ -223,6 +223,19 @@
         assertFalse(app.canAffectSystemUiFlags());
     }
 
+    @Test
+    public void testIsSelfOrAncestorWindowAnimating() throws Exception {
+        final WindowState root = createWindow(null, TYPE_APPLICATION, "root");
+        final WindowState child1 = createWindow(root, FIRST_SUB_WINDOW, "child1");
+        final WindowState child2 = createWindow(child1, FIRST_SUB_WINDOW, "child2");
+        assertFalse(child2.isSelfOrAncestorWindowAnimatingExit());
+        child2.mAnimatingExit = true;
+        assertTrue(child2.isSelfOrAncestorWindowAnimatingExit());
+        child2.mAnimatingExit = false;
+        root.mAnimatingExit = true;
+        assertTrue(child2.isSelfOrAncestorWindowAnimatingExit());
+    }
+
     private void testPrepareWindowToDisplayDuringRelayout(boolean wasVisible) {
         final WindowState root = createWindow(null, TYPE_APPLICATION, "root");
         root.mAttrs.flags |= WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON;