Fix fitWithinBounds to actually apply stack bounds.

Bug: 23749629
Change-Id: Idfca4a83647c3a70c954caeca70d73aa9deee38b
This commit is contained in:
Filip Gruszczynski
2015-09-02 17:21:21 -07:00
parent 3916e7e757
commit aff7f134a2
4 changed files with 39 additions and 40 deletions

View File

@@ -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;
}

View File

@@ -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.

View File

@@ -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) {

View File

@@ -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;
/**
* 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;
}
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;
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.left += horizontalDiff;
mTmpRect.right += horizontalDiff;
bounds.left += horizontalDiff;
bounds.right += horizontalDiff;
}
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.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;
}
mTmpRect.top += verticalDiff;
mTmpRect.bottom += verticalDiff;
bounds.top += verticalDiff;
bounds.bottom += verticalDiff;
}
return mTmpRect;
}
void dump(PrintWriter pw, String prefix) {