From a6e902ec61ab1cd8f7d5df84deab6f26471c22fd Mon Sep 17 00:00:00 2001 From: Wale Ogunwale Date: Mon, 21 Sep 2015 18:37:15 -0700 Subject: [PATCH] Properly size tasks based on stack size. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There were a few places we weren’t doing this correctly * When a new task is created the bounds should be the stack bounds if the task is resizeable and not in freeform mode. * When resizing a stack each task in the stack should be resized base on if it is resizable vs. using the top running activity in the stack to determine if all the tasks should be resized. Change-Id: If3448c5629313e7e7fb91ffe8506014f16ad72db --- .../com/android/server/am/ActivityStack.java | 2 ++ .../server/am/ActivityStackSupervisor.java | 25 ++++++++----------- .../com/android/server/am/TaskRecord.java | 2 +- .../java/com/android/server/wm/TaskStack.java | 12 ++------- .../server/wm/WindowManagerService.java | 5 ++-- 5 files changed, 18 insertions(+), 28 deletions(-) diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java index 3fcffd78d049e..ee4dbd4ca4513 100644 --- a/services/core/java/com/android/server/am/ActivityStack.java +++ b/services/core/java/com/android/server/am/ActivityStack.java @@ -4564,6 +4564,8 @@ final class ActivityStack { addTask(task, toTop, false); if (mTaskPositioner != null) { mTaskPositioner.updateDefaultBounds(task, mTaskHistory, info.initialLayout); + } else if (mBounds != null && task.mResizeable) { + task.updateOverrideConfiguration(mBounds); } return task; } diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java index 3c181e1086d41..f546c1dc94f08 100644 --- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java +++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java @@ -2971,31 +2971,29 @@ public final class ActivityStackSupervisor implements DisplayListener { } ActivityRecord r = stack.topRunningActivityLocked(null); - final boolean resizeTasks = r != null && r.task.mResizeable; mTmpBounds.clear(); mTmpConfigs.clear(); - if (resizeTasks) { - ArrayList tasks = stack.getAllTasks(); - for (int i = tasks.size() - 1; i >= 0; i--) { - TaskRecord task = tasks.get(i); + ArrayList tasks = stack.getAllTasks(); + for (int i = tasks.size() - 1; i >= 0; i--) { + TaskRecord task = tasks.get(i); + if (task.mResizeable) { if (stack.mStackId == FREEFORM_WORKSPACE_STACK_ID) { - // For freeform stack we don't adjust the size of the tasks to match that of - // the stack, but we do try to make sure the tasks are still contained with the - // bounds of the stack. + // For freeform stack we don't adjust the size of the tasks to match that + // of the stack, but we do try to make sure the tasks are still contained + // with the bounds of the stack. tempRect2.set(task.mBounds); fitWithinBounds(tempRect2, bounds); task.updateOverrideConfiguration(tempRect2); } else { task.updateOverrideConfiguration(bounds); } - - mTmpConfigs.put(task.taskId, task.mOverrideConfig); - mTmpBounds.put(task.taskId, task.mBounds); } + + mTmpConfigs.put(task.taskId, task.mOverrideConfig); + mTmpBounds.put(task.taskId, task.mBounds); } - stack.mFullscreen = mWindowManager.resizeStack(stackId, bounds, resizeTasks, mTmpConfigs, - mTmpBounds); + stack.mFullscreen = mWindowManager.resizeStack(stackId, bounds, mTmpConfigs, mTmpBounds); if (stack.mStackId == DOCKED_STACK_ID) { // Dock stack funness...Yay! if (stack.mFullscreen) { @@ -3008,7 +3006,6 @@ public final class ActivityStackSupervisor implements DisplayListener { } } - final ArrayList tasks = stack.getAllTasks(); final int count = tasks.size(); for (int i = 0; i < count; i++) { moveTaskToStackLocked(tasks.get(i).taskId, diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java index 8f10f083c0ff9..43f5baab793f2 100644 --- a/services/core/java/com/android/server/am/TaskRecord.java +++ b/services/core/java/com/android/server/am/TaskRecord.java @@ -1235,7 +1235,7 @@ final class TaskRecord { if (stack == null || stack.mStackId == HOME_STACK_ID || stack.mStackId == FULLSCREEN_WORKSPACE_STACK_ID) { - return null; + return (mResizeable && stack != null) ? stack.mBounds : null; } else if (stack.mStackId == DOCKED_STACK_ID) { return stack.mBounds; } diff --git a/services/core/java/com/android/server/wm/TaskStack.java b/services/core/java/com/android/server/wm/TaskStack.java index 571540fade62d..86597badb1c75 100644 --- a/services/core/java/com/android/server/wm/TaskStack.java +++ b/services/core/java/com/android/server/wm/TaskStack.java @@ -118,30 +118,22 @@ public class TaskStack implements DimLayer.DimLayerUser { /** * Set the bounds of the stack and its containing tasks. * @param stackBounds New stack bounds. Passing in null sets the bounds to fullscreen. - * @param resizeTasks If true, the tasks within the stack will also be resized. * @param configs Configuration for individual tasks, keyed by task id. * @param taskBounds Bounds for individual tasks, keyed by task id. * @return True if the stack bounds was changed. * */ - boolean setBounds(Rect stackBounds, boolean resizeTasks, SparseArray configs, - SparseArray taskBounds) { + boolean setBounds( + Rect stackBounds, SparseArray configs, SparseArray taskBounds) { if (!setBounds(stackBounds)) { return false; } - if (!resizeTasks) { - return true; - } - // Update bounds of containing tasks. for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { final Task task = mTasks.get(taskNdx); Configuration config = configs.get(task.mTaskId); if (config != null) { Rect bounds = taskBounds.get(task.mTaskId); - if (bounds == null) { - bounds = stackBounds; - } task.setBounds(bounds, config); } else { Slog.wtf(TAG, "No config for task: " + task + ", is there a mismatch with AM?"); diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 1b38b433a7796..29598ab194764 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -4632,12 +4632,11 @@ public class WindowManagerService extends IWindowManager.Stub * Re-sizes a stack and its containing tasks. * @param stackId Id of stack to resize. * @param bounds New stack bounds. Passing in null sets the bounds to fullscreen. - * @param resizeTasks If true, the tasks within the stack will also be resized. * @param configs Configurations for tasks in the resized stack, keyed by task id. * @param taskBounds Bounds for tasks in the resized stack, keyed by task id. * @return True if the stack is now fullscreen. * */ - public boolean resizeStack(int stackId, Rect bounds, boolean resizeTasks, + public boolean resizeStack(int stackId, Rect bounds, SparseArray configs, SparseArray taskBounds) { synchronized (mWindowMap) { final TaskStack stack = mStackIdToStack.get(stackId); @@ -4645,7 +4644,7 @@ public class WindowManagerService extends IWindowManager.Stub throw new IllegalArgumentException("resizeStack: stackId " + stackId + " not found."); } - if (stack.setBounds(bounds, resizeTasks, configs, taskBounds)) { + if (stack.setBounds(bounds, configs, taskBounds)) { stack.resizeWindows(); stack.getDisplayContent().layoutNeeded = true; mWindowPlacerLocked.performSurfacePlacement();