Fix WM missing stack/task when activity is force stopped and restarted am: d9d35bdfcf

am: c35df3de2f

Change-Id: I9ca53012b924278e32465536ad12b98dd887ac9a
This commit is contained in:
Chong Zhang
2016-08-05 20:14:27 +00:00
committed by android-build-merger
3 changed files with 37 additions and 8 deletions

View File

@@ -781,20 +781,25 @@ public final class ActivityStackSupervisor implements DisplayListener {
}
}
static int nextTaskIdForUser(int taskId, int userId) {
int nextTaskId = taskId + 1;
if (nextTaskId == (userId + 1) * MAX_TASK_IDS_PER_USER) {
// Wrap around as there will be smaller task ids that are available now.
nextTaskId -= MAX_TASK_IDS_PER_USER;
}
return nextTaskId;
}
int getNextTaskIdForUserLocked(int userId) {
final int currentTaskId = mCurTaskIdForUser.get(userId, userId * MAX_TASK_IDS_PER_USER);
// for a userId u, a taskId can only be in the range
// [u*MAX_TASK_IDS_PER_USER, (u+1)*MAX_TASK_IDS_PER_USER-1], so if MAX_TASK_IDS_PER_USER
// was 10, user 0 could only have taskIds 0 to 9, user 1: 10 to 19, user 2: 20 to 29, so on.
int candidateTaskId = currentTaskId;
int candidateTaskId = nextTaskIdForUser(currentTaskId, userId);
while (mRecentTasks.taskIdTakenForUserLocked(candidateTaskId, userId)
|| anyTaskForIdLocked(candidateTaskId, !RESTORE_FROM_RECENTS,
INVALID_STACK_ID) != null) {
candidateTaskId++;
if (candidateTaskId == (userId + 1) * MAX_TASK_IDS_PER_USER) {
// Wrap around as there will be smaller task ids that are available now.
candidateTaskId -= MAX_TASK_IDS_PER_USER;
}
candidateTaskId = nextTaskIdForUser(candidateTaskId, userId);
if (candidateTaskId == currentTaskId) {
// Something wrong!
// All MAX_TASK_IDS_PER_USER task ids are taken up by running tasks for this user

View File

@@ -191,6 +191,16 @@ class DisplayContent {
return mHomeStack;
}
TaskStack getStackById(int stackId) {
for (int i = mStacks.size() - 1; i >= 0; --i) {
final TaskStack stack = mStacks.get(i);
if (stack.mStackId == stackId) {
return stack;
}
}
return null;
}
void updateDisplayInfo() {
mDisplay.getDisplayInfo(mDisplayInfo);
mDisplay.getMetrics(mDisplayMetrics);

View File

@@ -5047,18 +5047,32 @@ public class WindowManagerService extends IWindowManager.Stub
try {
synchronized (mWindowMap) {
final DisplayContent displayContent = mDisplayContents.get(displayId);
boolean attachedToDisplay = false;
if (displayContent != null) {
TaskStack stack = mStackIdToStack.get(stackId);
if (stack == null) {
if (DEBUG_STACK) Slog.d(TAG_WM, "attachStack: stackId=" + stackId);
stack = new TaskStack(this, stackId);
stack = displayContent.getStackById(stackId);
if (stack != null) {
// It's already attached to the display. Detach and re-attach
// because onTop might change, and be sure to clear mDeferDetach!
displayContent.detachStack(stack);
stack.mDeferDetach = false;
attachedToDisplay = true;
} else {
stack = new TaskStack(this, stackId);
}
mStackIdToStack.put(stackId, stack);
if (stackId == DOCKED_STACK_ID) {
getDefaultDisplayContentLocked().mDividerControllerLocked
.notifyDockedStackExistsChanged(true);
}
}
stack.attachDisplayContent(displayContent);
if (!attachedToDisplay) {
stack.attachDisplayContent(displayContent);
}
displayContent.attachStack(stack, onTop);
if (stack.getRawFullscreen()) {
return null;