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

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

Merge "Removing hide IME call onWindowLostFocus for STATE_ALWAYS_HIDDEN" into main

parents 5347604f 11085970
Loading
Loading
Loading
Loading
+20 −21
Original line number Original line Diff line number Diff line
@@ -938,27 +938,6 @@ public final class InputMethodManager {
            synchronized (mH) {
            synchronized (mH) {
                if (mCurRootView == viewRootImpl) {
                if (mCurRootView == viewRootImpl) {
                    mCurRootViewWindowFocused = false;
                    mCurRootViewWindowFocused = false;

                    if (Flags.refactorInsetsController() && mCurRootView != null) {
                        final int softInputMode = mCurRootView.mWindowAttributes.softInputMode;
                        final int state =
                                softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE;
                        if (state == WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) {
                            // when losing focus (e.g., by going to another window), we reset the
                            // requestedVisibleTypes of WindowInsetsController by hiding the IME
                            final var statsToken = ImeTracker.forLogging().onStart(
                                    ImeTracker.TYPE_HIDE, ImeTracker.ORIGIN_CLIENT,
                                    SoftInputShowHideReason.HIDE_WINDOW_LOST_FOCUS,
                                    false /* fromUser */);
                            if (DEBUG) {
                                Log.d(TAG, "onWindowLostFocus, hiding IME because "
                                        + "of STATE_ALWAYS_HIDDEN");
                            }
                            mCurRootView.getInsetsController().hide(WindowInsets.Type.ime(),
                                    false /* fromIme */, statsToken);
                        }
                    }

                    clearCurRootViewIfNeeded();
                    clearCurRootViewIfNeeded();
                }
                }
            }
            }
@@ -1012,6 +991,26 @@ public final class InputMethodManager {
        @GuardedBy("mH")
        @GuardedBy("mH")
        private void setCurrentRootViewLocked(ViewRootImpl rootView) {
        private void setCurrentRootViewLocked(ViewRootImpl rootView) {
            final boolean wasEmpty = mCurRootView == null;
            final boolean wasEmpty = mCurRootView == null;
            if (Flags.refactorInsetsController() && !wasEmpty && mCurRootView != rootView) {
                final int softInputMode = mCurRootView.mWindowAttributes.softInputMode;
                final int state =
                        softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE;
                if (state == WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN) {
                    // when losing input focus (e.g., by going to another window), we reset the
                    // requestedVisibleTypes of WindowInsetsController by hiding the IME
                    final var statsToken = ImeTracker.forLogging().onStart(
                            ImeTracker.TYPE_HIDE, ImeTracker.ORIGIN_CLIENT,
                            SoftInputShowHideReason.HIDE_WINDOW_LOST_FOCUS,
                            false /* fromUser */);
                    if (DEBUG) {
                        Log.d(TAG, "setCurrentRootViewLocked, hiding IME because "
                                + "of STATE_ALWAYS_HIDDEN");
                    }
                    mCurRootView.getInsetsController().hide(WindowInsets.Type.ime(),
                            false /* fromIme */, statsToken);
                }
            }

            mImeDispatcher.switchRootView(mCurRootView, rootView);
            mImeDispatcher.switchRootView(mCurRootView, rootView);
            mCurRootView = rootView;
            mCurRootView = rootView;
            if (wasEmpty && mCurRootView != null) {
            if (wasEmpty && mCurRootView != null) {