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

Commit 1a9c49f6 authored by Chris Li's avatar Chris Li Committed by Android (Google) Code Review
Browse files

Merge "setAdjacentTaskFragments for paired TaskFragment" into sc-v2-dev

parents e85c2681 36c3af87
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -506,15 +506,17 @@ public final class WindowContainerTransaction implements Parcelable {
     * {@link #setAdjacentRoots(WindowContainerToken, WindowContainerToken)}, but can be used with
     * fragmentTokens when that TaskFragments haven't been created (but will be created in the same
     * {@link WindowContainerTransaction}).
     * To reset it, pass {@code null} for {@code fragmentToken2}.
     * @param fragmentToken1    client assigned unique token to create TaskFragment with specified
     *                          in {@link TaskFragmentCreationParams#getFragmentToken()}.
     * @param fragmentToken2    client assigned unique token to create TaskFragment with specified
     *                          in {@link TaskFragmentCreationParams#getFragmentToken()}.
     *                          in {@link TaskFragmentCreationParams#getFragmentToken()}. If it is
     *                          {@code null}, the transaction will reset the adjacent TaskFragment.
     * @hide
     */
    @NonNull
    public WindowContainerTransaction setAdjacentTaskFragments(
            @NonNull IBinder fragmentToken1, @NonNull IBinder fragmentToken2) {
            @NonNull IBinder fragmentToken1, @Nullable IBinder fragmentToken2) {
        final HierarchyOp hierarchyOp =
                new HierarchyOp.Builder(HierarchyOp.HIERARCHY_OP_TYPE_SET_ADJACENT_TASK_FRAGMENTS)
                        .setContainer(fragmentToken1)
+4 −0
Original line number Diff line number Diff line
@@ -116,6 +116,9 @@ class JetpackTaskFragmentOrganizer extends TaskFragmentOrganizer {
                secondaryFragmentBounds, WINDOWING_MODE_MULTI_WINDOW, activityIntent,
                activityOptions);

        // Set adjacent to each other so that the containers below will be invisible.
        wct.setAdjacentTaskFragments(launchingFragmentToken, secondaryFragmentToken);

        applyTransaction(wct);
    }

@@ -126,6 +129,7 @@ class JetpackTaskFragmentOrganizer extends TaskFragmentOrganizer {
     */
    void expandTaskFragment(WindowContainerTransaction wct, IBinder fragmentToken) {
        resizeTaskFragment(wct, fragmentToken, new Rect());
        wct.setAdjacentTaskFragments(fragmentToken, null);
    }

    /**
+3 −5
Original line number Diff line number Diff line
@@ -142,8 +142,9 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
            resizeTaskFragmentIfRegistered(wct, secondaryContainer, secondaryRectBounds);
        }

        // TODO(b/190433398): The primary container and the secondary container should also be set
        // as adjacent (WCT#setAdjacentRoots) to make activities behind invisible.
        // Set adjacent to each other so that the containers below will be invisible.
        wct.setAdjacentTaskFragments(
                primaryContainer.getTaskFragmentToken(), secondaryContainer.getTaskFragmentToken());
        applyTransaction(wct);

        mController.registerSplit(primaryContainer, primaryActivity, secondaryContainer, rule);
@@ -184,9 +185,6 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
        primaryContainer.setLastRequestedBounds(primaryRectBounds);
        secondaryContainer.setLastRequestedBounds(secondaryRectBounds);

        // TODO(b/190433398): The primary container and the secondary container should also be set
        // as adjacent (WCT#setAdjacentRoots) to make activities behind invisible.

        mController.registerSplit(primaryContainer, launchingActivity, secondaryContainer,
                rule);
    }
+20 −4
Original line number Diff line number Diff line
@@ -161,7 +161,8 @@ class TaskFragment extends WindowContainer<WindowContainer> {
    /** Avoid reentrant of {@link #removeImmediately()}. */
    private boolean mRemoving;

    // The TaskFragment that adjacent to this one.
    /** The TaskFragment that is adjacent to this one. */
    @Nullable
    private TaskFragment mAdjacentTaskFragment;

    /**
@@ -282,9 +283,23 @@ class TaskFragment extends WindowContainer<WindowContainer> {
        mRemoteToken = new RemoteToken(this);
    }

    void setAdjacentTaskFragment(TaskFragment taskFragment) {
    void setAdjacentTaskFragment(@Nullable TaskFragment taskFragment) {
        if (mAdjacentTaskFragment == taskFragment) {
            return;
        }
        resetAdjacentTaskFragment();
        if (taskFragment != null) {
            mAdjacentTaskFragment = taskFragment;
        taskFragment.mAdjacentTaskFragment = this;
            taskFragment.setAdjacentTaskFragment(this);
        }
    }

    private void resetAdjacentTaskFragment() {
        // Reset the adjacent TaskFragment if its adjacent TaskFragment is also this TaskFragment.
        if (mAdjacentTaskFragment != null && mAdjacentTaskFragment.mAdjacentTaskFragment == this) {
            mAdjacentTaskFragment.mAdjacentTaskFragment = null;
        }
        mAdjacentTaskFragment = null;
    }

    void setTaskFragmentOrganizer(TaskFragmentOrganizerToken organizer, int pid) {
@@ -1951,6 +1966,7 @@ class TaskFragment extends WindowContainer<WindowContainer> {
            return;
        }
        mRemoving = true;
        resetAdjacentTaskFragment();
        super.removeImmediately();
        sendTaskFragmentVanished();
        mRemoving = false;
+4 −2
Original line number Diff line number Diff line
@@ -720,8 +720,10 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
                fragmentToken = hop.getContainer();
                final IBinder adjacentFragmentToken = hop.getAdjacentRoot();
                final TaskFragment tf1 = mLaunchTaskFragments.get(fragmentToken);
                final TaskFragment tf2 = mLaunchTaskFragments.get(adjacentFragmentToken);
                if (tf1 == null || tf2 == null) {
                final TaskFragment tf2 = adjacentFragmentToken != null
                        ? mLaunchTaskFragments.get(adjacentFragmentToken)
                        : null;
                if (tf1 == null || (adjacentFragmentToken != null && tf2 == null)) {
                    final Throwable exception = new IllegalArgumentException(
                            "Not allowed to set adjacent on invalid fragment tokens");
                    sendTaskFragmentOperationFailure(organizer, errorCallbackToken, exception);