Set right bounds/configuration for task when positioned in stack.
When AMS.positionTaskInStack API is called we need to make sure
the task has the right bounds and configuration if it is moving
to a different stack.
Bug: 25501082
Change-Id: I2a80aa08a4ee52d860502ab16b6cdb432c954084
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index ea0db6b..91613ce 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -4606,14 +4606,20 @@
voiceInteractor);
// add the task to stack first, mTaskPositioner might need the stack association
addTask(task, toTop, false);
- if (mTaskPositioner != null) {
- mTaskPositioner.updateDefaultBounds(task, mTaskHistory, info.layout);
- } else if (mBounds != null && task.mResizeable) {
+ if (!layoutTaskInStack(task, info.layout) && mBounds != null && task.mResizeable) {
task.updateOverrideConfiguration(mBounds);
}
return task;
}
+ boolean layoutTaskInStack(TaskRecord task, ActivityInfo.Layout layout) {
+ if (mTaskPositioner == null) {
+ return false;
+ }
+ mTaskPositioner.updateDefaultBounds(task, mTaskHistory, layout);
+ return true;
+ }
+
ArrayList<TaskRecord> getAllTasks() {
return new ArrayList<>(mTaskHistory);
}
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index f624424..80034b3 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -3420,9 +3420,12 @@
Slog.w(TAG, "positionTaskInStackLocked: no task for id=" + taskId);
return;
}
- ActivityStack stack =
- getStack(stackId, CREATE_IF_NEEDED, !ON_TOP);
- mWindowManager.positionTaskInStack(taskId, stackId, position);
+ final ActivityStack stack = getStack(stackId, CREATE_IF_NEEDED, !ON_TOP);
+
+ task.updateOverrideConfigurationForStack(stack);
+
+ mWindowManager.positionTaskInStack(
+ taskId, stackId, position, task.mBounds, task.mOverrideConfig);
final boolean stackChanged = task.stack != null && task.stack != stack;
if (stackChanged) {
task.stack.removeTask(task, "moveTaskToStack", MOVING);
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 803a273..4b72693 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -1234,6 +1234,31 @@
return !mOverrideConfig.equals(oldConfig) ? mOverrideConfig : null;
}
+ /** Updates the task's bounds and override configuration to match what is expected for the
+ * input stack. */
+ void updateOverrideConfigurationForStack(ActivityStack inStack) {
+ if (stack != null && stack == inStack) {
+ return;
+ }
+
+ if (inStack.mStackId == FREEFORM_WORKSPACE_STACK_ID) {
+ if (!mResizeable) {
+ throw new IllegalArgumentException("Can not position non-resizeable task="
+ + this + " in stack=" + inStack);
+ }
+ if (mBounds != null) {
+ return;
+ }
+ if (mLastNonFullscreenBounds != null) {
+ updateOverrideConfiguration(mLastNonFullscreenBounds);
+ } else {
+ inStack.layoutTaskInStack(this, null);
+ }
+ } else {
+ updateOverrideConfiguration(inStack.mBounds);
+ }
+ }
+
/**
* Returns the correct stack to use based on task type and currently set bounds,
* regardless of the focused stack and current stack association of the task.
diff --git a/services/core/java/com/android/server/wm/Task.java b/services/core/java/com/android/server/wm/Task.java
index 6aaf3c7..7c92684 100644
--- a/services/core/java/com/android/server/wm/Task.java
+++ b/services/core/java/com/android/server/wm/Task.java
@@ -135,7 +135,7 @@
stack.addTask(this, toTop);
}
- void positionTaskInStack(TaskStack stack, int position) {
+ void positionTaskInStack(TaskStack stack, int position, Rect bounds, Configuration config) {
if (mStack != null && stack != mStack) {
if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: removing taskId=" + mTaskId
+ " from stack=" + mStack);
@@ -143,6 +143,7 @@
mStack.removeTask(this);
}
stack.positionTask(this, position, showForAllUsers());
+ setBounds(bounds, config);
}
boolean removeAppToken(AppWindowToken wtoken) {
diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java
index e98333e..3c2ec82 100644
--- a/services/core/java/com/android/server/wm/WindowManagerService.java
+++ b/services/core/java/com/android/server/wm/WindowManagerService.java
@@ -4795,7 +4795,8 @@
}
}
- public void positionTaskInStack(int taskId, int stackId, int position) {
+ public void positionTaskInStack(int taskId, int stackId, int position, Rect bounds,
+ Configuration config) {
synchronized (mWindowMap) {
if (DEBUG_STACK) Slog.i(TAG, "positionTaskInStack: positioning taskId=" + taskId
+ " in stackId=" + stackId + " at " + position);
@@ -4811,7 +4812,7 @@
"positionTaskInStack: could not find stackId=" + stackId);
return;
}
- task.positionTaskInStack(stack, position);
+ task.positionTaskInStack(stack, position, bounds, config);
final DisplayContent displayContent = stack.getDisplayContent();
displayContent.layoutNeeded = true;
mWindowPlacerLocked.performSurfacePlacement();