Clean-up some out-dated layout shenanigans

Task.isFullscreen was checking for empty bounds, this wasn't
accounting for the (new) difference between being FULLSCREEN
(by policy) and actually filling the screen. This resulted in
certain checks not working properly (eg. letterbox surface
layout). isFullscreen has been removed and the callers now
check for what they care about.

useCurrentBounds is effectively dead-code now. It was
originally to deal with multi-user cases to prevent docked
stack of one user influencing the size of another user's
stacks. Nowadays, mode changes through the configuration
hierarchy handles these adjustments and falling-back on
displayBounds won't be appropriate in nested situations.

getAnimationBounds was basically trying to duplicate the
logic already performed by the hierarchy configuration
update. Specifically, looking at the mode and picking
which bounds to use. This is redundant and was actually
causing problems because new policies handled in the
hierarchy weren't being reproduced faithfully here. However,
due to letterbox, we can't use AppWindowToken bounds
directly. So for now we just use task (instead of stack)
for a representation of "the window" that also works
for freeform.

Letterbox layout was only being calculated relative to the
task. For fixed-orientation letterbox, this doesn't work
because the task itself needs to be letterboxed. For now,
this CL hard-codes an additional level (stack) and unions
that for the "letterbox fill region". We should probably
replace this with a recursive solution, but there's
currently still some issues that might require moving this
stuff around anyways.

Bug: 124626708
Test: launch a portrait-only app into fullscreen on a
      landscape-only display.
      atest AppWindowTokenTests WindowFrameTests
Change-Id: I1375c1988fbc8460802f30acee2207289fdb18e7
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 5ba6c76..ea3a7d5 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -1979,7 +1979,14 @@
                 mLetterbox.attachInput(w);
             }
             getPosition(mTmpPoint);
-            mLetterbox.layout(getParent().getBounds(), w.getFrameLw(), mTmpPoint);
+            // Get the bounds of the "space-to-fill". We union the Task and the Stack bounds here
+            // to handle both split window (where task-bounds can be larger) and orientation
+            // letterbox (where the task is letterboxed within stack).
+            Rect spaceToFill = getTask().getBounds();
+            if (getStack() != null) {
+                spaceToFill.union(getStack().getBounds());
+            }
+            mLetterbox.layout(spaceToFill, w.getFrameLw(), mTmpPoint);
         } else if (mLetterbox != null) {
             mLetterbox.hide();
         }
@@ -2448,28 +2455,6 @@
         return boundsLayer;
     }
 
-    /** Get position and crop region of animation. */
-    @VisibleForTesting
-    void getAnimationBounds(Point outPosition, Rect outBounds) {
-        outPosition.set(0, 0);
-        outBounds.setEmpty();
-
-        final TaskStack stack = getStack();
-        final Task task = getTask();
-        if (task != null && task.inFreeformWindowingMode()) {
-            task.getRelativeDisplayedPosition(outPosition);
-            task.getBounds(outBounds);
-        } else if (stack != null) {
-            stack.getRelativeDisplayedPosition(outPosition);
-            // Use stack bounds in order to have the ability to animate outside the task region.
-            // Needs to be consistent when {@link #mNeedsAnimationBoundsLayer} is set that crops
-            // according to the bounds.
-            stack.getBounds(outBounds);
-        }
-        // We have the relative position so the local position can be removed from bounds.
-        outBounds.offsetTo(0, 0);
-    }
-
     @Override
     Rect getDisplayedBounds() {
         final Task task = getTask();
@@ -2501,7 +2486,12 @@
         if (okToAnimate()) {
             final AnimationAdapter adapter;
             AnimationAdapter thumbnailAdapter = null;
-            getAnimationBounds(mTmpPoint, mTmpRect);
+
+            // Separate position and size for use in animators. Use task-bounds for now so
+            // that activity-level letterbox (maxAspectRatio) is included in the animation.
+            mTmpRect.set(getTask() != null ? getTask().getBounds() : getBounds());
+            mTmpPoint.set(mTmpRect.left, mTmpRect.top);
+            mTmpRect.offsetTo(0, 0);
 
             final boolean isChanging = AppTransition.isChangeTransit(transit) && enter
                     && getDisplayContent().mChangingApps.contains(this);