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

Commit 3388bd2a authored by Darryl L Johnson's avatar Darryl L Johnson
Browse files

Protect against assumptions of an existing home stack.

Since there is no longer a guarantee that a home stack will
exist this:
- Adds a method to create a home stack if the display should have one
  and it doesn't exist.
- Replaces calls to DisplayContent#getHomeStack() if those calls assumed
  a home stack would exist.

Bug: 144085050
Fixes: 144085050
Test: RootActivityContainerTests
Test: DisplayContentTests

Change-Id: Iec6b5ccf66fed7777d19b61c5624bd097edb6786
parent b2e935ae
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -2664,7 +2664,8 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        // DisplayContent#topRunningActivity().
        final ActivityRecord next = display.topRunningActivity();
        final boolean isLastStackOverEmptyHome =
                next == null && stack.isFocusedStackOnDisplay() && display.getRootHomeTask() != null;
                next == null && stack.isFocusedStackOnDisplay()
                        && display.getOrCreateRootHomeTask() != null;
        if (isLastStackOverEmptyHome) {
            // Don't destroy activity immediately if this is the last activity on the display and
            // the display contains home stack. Although there is no next activity at the moment,
+1 −1
Original line number Diff line number Diff line
@@ -1365,7 +1365,7 @@ class ActivityStarter {
                    break;
                case WINDOWING_MODE_SPLIT_SCREEN_PRIMARY:
                    final ActivityStack homeStack =
                            startedActivityStack.getDisplay().getRootHomeTask();
                            startedActivityStack.getDisplay().getOrCreateRootHomeTask();
                    if (homeStack != null && homeStack.shouldBeVisible(null /* starting */)) {
                        mService.mWindowManager.showRecentApps();
                    }
+16 −5
Original line number Diff line number Diff line
@@ -1946,6 +1946,20 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        return mTaskContainers.getRootHomeTask();
    }

    /**
     * Returns the existing home stack or creates and returns a new one if it should exist for the
     * display.
     */
    @Nullable
    ActivityStack getOrCreateRootHomeTask() {
        ActivityStack homeTask = getRootHomeTask();
        if (homeTask == null && supportsSystemDecorations() && !isUntrustedVirtualDisplay()) {
            homeTask = createStack(WINDOWING_MODE_FULLSCREEN, ACTIVITY_TYPE_HOME,
                    false /* onTop */);
        }
        return homeTask;
    }

    /** @return The primary split-screen task, and {@code null} otherwise. */
    ActivityStack getRootSplitScreenPrimaryTask() {
        return mTaskContainers.getRootSplitScreenPrimaryTask();
@@ -4284,9 +4298,6 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        }

        ActivityStack getRootHomeTask() {
            if (mRootHomeTask == null && mDisplayId == DEFAULT_DISPLAY) {
                Slog.e(TAG_WM, "getHomeStack: Returning null from this=" + this);
            }
            return mRootHomeTask;
        }

@@ -6099,7 +6110,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
        } finally {
            final ActivityStack topFullscreenStack =
                    getTopStackInWindowingMode(WINDOWING_MODE_FULLSCREEN);
            final ActivityStack homeStack = getRootHomeTask();
            final ActivityStack homeStack = getOrCreateRootHomeTask();
            if (topFullscreenStack != null && homeStack != null && !isTopStack(homeStack)) {
                // Whenever split-screen is dismissed we want the home stack directly behind the
                // current top fullscreen stack so it shows up when the top stack is finished.
@@ -6661,7 +6672,7 @@ class DisplayContent extends WindowContainer<DisplayContent.DisplayChildWindowCo
    }

    void moveHomeStackToFront(String reason) {
        final ActivityStack homeStack = getRootHomeTask();
        final ActivityStack homeStack = getOrCreateRootHomeTask();
        if (homeStack != null) {
            homeStack.moveToFront(reason);
        }
+7 −5
Original line number Diff line number Diff line
@@ -1992,8 +1992,6 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        removeStacksInWindowingModes(WINDOWING_MODE_PINNED);

        mUserStackInFront.put(mCurrentUser, focusStackId);
        final int restoreStackId =
                mUserStackInFront.get(userId, getDefaultDisplay().getRootHomeTask().getRootTaskId());
        mCurrentUser = userId;

        mStackSupervisor.mStartingUsers.add(uss);
@@ -2009,9 +2007,10 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
            }
        }

        final int restoreStackId = mUserStackInFront.get(userId);
        ActivityStack stack = getStack(restoreStackId);
        if (stack == null) {
            stack = getDefaultDisplay().getRootHomeTask();
            stack = getDefaultDisplay().getOrCreateRootHomeTask();
        }
        final boolean homeInFront = stack.isActivityTypeHome();
        if (stack.isOnHomeDisplay()) {
@@ -2033,8 +2032,11 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
     */
    void updateUserStack(int userId, ActivityStack stack) {
        if (userId != mCurrentUser) {
            mUserStackInFront.put(userId, stack != null ? stack.getRootTaskId()
                    : getDefaultDisplay().getRootHomeTask().getRootTaskId());
            if (stack == null) {
                stack = getDefaultDisplay().getOrCreateRootHomeTask();
            }

            mUserStackInFront.put(userId, stack.getRootTaskId());
        }
    }

+2 −1
Original line number Diff line number Diff line
@@ -1477,7 +1477,8 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
        // Some system windows (e.g. "Power off" dialog) don't have a task, but we would still
        // associate them with some stack to enable dimming.
        final DisplayContent dc = getDisplayContent();
        return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null ? dc.getRootHomeTask() : null;
        return mAttrs.type >= FIRST_SYSTEM_WINDOW && dc != null
                ? dc.getOrCreateRootHomeTask() : null;
    }

    /**
Loading