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

Commit e9a10374 authored by Chris Li's avatar Chris Li
Browse files

Apply TaskFragmentOrganizer changes in one WCT (1/2)

Before, when receive TaskFragment transaction, we apply changes in
multiple WindowContainerTransactions. Now, update to apply all changes
in one WCT for the whole TaskFragment transaction.

Will update the TestAPI in the followup cl.

Bug: 240519866
Test: pass existing
Change-Id: I2e15b187bee95193874d76bc6963d3e01eba3910
parent 99da16cd
Loading
Loading
Loading
Loading
+19 −4
Original line number Diff line number Diff line
@@ -147,13 +147,25 @@ public class TaskFragmentOrganizer extends WindowOrganizer {
        }
    }

    /** Called when a TaskFragment is created and organized by this organizer. */
    /**
     * Called when a TaskFragment is created and organized by this organizer.
     *
     * @param taskFragmentInfo  Info of the TaskFragment that is created.
     */
    public void onTaskFragmentAppeared(@NonNull TaskFragmentInfo taskFragmentInfo) {}

    /** Called when the status of an organized TaskFragment is changed. */
    /**
     * Called when the status of an organized TaskFragment is changed.
     *
     * @param taskFragmentInfo  Info of the TaskFragment that is changed.
     */
    public void onTaskFragmentInfoChanged(@NonNull TaskFragmentInfo taskFragmentInfo) {}

    /** Called when an organized TaskFragment is removed. */
    /**
     * Called when an organized TaskFragment is removed.
     *
     * @param taskFragmentInfo  Info of the TaskFragment that is removed.
     */
    public void onTaskFragmentVanished(@NonNull TaskFragmentInfo taskFragmentInfo) {}

    /**
@@ -176,6 +188,9 @@ public class TaskFragmentOrganizer extends WindowOrganizer {
     * For case like screen size change, it will trigger onTaskFragmentParentInfoChanged with new
     * Task bounds, but may not trigger onTaskFragmentInfoChanged because there can be an override
     * bounds.
     *
     * @param taskId    Id of the parent Task that is changed.
     * @param parentConfig  Config of the parent Task.
     * @hide
     */
    public void onTaskFragmentParentInfoChanged(int taskId, @NonNull Configuration parentConfig) {
@@ -226,7 +241,7 @@ public class TaskFragmentOrganizer extends WindowOrganizer {
    /**
     * Called when an Activity is reparented to the Task with organized TaskFragment. For example,
     * when an Activity enters and then exits Picture-in-picture, it will be reparented back to its
     * orginial Task. In this case, we need to notify the organizer so that it can check if the
     * original Task. In this case, we need to notify the organizer so that it can check if the
     * Activity matches any split rule.
     *
     * @param taskId            The Task that the activity is reparented to.
+32 −26
Original line number Diff line number Diff line
@@ -62,13 +62,18 @@ class JetpackTaskFragmentOrganizer extends TaskFragmentOrganizer {
     * Callback that notifies the controller about changes to task fragments.
     */
    interface TaskFragmentCallback {
        void onTaskFragmentAppeared(@NonNull TaskFragmentInfo taskFragmentInfo);
        void onTaskFragmentInfoChanged(@NonNull TaskFragmentInfo taskFragmentInfo);
        void onTaskFragmentVanished(@NonNull TaskFragmentInfo taskFragmentInfo);
        void onTaskFragmentParentInfoChanged(int taskId, @NonNull Configuration parentConfig);
        void onActivityReparentedToTask(int taskId, @NonNull Intent activityIntent,
                @NonNull IBinder activityToken);
        void onTaskFragmentError(@Nullable TaskFragmentInfo taskFragmentInfo, int opType);
        void onTaskFragmentAppeared(@NonNull WindowContainerTransaction wct,
                @NonNull TaskFragmentInfo taskFragmentInfo);
        void onTaskFragmentInfoChanged(@NonNull WindowContainerTransaction wct,
                @NonNull TaskFragmentInfo taskFragmentInfo);
        void onTaskFragmentVanished(@NonNull WindowContainerTransaction wct,
                @NonNull TaskFragmentInfo taskFragmentInfo);
        void onTaskFragmentParentInfoChanged(@NonNull WindowContainerTransaction wct,
                int taskId, @NonNull Configuration parentConfig);
        void onActivityReparentedToTask(@NonNull WindowContainerTransaction wct,
                int taskId, @NonNull Intent activityIntent, @NonNull IBinder activityToken);
        void onTaskFragmentError(@NonNull WindowContainerTransaction wct,
                @Nullable TaskFragmentInfo taskFragmentInfo, int opType);
    }

    /**
@@ -158,27 +163,16 @@ class JetpackTaskFragmentOrganizer extends TaskFragmentOrganizer {
        updateWindowingMode(wct, fragmentToken, WINDOWING_MODE_UNDEFINED);
    }

    /**
     * Expands an existing TaskFragment to fill parent.
     * @param fragmentToken token of an existing TaskFragment.
     */
    void expandTaskFragment(@NonNull IBinder fragmentToken) {
        WindowContainerTransaction wct = new WindowContainerTransaction();
        expandTaskFragment(wct, fragmentToken);
        applyTransaction(wct);
    }

    /**
     * Expands an Activity to fill parent by moving it to a new TaskFragment.
     * @param fragmentToken token to create new TaskFragment with.
     * @param activity      activity to move to the fill-parent TaskFragment.
     */
    void expandActivity(@NonNull IBinder fragmentToken, @NonNull Activity activity) {
        final WindowContainerTransaction wct = new WindowContainerTransaction();
    void expandActivity(@NonNull WindowContainerTransaction wct, @NonNull IBinder fragmentToken,
            @NonNull Activity activity) {
        createTaskFragmentAndReparentActivity(
                wct, fragmentToken, activity.getActivityToken(), new Rect(),
                WINDOWING_MODE_UNDEFINED, activity);
        applyTransaction(wct);
    }

    /**
@@ -278,43 +272,55 @@ class JetpackTaskFragmentOrganizer extends TaskFragmentOrganizer {

    @Override
    public void onTaskFragmentAppeared(@NonNull TaskFragmentInfo taskFragmentInfo) {
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        final IBinder fragmentToken = taskFragmentInfo.getFragmentToken();
        mFragmentInfos.put(fragmentToken, taskFragmentInfo);
        mCallback.onTaskFragmentAppeared(taskFragmentInfo);
        mCallback.onTaskFragmentAppeared(wct, taskFragmentInfo);
        applyTransaction(wct);
    }

    @Override
    public void onTaskFragmentInfoChanged(@NonNull TaskFragmentInfo taskFragmentInfo) {
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        final IBinder fragmentToken = taskFragmentInfo.getFragmentToken();
        mFragmentInfos.put(fragmentToken, taskFragmentInfo);
        mCallback.onTaskFragmentInfoChanged(taskFragmentInfo);
        mCallback.onTaskFragmentInfoChanged(wct, taskFragmentInfo);
        applyTransaction(wct);
    }

    @Override
    public void onTaskFragmentVanished(@NonNull TaskFragmentInfo taskFragmentInfo) {
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        mFragmentInfos.remove(taskFragmentInfo.getFragmentToken());
        mCallback.onTaskFragmentVanished(taskFragmentInfo);
        mCallback.onTaskFragmentVanished(wct, taskFragmentInfo);
        applyTransaction(wct);
    }

    @Override
    public void onTaskFragmentParentInfoChanged(int taskId, @NonNull Configuration parentConfig) {
        mCallback.onTaskFragmentParentInfoChanged(taskId, parentConfig);
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        mCallback.onTaskFragmentParentInfoChanged(wct, taskId, parentConfig);
        applyTransaction(wct);
    }

    @Override
    public void onActivityReparentedToTask(int taskId, @NonNull Intent activityIntent,
            @NonNull IBinder activityToken) {
        mCallback.onActivityReparentedToTask(taskId, activityIntent, activityToken);
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        mCallback.onActivityReparentedToTask(wct, taskId, activityIntent, activityToken);
        applyTransaction(wct);
    }

    @Override
    public void onTaskFragmentError(@NonNull IBinder errorCallbackToken,
            @Nullable TaskFragmentInfo taskFragmentInfo,
            int opType, @NonNull Throwable exception) {
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        if (taskFragmentInfo != null) {
            final IBinder fragmentToken = taskFragmentInfo.getFragmentToken();
            mFragmentInfos.put(fragmentToken, taskFragmentInfo);
        }
        mCallback.onTaskFragmentError(taskFragmentInfo, opType);
        mCallback.onTaskFragmentError(wct, taskFragmentInfo, opType);
        applyTransaction(wct);
    }
}
+94 −60

File changed.

Preview size limit exceeded, changes collapsed.

+7 −30
Original line number Diff line number Diff line
@@ -108,31 +108,12 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
        registerOrganizer();
    }

    /**
     * Updates the presentation of the provided container.
     */
    void updateContainer(@NonNull TaskFragmentContainer container) {
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        mController.updateContainer(wct, container);
        applyTransaction(wct);
    }

    /**
     * Deletes the specified container and all other associated and dependent containers in the same
     * transaction.
     */
    void cleanupContainer(@NonNull TaskFragmentContainer container, boolean shouldFinishDependent) {
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        cleanupContainer(container, shouldFinishDependent, wct);
        applyTransaction(wct);
    }

    /**
     * Deletes the specified container and all other associated and dependent containers in the same
     * transaction.
     */
    void cleanupContainer(@NonNull TaskFragmentContainer container, boolean shouldFinishDependent,
            @NonNull WindowContainerTransaction wct) {
    void cleanupContainer(@NonNull WindowContainerTransaction wct,
            @NonNull TaskFragmentContainer container, boolean shouldFinishDependent) {
        container.finish(shouldFinishDependent, this, wct, mController);

        final TaskFragmentContainer newTopContainer = mController.getTopActiveContainer(
@@ -190,10 +171,9 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
     *                          created and the activity will be re-parented to it.
     * @param rule The split rule to be applied to the container.
     */
    void createNewSplitContainer(@NonNull Activity primaryActivity,
            @NonNull Activity secondaryActivity, @NonNull SplitPairRule rule) {
        final WindowContainerTransaction wct = new WindowContainerTransaction();

    void createNewSplitContainer(@NonNull WindowContainerTransaction wct,
            @NonNull Activity primaryActivity, @NonNull Activity secondaryActivity,
            @NonNull SplitPairRule rule) {
        final Rect parentBounds = getParentContainerBounds(primaryActivity);
        final Pair<Size, Size> minDimensionsPair = getActivitiesMinDimensionsPair(primaryActivity,
                secondaryActivity);
@@ -219,8 +199,6 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
                minDimensionsPair);

        mController.registerSplit(wct, primaryContainer, primaryActivity, secondaryContainer, rule);

        applyTransaction(wct);
    }

    /**
@@ -262,7 +240,8 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
     * @param rule              The split rule to be applied to the container.
     * @param isPlaceholder     Whether the launch is a placeholder.
     */
    void startActivityToSide(@NonNull Activity launchingActivity, @NonNull Intent activityIntent,
    void startActivityToSide(@NonNull WindowContainerTransaction wct,
            @NonNull Activity launchingActivity, @NonNull Intent activityIntent,
            @Nullable Bundle activityOptions, @NonNull SplitRule rule, boolean isPlaceholder) {
        final Rect parentBounds = getParentContainerBounds(launchingActivity);
        final Pair<Size, Size> minDimensionsPair = getActivityIntentMinDimensionsPair(
@@ -284,7 +263,6 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
                launchingActivity, taskId);
        final int windowingMode = mController.getTaskContainer(taskId)
                .getWindowingModeForSplitTaskFragment(primaryRectBounds);
        final WindowContainerTransaction wct = new WindowContainerTransaction();
        mController.registerSplit(wct, primaryContainer, launchingActivity, secondaryContainer,
                rule);
        startActivityToSide(wct, primaryContainer.getTaskFragmentToken(), primaryRectBounds,
@@ -294,7 +272,6 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer {
            // When placeholder is launched in split, we should keep the focus on the primary.
            wct.requestFocusOnTaskFragment(primaryContainer.getTaskFragmentToken());
        }
        applyTransaction(wct);
    }

    /**
+9 −6
Original line number Diff line number Diff line
@@ -251,19 +251,22 @@ class TaskFragmentContainer {
        return mInfo;
    }

    void setInfo(@NonNull TaskFragmentInfo info) {
    void setInfo(@NonNull WindowContainerTransaction wct, @NonNull TaskFragmentInfo info) {
        if (!mIsFinished && mInfo == null && info.isEmpty()) {
            // onTaskFragmentAppeared with empty info. We will remove the TaskFragment if no
            // pending appeared intent/activities. Otherwise, wait and removing the TaskFragment if
            // it is still empty after timeout.
            if (mPendingAppearedIntent != null || !mPendingAppearedActivities.isEmpty()) {
                mAppearEmptyTimeout = () -> {
                    mAppearEmptyTimeout = null;
                    // Call without the pass-in wct when timeout. We need to applyWct directly
                    // in this case.
                    mController.onTaskFragmentAppearEmptyTimeout(this);
                };
            if (mPendingAppearedIntent != null || !mPendingAppearedActivities.isEmpty()) {
                mController.getHandler().postDelayed(mAppearEmptyTimeout, APPEAR_EMPTY_TIMEOUT_MS);
            } else {
                mAppearEmptyTimeout.run();
                mAppearEmptyTimeout = null;
                mController.onTaskFragmentAppearEmptyTimeout(wct, this);
            }
        } else if (mAppearEmptyTimeout != null && !info.isEmpty()) {
            mController.getHandler().removeCallbacks(mAppearEmptyTimeout);
Loading