Set initial position for WindowAnimation and reparent animation leash.

1. Set the initial position for the WindowAnimationSpec to be the stack
position.
2. Reparent the animation leash to mAnimationLayer
3. Updated Surface names for clarity.

Test: Opening apps animate from the correct start location. When apps
are animating, their layers are reparented to the correct animation
layer.

Change-Id: I3e3a1e45f0a0cf9d471dee105abd9bce05d1e91d
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 04a1beb..444a05d 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -52,7 +52,6 @@
 import static com.android.server.wm.proto.AppWindowTokenProto.WINDOW_TOKEN;
 
 import android.annotation.CallSuper;
-import android.annotation.NonNull;
 import android.app.Activity;
 import android.content.res.Configuration;
 import android.graphics.GraphicBuffer;
@@ -216,6 +215,8 @@
     /** Whether this token should be boosted at the top of all app window tokens. */
     private boolean mNeedsZBoost;
 
+    private final Point mTmpPoint = new Point();
+
     AppWindowToken(WindowManagerService service, IApplicationToken token, boolean voiceInteraction,
             DisplayContent dc, long inputDispatchingTimeoutNanos, boolean fullscreen,
             boolean showForAllUsers, int targetSdk, int orientation, int rotationAnimationHint,
@@ -1503,6 +1504,12 @@
                 true /* topToBottom */);
     }
 
+    @Override
+    public SurfaceControl.Builder makeAnimationLeash() {
+        return super.makeAnimationLeash()
+                .setParent(getAppAnimationLayer());
+    }
+
     boolean applyAnimationLocked(WindowManager.LayoutParams lp, int transit, boolean enter,
             boolean isVoiceInteraction) {
 
@@ -1521,8 +1528,13 @@
         if (okToAnimate()) {
             final Animation a = loadAnimation(lp, transit, enter, isVoiceInteraction);
             if (a != null) {
+                final TaskStack stack = getStack();
+                mTmpPoint.set(0, 0);
+                if (stack != null) {
+                    stack.getRelativePosition(mTmpPoint);
+                }
                 final AnimationAdapter adapter = new LocalAnimationAdapter(
-                        new WindowAnimationSpec(a, new Point(),
+                        new WindowAnimationSpec(a, mTmpPoint,
                                 mService.mAppTransition.canSkipFirstFrame()),
                         mService.mSurfaceAnimationRunner);
                 startAnimation(getPendingTransaction(), adapter, !isVisible());