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

Commit 92743979 authored by Felix Stern's avatar Felix Stern Committed by Android (Google) Code Review
Browse files

Merge "Avoid handling the back key event, when IME is currently hiding" into main

parents e5e77e59 6ec6fb19
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;