Migrated some windowing methods from StackId to WindowConfiguration

First pass at transitioning away from using stack ids for windowing mode
to WindowConfiguration. Added some TODO that will require the introduction
of applicationType in WindowConfiguration before additional conversation
can be done.

Test: bit FrameworksServicesTests:com.android.server.wm.WindowConfigurationTests
Test: adb shell am instrument -w -e package com.android.server.wm com.android.frameworks.servicestests/android.support.test.runner.AndroidJUnitRunner
Test: go/wm-smoke
Change-Id: I2b315623faa16445a9f942e082089123842cb5a1
diff --git a/services/core/java/com/android/server/am/ActivityManagerService.java b/services/core/java/com/android/server/am/ActivityManagerService.java
index 70fdcef..f6aa44a 100644
--- a/services/core/java/com/android/server/am/ActivityManagerService.java
+++ b/services/core/java/com/android/server/am/ActivityManagerService.java
@@ -10150,7 +10150,7 @@
                 //   that task to freeform
                 // - otherwise the task is not moved
                 int stackId = task.getStackId();
-                if (!StackId.isTaskResizeAllowed(stackId)) {
+                if (!task.getWindowConfiguration().canResizeTask()) {
                     throw new IllegalArgumentException("resizeTask not allowed on task=" + task);
                 }
                 if (bounds == null && stackId == FREEFORM_WORKSPACE_STACK_ID) {
@@ -10516,17 +10516,6 @@
     }
 
     @Override
-    public int getActivityStackId(IBinder token) throws RemoteException {
-        synchronized (this) {
-            ActivityStack stack = ActivityRecord.getStackLocked(token);
-            if (stack == null) {
-                return INVALID_STACK_ID;
-            }
-            return stack.mStackId;
-        }
-    }
-
-    @Override
     public void exitFreeformMode(IBinder token) throws RemoteException {
         synchronized (this) {
             long ident = Binder.clearCallingIdentity();
diff --git a/services/core/java/com/android/server/am/ActivityMetricsLogger.java b/services/core/java/com/android/server/am/ActivityMetricsLogger.java
index f396e9e..aae98a6 100644
--- a/services/core/java/com/android/server/am/ActivityMetricsLogger.java
+++ b/services/core/java/com/android/server/am/ActivityMetricsLogger.java
@@ -4,11 +4,12 @@
 import static android.app.ActivityManager.START_TASK_TO_FRONT;
 import static android.app.ActivityManager.StackId.ASSISTANT_STACK_ID;
 import static android.app.ActivityManager.StackId.DOCKED_STACK_ID;
-import static android.app.ActivityManager.StackId.FREEFORM_WORKSPACE_STACK_ID;
-import static android.app.ActivityManager.StackId.FULLSCREEN_WORKSPACE_STACK_ID;
 import static android.app.ActivityManager.StackId.INVALID_STACK_ID;
-import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
 import static android.app.ActivityManagerInternal.APP_TRANSITION_TIMEOUT;
+import static android.app.WindowConfiguration.WINDOWING_MODE_DOCKED;
+import static android.app.WindowConfiguration.WINDOWING_MODE_FREEFORM;
+import static android.app.WindowConfiguration.WINDOWING_MODE_FULLSCREEN;
+import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
 import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION;
 import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_BIND_APPLICATION_DELAY_MS;
 import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.APP_TRANSITION_CALLING_PACKAGE_NAME;
@@ -117,17 +118,19 @@
         }
         mWindowState = WINDOW_STATE_INVALID;
         stack = mSupervisor.getFocusedStack();
-        if (stack.mStackId == PINNED_STACK_ID) {
+        int windowingMode = stack.getWindowingMode();
+        if (windowingMode == WINDOWING_MODE_PINNED) {
             stack = mSupervisor.findStackBehind(stack);
+            windowingMode = stack.getWindowingMode();
         }
         if (StackId.isHomeOrRecentsStack(stack.mStackId)
-                || stack.mStackId == FULLSCREEN_WORKSPACE_STACK_ID) {
+                || windowingMode == WINDOWING_MODE_FULLSCREEN) {
             mWindowState = WINDOW_STATE_STANDARD;
-        } else if (stack.mStackId == DOCKED_STACK_ID) {
+        } else if (windowingMode == WINDOWING_MODE_DOCKED) {
             Slog.wtf(TAG, "Docked stack shouldn't be the focused stack, because it reported not"
                     + " being visible.");
             mWindowState = WINDOW_STATE_INVALID;
-        } else if (stack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
+        } else if (windowingMode == WINDOWING_MODE_FREEFORM) {
             mWindowState = WINDOW_STATE_FREEFORM;
         } else if (stack.mStackId == ASSISTANT_STACK_ID) {
             mWindowState = WINDOW_STATE_ASSISTANT;
diff --git a/services/core/java/com/android/server/am/ActivityRecord.java b/services/core/java/com/android/server/am/ActivityRecord.java
index 8ca6645..be81abd 100644
--- a/services/core/java/com/android/server/am/ActivityRecord.java
+++ b/services/core/java/com/android/server/am/ActivityRecord.java
@@ -1118,19 +1118,14 @@
         return mActivityType == ASSISTANT_ACTIVITY_TYPE;
     }
 
-    boolean isApplicationActivity() {
-        return mActivityType == APPLICATION_ACTIVITY_TYPE;
-    }
-
     boolean isPersistable() {
         return (info.persistableMode == PERSIST_ROOT_ONLY ||
                 info.persistableMode == PERSIST_ACROSS_REBOOTS) &&
-                (intent == null ||
-                        (intent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
+                (intent == null || (intent.getFlags() & FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS) == 0);
     }
 
     boolean isFocusable() {
-        return StackId.canReceiveKeys(task.getStackId()) || isAlwaysFocusable();
+        return getWindowConfiguration().canReceiveKeys() || isAlwaysFocusable();
     }
 
     boolean isResizeable() {
@@ -2315,7 +2310,7 @@
         // We must base this on the parent configuration, because we set our override
         // configuration's appBounds based on the result of this method. If we used our own
         // configuration, it would be influenced by past invocations.
-        final Rect appBounds = getParent().getConfiguration().windowConfiguration.getAppBounds();
+        final Rect appBounds = getParent().getWindowConfiguration().getAppBounds();
         final int containingAppWidth = appBounds.width();
         final int containingAppHeight = appBounds.height();
         int maxActivityWidth = containingAppWidth;
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 978d586..a9a06d0 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -904,7 +904,8 @@
             int addIndex = mStacks.size();
             if (addIndex > 0) {
                 final ActivityStack topStack = mStacks.get(addIndex - 1);
-                if (StackId.isAlwaysOnTop(topStack.mStackId) && topStack != this) {
+                if (topStack.getWindowConfiguration().isAlwaysOnTop()
+                        && topStack != this) {
                     // If the top stack is always on top, we move this stack just below it.
                     addIndex--;
                 }
@@ -916,7 +917,7 @@
     }
 
     boolean isFocusable() {
-        if (StackId.canReceiveKeys(mStackId)) {
+        if (getWindowConfiguration().canReceiveKeys()) {
             return true;
         }
         // The stack isn't focusable. See if its top activity is focusable to force focus on the
@@ -1721,11 +1722,12 @@
         }
         final int stackBehindTopId = (stackBehindTopIndex >= 0)
                 ? mStacks.get(stackBehindTopIndex).mStackId : INVALID_STACK_ID;
-        if (topStackId == DOCKED_STACK_ID || StackId.isAlwaysOnTop(topStackId)) {
+        final boolean alwaysOnTop = topStack.getWindowConfiguration().isAlwaysOnTop();
+        if (topStackId == DOCKED_STACK_ID || alwaysOnTop) {
             if (stackIndex == stackBehindTopIndex) {
                 // Stacks directly behind the docked or pinned stack are always visible.
                 return STACK_VISIBLE;
-            } else if (StackId.isAlwaysOnTop(topStackId) && stackIndex == stackBehindTopIndex - 1) {
+            } else if (alwaysOnTop && stackIndex == stackBehindTopIndex - 1) {
                 // Otherwise, this stack can also be visible if it is directly behind a docked stack
                 // or translucent assistant stack behind an always-on-top top-most stack
                 if (stackBehindTopId == DOCKED_STACK_ID) {
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 441df0b..752dc12 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -2362,8 +2362,9 @@
             return;
         }
 
-        if (!allowResizeInDockedMode && !StackId.tasksAreFloating(stackId) &&
-                getStack(DOCKED_STACK_ID) != null) {
+        if (!allowResizeInDockedMode
+                && !stack.getWindowConfiguration().tasksAreFloating()
+                && getStack(DOCKED_STACK_ID) != null) {
             // If the docked stack exists, don't resize non-floating stacks independently of the
             // size computed from the docked stack size (otherwise they will be out of sync)
             return;
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 3bc1b2f..ef4869d 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -473,7 +473,7 @@
     void removeWindowContainer() {
         mService.mStackSupervisor.removeLockedTaskLocked(this);
         mWindowContainerController.removeContainer();
-        if (!StackId.persistTaskBounds(getStackId())) {
+        if (!getWindowConfiguration().persistTaskBounds()) {
             // Reset current bounds for task whose bounds shouldn't be persisted so it uses
             // default configuration the next time it launches.
             updateOverrideConfiguration(null);
@@ -2108,8 +2108,9 @@
         final Configuration newConfig = getOverrideConfiguration();
 
         mFullscreen = bounds == null;
+        final boolean persistBounds = getWindowConfiguration().persistTaskBounds();
         if (mFullscreen) {
-            if (mBounds != null && StackId.persistTaskBounds(mStack.mStackId)) {
+            if (mBounds != null && persistBounds) {
                 mLastNonFullscreenBounds = mBounds;
             }
             mBounds = null;
@@ -2122,7 +2123,7 @@
             } else {
                 mBounds.set(mTmpRect);
             }
-            if (mStack == null || StackId.persistTaskBounds(mStack.mStackId)) {
+            if (mStack == null || persistBounds) {
                 mLastNonFullscreenBounds = mBounds;
             }
             computeOverrideConfiguration(newConfig, mTmpRect, insetBounds,
@@ -2242,7 +2243,7 @@
     }
 
     /** Returns the bounds that should be used to launch this task. */
-    Rect getLaunchBounds() {
+    private Rect getLaunchBounds() {
         if (mStack == null) {
             return null;
         }
@@ -2254,7 +2255,7 @@
                 || stackId == FULLSCREEN_WORKSPACE_STACK_ID
                 || (stackId == DOCKED_STACK_ID && !isResizeable())) {
             return isResizeable() ? mStack.mBounds : null;
-        } else if (!StackId.persistTaskBounds(stackId)) {
+        } else if (!getWindowConfiguration().persistTaskBounds()) {
             return mStack.mBounds;
         }
         return mLastNonFullscreenBounds;
diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java
index 00d387a..7545a10 100644
--- a/services/core/java/com/android/server/wm/AppWindowToken.java
+++ b/services/core/java/com/android/server/wm/AppWindowToken.java
@@ -514,7 +514,7 @@
     }
 
     boolean windowsAreFocusable() {
-        return StackId.canReceiveKeys(getTask().mStack.mStackId) || mAlwaysFocusable;
+        return getWindowConfiguration().canReceiveKeys() || mAlwaysFocusable;
     }
 
     AppWindowContainerController getController() {
diff --git a/services/core/java/com/android/server/wm/ConfigurationContainer.java b/services/core/java/com/android/server/wm/ConfigurationContainer.java
index 6711257..1d3f198 100644
--- a/services/core/java/com/android/server/wm/ConfigurationContainer.java
+++ b/services/core/java/com/android/server/wm/ConfigurationContainer.java
@@ -110,6 +110,15 @@
         }
     }
 
+    public WindowConfiguration getWindowConfiguration() {
+        return mFullConfiguration.windowConfiguration;
+    }
+
+    /** Returns the windowing mode the configuration container is currently in. */
+    public int getWindowingMode() {
+        return mFullConfiguration.windowConfiguration.getWindowingMode();
+    }
+
     /** Sets the windowing mode for the configuration container. */
     void setWindowingMode(/*@WindowConfiguration.WindowingMode TODO: causes build error...why?*/
             int windowingMode) {
diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java
index c295241..bf1c3f7 100644
--- a/services/core/java/com/android/server/wm/DisplayContent.java
+++ b/services/core/java/com/android/server/wm/DisplayContent.java
@@ -1809,7 +1809,7 @@
         mTmpTaskForResizePointSearchResult.reset();
         for (int stackNdx = mTaskStackContainers.size() - 1; stackNdx >= 0; --stackNdx) {
             final TaskStack stack = mTaskStackContainers.get(stackNdx);
-            if (!StackId.isTaskResizeAllowed(stack.mStackId)) {
+            if (!stack.getWindowConfiguration().canResizeTask()) {
                 return null;
             }
 
@@ -3373,7 +3373,8 @@
 
         @Override
         void positionChildAt(int position, TaskStack child, boolean includingParents) {
-            if (StackId.isAlwaysOnTop(child.mStackId) && position != POSITION_TOP) {
+            if (child.getWindowConfiguration().isAlwaysOnTop()
+                    && position != POSITION_TOP) {
                 // This stack is always-on-top, override the default behavior.
                 Slog.w(TAG_WM, "Ignoring move of always-on-top stack=" + this + " to bottom");
 
diff --git a/services/core/java/com/android/server/wm/StackWindowController.java b/services/core/java/com/android/server/wm/StackWindowController.java
index 189689b..3f6378a 100644
--- a/services/core/java/com/android/server/wm/StackWindowController.java
+++ b/services/core/java/com/android/server/wm/StackWindowController.java
@@ -19,6 +19,7 @@
 import static android.app.ActivityManager.StackId.PINNED_STACK_ID;
 
 import android.app.ActivityManager.StackId;
+import android.app.WindowConfiguration;
 import android.content.res.Configuration;
 import android.graphics.Rect;
 import android.os.Handler;
@@ -282,7 +283,7 @@
             config.windowConfiguration.setAppBounds(!bounds.isEmpty() ? bounds : null);
             boolean intersectParentBounds = false;
 
-            if (StackId.tasksAreFloating(mStackId)) {
+            if (stack.getWindowConfiguration().tasksAreFloating()) {
                 // Floating tasks should not be resized to the screen's bounds.
 
                 if (mStackId == PINNED_STACK_ID && bounds.width() == mTmpDisplayBounds.width() &&
@@ -359,7 +360,7 @@
                 bounds.height() == displayInfo.logicalHeight)) {
             // If the bounds are fullscreen, return the value of the fullscreen configuration
             return displayContent.getConfiguration().smallestScreenWidthDp;
-        } else if (StackId.tasksAreFloating(mStackId)) {
+        } else if (mContainer.getWindowConfiguration().tasksAreFloating()) {
             // For floating tasks, calculate the smallest width from the bounds of the task
             return (int) (Math.min(bounds.width(), bounds.height()) / density);
         } else {
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 6349b05..60384f27 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -244,7 +244,7 @@
         // Update task bounds if needed.
         updateDisplayInfo(getDisplayContent());
 
-        if (StackId.windowsAreScaleable(mStack.mStackId)) {
+        if (getWindowConfiguration().windowsAreScaleable()) {
             // We force windows out of SCALING_MODE_FREEZE so that we can continue to animate them
             // while a resize is pending.
             forceWindowsScaleable(true /* force */);
@@ -572,7 +572,7 @@
         //   from its stack. The stack will take care of task rotation for the other case.
         mTmpRect2.set(mBounds);
 
-        if (!StackId.isTaskResizeAllowed(mStack.mStackId)) {
+        if (!getWindowConfiguration().canResizeTask()) {
             setBounds(mTmpRect2, getOverrideConfiguration());
             return;
         }
@@ -620,7 +620,7 @@
      * we will have a jump at the end.
      */
     boolean isFloating() {
-        return StackId.tasksAreFloating(mStack.mStackId)
+        return getWindowConfiguration().tasksAreFloating()
                 && !mStack.isAnimatingBoundsToFullscreen() && !mPreserveNonFloatingState;
     }
 
@@ -709,7 +709,7 @@
 
     @Override
     boolean fillsParent() {
-        return mFillsParent || !StackId.isTaskResizeAllowed(mStack.mStackId);
+        return mFillsParent || !getWindowConfiguration().canResizeTask();
     }
 
     @Override
diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java
index 6dbdcc4..8a4a49a 100644
--- a/services/core/java/com/android/server/wm/TaskStack.java
+++ b/services/core/java/com/android/server/wm/TaskStack.java
@@ -1439,7 +1439,7 @@
 
     void findTaskForResizePoint(int x, int y, int delta,
             DisplayContent.TaskForResizePointSearchResult results) {
-        if (!StackId.isTaskResizeAllowed(mStackId)) {
+        if (!getWindowConfiguration().canResizeTask()) {
             results.searchDone = true;
             return;
         }
@@ -1636,10 +1636,6 @@
         return false;
     }
 
-    public boolean hasMovementAnimations() {
-        return StackId.hasMovementAnimations(mStackId);
-    }
-
     public boolean isForceScaled() {
         return mBoundsAnimating;
     }
diff --git a/services/core/java/com/android/server/wm/WindowState.java b/services/core/java/com/android/server/wm/WindowState.java
index 5a181f1..f7ab534 100644
--- a/services/core/java/com/android/server/wm/WindowState.java
+++ b/services/core/java/com/android/server/wm/WindowState.java
@@ -1737,7 +1737,7 @@
         if (mToken.okToAnimate()
                 && (mAttrs.privateFlags & PRIVATE_FLAG_NO_MOVE_ANIMATION) == 0
                 && !isDragResizing() && !adjustedForMinimizedDockOrIme
-                && (task == null || getTask().mStack.hasMovementAnimations())
+                && getWindowConfiguration().hasMovementAnimations()
                 && !mWinAnimator.mLastHidden) {
             mWinAnimator.setMoveAnimation(left, top);
         }
@@ -2422,7 +2422,7 @@
      * because we want to preserve its location on screen to be re-activated later when the user
      * interacts with it.
      */
-    boolean shouldKeepVisibleDeadAppWindow() {
+    private boolean shouldKeepVisibleDeadAppWindow() {
         if (!isWinVisibleLw() || mAppToken == null || mAppToken.isClientHidden()) {
             // Not a visible app window or the app isn't dead.
             return false;
@@ -2440,8 +2440,7 @@
             return false;
         }
 
-        final TaskStack stack = getStack();
-        return stack != null && StackId.keepVisibleDeadAppWindowOnScreen(stack.mStackId);
+        return getWindowConfiguration().keepVisibleDeadAppWindowOnScreen();
     }
 
     /** @return true if this window desires key events. */
@@ -3209,7 +3208,7 @@
         // one or more frame to wrong offset. So here we send fullscreen backdrop if either
         // isDragResizing() or isDragResizeChanged() is true.
         boolean resizing = isDragResizing() || isDragResizeChanged();
-        if (StackId.useWindowFrameForBackdrop(getStackId()) || !resizing) {
+        if (getWindowConfiguration().useWindowFrameForBackdrop() || !resizing) {
             return frame;
         }
         final DisplayInfo displayInfo = getDisplayInfo();
diff --git a/services/core/java/com/android/server/wm/WindowStateAnimator.java b/services/core/java/com/android/server/wm/WindowStateAnimator.java
index 9d3db7c..906cac6 100644
--- a/services/core/java/com/android/server/wm/WindowStateAnimator.java
+++ b/services/core/java/com/android/server/wm/WindowStateAnimator.java
@@ -49,6 +49,7 @@
 import static com.android.server.wm.proto.WindowStateAnimatorProto.LAST_CLIP_RECT;
 import static com.android.server.wm.proto.WindowStateAnimatorProto.SURFACE;
 
+import android.app.WindowConfiguration;
 import android.content.Context;
 import android.graphics.Matrix;
 import android.graphics.PixelFormat;
@@ -1145,7 +1146,7 @@
         final TaskStack stack = w.getTask().mStack;
         stack.getDimBounds(finalClipRect);
 
-        if (StackId.tasksAreFloating(stack.mStackId)) {
+        if (stack.getWindowConfiguration().tasksAreFloating()) {
             w.expandForSurfaceInsets(finalClipRect);
         }
 
@@ -1165,6 +1166,7 @@
             transform.mapRect(finalCrop);
             finalClipRect.top = (int)finalCrop.top;
             finalClipRect.left = (int)finalCrop.left;
+            // TODO: Are the assignments below a mistake?
             finalClipRect.right = (int)finalClipRect.right;
             finalClipRect.bottom = (int)finalClipRect.bottom;
         }
@@ -1324,8 +1326,8 @@
 
         // We need to do some acrobatics with surface position, because their clip region is
         // relative to the inside of the surface, but the stack bounds aren't.
-        if (StackId.hasWindowShadow(stack.mStackId)
-                && !StackId.isTaskResizeAllowed(stack.mStackId)) {
+        final WindowConfiguration winConfig = w.getWindowConfiguration();
+        if (winConfig.hasWindowShadow() && !winConfig.canResizeTask()) {
                 // The windows in this stack display drop shadows and the fill the entire stack
                 // area. Adjust the stack bounds we will use to cropping take into account the
                 // offsets we use to display the drop shadow so it doesn't get cropped.
@@ -1760,8 +1762,7 @@
      * @return Returns true if the surface was successfully shown.
      */
     private boolean showSurfaceRobustlyLocked() {
-        final Task task = mWin.getTask();
-        if (task != null && StackId.windowsAreScaleable(task.mStack.mStackId)) {
+        if (mWin.getWindowConfiguration().windowsAreScaleable()) {
             mSurfaceController.forceScaleableInTransaction(true);
         }