Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 82c5197d authored by Chong Zhang's avatar Chong Zhang Committed by Android (Google) Code Review
Browse files

Merge "Fix WM missing stack/task when activity is force stopped and restarted" into nyc-mr1-dev

parents 9d90b758 d9d35bdf
Loading
Loading
Loading
Loading
+11 −6
Original line number Diff line number Diff line
@@ -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
+10 −0
Original line number Diff line number Diff line
@@ -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);
+16 −2
Original line number Diff line number Diff line
@@ -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 = 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);
                        }
                    }
                    if (!attachedToDisplay) {
                        stack.attachDisplayContent(displayContent);
                    }
                    displayContent.attachStack(stack, onTop);
                    if (stack.getRawFullscreen()) {
                        return null;