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

Commit b73cda83 authored by Louis Chang's avatar Louis Chang Committed by Android (Google) Code Review
Browse files

Merge "Move the task to back while pressing back on the last activity" into tm-qpr-dev

parents 1ed40ed7 99b94497
Loading
Loading
Loading
Loading
+10 −13
Original line number Diff line number Diff line
@@ -1684,7 +1684,7 @@ public class Activity extends ContextThemeWrapper
                .isOnBackInvokedCallbackEnabled(this);
        if (aheadOfTimeBack) {
            // Add onBackPressed as default back behavior.
            mDefaultBackCallback = this::navigateBack;
            mDefaultBackCallback = this::onBackInvoked;
            getOnBackInvokedDispatcher().registerSystemOnBackInvokedCallback(mDefaultBackCallback);
        }
    }
@@ -4002,23 +4002,20 @@ public class Activity extends ContextThemeWrapper
        if (!fragmentManager.isStateSaved() && fragmentManager.popBackStackImmediate()) {
            return;
        }
        navigateBack();
        onBackInvoked();
    }

    private void navigateBack() {
        if (!isTaskRoot()) {
            // If the activity is not the root of the task, allow finish to proceed normally.
            finishAfterTransition();
            return;
        }
        // Inform activity task manager that the activity received a back press while at the
        // root of the task. This call allows ActivityTaskManager to intercept or move the task
        // to the back.
        ActivityClient.getInstance().onBackPressedOnTaskRoot(mToken,
    private void onBackInvoked() {
        // Inform activity task manager that the activity received a back press.
        // This call allows ActivityTaskManager to intercept or move the task
        // to the back when needed.
        ActivityClient.getInstance().onBackPressed(mToken,
                new RequestFinishCallback(new WeakReference<>(this)));

        if (isTaskRoot()) {
            getAutofillClientController().onActivityBackPressed(mIntent);
        }
    }

    /**
     * Called when a key shortcut event is not handled by any of the views in the Activity.
+2 −2
Original line number Diff line number Diff line
@@ -525,9 +525,9 @@ public class ActivityClient {
        }
    }

    void onBackPressedOnTaskRoot(IBinder token, IRequestFinishCallback callback) {
    void onBackPressed(IBinder token, IRequestFinishCallback callback) {
        try {
            getActivityClientController().onBackPressedOnTaskRoot(token, callback);
            getActivityClientController().onBackPressed(token, callback);
        } catch (RemoteException e) {
            e.rethrowFromSystemServer();
        }
+2 −3
Original line number Diff line number Diff line
@@ -145,10 +145,9 @@ interface IActivityClientController {
    void unregisterRemoteAnimations(in IBinder token);

    /**
     * Reports that an Activity received a back key press when there were no additional activities
     * on the back stack.
     * Reports that an Activity received a back key press.
     */
    oneway void onBackPressedOnTaskRoot(in IBinder activityToken,
    oneway void onBackPressed(in IBinder activityToken,
            in IRequestFinishCallback callback);

    /** Reports that the splash screen view has attached to activity.  */
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ package android.app;

/**
 * This callback allows ActivityTaskManager to ask the calling Activity
 * to finish in response to a call to onBackPressedOnTaskRoot.
 * to finish in response to a call to onBackPressed.
 *
 * {@hide}
 */
+32 −0
Original line number Diff line number Diff line
@@ -739,6 +739,29 @@ public final class WindowContainerTransaction implements Parcelable {
        return this;
    }

    /**
     * Sets the TaskFragment {@code container} to have a companion TaskFragment {@code companion}.
     * This indicates that the organizer will remove the TaskFragment when the companion
     * TaskFragment is removed.
     *
     * @param container the TaskFragment container
     * @param companion the companion TaskFragment. If it is {@code null}, the transaction will
     *                  reset the companion TaskFragment.
     * @hide
     */
    @NonNull
    public WindowContainerTransaction setCompanionTaskFragment(@NonNull IBinder container,
            @Nullable IBinder companion) {
        final HierarchyOp hierarchyOp =
                new HierarchyOp.Builder(
                        HierarchyOp.HIERARCHY_OP_TYPE_SET_COMPANION_TASK_FRAGMENT)
                        .setContainer(container)
                        .setReparentContainer(companion)
                        .build();
        mHierarchyOps.add(hierarchyOp);
        return this;
    }

    /**
     * Sets/removes the always on top flag for this {@code windowContainer}. See
     * {@link com.android.server.wm.ConfigurationContainer#setAlwaysOnTop(boolean)}.
@@ -1217,6 +1240,7 @@ public final class WindowContainerTransaction implements Parcelable {
        public static final int HIERARCHY_OP_TYPE_SET_ALWAYS_ON_TOP = 19;
        public static final int HIERARCHY_OP_TYPE_REMOVE_TASK = 20;
        public static final int HIERARCHY_OP_TYPE_FINISH_ACTIVITY = 21;
        public static final int HIERARCHY_OP_TYPE_SET_COMPANION_TASK_FRAGMENT = 22;

        // The following key(s) are for use with mLaunchOptions:
        // When launching a task (eg. from recents), this is the taskId to be launched.
@@ -1430,6 +1454,11 @@ public final class WindowContainerTransaction implements Parcelable {
            return mReparent;
        }

        @NonNull
        public IBinder getCompanionContainer() {
            return mReparent;
        }

        @NonNull
        public IBinder getCallingActivity() {
            return mReparent;
@@ -1540,6 +1569,9 @@ public final class WindowContainerTransaction implements Parcelable {
                    return "{RemoveTask: task=" + mContainer + "}";
                case HIERARCHY_OP_TYPE_FINISH_ACTIVITY:
                    return "{finishActivity: activity=" + mContainer + "}";
                case HIERARCHY_OP_TYPE_SET_COMPANION_TASK_FRAGMENT:
                    return "{setCompanionTaskFragment: container = " + mContainer + " companion = "
                            + mReparent + "}";
                default:
                    return "{mType=" + mType + " container=" + mContainer + " reparent=" + mReparent
                            + " mToTop=" + mToTop
Loading