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

Commit f29202e9 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Send taskInfo instead of root task info in onBackPressedOnTaskRoot callback" into main

parents c4e5377b 60537360
Loading
Loading
Loading
Loading
+13 −7
Original line number Diff line number Diff line
@@ -567,21 +567,27 @@ public final class WindowContainerTransaction implements Parcelable {
    }

    /**
     * Sets whether back press should be intercepted for the root activity of the given task
     * container. If true, then
     * {@link TaskOrganizer#onBackPressedOnTaskRoot(ActivityManager.RunningTaskInfo)} will be
     * called.
     * Sets whether back press should be intercepted for the root activity of the given root task
     * or its children.
     *
     * @param container The window container of the task that the intercept-back state is set on.
     * <p>When {@code true}, the system will invoke
     * {@link TaskOrganizer#onBackPressedOnTaskRoot(ActivityManager.RunningTaskInfo)}, providing
     * the {@link ActivityManager.RunningTaskInfo} of the task that received the back press.
     * This interception mechanism is specifically designed to be applied to the root task
     * container only.
     *
     * @param rootTaskContainer The window container of the task that the intercept-back state is
     *                          set on. This parameter is expected to refer to the root task of a
     *                          task stack.
     * @param interceptBackPressed {@code true} to allow back to be intercepted for the root
     *                             activity of the task, {@code false} otherwise.
     * @hide
     */
    @NonNull
    public WindowContainerTransaction setInterceptBackPressedOnTaskRoot(
            @NonNull WindowContainerToken container,
            @NonNull WindowContainerToken rootTaskContainer,
            boolean interceptBackPressed) {
        final Change change = getOrCreateChange(container.asBinder());
        final Change change = getOrCreateChange(rootTaskContainer.asBinder());
        change.mChangeMask |= Change.CHANGE_INTERCEPT_BACK_PRESSED;
        change.mInterceptBackPressed = interceptBackPressed;
        return this;
+6 −0
Original line number Diff line number Diff line
@@ -106,6 +106,12 @@ public class ShellTaskOrganizer extends TaskOrganizer {
    public interface TaskListener extends TaskVanishedListener, TaskAppearedListener,
            TaskInfoChangedListener {

        /**
         * Invoked when back is pressed on the base activity of the task. If the task is not
         * organized, there will be no callback.
         *
         * @param taskInfo The RunningTaskInfo for the Task which received back event.
         */
        default void onBackPressedOnTaskRoot(RunningTaskInfo taskInfo) {}
        /** Whether this task listener supports compat UI. */
        default boolean supportCompatUI() {
+1 −1
Original line number Diff line number Diff line
@@ -1818,7 +1818,7 @@ class ActivityClientController extends IActivityClientController.Stub {
                final ActivityRecord root = task.getRootActivity(false /*ignoreRelinquishIdentity*/,
                        true /*setToBottomIfNone*/);
                if (r == root && mService.mWindowOrganizerController.mTaskOrganizerController
                        .handleInterceptBackPressedOnTaskRoot(r.getRootTask())) {
                        .handleInterceptBackPressedOnTaskRoot(r)) {
                    // This task is handled by a task organizer that has requested the back
                    // pressed callback.
                    return;
+13 −2
Original line number Diff line number Diff line
@@ -1139,10 +1139,21 @@ class TaskOrganizerController extends ITaskOrganizerController.Stub {
        }
    }

    public boolean handleInterceptBackPressedOnTaskRoot(Task task) {
        if (!shouldInterceptBackPressedOnRootTask(task)) {
    public boolean handleInterceptBackPressedOnTaskRoot(ActivityRecord r) {
        // Intercept are set on the root task
        if (!shouldInterceptBackPressedOnRootTask(r.getRootTask())) {
            return false;
        }

        // Task for which back event is received will be send as part of onBackPressedOnTaskRoot
        Task task = r.getTask();

        if (task.mTaskOrganizer == null) {
            Slog.w(TAG, "Cannot handle BackPressedOnTaskRoot because task organizer is "
                    + "not present for taskId: " + task.mTaskId);
            return false;
        }

        final TaskOrganizerPendingEventsQueue pendingEventsQueue =
                mTaskOrganizerStates.get(task.mTaskOrganizer.asBinder())
                        .mPendingEventsQueue;
+2 −0
Original line number Diff line number Diff line
@@ -1510,9 +1510,11 @@ public class WindowOrganizerTests extends WindowTestsBase {
        final ITaskOrganizer organizer = registerMockOrganizer();
        final Task rootTask = createRootTask();
        final Task task = createTask(rootTask);
        task.setTaskOrganizer(organizer);
        final ActivityRecord activity = createActivityRecord(rootTask.mDisplayContent, task);
        final Task rootTask2 = createRootTask();
        final Task task2 = createTask(rootTask2);
        task2.setTaskOrganizer(organizer);
        final ActivityRecord activity2 = createActivityRecord(rootTask.mDisplayContent, task2);

        assertTrue(rootTask.isOrganized());