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

Commit e1961f17 authored by Kazuki Takise's avatar Kazuki Takise
Browse files

Use leaf task as presentation host

With the introduction of desks, which are parent tasks of desktop
freeform windows, using the root task of a presentation host
activity is no longer valid (because the root task is a desk).

Flag: com.android.window.flags.enable_presentation_for_connected_displays
Bug: 418850221
Test: PresentationTest
Change-Id: Icb244618be643dfc2989e18f05ae0770a709fa65
parent af3aec1e
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -137,7 +137,7 @@ class PresentationController implements DisplayManager.DisplayListener {
            hostTask = presentation.mHostTask;
        } else if (win == null) {
            final Task globallyFocusedTask =
                    displayContent.mWmService.mRoot.getTopDisplayFocusedRootTask();
                    displayContent.mWmService.mRoot.getTopDisplayFocusedLeafTask();
            if (globallyFocusedTask != null && uid == globallyFocusedTask.effectiveUid) {
                hostTask = globallyFocusedTask;
            }
@@ -195,7 +195,7 @@ class PresentationController implements DisplayManager.DisplayListener {
        Task hostTask = null;
        if (ENABLE_PRESENTATION_FOR_CONNECTED_DISPLAYS.isTrue()) {
            final Task globallyFocusedTask =
                    win.mWmService.mRoot.getTopDisplayFocusedRootTask();
                    win.mWmService.mRoot.getTopDisplayFocusedLeafTask();
            if (globallyFocusedTask != null && uid == globallyFocusedTask.effectiveUid) {
                hostTask = globallyFocusedTask;
            }
+8 −0
Original line number Diff line number Diff line
@@ -1756,6 +1756,14 @@ class RootWindowContainer extends WindowContainer<DisplayContent>
        return null;
    }

    @Nullable
    Task getTopDisplayFocusedLeafTask() {
        final Task rootTask = getTopDisplayFocusedRootTask();
        return rootTask != null
                ? rootTask.getTopLeafTask(TaskFragment::isFocusableAndVisible)
                : null;
    }

    @Nullable
    ActivityRecord getTopResumedActivity() {
        final Task focusedRootTask = getTopDisplayFocusedRootTask();
+5 −1
Original line number Diff line number Diff line
@@ -2583,9 +2583,13 @@ class Task extends TaskFragment {

    /** Return the top-most leaf-task under this one, or this task if it is a leaf. */
    public Task getTopLeafTask() {
        return getTopLeafTask(alwaysTruePredicate());
    }

    Task getTopLeafTask(Predicate<Task> filter) {
        for (int i = mChildren.size() - 1; i >= 0; --i) {
            final Task child = mChildren.get(i).asTask();
            if (child == null) continue;
            if (child == null || !filter.test(child)) continue;
            return child.getTopLeafTask();
        }
        return this;
+8 −0
Original line number Diff line number Diff line
@@ -273,6 +273,14 @@ public class PresentationControllerTests extends WindowTestsBase {
        return dc;
    }

    static ActivityRecord createActivityRecord(Task task) {
        final ActivityRecord activity = createActivityRecord(task.getDisplayContent(), task);
        // PresentationController finds a host task based on the top resumed activity, so make sure
        // to set activity to be resumed in the parent task.
        task.setResumedActivity(activity, "createActivityRecord");
        return activity;
    }

    private void completeTransition(@NonNull Transition transition, boolean abortSync) {
        final ActionChain chain = ActionChain.testFinish(transition);
        if (abortSync) {