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

Commit 25c5f97e authored by Louis Chang's avatar Louis Chang Committed by Automerger Merge Worker
Browse files

Merge "Sending TaskFragmentInfo and operation type in #onTaskFragmentError"...

Merge "Sending TaskFragmentInfo and operation type in #onTaskFragmentError" into tm-qpr-dev am: 8be2f810

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19321166



Change-Id: I8aad77caa6cb353a7fa926461aea9eb940178568
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 9c2fa2c4 8be2f810
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -3351,7 +3351,8 @@ package android.window {
    method @NonNull public java.util.concurrent.Executor getExecutor();
    method @NonNull public android.window.TaskFragmentOrganizerToken getOrganizerToken();
    method public void onTaskFragmentAppeared(@NonNull android.window.TaskFragmentInfo);
    method public void onTaskFragmentError(@NonNull android.os.IBinder, @NonNull Throwable);
    method @Deprecated public void onTaskFragmentError(@NonNull android.os.IBinder, @NonNull Throwable);
    method public void onTaskFragmentError(@NonNull android.os.IBinder, @Nullable android.window.TaskFragmentInfo, int, @NonNull Throwable);
    method public void onTaskFragmentInfoChanged(@NonNull android.window.TaskFragmentInfo);
    method public void onTaskFragmentParentInfoChanged(@NonNull android.os.IBinder, @NonNull android.content.res.Configuration);
    method public void onTaskFragmentVanished(@NonNull android.window.TaskFragmentInfo);
+4 −3
Original line number Diff line number Diff line
@@ -45,10 +45,11 @@ oneway interface ITaskFragmentOrganizer {
     *
     * @param errorCallbackToken    Token set through {@link
     *                              WindowContainerTransaction#setErrorCallbackToken(IBinder)}
     * @param exceptionBundle   Bundle containing the exception. Should be created with
     *                          {@link TaskFragmentOrganizer#putExceptionInBundle}.
     * @param errorBundle       Bundle containing the exception, operation type and TaskFragmentInfo
     *                          if any. Should be created with
     *                          {@link TaskFragmentOrganizer#putErrorInfoInBundle}.
     */
    void onTaskFragmentError(in IBinder errorCallbackToken, in Bundle exceptionBundle);
    void onTaskFragmentError(in IBinder errorCallbackToken, in Bundle errorBundle);

    /**
     * Called when an Activity is reparented to the Task with organized TaskFragment. For example,
+47 −10
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package android.window;

import android.annotation.CallSuper;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.TestApi;
import android.content.Intent;
import android.content.res.Configuration;
@@ -39,16 +40,23 @@ public class TaskFragmentOrganizer extends WindowOrganizer {
     * Key to the exception in {@link Bundle} in {@link ITaskFragmentOrganizer#onTaskFragmentError}.
     */
    private static final String KEY_ERROR_CALLBACK_EXCEPTION = "fragment_exception";
    private static final String KEY_ERROR_CALLBACK_TASK_FRAGMENT_INFO = "task_fragment_info";
    private static final String KEY_ERROR_CALLBACK_OP_TYPE = "operation_type";

    /**
     * Creates a {@link Bundle} with an exception that can be passed to
     * {@link ITaskFragmentOrganizer#onTaskFragmentError}.
     * Creates a {@link Bundle} with an exception, operation type and TaskFragmentInfo (if any)
     * that can be passed to {@link ITaskFragmentOrganizer#onTaskFragmentError}.
     * @hide
     */
    public static Bundle putExceptionInBundle(@NonNull Throwable exception) {
        final Bundle exceptionBundle = new Bundle();
        exceptionBundle.putSerializable(KEY_ERROR_CALLBACK_EXCEPTION, exception);
        return exceptionBundle;
    public static @NonNull Bundle putErrorInfoInBundle(@NonNull Throwable exception,
            @Nullable TaskFragmentInfo info, int opType) {
        final Bundle errorBundle = new Bundle();
        errorBundle.putSerializable(KEY_ERROR_CALLBACK_EXCEPTION, exception);
        if (info != null) {
            errorBundle.putParcelable(KEY_ERROR_CALLBACK_TASK_FRAGMENT_INFO, info);
        }
        errorBundle.putInt(KEY_ERROR_CALLBACK_OP_TYPE, opType);
        return errorBundle;
    }

    /**
@@ -151,10 +159,33 @@ public class TaskFragmentOrganizer extends WindowOrganizer {
     * @param errorCallbackToken    token set in
     *                             {@link WindowContainerTransaction#setErrorCallbackToken(IBinder)}
     * @param exception             exception from the server side.
     *
     * @deprecated Use {@link #onTaskFragmentError(IBinder, TaskFragmentInfo, int, Throwable)}
     * instead.
     */
    @Deprecated
    public void onTaskFragmentError(
            @NonNull IBinder errorCallbackToken, @NonNull Throwable exception) {}

    /**
     * Called when the {@link WindowContainerTransaction} created with
     * {@link WindowContainerTransaction#setErrorCallbackToken(IBinder)} failed on the server side.
     *
     * @param errorCallbackToken    token set in
     *                             {@link WindowContainerTransaction#setErrorCallbackToken(IBinder)}
     * @param taskFragmentInfo  The {@link TaskFragmentInfo}. This could be {@code null} if no
     *                          TaskFragment created.
     * @param opType            The {@link WindowContainerTransaction.HierarchyOp} of the failed
     *                          transaction operation.
     * @param exception             exception from the server side.
     */
    public void onTaskFragmentError(
            @NonNull IBinder errorCallbackToken, @Nullable TaskFragmentInfo taskFragmentInfo,
            int opType, @NonNull Throwable exception) {
        // Doing so to keep compatibility. This will be removed in the next release.
        onTaskFragmentError(errorCallbackToken, exception);
    }

    /**
     * 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
@@ -217,10 +248,16 @@ public class TaskFragmentOrganizer extends WindowOrganizer {

        @Override
        public void onTaskFragmentError(
                @NonNull IBinder errorCallbackToken, @NonNull Bundle exceptionBundle) {
            mExecutor.execute(() -> TaskFragmentOrganizer.this.onTaskFragmentError(
                    errorCallbackToken,
                    (Throwable) exceptionBundle.getSerializable(KEY_ERROR_CALLBACK_EXCEPTION)));
                @NonNull IBinder errorCallbackToken, @NonNull Bundle errorBundle) {
            mExecutor.execute(() -> {
                final TaskFragmentInfo info = errorBundle.getParcelable(
                        KEY_ERROR_CALLBACK_TASK_FRAGMENT_INFO, TaskFragmentInfo.class);
                TaskFragmentOrganizer.this.onTaskFragmentError(
                        errorCallbackToken, info,
                        errorBundle.getInt(KEY_ERROR_CALLBACK_OP_TYPE),
                        (Throwable) errorBundle.getSerializable(KEY_ERROR_CALLBACK_EXCEPTION,
                                java.lang.Throwable.class));
            });
        }

        @Override
+15 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ class JetpackTaskFragmentOrganizer extends TaskFragmentOrganizer {
                @NonNull Configuration parentConfig);
        void onActivityReparentToTask(int taskId, @NonNull Intent activityIntent,
                @NonNull IBinder activityToken);
        void onTaskFragmentError(@Nullable TaskFragmentInfo taskFragmentInfo, int opType);
    }

    /**
@@ -323,4 +324,18 @@ class JetpackTaskFragmentOrganizer extends TaskFragmentOrganizer {
            mCallback.onActivityReparentToTask(taskId, activityIntent, activityToken);
        }
    }

    @Override
    public void onTaskFragmentError(@NonNull IBinder errorCallbackToken,
            @Nullable TaskFragmentInfo taskFragmentInfo,
            int opType, @NonNull Throwable exception) {
        if (taskFragmentInfo != null) {
            final IBinder fragmentToken = taskFragmentInfo.getFragmentToken();
            mFragmentInfos.put(fragmentToken, taskFragmentInfo);
        }

        if (mCallback != null) {
            mCallback.onTaskFragmentError(taskFragmentInfo, opType);
        }
    }
}
+33 −0
Original line number Diff line number Diff line
@@ -19,6 +19,8 @@ package androidx.window.extensions.embedding;
import static android.app.ActivityManager.START_SUCCESS;
import static android.app.WindowConfiguration.WINDOWING_MODE_PINNED;
import static android.app.WindowConfiguration.WINDOWING_MODE_UNDEFINED;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT;
import static android.window.WindowContainerTransaction.HierarchyOp.HIERARCHY_OP_TYPE_START_ACTIVITY_IN_TASK_FRAGMENT;

import static androidx.window.extensions.embedding.SplitContainer.getFinishPrimaryWithSecondaryBehavior;
import static androidx.window.extensions.embedding.SplitContainer.getFinishSecondaryWithPrimaryBehavior;
@@ -296,6 +298,37 @@ public class SplitController implements JetpackTaskFragmentOrganizer.TaskFragmen
        }
    }

    @Override
    public void onTaskFragmentError(@Nullable TaskFragmentInfo taskFragmentInfo, int opType) {
        synchronized (mLock) {
            switch (opType) {
                case HIERARCHY_OP_TYPE_START_ACTIVITY_IN_TASK_FRAGMENT:
                case HIERARCHY_OP_TYPE_REPARENT_ACTIVITY_TO_TASK_FRAGMENT: {
                    final TaskFragmentContainer container;
                    if (taskFragmentInfo != null) {
                        container = getContainer(taskFragmentInfo.getFragmentToken());
                    } else {
                        container = null;
                    }
                    if (container == null) {
                        break;
                    }

                    // Update the latest taskFragmentInfo and perform necessary clean-up
                    container.setInfo(taskFragmentInfo);
                    container.clearPendingAppearedActivities();
                    if (container.isEmpty()) {
                        mPresenter.cleanupContainer(container, false /* shouldFinishDependent */);
                    }
                    break;
                }
                default:
                    Log.e(TAG, "onTaskFragmentError: taskFragmentInfo = " + taskFragmentInfo
                            + ", opType = " + opType);
            }
        }
    }

    /** Called on receiving {@link #onTaskFragmentVanished(TaskFragmentInfo)} for cleanup. */
    private void cleanupTaskFragment(@NonNull IBinder taskFragmentToken) {
        for (int i = mTaskContainers.size() - 1; i >= 0; i--) {
Loading