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

Commit 625f5e28 authored by Vadim Caen's avatar Vadim Caen
Browse files

Add enableOnBackInvokedCallaback manifest attribute

Add a manifest flag for applications to opt-out of the new back
navigation system.

Test: atest
CtsWindowManagerDeviceTestCases: android.server.wm.BackNavigationLegacyTest
Bug: 217709328
Change-Id: I43d09a37b126e59bdb8f20bb83cf6d99e53a1e91
parent ebcfbdfc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -631,6 +631,7 @@ package android {
    field public static final int elevation = 16843840; // 0x1010440
    field public static final int ellipsize = 16842923; // 0x10100ab
    field public static final int ems = 16843096; // 0x1010158
    field public static final int enableOnBackInvokedCallback;
    field public static final int enableVrMode = 16844069; // 0x1010525
    field public static final int enabled = 16842766; // 0x101000e
    field public static final int end = 16843996; // 0x10104dc
+4 −1
Original line number Diff line number Diff line
@@ -1649,7 +1649,10 @@ public class Activity extends ContextThemeWrapper
        }
        mRestoredFromBundle = savedInstanceState != null;
        mCalled = true;
        if (!WindowOnBackInvokedDispatcher.shouldUseLegacyBack()) {

        boolean aheadOfTimeBack = WindowOnBackInvokedDispatcher
                .isOnBackInvokedCallbackEnabled(this);
        if (aheadOfTimeBack) {
            // Add onBackPressed as default back behavior.
            mDefaultBackCallback = new OnBackInvokedCallback() {
                @Override
+3 −2
Original line number Diff line number Diff line
@@ -456,7 +456,8 @@ public class Dialog implements DialogInterface, Window.Callback,
     */
    protected void onStart() {
        if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(true);
        if (mContext != null && !WindowOnBackInvokedDispatcher.shouldUseLegacyBack()) {
        if (mContext != null
                && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) {
            // Add onBackPressed as default back behavior.
            mDefaultBackCallback = new OnBackInvokedCallback() {
                @Override
@@ -703,7 +704,7 @@ public class Dialog implements DialogInterface, Window.Callback,
        if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE)
                && event.isTracking()
                && !event.isCanceled()
                && WindowOnBackInvokedDispatcher.shouldUseLegacyBack()) {
                && !WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) {
            onBackPressed();
            return true;
        }
+26 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.util.ArraySet;
import android.util.Printer;
import android.util.SparseArray;
import android.util.proto.ProtoOutputStream;
import android.view.OnBackInvokedCallback;

import com.android.internal.util.ArrayUtils;
import com.android.internal.util.Parcelling;
@@ -801,11 +802,24 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     */
    public static final int PRIVATE_FLAG_EXT_ATTRIBUTIONS_ARE_USER_VISIBLE = 1 << 2;


    /**
     * If false, {@link android.view.KeyEvent#KEYCODE_BACK} related events will be forwarded to
     * the Activities, Dialogs and Views and {@link android.app.Activity#onBackPressed()},
     * {@link android.app.Dialog#onBackPressed} will be called. Otherwise, those events will be
     * replaced by a call to {@link OnBackInvokedCallback#onBackInvoked()} on the focused window.
     *
     * @hide
     * @see android.R.styleable.AndroidManifestApplication_enableOnBackInvokedCallback
     */
    public static final int PRIVATE_FLAG_EXT_ENABLE_ON_BACK_INVOKED_CALLBACK = 1 << 3;

    /** @hide */
    @IntDef(flag = true, prefix = { "PRIVATE_FLAG_EXT_" }, value = {
            PRIVATE_FLAG_EXT_PROFILEABLE,
            PRIVATE_FLAG_EXT_REQUEST_FOREGROUND_SERVICE_EXEMPTION,
            PRIVATE_FLAG_EXT_ATTRIBUTIONS_ARE_USER_VISIBLE,
            PRIVATE_FLAG_EXT_ENABLE_ON_BACK_INVOKED_CALLBACK,
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface ApplicationInfoPrivateFlagsExt {}
@@ -1683,6 +1697,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
                pw.println(prefix + "localeConfigRes=0x"
                        + Integer.toHexString(localeConfigRes));
            }
            pw.println(prefix + "enableOnBackInvokedCallback=" + isOnBackInvokedCallbackEnabled());
        }
        pw.println(prefix + "createTimestamp=" + createTimestamp);
        if (mKnownActivityEmbeddingCerts != null) {
@@ -2565,6 +2580,17 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
                & ApplicationInfo.PRIVATE_FLAG_EXT_REQUEST_FOREGROUND_SERVICE_EXEMPTION) != 0;
    }

    /**
     * Returns whether the application will use the {@link android.view.OnBackInvokedCallback}
     * navigation system instead of the {@link android.view.KeyEvent#KEYCODE_BACK} and related
     * callbacks.
     *
     * @hide
     */
    public boolean isOnBackInvokedCallbackEnabled() {
        return ((privateFlagsExt & PRIVATE_FLAG_EXT_ENABLE_ON_BACK_INVOKED_CALLBACK)) != 0;
    }

    /**
     * @hide
     */
+2 −2
Original line number Diff line number Diff line
@@ -1201,7 +1201,7 @@ public final class ViewRootImpl implements ViewParent,
                        mTmpFrames.displayFrame, mTempRect2, mTmpFrames.frame);
                setFrame(mTmpFrames.frame);
                registerBackCallbackOnWindow();
                if (WindowOnBackInvokedDispatcher.shouldUseLegacyBack()) {
                if (!WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) {
                    // For apps requesting legacy back behavior, we add a compat callback that
                    // dispatches {@link KeyEvent#KEYCODE_BACK} to their root views.
                    // This way from system point of view, these apps are providing custom
@@ -6507,7 +6507,7 @@ public final class ViewRootImpl implements ViewParent,

            if (isBack(event)
                    && mContext != null
                    && !WindowOnBackInvokedDispatcher.shouldUseLegacyBack()) {
                    && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) {
                // Invoke the appropriate {@link OnBackInvokedCallback} if the new back
                // navigation should be used, and the key event is not handled by anything else.
                OnBackInvokedCallback topCallback =
Loading