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

Commit cc5c7c5c authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Move #mLastImeTargetWindow to ImeVisibilityStateComputer

This is a mechanical refactoring to move

  InputMethodManagerService#mLastImeTargetWindow

to ImeVisibilityStateComputer, which will soon become per-user
instance.

There must be no observable behavior change.

Bug: 349904272
Test: presubmit
Flag: EXEMPT refactor
Change-Id: Ib47886800cd7efb4ba5e5055113b9c1e6404e2b8
parent e47b907e
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import android.accessibilityservice.AccessibilityService;
import android.annotation.AnyThread;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.content.res.Configuration;
import android.os.Binder;
@@ -128,6 +129,15 @@ public final class ImeVisibilityStateComputer {
    @GuardedBy("ImfLock.class")
    private IBinder mCurVisibleImeInputTarget;

    /**
     * The last window token that we confirmed that IME started talking to.  This is always updated
     * upon reports from the input method.  If the window state is already changed before the report
     * is handled, this field just keeps the last value.
     */
    @GuardedBy("ImfLock.class")
    @Nullable
    private IBinder mLastImeTargetWindow;

    /** Represent the invalid IME visibility state */
    public static final int STATE_INVALID = -1;

@@ -479,8 +489,7 @@ public final class ImeVisibilityStateComputer {
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
                // Do nothing but preserving the last IME requested visibility state.
                final ImeTargetWindowState lastState =
                        getWindowStateOrNull(mService.mLastImeTargetWindow);
                final ImeTargetWindowState lastState = getWindowStateOrNull(mLastImeTargetWindow);
                if (lastState != null) {
                    state.setRequestedImeVisible(lastState.mRequestedImeVisible);
                }
@@ -631,6 +640,17 @@ public final class ImeVisibilityStateComputer {
        mInputShown = inputShown;
    }

    @GuardedBy("ImfLock.class")
    @Nullable
    IBinder getLastImeTargetWindow() {
        return mLastImeTargetWindow;
    }

    @GuardedBy("ImfLock.class")
    void setLastImeTargetWindow(@Nullable IBinder imeTargetWindow) {
        mLastImeTargetWindow = imeTargetWindow;
    }

    @GuardedBy("ImfLock.class")
    void dumpDebug(ProtoOutputStream proto, long fieldId) {
        proto.write(SHOW_EXPLICITLY_REQUESTED, mRequestedShowExplicitly);
@@ -647,6 +667,7 @@ public final class ImeVisibilityStateComputer {
                + " mShowForced=" + mShowForced);
        p.println(prefix + "mImeHiddenByDisplayPolicy=" + mPolicy.isImeHiddenByDisplayPolicy());
        p.println(prefix + "mInputShown=" + mInputShown);
        p.println(prefix + "mLastImeTargetWindow=" + mLastImeTargetWindow);
    }

    /**
+10 −17
Original line number Diff line number Diff line
@@ -494,14 +494,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        return getUserData(userId).mBindingController;
    }

    /**
     * The last window token that we confirmed that IME started talking to.  This is always updated
     * upon reports from the input method.  If the window state is already changed before the report
     * is handled, this field just keeps the last value.
     */
    @MultiUserUnawareField
    IBinder mLastImeTargetWindow;

    /**
     * Map of window perceptible states indexed by their associated window tokens.
     *
@@ -2740,7 +2732,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            if (targetWindow != null) {
                mWindowManagerInternal.updateInputMethodTargetWindow(token, targetWindow);
            }
            mLastImeTargetWindow = targetWindow;
            mVisibilityStateComputer.setLastImeTargetWindow(targetWindow);
        }
    }

@@ -4629,8 +4621,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            proto.write(CUR_SEQ, bindingController.getSequenceNumber());
            proto.write(CUR_CLIENT, Objects.toString(userData.mCurClient));
            userData.mImeBindingState.dumpDebug(proto, mWindowManagerInternal);
            proto.write(LAST_IME_TARGET_WINDOW_NAME,
                    mWindowManagerInternal.getWindowName(mLastImeTargetWindow));
            proto.write(LAST_IME_TARGET_WINDOW_NAME, mWindowManagerInternal.getWindowName(
                    mVisibilityStateComputer.getLastImeTargetWindow()));
            proto.write(CUR_FOCUSED_WINDOW_SOFT_INPUT_MODE, InputMethodDebug.softInputModeToString(
                    userData.mImeBindingState.mFocusedWindowSoftInputMode));
            if (userData.mCurEditorInfo != null) {
@@ -4804,8 +4796,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                                    .setImeVisibility(false, statsToken);
                        }
                    } else {
                        hideCurrentInputLocked(mLastImeTargetWindow, statsToken, flags,
                                null /* resultReceiver */, reason, userId);
                        hideCurrentInputLocked(mVisibilityStateComputer.getLastImeTargetWindow(),
                                statsToken, flags, null /* resultReceiver */, reason, userId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -4843,9 +4835,9 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                                    .setImeVisibility(true, statsToken);
                        }
                    } else {
                        showCurrentInputLocked(mLastImeTargetWindow, statsToken, flags,
                                MotionEvent.TOOL_TYPE_UNKNOWN, null /* resultReceiver */, reason,
                                userId);
                        showCurrentInputLocked(mVisibilityStateComputer.getLastImeTargetWindow(),
                                statsToken, flags, MotionEvent.TOOL_TYPE_UNKNOWN,
                                null /* resultReceiver */, reason, userId);
                    }
                } finally {
                    Binder.restoreCallingIdentity(ident);
@@ -5869,7 +5861,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                // Hide the IME method menu only when the IME surface parent is changed by the
                // input target changed, in case seeing the dialog dismiss flickering during
                // the next focused window starting the input connection.
                if (mLastImeTargetWindow != userData.mImeBindingState.mFocusedWindow) {
                if (mVisibilityStateComputer.getLastImeTargetWindow()
                        != userData.mImeBindingState.mFocusedWindow) {
                    if (Flags.imeSwitcherRevamp()) {
                        final var bindingController = getInputMethodBindingController(userId);
                        mMenuControllerNew.hide(bindingController.getCurTokenDisplayId(), userId);
+1 −1
Original line number Diff line number Diff line
@@ -251,7 +251,7 @@ public class ImeVisibilityStateComputerTest extends InputMethodManagerServiceTes
        synchronized (ImfLock.class) {
            // Assume the last IME targeted window has requested IME visible
            final IBinder lastImeTargetWindowToken = new Binder();
            mInputMethodManagerService.mLastImeTargetWindow = lastImeTargetWindowToken;
            mComputer.setLastImeTargetWindow(lastImeTargetWindowToken);
            mComputer.requestImeVisibility(lastImeTargetWindowToken, true);
            final ImeTargetWindowState lastState = mComputer.getWindowStateOrNull(
                    lastImeTargetWindowToken);