Apply IME adjust to newly added window

bug: 28390108
Change-Id: I72132d68cb41056fb69f2fe38fa13f2b3c9ce3d6
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 7ee26a0..efabe31 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -322,6 +322,32 @@
         mPreparedFrozenBounds.set(mBounds);
     }
 
+    /**
+     * Align the task to the adjusted bounds.
+     *
+     * @param adjustedBounds Adjusted bounds to which the task should be aligned.
+     * @param tempInsetBounds Insets bounds for the task.
+     * @param alignBottom True if the task's bottom should be aligned to the adjusted
+     *                    bounds's bottom; false if the task's top should be aligned
+     *                    the adjusted bounds's top.
+     */
+    void alignToAdjustedBounds(
+            Rect adjustedBounds, Rect tempInsetBounds, boolean alignBottom) {
+        if (!isResizeable() || mOverrideConfig == Configuration.EMPTY) {
+            return;
+        }
+
+        getBounds(mTmpRect2);
+        if (alignBottom) {
+            int offsetY = adjustedBounds.bottom - mTmpRect2.bottom;
+            mTmpRect2.offset(0, offsetY);
+        } else {
+            mTmpRect2.offsetTo(adjustedBounds.left, adjustedBounds.top);
+        }
+        setTempInsetBounds(tempInsetBounds);
+        resizeLocked(mTmpRect2, mOverrideConfig, false /* forced */);
+    }
+
     void resetScrollLocked() {
         if (mScrollValid) {
             mScrollValid = false;