Preserve non-floating state when entering pinned stack.

When transitioning between the fullscreen and pinned states
we often have a situation where we go from having a navigation and
status bar in the window to not. We'd like to use the source bounds
animation to crop these out rather than a sudden jump or scaling
but in order to do so we need to ensure they last until the end
of the animation. We track this state, and return the appropriate
value from isFloating. Furthermore, we add support to the bounds
animation to use the content frame as a source bounds when there
is no source bounds present, this means that we can crop out the
navigation and status bar so they will be invisible by the end of
the animation.

Bug: 37531386
Test: Manual
Change-Id: I72c549e3a3318534428d17b68ebee5832c32e6d7
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 0a999e6..27661e2 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -92,6 +92,12 @@
 
     private TaskDescription mTaskDescription;
 
+    // If set to true, the task will report that it is not in the floating
+    // state regardless of it's stack affilation. As the floating state drives
+    // production of content insets this can be used to preserve them across
+    // stack moves and we in fact do so when moving from full screen to pinned.
+    private boolean mPreserveNonFloatingState = false;
+
     Task(int taskId, TaskStack stack, int userId, WindowManagerService service, Rect bounds,
             Configuration overrideConfig, int resizeMode, boolean supportsPictureInPicture,
             boolean homeTask, TaskDescription taskDescription,
@@ -194,6 +200,16 @@
         EventLog.writeEvent(WM_TASK_REMOVED, mTaskId, "reParentTask");
         final DisplayContent prevDisplayContent = getDisplayContent();
 
+        // If we are moving from the fullscreen stack to the pinned stack
+        // then we want to preserve our insets so that there will not
+        // be a jump in the area covered by system decorations. We rely
+        // on the pinned animation to later unset this value.
+        if (stack.mStackId == PINNED_STACK_ID) {
+            mPreserveNonFloatingState = true;
+        } else {
+            mPreserveNonFloatingState = false;
+        }
+
         getParent().removeChild(this);
         stack.addTask(this, position, showForAllUsers(), moveParents);
 
@@ -593,7 +609,8 @@
      * we will have a jump at the end.
      */
     boolean isFloating() {
-        return StackId.tasksAreFloating(mStack.mStackId) && !mStack.isAnimatingBoundsToFullscreen();
+        return StackId.tasksAreFloating(mStack.mStackId)
+                && !mStack.isAnimatingBoundsToFullscreen() && !mPreserveNonFloatingState;
     }
 
     WindowState getTopVisibleAppMainWindow() {
@@ -675,6 +692,10 @@
         return toShortString();
     }
 
+    void clearPreserveNonFloatingState() {
+        mPreserveNonFloatingState = false;
+    }
+
     @Override
     public String toShortString() {
         return "Task=" + mTaskId;