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

Commit fd76c2da authored by Jiaming Liu's avatar Jiaming Liu
Browse files

Add TF flag to allow transitions when empty

By default, the TaskFragment waits until it becomes non-empty to start
transitions. If mAllowTransitionWhenEmpty is set to true, then it will
start transition even if it is empty. This is need for Launcher to
create an empty TF and obtain the surface before launching the -1
activity.

Bug: 320720349
Test: atest TaskFragmentTest
Change-Id: Ie7aca6391032e660dd2bc243ddba53db945af09f
parent 27aeef3c
Loading
Loading
Loading
Loading
+34 −2
Original line number Diff line number Diff line
@@ -94,11 +94,18 @@ public final class TaskFragmentCreationParams implements Parcelable {
    @Nullable
    private final IBinder mPairedActivityToken;

    /**
     * If {@code true}, transitions are allowed even if the TaskFragment is empty. If
     * {@code false}, transitions will wait until the TaskFragment becomes non-empty or other
     * conditions are met. Default to {@code false}.
     */
    private final boolean mAllowTransitionWhenEmpty;

    private TaskFragmentCreationParams(
            @NonNull TaskFragmentOrganizerToken organizer, @NonNull IBinder fragmentToken,
            @NonNull IBinder ownerToken, @NonNull Rect initialRelativeBounds,
            @WindowingMode int windowingMode, @Nullable IBinder pairedPrimaryFragmentToken,
            @Nullable IBinder pairedActivityToken) {
            @Nullable IBinder pairedActivityToken, boolean allowTransitionWhenEmpty) {
        if (pairedPrimaryFragmentToken != null && pairedActivityToken != null) {
            throw new IllegalArgumentException("pairedPrimaryFragmentToken and"
                    + " pairedActivityToken should not be set at the same time.");
@@ -110,6 +117,7 @@ public final class TaskFragmentCreationParams implements Parcelable {
        mWindowingMode = windowingMode;
        mPairedPrimaryFragmentToken = pairedPrimaryFragmentToken;
        mPairedActivityToken = pairedActivityToken;
        mAllowTransitionWhenEmpty = allowTransitionWhenEmpty;
    }

    @NonNull
@@ -155,6 +163,11 @@ public final class TaskFragmentCreationParams implements Parcelable {
        return mPairedActivityToken;
    }

    /** @hide */
    public boolean getAllowTransitionWhenEmpty() {
        return mAllowTransitionWhenEmpty;
    }

    private TaskFragmentCreationParams(Parcel in) {
        mOrganizer = TaskFragmentOrganizerToken.CREATOR.createFromParcel(in);
        mFragmentToken = in.readStrongBinder();
@@ -163,6 +176,7 @@ public final class TaskFragmentCreationParams implements Parcelable {
        mWindowingMode = in.readInt();
        mPairedPrimaryFragmentToken = in.readStrongBinder();
        mPairedActivityToken = in.readStrongBinder();
        mAllowTransitionWhenEmpty = in.readBoolean();
    }

    /** @hide */
@@ -175,6 +189,7 @@ public final class TaskFragmentCreationParams implements Parcelable {
        dest.writeInt(mWindowingMode);
        dest.writeStrongBinder(mPairedPrimaryFragmentToken);
        dest.writeStrongBinder(mPairedActivityToken);
        dest.writeBoolean(mAllowTransitionWhenEmpty);
    }

    @NonNull
@@ -201,6 +216,7 @@ public final class TaskFragmentCreationParams implements Parcelable {
                + " windowingMode=" + mWindowingMode
                + " pairedFragmentToken=" + mPairedPrimaryFragmentToken
                + " pairedActivityToken=" + mPairedActivityToken
                + " allowTransitionWhenEmpty=" + mAllowTransitionWhenEmpty
                + "}";
    }

@@ -234,6 +250,8 @@ public final class TaskFragmentCreationParams implements Parcelable {
        @Nullable
        private IBinder mPairedActivityToken;

        private boolean mAllowTransitionWhenEmpty;

        public Builder(@NonNull TaskFragmentOrganizerToken organizer,
                @NonNull IBinder fragmentToken, @NonNull IBinder ownerToken) {
            mOrganizer = organizer;
@@ -298,12 +316,26 @@ public final class TaskFragmentCreationParams implements Parcelable {
            return this;
        }

        /**
         * Sets whether transitions are allowed when the TaskFragment is empty. If {@code true},
         * transitions are allowed when the TaskFragment is empty. If {@code false}, transitions
         * will wait until the TaskFragment becomes non-empty or other conditions are met. Default
         * to {@code false}.
         *
         * @hide
         */
        @NonNull
        public Builder setAllowTransitionWhenEmpty(boolean allowTransitionWhenEmpty) {
            mAllowTransitionWhenEmpty = allowTransitionWhenEmpty;
            return this;
        }

        /** Constructs the options to create TaskFragment with. */
        @NonNull
        public TaskFragmentCreationParams build() {
            return new TaskFragmentCreationParams(mOrganizer, mFragmentToken, mOwnerToken,
                    mInitialRelativeBounds, mWindowingMode, mPairedPrimaryFragmentToken,
                    mPairedActivityToken);
                    mPairedActivityToken, mAllowTransitionWhenEmpty);
        }
    }
}
+25 −2
Original line number Diff line number Diff line
@@ -369,6 +369,15 @@ class TaskFragment extends WindowContainer<WindowContainer> {
     */
    private boolean mMoveToBottomIfClearWhenLaunch;

    /**
     * If {@code true}, transitions are allowed even if this TaskFragment is empty. If
     * {@code false}, transitions will wait until this TaskFragment becomes non-empty or other
     * conditions are met. Default to {@code false}.
     *
     * @see #isReadyToTransit
     */
    private boolean mAllowTransitionWhenEmpty;

    /** When set, will force the task to report as invisible. */
    static final int FLAG_FORCE_HIDDEN_FOR_PINNED_TASK = 1;
    static final int FLAG_FORCE_HIDDEN_FOR_TASK_ORG = 1 << 1;
@@ -509,6 +518,19 @@ class TaskFragment extends WindowContainer<WindowContainer> {
        mIsolatedNav = isolatedNav;
    }

    /**
     * Sets whether transitions are allowed when the TaskFragment is empty. If {@code true},
     * transitions are allowed when the TaskFragment is empty. If {@code false}, transitions
     * will wait until the TaskFragment becomes non-empty or other conditions are met. Default
     * to {@code false}.
     */
    void setAllowTransitionWhenEmpty(boolean allowTransitionWhenEmpty) {
        if (!isEmbedded()) {
            return;
        }
        mAllowTransitionWhenEmpty = allowTransitionWhenEmpty;
    }

    /** @see #mIsolatedNav */
    boolean isIsolatedNav() {
        return isEmbedded() && mIsolatedNav;
@@ -2814,8 +2836,9 @@ class TaskFragment extends WindowContainer<WindowContainer> {
            return true;
        }
        // We don't want to start the transition if the organized TaskFragment is empty, unless
        // it is requested to be removed.
        if (getTopNonFinishingActivity() != null || mIsRemovalRequested) {
        // it is requested to be removed or the mAllowTransitionWhenEmpty flag is true.
        if (getTopNonFinishingActivity() != null || mIsRemovalRequested
                || mAllowTransitionWhenEmpty) {
            return true;
        }
        // Organizer shouldn't change embedded TaskFragment in PiP.
+1 −0
Original line number Diff line number Diff line
@@ -2202,6 +2202,7 @@ class WindowOrganizerController extends IWindowOrganizerController.Stub
        }
        final TaskFragment taskFragment = new TaskFragment(mService,
                creationParams.getFragmentToken(), true /* createdByOrganizer */);
        taskFragment.setAllowTransitionWhenEmpty(creationParams.getAllowTransitionWhenEmpty());
        // Set task fragment organizer immediately, since it might have to be notified about further
        // actions.
        TaskFragmentOrganizerToken organizerToken = creationParams.getOrganizer();
+4 −0
Original line number Diff line number Diff line
@@ -436,6 +436,10 @@ public class TaskFragmentTest extends WindowTestsBase {
        // Not ready if the task is still visible when the TaskFragment becomes empty.
        doReturn(true).when(task).isVisibleRequested();
        assertFalse(taskFragment.isReadyToTransit());

        // Ready if the mAllowTransitionWhenEmpty flag is true.
        taskFragment.setAllowTransitionWhenEmpty(true);
        assertTrue(taskFragment.isReadyToTransit());
    }

    @Test