Fix z-order when transfering animations

We need to reparent the transfered leash to the the animation
layer, not the original parent

Test: Open Play Movies, observe correct z-order during cold-launch
Test: go/wm-smoke
Test: SurfaceAnimatorTest
Change-Id: Ic5a68c68514bb3560b6877a9a29c506aeccee2bf
diff --git a/services/core/java/com/android/server/wm/AppWindowThumbnail.java b/services/core/java/com/android/server/wm/AppWindowThumbnail.java
index b86cd50..c16a531 100644
--- a/services/core/java/com/android/server/wm/AppWindowThumbnail.java
+++ b/services/core/java/com/android/server/wm/AppWindowThumbnail.java
@@ -139,7 +139,7 @@
 
     @Override
     public Builder makeAnimationLeash() {
-        return mAppToken.makeSurface().setParent(mAppToken.getAppAnimationLayer());
+        return mAppToken.makeSurface();
     }
 
     @Override
@@ -148,6 +148,11 @@
     }
 
     @Override
+    public SurfaceControl getAnimationLeashParent() {
+        return mAppToken.getAppAnimationLayer();
+    }
+
+    @Override
     public SurfaceControl getParentSurfaceControl() {
         return mAppToken.getParentSurfaceControl();
     }
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 44d7948..3f99591 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -1512,9 +1512,8 @@
     }
 
     @Override
-    public SurfaceControl.Builder makeAnimationLeash() {
-        return super.makeAnimationLeash()
-                .setParent(getAppAnimationLayer());
+    public SurfaceControl getAnimationLeashParent() {
+        return getAppAnimationLayer();
     }
 
     boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
diff --git a/services/core/java/com/android/server/wm/SurfaceAnimator.java b/services/core/java/com/android/server/wm/SurfaceAnimator.java
index bf2c85d6..a32e711 100644
--- a/services/core/java/com/android/server/wm/SurfaceAnimator.java
+++ b/services/core/java/com/android/server/wm/SurfaceAnimator.java
@@ -219,7 +219,7 @@
             return;
         }
         final SurfaceControl surface = mAnimatable.getSurfaceControl();
-        final SurfaceControl parent = mAnimatable.getParentSurfaceControl();
+        final SurfaceControl parent = mAnimatable.getAnimationLeashParent();
         if (surface == null || parent == null) {
             Slog.w(TAG, "Unable to transfer animation, surface or parent is null");
             cancelAnimation();
@@ -293,6 +293,7 @@
             int height, boolean hidden) {
         if (DEBUG_ANIM) Slog.i(TAG, "Reparenting to leash");
         final SurfaceControl.Builder builder = mAnimatable.makeAnimationLeash()
+                .setParent(mAnimatable.getAnimationLeashParent())
                 .setName(surface + " - animation-leash")
                 .setSize(width, height);
         final SurfaceControl leash = builder.build();
@@ -361,6 +362,11 @@
         SurfaceControl.Builder makeAnimationLeash();
 
         /**
+         * @return The parent that should be used for the animation leash.
+         */
+        @Nullable SurfaceControl getAnimationLeashParent();
+
+        /**
          * @return The surface of the object to be animated.
          */
         @Nullable SurfaceControl getSurfaceControl();
diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java
index b251b53..5d445ef 100644
--- a/services/core/java/com/android/server/wm/WindowContainer.java
+++ b/services/core/java/com/android/server/wm/WindowContainer.java
@@ -1088,6 +1088,11 @@
         return makeSurface();
     }
 
+    @Override
+    public SurfaceControl getAnimationLeashParent() {
+        return getParentSurfaceControl();
+    }
+
     /**
      * @return The layer on which all app animations are happening.
      */