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

Commit da6336c3 authored by wilsonshih's avatar wilsonshih Committed by Wei Sheng Shih
Browse files

Do not register OnBackInvokedCallback for SoftInputWindow.

By default Dialog#onStart will register onBackInvokedCallback, which
should be necessary since InputMethodService will register
CompatOnBackInvokedCallback for input method window.

Bug: 294162707
Test: atest BackGestureInvokedTest
Test: manual, launch Calendar then trigger back several times, verify
the back gesture can close app normally.

Change-Id: Icacfef60666fba1522f9d0f4ddc47e74a4560a32
Merged-In: Icacfef60666fba1522f9d0f4ddc47e74a4560a32
parent 76eed813
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -454,12 +454,11 @@ public class Dialog implements DialogInterface, Window.Callback,
     */
    protected void onStart() {
        if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(true);
        if (mContext != null
        if (allowsRegisterDefaultOnBackInvokedCallback() && mContext != null
                && WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) {
            // Add onBackPressed as default back behavior.
            mDefaultBackCallback = this::onBackPressed;
            getOnBackInvokedDispatcher().registerSystemOnBackInvokedCallback(mDefaultBackCallback);
            mDefaultBackCallback = null;
        }
    }

@@ -470,9 +469,18 @@ public class Dialog implements DialogInterface, Window.Callback,
        if (mActionBar != null) mActionBar.setShowHideAnimationEnabled(false);
        if (mDefaultBackCallback != null) {
            getOnBackInvokedDispatcher().unregisterOnBackInvokedCallback(mDefaultBackCallback);
            mDefaultBackCallback = null;
        }
    }

    /**
     * Whether this dialog allows to register the default onBackInvokedCallback.
     * @hide
     */
    protected boolean allowsRegisterDefaultOnBackInvokedCallback() {
        return true;
    }

    private static final String DIALOG_SHOWING_TAG = "android:dialogShowing";
    private static final String DIALOG_HIERARCHY_TAG = "android:dialogHierarchy";

@@ -697,7 +705,8 @@ public class Dialog implements DialogInterface, Window.Callback,
        if ((keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE)
                && event.isTracking()
                && !event.isCanceled()
                && !WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)) {
                && (!WindowOnBackInvokedDispatcher.isOnBackInvokedCallbackEnabled(mContext)
                || !allowsRegisterDefaultOnBackInvokedCallback())) {
            onBackPressed();
            return true;
        }
+7 −0
Original line number Diff line number Diff line
@@ -79,6 +79,13 @@ final class SoftInputWindow extends Dialog {
    @WindowState
    private int mWindowState = WindowState.TOKEN_PENDING;

    @Override
    protected boolean allowsRegisterDefaultOnBackInvokedCallback() {
        // Do not register OnBackInvokedCallback from Dialog#onStart, InputMethodService will
        // register CompatOnBackInvokedCallback for input method window.
        return false;
    }

    /**
     * Set {@link IBinder} window token to the window.
     *