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

Commit 55d276a2 authored by Louis Chang's avatar Louis Chang
Browse files

[4/n] Pin ActivityStack

Keeps the pinned TaskFragment on the front in WM hierarchy when needed.

Do not launch placeholder or make it always-expand if the container
is pinned.

Bug: 208573140
Test: TaskFragmentOrganizerControllerTest
Change-Id: I22e258ef039e3128f56078bb77d6a637fb545942
parent 4944e8e0
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -73,6 +73,13 @@ public final class TaskFragmentOperation implements Parcelable {
    /** Sets the relative bounds with {@link WindowContainerTransaction#setRelativeBounds}. */
    public static final int OP_TYPE_SET_RELATIVE_BOUNDS = 9;

    /**
     * Reorders the TaskFragment to be the front-most TaskFragment in the Task.
     * Note that there could still have other WindowContainer on top of the front-most
     * TaskFragment, such as a non-embedded Activity.
     */
    public static final int OP_TYPE_REORDER_TO_FRONT = 10;

    @IntDef(prefix = { "OP_TYPE_" }, value = {
            OP_TYPE_UNKNOWN,
            OP_TYPE_CREATE_TASK_FRAGMENT,
@@ -84,7 +91,8 @@ public final class TaskFragmentOperation implements Parcelable {
            OP_TYPE_REQUEST_FOCUS_ON_TASK_FRAGMENT,
            OP_TYPE_SET_COMPANION_TASK_FRAGMENT,
            OP_TYPE_SET_ANIMATION_PARAMS,
            OP_TYPE_SET_RELATIVE_BOUNDS
            OP_TYPE_SET_RELATIVE_BOUNDS,
            OP_TYPE_REORDER_TO_FRONT
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface OperationType {}
+6 −1
Original line number Diff line number Diff line
@@ -1621,6 +1621,12 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
            // background.
            return;
        }
        final SplitContainer splitContainer = getActiveSplitForContainer(container);
        if (splitContainer instanceof SplitPinContainer
                && updateSplitContainerIfNeeded(splitContainer, wct, null /* splitAttributes */)) {
            // A SplitPinContainer exists and is updated.
            return;
        }
        if (launchPlaceholderIfNecessary(wct, container)) {
            // Placeholder was launched, the positions will be updated when the activity is added
            // to the secondary container.
@@ -1633,7 +1639,6 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
            // If the info is not available yet the task fragment will be expanded when it's ready
            return;
        }
        SplitContainer splitContainer = getActiveSplitForContainer(container);
        if (splitContainer == null) {
            return;
        }
+12 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package androidx.window.extensions.embedding;

import static android.content.pm.PackageManager.MATCH_ALL;
import static android.window.TaskFragmentOperation.OP_TYPE_REORDER_TO_FRONT;

import android.app.Activity;
import android.app.ActivityThread;
@@ -39,6 +40,7 @@ import android.view.WindowInsets;
import android.view.WindowMetrics;
import android.window.TaskFragmentAnimationParams;
import android.window.TaskFragmentCreationParams;
import android.window.TaskFragmentOperation;
import android.window.WindowContainerTransaction;

import androidx.annotation.IntDef;
@@ -420,6 +422,16 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
        container.setLastRequestedBounds(fragmentOptions.getInitialRelativeBounds());
        container.setLastRequestedWindowingMode(fragmentOptions.getWindowingMode());
        super.createTaskFragment(wct, fragmentOptions);

        // Reorders the pinned TaskFragment to front to ensure it is the front-most TaskFragment.
        final SplitPinContainer pinnedContainer =
                container.getTaskContainer().getSplitPinContainer();
        if (pinnedContainer != null) {
            final TaskFragmentOperation operation = new TaskFragmentOperation.Builder(
                    OP_TYPE_REORDER_TO_FRONT).build();
            wct.addTaskFragmentOperation(
                    pinnedContainer.getSecondaryContainer().getTaskFragmentToken(), operation);
        }
    }

    @Override
+3 −3
Original line number Diff line number Diff line
@@ -307,14 +307,14 @@ class TaskContainer {
        }

        final TaskFragmentContainer pinnedContainer = mSplitPinContainer.getSecondaryContainer();
        final int index = mContainers.indexOf(pinnedContainer);
        if (index <= 0) {
        final int pinnedContainerIndex = mContainers.indexOf(pinnedContainer);
        if (pinnedContainerIndex <= 0) {
            removeSplitPinContainer();
            return;
        }

        // Ensure the pinned container is top-most.
        if (index != mContainers.size() - 1) {
        if (pinnedContainerIndex != mContainers.size() - 1) {
            mContainers.remove(pinnedContainer);
            mContainers.add(pinnedContainer);
        }
+14 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static android.view.Display.DEFAULT_DISPLAY;
import static android.window.TaskFragmentOperation.OP_TYPE_CLEAR_ADJACENT_TASK_FRAGMENTS;
import static android.window.TaskFragmentOperation.OP_TYPE_CREATE_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_DELETE_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_REORDER_TO_FRONT;
import static android.window.TaskFragmentOperation.OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_REQUEST_FOCUS_ON_TASK_FRAGMENT;
import static android.window.TaskFragmentOperation.OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS;
@@ -1333,6 +1334,19 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
                taskFragment.setAnimationParams(animationParams);
                break;
            }
            case OP_TYPE_REORDER_TO_FRONT: {
                final Task task = taskFragment.getTask();
                if (task != null) {
                    final TaskFragment topTaskFragment = task.getTaskFragment(
                            tf -> tf.asTask() == null);
                    if (topTaskFragment != null && topTaskFragment != taskFragment) {
                        final int index = task.mChildren.indexOf(topTaskFragment);
                        task.mChildren.remove(taskFragment);
                        task.mChildren.add(index, taskFragment);
                    }
                }
                break;
            }
        }
        return effects;
    }
Loading