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

Commit aa48dc3c authored by Vadim Caen's avatar Vadim Caen
Browse files

Prevent callback registration when back flag is disabled

When the enableOnBackInvokedCallback is set to false (or not set),
registering an OnBackInvokedCallback should be a no-op to avoid
overriding the default compat callback.

Test: Manual testing registering a callback on an app with the flag
disabled and doing a back gesture. Currently we don't have test
executing a back gesture so automated tests are not possible

Bug: 235206960

Change-Id: I54d843f11130a78ed5a68cbe4722e601a2086ee1
parent d6339f26
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -800,6 +800,7 @@ package android.content.pm {

  public class ApplicationInfo extends android.content.pm.PackageItemInfo implements android.os.Parcelable {
    method public boolean hasRequestForegroundServiceExemption();
    method public boolean isOnBackInvokedCallbackEnabled();
    method public boolean isPrivilegedApp();
    method public boolean isSystemApp();
    method public void setEnableOnBackInvokedCallback(boolean);
+0 −2
Original line number Diff line number Diff line
@@ -1482,8 +1482,6 @@ public class Dialog implements DialogInterface, Window.Callback,
    /**
     * Returns the {@link OnBackInvokedDispatcher} instance associated with the window that this
     * dialog is attached to.
     *
     * Returns null if the dialog is not attached to a window with a decor.
     */
    @NonNull
    public OnBackInvokedDispatcher getOnBackInvokedDispatcher() {
+1 −0
Original line number Diff line number Diff line
@@ -2588,6 +2588,7 @@ public class ApplicationInfo extends PackageItemInfo implements Parcelable {
     *
     * @hide
     */
    @TestApi
    public boolean isOnBackInvokedCallbackEnabled() {
        return ((privateFlagsExt & PRIVATE_FLAG_EXT_ENABLE_ON_BACK_INVOKED_CALLBACK)) != 0;
    }
+2 −1
Original line number Diff line number Diff line
@@ -135,6 +135,7 @@ import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.window.CompatOnBackInvokedCallback;
import android.window.ImeOnBackInvokedDispatcher;
import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher;
@@ -366,7 +367,7 @@ public class InputMethodService extends AbstractInputMethodService {
    private RingBuffer<MotionEvent> mPendingEvents;
    private ImeOnBackInvokedDispatcher mImeDispatcher;
    private Boolean mBackCallbackRegistered = false;
    private final OnBackInvokedCallback mCompatBackCallback = this::compatHandleBack;
    private final CompatOnBackInvokedCallback mCompatBackCallback = this::compatHandleBack;
    private Runnable mImeSurfaceRemoverRunnable;
    private Runnable mFinishHwRunnable;
    private long mStylusHwSessionsTimeout = STYLUS_HANDWRITING_IDLE_TIMEOUT_MS;
+5 −10
Original line number Diff line number Diff line
@@ -196,6 +196,7 @@ import android.view.contentcapture.MainContentCaptureSession;
import android.view.inputmethod.InputMethodManager;
import android.widget.Scroller;
import android.window.ClientWindowFrames;
import android.window.CompatOnBackInvokedCallback;
import android.window.OnBackInvokedCallback;
import android.window.OnBackInvokedDispatcher;
import android.window.SurfaceSyncer;
@@ -339,13 +340,12 @@ public final class ViewRootImpl implements ViewParent,
    /**
     * The top level {@link OnBackInvokedDispatcher}.
     */
    private final WindowOnBackInvokedDispatcher mOnBackInvokedDispatcher =
            new WindowOnBackInvokedDispatcher();
    private final WindowOnBackInvokedDispatcher mOnBackInvokedDispatcher;
    /**
     * Compatibility {@link OnBackInvokedCallback} that dispatches KEYCODE_BACK events
     * to view root for apps using legacy back behavior.
     */
    private OnBackInvokedCallback mCompatOnBackInvokedCallback;
    private CompatOnBackInvokedCallback mCompatOnBackInvokedCallback;

    /**
     * Callback for notifying about global configuration changes.
@@ -963,6 +963,8 @@ public final class ViewRootImpl implements ViewParent,
        mFastScrollSoundEffectsEnabled = audioManager.areNavigationRepeatSoundEffectsEnabled();

        mScrollCaptureRequestTimeout = SCROLL_CAPTURE_REQUEST_TIMEOUT_MILLIS;
        mOnBackInvokedDispatcher = new WindowOnBackInvokedDispatcher(
                context.getApplicationInfo().isOnBackInvokedCallbackEnabled());
    }

    public static void addFirstDrawHandler(Runnable callback) {
@@ -10857,13 +10859,6 @@ public final class ViewRootImpl implements ViewParent,
                OnBackInvokedDispatcher.PRIORITY_DEFAULT, mCompatOnBackInvokedCallback);
    }

    private void unregisterCompatOnBackInvokedCallback() {
        if (mCompatOnBackInvokedCallback != null) {
            mOnBackInvokedDispatcher.unregisterOnBackInvokedCallback(mCompatOnBackInvokedCallback);
            mCompatOnBackInvokedCallback = null;
        }
    }

    @Override
    public void setTouchableRegion(Region r) {
        if (r != null) {
Loading