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

Commit 8dc1b03a authored by Louis Chang's avatar Louis Chang
Browse files

Fix unable to back when starting new TF on AE primary

The focsued app was not updated when starting an Activity C on
a new TaskFragment while the secondary container is pinned
(A|B) -> (C|B). That's because the focused app is used to be
updated to the top-most resumed activity of the top-most focused
Task.

In that case, the focused window is also null because both the
window of C and B are in a different TF than the focused
app's TF, so cannot be focused.

Updates the last resumed activity regardless of the activity
is the top-most one.

Bug: 329539209
Test: TaskFragmentTest
Change-Id: I7f307084b8814b922f7c9defd40bb468eddf71b9
parent b67dfbd3
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -2266,7 +2266,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
     * activity releases the top state and reports back, message about acquiring top state will be
     * sent to the new top resumed activity.
     */
    void updateTopResumedActivityIfNeeded(String reason) {
    ActivityRecord updateTopResumedActivityIfNeeded(String reason) {
        final ActivityRecord prevTopActivity = mTopResumedActivity;
        final Task topRootTask = mRootWindowContainer.getTopDisplayFocusedRootTask();
        if (topRootTask == null || topRootTask.getTopResumedActivity() == prevTopActivity) {
@@ -2279,7 +2279,7 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
                // according to the current top focused activity.
                mService.updateTopApp(null /* topResumedActivity */);
            }
            return;
            return mTopResumedActivity;
        }

        // Ask previous activity to release the top state.
@@ -2306,6 +2306,8 @@ public class ActivityTaskSupervisor implements RecentTasks.Callbacks {
        scheduleTopResumedActivityStateIfNeeded();

        mService.updateTopApp(mTopResumedActivity);

        return mTopResumedActivity;
    }

    /** Schedule current top resumed activity state loss */
+7 −1
Original line number Diff line number Diff line
@@ -579,7 +579,13 @@ class TaskFragment extends WindowContainer<WindowContainer> {

        final ActivityRecord prevR = mResumedActivity;
        mResumedActivity = r;
        mTaskSupervisor.updateTopResumedActivityIfNeeded(reason);
        final ActivityRecord topResumed = mTaskSupervisor.updateTopResumedActivityIfNeeded(reason);
        if (mResumedActivity != null && topResumed != null && topResumed.isEmbedded()
                && topResumed.getTaskFragment().getAdjacentTaskFragment() == this) {
            // Explicitly updates the last resumed Activity if the resumed activity is
            // adjacent to the top-resumed embedded activity.
            mAtmService.setLastResumedActivityUncheckLocked(mResumedActivity, reason);
        }
        if (r == null && prevR.mDisplayContent != null
                && prevR.mDisplayContent.getFocusedRootTask() == null) {
            // Only need to notify DWPC when no activity will resume.
+26 −0
Original line number Diff line number Diff line
@@ -898,6 +898,32 @@ public class TaskFragmentTest extends WindowTestsBase {
        }
    }

    @Test
    public void testSetResumedActivity() {
        // Setup two activities in ActivityEmbedding split.
        final Task task = createTask(mDisplayContent);
        final TaskFragment taskFragmentLeft = new TaskFragmentBuilder(mAtm)
                .setParentTask(task)
                .createActivityCount(1)
                .build();
        final TaskFragment taskFragmentRight = new TaskFragmentBuilder(mAtm)
                .setParentTask(task)
                .createActivityCount(1)
                .build();
        taskFragmentRight.setAdjacentTaskFragment(taskFragmentLeft);
        taskFragmentLeft.setAdjacentTaskFragment(taskFragmentRight);
        final ActivityRecord appLeftTop = taskFragmentLeft.getTopMostActivity();
        final ActivityRecord appRightTop = taskFragmentRight.getTopMostActivity();

        // Ensure the focused app is updated when the right activity resumed.
        taskFragmentRight.setResumedActivity(appRightTop, "test");
        assertEquals(appRightTop, task.getDisplayContent().mFocusedApp);

        // Ensure the focused app is updated when the left activity resumed.
        taskFragmentLeft.setResumedActivity(appLeftTop, "test");
        assertEquals(appLeftTop, task.getDisplayContent().mFocusedApp);
    }

    private WindowState createAppWindow(ActivityRecord app, String name) {
        final WindowState win = createWindow(null, TYPE_BASE_APPLICATION, app, name,
                0 /* ownerId */, false /* ownerCanAddInternalSystemWindow */, new TestIWindow());