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

Commit cc56871d authored by Louis Chang's avatar Louis Chang
Browse files

Ensure activity display with an empty stack can be released

The activities in home stack was destroyed/removed and resulted
in an empty home stack. Activity display was leaked due to it
had an empty home stack left which prevented it from being released.
Making sure activity display with an empty home stack can also
be released.

Also fixed an issue that home activity was not being resumed due
to early return in recursively resuming top activities.

Bug: 126747441
Test: atest ActivityManagerMultiDisplayTests
Change-Id: I243fab507268f81df0a8067883157d63f0f79c22
parent 3057634f
Loading
Loading
Loading
Loading
+11 −1
Original line number Original line Diff line number Diff line
@@ -1173,7 +1173,17 @@ class ActivityDisplay extends ConfigurationContainer<ActivityStack>
    }
    }


    private void releaseSelfIfNeeded() {
    private void releaseSelfIfNeeded() {
        if (mStacks.isEmpty() && mRemoved) {
        if (!mRemoved || mDisplayContent == null) {
            return;
        }

        final ActivityStack stack = mStacks.size() == 1 ? mStacks.get(0) : null;
        if (stack != null && stack.isActivityTypeHome() && stack.getAllTasks().isEmpty()) {
            // Release this display if an empty home stack is the only thing left.
            // Since it is the last stack, this display will be released along with the stack
            // removal.
            stack.remove();
        } else if (mStacks.isEmpty()) {
            mDisplayContent.removeIfPossible();
            mDisplayContent.removeIfPossible();
            mDisplayContent = null;
            mDisplayContent = null;
            mRootActivityContainer.removeChild(this);
            mRootActivityContainer.removeChild(this);
+11 −1
Original line number Original line Diff line number Diff line
@@ -3053,8 +3053,18 @@ class ActivityStack extends ConfigurationContainer {
        ActivityOptions.abort(options);
        ActivityOptions.abort(options);
        if (DEBUG_STATES) Slog.d(TAG_STATES,
        if (DEBUG_STATES) Slog.d(TAG_STATES,
                "resumeTopActivityInNextFocusableStack: " + reason + ", go home");
                "resumeTopActivityInNextFocusableStack: " + reason + ", go home");
        if (isActivityTypeHome()) {
            // resumeTopActivityUncheckedLocked has been prevented to run recursively. Post a
            // runnable to resume home since we are currently in the process of resuming top
            // activity in home stack.
            // See {@link #mInResumeTopActivity}.
            mService.mH.post(
                    () -> mRootActivityContainer.resumeHomeActivity(prev, reason, mDisplayId));
            return true;
        } else {
            return mRootActivityContainer.resumeHomeActivity(prev, reason, mDisplayId);
            return mRootActivityContainer.resumeHomeActivity(prev, reason, mDisplayId);
        }
        }
    }


    /** Returns the position the input task should be placed in this stack. */
    /** Returns the position the input task should be placed in this stack. */
    int getAdjustedPositionForTask(TaskRecord task, int suggestedPosition,
    int getAdjustedPositionForTask(TaskRecord task, int suggestedPosition,