Report re-sized stacks/task as fullscreen when docked stack isn't visible

When a docked stack exist we resize all other stacks and crop their
window content to the stack size. This was also been done when the
docked stack exist, but not visible. E.g the primary user has a docked
stack, but the secondary user doesn't, so the windows of the secondary
user get cropped.
We now report stacks/task sizes as fullscreen whenever the docked stack
isn't visible.

Bug: 24366804
Change-Id: Ia3f24e6f7d33fc175348e27db24a15ce3027e6f7
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index d1111f7..bc078f9 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -245,8 +245,32 @@
         return true;
     }
 
+    /** Return true if the current bound can get outputted to the rest of the system as-is. */
+    private boolean useCurrentBounds() {
+        final DisplayContent displayContent = mStack.getDisplayContent();
+        if (mFullscreen
+                || mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID
+                || mStack.mStackId == DOCKED_STACK_ID
+                || displayContent == null
+                || displayContent.getDockedStackLocked() != null) {
+            return true;
+        }
+        return false;
+    }
+
+    /** Bounds of the task with other system factors taken into consideration. */
     void getBounds(Rect out) {
-        out.set(mBounds);
+        if (useCurrentBounds()) {
+            // No need to adjust the output bounds if fullscreen or the docked stack is visible
+            // since it is already what we want to represent to the rest of the system.
+            out.set(mBounds);
+            return;
+        }
+
+        // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
+        // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
+        // system.
+        mStack.getDisplayContent().getLogicalDisplayRect(out);
     }
 
     void setDragResizing(boolean dragResizing) {
@@ -433,10 +457,6 @@
         return mStack != null && mStack.mStackId == FREEFORM_WORKSPACE_STACK_ID;
     }
 
-    boolean inDockedWorkspace() {
-        return mStack != null && mStack.mStackId == DOCKED_STACK_ID;
-    }
-
     WindowState getTopAppMainWindow() {
         final int tokensCount = mAppTokens.size();
         return tokensCount > 0 ? mAppTokens.get(tokensCount - 1).findMainWindow() : null;
@@ -444,7 +464,13 @@
 
     @Override
     public boolean isFullscreen() {
-        return mFullscreen;
+        if (useCurrentBounds()) {
+            return mFullscreen;
+        }
+        // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
+        // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
+        // system.
+        return true;
     }
 
     @Override
diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java
index 3b08284..6333b2b 100644
--- a/services/core/java/com/android/server/wm/TaskStack.java
+++ b/services/core/java/com/android/server/wm/TaskStack.java
@@ -181,10 +181,40 @@
         return true;
     }
 
-    void getBounds(Rect out) {
+    /** Bounds of the stack without adjusting for other factors in the system like visibility
+     * of docked stack.
+     * Most callers should be using {@link #getBounds} as it take into consideration other system
+     * factors. */
+    void getRawBounds(Rect out) {
         out.set(mBounds);
     }
 
+    /** Return true if the current bound can get outputted to the rest of the system as-is. */
+    private boolean useCurrentBounds() {
+        if (mFullscreen
+                || mStackId == DOCKED_STACK_ID
+                || mDisplayContent == null
+                || mDisplayContent.getDockedStackLocked() != null) {
+            return true;
+        }
+        return false;
+    }
+
+    /** Bounds of the stack with other system factors taken into consideration. */
+    void getBounds(Rect out) {
+        if (useCurrentBounds()) {
+            // No need to adjust the output bounds if fullscreen or the docked stack is visible
+            // since it is already what we want to represent to the rest of the system.
+            out.set(mBounds);
+            return;
+        }
+
+        // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
+        // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
+        // system.
+        mDisplayContent.getLogicalDisplayRect(out);
+    }
+
     void updateDisplayInfo(Rect bounds) {
         if (mDisplayContent != null) {
             if (bounds != null) {
@@ -520,9 +550,23 @@
         }
     }
 
+    /** Fullscreen status of the stack without adjusting for other factors in the system like
+     * visibility of docked stack.
+     * Most callers should be using {@link #isFullscreen} as it take into consideration other
+     * system factors. */
+    boolean getRawFullscreen() {
+        return mFullscreen;
+    }
+
     @Override
     public boolean isFullscreen() {
-        return mFullscreen;
+        if (useCurrentBounds()) {
+            return mFullscreen;
+        }
+        // The bounds has been adjusted to accommodate for a docked stack, but the docked stack
+        // is not currently visible. Go ahead a represent it as fullscreen to the rest of the
+        // system.
+        return true;
     }
 
     @Override
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index ea26822..731ebc0 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -4517,11 +4517,11 @@
                     for (int winNdx = windows.size() - 1; winNdx >= 0; --winNdx) {
                         windows.get(winNdx).reportResized();
                     }
-                    if (stack.isFullscreen()) {
+                    if (stack.getRawFullscreen()) {
                         return null;
                     }
                     Rect bounds = new Rect();
-                    stack.getBounds(bounds);
+                    stack.getRawBounds(bounds);
                     return bounds;
                 }
             }
@@ -4644,7 +4644,7 @@
                 stack.getDisplayContent().layoutNeeded = true;
                 mWindowPlacerLocked.performSurfacePlacement();
             }
-            return stack.isFullscreen();
+            return stack.getRawFullscreen();
         }
     }