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

Commit 33a2865b authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Fix IME not dismissed with back gesture

Callback methods of callbacks registered by IME should be run on the same thread the ViewRootImpl holding IME's WindowOnBackInvokedDispatcher is created on.

Bug: 345427620
Test: Manual, i.e. verifying that IME is dismissed by back gesture without throwing IllegalStateException
Change-Id: I2883201aa59bb264e4c02246007c7c4788e8b07c
parent 584b3fe1
Loading
Loading
Loading
Loading
+9 −2
Original line number Diff line number Diff line
@@ -55,6 +55,9 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc
    static final int RESULT_CODE_UNREGISTER = 1;
    @NonNull
    private final ResultReceiver mResultReceiver;
    // The handler to run callbacks on. This should be on the same thread
    // the ViewRootImpl holding IME's WindowOnBackInvokedDispatcher is created on.
    private Handler mHandler;

    public ImeOnBackInvokedDispatcher(Handler handler) {
        mResultReceiver = new ResultReceiver(handler) {
@@ -68,6 +71,10 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc
        };
    }

    void setHandler(@NonNull Handler handler) {
        mHandler = handler;
    }

    /**
     * Override this method to return the {@link WindowOnBackInvokedDispatcher} of the window
     * that should receive the forwarded callback.
@@ -326,7 +333,7 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc

        @Override
        public void onBackInvoked() {
            mCallback.onBackInvoked();
            mHandler.post(mCallback::onBackInvoked);
        }

        @Override
@@ -336,7 +343,7 @@ public class ImeOnBackInvokedDispatcher implements OnBackInvokedDispatcher, Parc

        private void maybeRunOnAnimationCallback(Consumer<OnBackAnimationCallback> block) {
            if (mCallback instanceof OnBackAnimationCallback) {
                block.accept((OnBackAnimationCallback) mCallback);
                mHandler.post(() -> block.accept((OnBackAnimationCallback) mCallback));
            }
        }
    }
+1 −0
Original line number Diff line number Diff line
@@ -550,6 +550,7 @@ public class WindowOnBackInvokedDispatcher implements OnBackInvokedDispatcher {
    public void setImeOnBackInvokedDispatcher(
            @NonNull ImeOnBackInvokedDispatcher imeDispatcher) {
        mImeDispatcher = imeDispatcher;
        mImeDispatcher.setHandler(mHandler);
    }

    /** Returns true if a non-null {@link ImeOnBackInvokedDispatcher} has been set. **/