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

Commit 6ec6fb19 authored by Felix Stern's avatar Felix Stern
Browse files

Avoid handling the back key event, when IME is currently hiding

When there was an ongoing hide animation (without predictive back enabled), and another swipe back happened, the second event went to the InputMethodService, where it was consumed.
This was caused by the fact, that the IME is only notified that it will be hidden at the end of the hide animation.
However, the second back event should go to the app.

This CL fixes this behaviour and doesn't dispatch the back key event to the IME, if there is an ongoing hide animation or predictive back animation in progress.

Bug: 375986921
Test: Manual, i.e. verifying that quick double back swipes are handled correctly (including after an interrupted IME hide animation)
Flag: android.view.inputmethod.refactor_insets_controller
Change-Id: Ic22f76b4708c4e5f090824d1d46833a97b19b49f
parent 95f5091d
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.annotation.NonNull;
import android.annotation.UiThread;
import android.util.Log;
import android.util.proto.ProtoOutputStream;
import android.view.inputmethod.Flags;
import android.view.inputmethod.InputMethodManager;

import com.android.internal.inputmethod.InputMethodDebug;
@@ -150,6 +151,17 @@ public final class ImeFocusController {
        if (!mHasImeFocus || isInLocalFocusMode(windowAttribute)) {
            return InputMethodManager.DISPATCH_NOT_HANDLED;
        }
        if (Flags.refactorInsetsController() && event instanceof KeyEvent keyEvent
                && keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            final var insetsController = mViewRootImpl.getInsetsController();
            if (insetsController.getAnimationType(WindowInsets.Type.ime())
                    == InsetsController.ANIMATION_TYPE_HIDE
                    || insetsController.isPredictiveBackImeHideAnimInProgress()) {
                // if there is an ongoing hide animation, the back event should not be dispatched
                // to the IME.
                return InputMethodManager.DISPATCH_NOT_HANDLED;
            }
        }
        final InputMethodManager imm =
                mViewRootImpl.mContext.getSystemService(InputMethodManager.class);
        if (imm == null) {
+2 −1
Original line number Diff line number Diff line
@@ -1910,7 +1910,8 @@ public class InsetsController implements WindowInsetsController, InsetsAnimation
        mImeSourceConsumer.onWindowFocusLost();
    }

    @VisibleForTesting
    /** Returns the current {@link AnimationType} of an {@link InsetsType}. */
    @VisibleForTesting(visibility = PACKAGE)
    public @AnimationType int getAnimationType(@InsetsType int type) {
        for (int i = mRunningAnimations.size() - 1; i >= 0; i--) {
            InsetsAnimationControlRunner control = mRunningAnimations.get(i).runner;