summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Filip Gruszczynski <gruszczy@google.com> 2015-09-03 23:02:41 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2015-09-03 23:02:41 +0000
commited76be0caa79d293446a983a5fdb27446087265c (patch)
treea376a460e89801af47f9caaf6ae8a813a3731225
parent2fd7cc5ba593c47cb9028faced8fa64905a16121 (diff)
parentaff7f134a29d0eeac9ec07db4b97c36ecb202ea5 (diff)
Merge "Fix fitWithinBounds to actually apply stack bounds."
-rw-r--r--services/core/java/com/android/server/am/ActivityStack.java5
-rw-r--r--services/core/java/com/android/server/am/ActivityStackSupervisor.java4
-rw-r--r--services/core/java/com/android/server/am/LaunchingTaskPositioner.java3
-rw-r--r--services/core/java/com/android/server/am/TaskRecord.java71
4 files changed, 41 insertions, 42 deletions
diff --git a/services/core/java/com/android/server/am/ActivityStack.java b/services/core/java/com/android/server/am/ActivityStack.java
index 37ddd4df7ffb..d2a6c02543a2 100644
--- a/services/core/java/com/android/server/am/ActivityStack.java
+++ b/services/core/java/com/android/server/am/ActivityStack.java
@@ -18,7 +18,6 @@ package com.android.server.am;
import static android.app.ActivityManager.DOCKED_STACK_ID;
import static android.app.ActivityManager.FREEFORM_WORKSPACE_STACK_ID;
-import static android.app.ActivityManager.FULLSCREEN_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.HOME_STACK_ID;
import static android.content.pm.ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
@@ -4588,7 +4587,7 @@ final class ActivityStack {
void addConfigOverride(ActivityRecord r, TaskRecord task) {
final Rect bounds = task.getLaunchBounds();
- final Configuration config = task.updateOverrideConfiguration(mStackId, bounds);
+ final Configuration config = task.updateOverrideConfiguration(bounds);
mWindowManager.addAppToken(task.mActivities.indexOf(r), r.appToken,
r.task.taskId, mStackId, r.info.screenOrientation, r.fullscreen,
(r.info.flags & ActivityInfo.FLAG_SHOW_FOR_ALL_USERS) != 0, r.userId,
@@ -4599,7 +4598,7 @@ final class ActivityStack {
private void setAppTask(ActivityRecord r, TaskRecord task) {
final Rect bounds = task.getLaunchBounds();
- final Configuration config = task.updateOverrideConfiguration(mStackId, bounds);
+ final Configuration config = task.updateOverrideConfiguration(bounds);
mWindowManager.setAppTask(r.appToken, task.taskId, task.getLaunchBounds(), config);
r.taskConfigOverride = task.mOverrideConfig;
}
diff --git a/services/core/java/com/android/server/am/ActivityStackSupervisor.java b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
index 33e0ef83299c..fb3007daa0a2 100644
--- a/services/core/java/com/android/server/am/ActivityStackSupervisor.java
+++ b/services/core/java/com/android/server/am/ActivityStackSupervisor.java
@@ -2925,7 +2925,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
ArrayList<TaskRecord> tasks = stack.getAllTasks();
for (int i = tasks.size() - 1; i >= 0; i--) {
TaskRecord task = tasks.get(i);
- task.updateOverrideConfiguration(stackId, bounds);
+ task.updateOverrideConfiguration(bounds);
mTmpConfigs.put(task.taskId, task.mOverrideConfig);
mTmpBounds.put(task.taskId, task.mBounds);
}
@@ -3029,7 +3029,7 @@ public final class ActivityStackSupervisor implements DisplayListener {
moveTaskToStackUncheckedLocked(task, stackId, ON_TOP, !FORCE_FOCUS, "resizeTask");
}
- final Configuration overrideConfig = task.updateOverrideConfiguration(stackId, bounds);
+ final Configuration overrideConfig = task.updateOverrideConfiguration(bounds);
// This variable holds information whether the configuration didn't change in a signficant
// way and the activity was kept the way it was. If it's false, it means the activity had
// to be relaunched due to configuration change.
diff --git a/services/core/java/com/android/server/am/LaunchingTaskPositioner.java b/services/core/java/com/android/server/am/LaunchingTaskPositioner.java
index 735c06ffbcf2..3d459157edbf 100644
--- a/services/core/java/com/android/server/am/LaunchingTaskPositioner.java
+++ b/services/core/java/com/android/server/am/LaunchingTaskPositioner.java
@@ -16,7 +16,6 @@
package com.android.server.am;
-import static android.app.ActivityManager.FREEFORM_WORKSPACE_STACK_ID;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_AM;
import static com.android.server.am.ActivityManagerDebugConfig.TAG_WITH_CLASS_NAME;
@@ -235,7 +234,7 @@ class LaunchingTaskPositioner {
break;
}
}
- task.updateOverrideConfiguration(FREEFORM_WORKSPACE_STACK_ID, proposal);
+ task.updateOverrideConfiguration(proposal);
}
private boolean shiftedToFar(Rect start, int shiftPolicy) {
diff --git a/services/core/java/com/android/server/am/TaskRecord.java b/services/core/java/com/android/server/am/TaskRecord.java
index 12c7b863e1e3..51f6a2a1721f 100644
--- a/services/core/java/com/android/server/am/TaskRecord.java
+++ b/services/core/java/com/android/server/am/TaskRecord.java
@@ -20,7 +20,6 @@ import static android.app.ActivityManager.DOCKED_STACK_ID;
import static android.app.ActivityManager.FREEFORM_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.FULLSCREEN_WORKSPACE_STACK_ID;
import static android.app.ActivityManager.HOME_STACK_ID;
-import static android.app.ActivityManager.INVALID_STACK_ID;
import static android.content.Intent.FLAG_ACTIVITY_NEW_DOCUMENT;
import static android.content.Intent.FLAG_ACTIVITY_RETAIN_IN_RECENTS;
import static android.content.pm.ActivityInfo.LOCK_TASK_LAUNCH_MODE_ALWAYS;
@@ -228,8 +227,6 @@ final class TaskRecord {
Configuration mOverrideConfig = Configuration.EMPTY;
- private Rect mTmpRect = new Rect();
-
TaskRecord(ActivityManagerService service, int _taskId, ActivityInfo info, Intent _intent,
IVoiceInteractionSession _voiceSession, IVoiceInteractor _voiceInteractor) {
mService = service;
@@ -1174,7 +1171,7 @@ final class TaskRecord {
activities, firstActiveTime, lastActiveTime, lastTimeOnTop, neverRelinquishIdentity,
taskDescription, taskAffiliation, prevTaskId, nextTaskId, taskAffiliationColor,
callingUid, callingPackage, resizeable, privileged);
- task.updateOverrideConfiguration(INVALID_STACK_ID, bounds);
+ task.updateOverrideConfiguration(bounds);
for (int activityNdx = activities.size() - 1; activityNdx >=0; --activityNdx) {
activities.get(activityNdx).task = task;
@@ -1188,12 +1185,12 @@ final class TaskRecord {
* Update task's override configuration based on the bounds.
* @return Update configuration or null if there is no change.
*/
- Configuration updateOverrideConfiguration(int stackId, Rect bounds) {
- if (stackId == FREEFORM_WORKSPACE_STACK_ID) {
+ Configuration updateOverrideConfiguration(Rect bounds) {
+ 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.
- bounds = fitWithinBounds(bounds);
+ fitWithinBounds(bounds, stack.mBounds);
}
if (Objects.equals(mBounds, bounds)) {
return null;
@@ -1262,39 +1259,43 @@ final class TaskRecord {
return mLastNonFullscreenBounds;
}
- /** Fits the tasks within the input bounds adjusting the task bounds as needed.
- * @param bounds Bounds to fit the task within. Nothing is done if null.
- * @return Returns final configuration after updating with the adjusted bounds.
- * */
- Rect fitWithinBounds(Rect bounds) {
- if (bounds == null || mBounds == null || bounds.contains(mBounds)) {
- return bounds;
- }
- mTmpRect.set(mBounds);
-
- if (mBounds.left < bounds.left || mBounds.right > bounds.right) {
- final int maxRight = bounds.right - (bounds.width() / FIT_WITHIN_BOUNDS_DIVIDER);
- int horizontalDiff = bounds.left - mBounds.left;
- if ((horizontalDiff < 0 && mBounds.left >= maxRight)
- || (mBounds.left + horizontalDiff >= maxRight)) {
- horizontalDiff = maxRight - mBounds.left;
- }
- mTmpRect.left += horizontalDiff;
- mTmpRect.right += horizontalDiff;
+ /**
+ * Adjust bounds to stay within stack bounds.
+ *
+ * Since bounds might be outside of stack bounds, this method tries to move the bounds in a way
+ * that keep them unchanged, but be contained within the stack bounds.
+ *
+ * @param bounds Bounds to be adjusted.
+ * @param stackBounds Bounds within which the other bounds should remain.
+ */
+ private static void fitWithinBounds(Rect bounds, Rect stackBounds) {
+ if (stackBounds == null || stackBounds.contains(bounds)) {
+ return;
}
- if (mBounds.top < bounds.top || mBounds.bottom > bounds.bottom) {
- final int maxBottom = bounds.bottom - (bounds.height() / FIT_WITHIN_BOUNDS_DIVIDER);
- int verticalDiff = bounds.top - mBounds.top;
- if ((verticalDiff < 0 && mBounds.top >= maxBottom)
- || (mBounds.top + verticalDiff >= maxBottom)) {
- verticalDiff = maxBottom - mBounds.top;
+ if (bounds.left < stackBounds.left || bounds.right > stackBounds.right) {
+ final int maxRight = stackBounds.right
+ - (stackBounds.width() / FIT_WITHIN_BOUNDS_DIVIDER);
+ int horizontalDiff = stackBounds.left - bounds.left;
+ if ((horizontalDiff < 0 && bounds.left >= maxRight)
+ || (bounds.left + horizontalDiff >= maxRight)) {
+ horizontalDiff = maxRight - bounds.left;
}
- mTmpRect.top += verticalDiff;
- mTmpRect.bottom += verticalDiff;
+ bounds.left += horizontalDiff;
+ bounds.right += horizontalDiff;
}
- return mTmpRect;
+ if (bounds.top < stackBounds.top || bounds.bottom > stackBounds.bottom) {
+ final int maxBottom = stackBounds.bottom
+ - (stackBounds.height() / FIT_WITHIN_BOUNDS_DIVIDER);
+ int verticalDiff = stackBounds.top - bounds.top;
+ if ((verticalDiff < 0 && bounds.top >= maxBottom)
+ || (bounds.top + verticalDiff >= maxBottom)) {
+ verticalDiff = maxBottom - bounds.top;
+ }
+ bounds.top += verticalDiff;
+ bounds.bottom += verticalDiff;
+ }
}
void dump(PrintWriter pw, String prefix) {