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

Commit 537a99fc authored by Ming-Shin Lu's avatar Ming-Shin Lu
Browse files

Migrate computeImeDisplayIdForTarget to ImeVisibilityStateComputer

To abtract the IME display computatation and this CL should not have any
behavior change.

Bug: 246309664
Test: atest CtsInputMethodTestCases InputMethodManagerServiceTests
Change-Id: I9e15358a1b101a526828115245a85964f06da4bd
parent 351bf0fa
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -21,10 +21,12 @@ import static android.server.inputmethod.InputMethodManagerServiceProto.ACCESSIB
import static android.server.inputmethod.InputMethodManagerServiceProto.SHOW_EXPLICITLY_REQUESTED;
import static android.server.inputmethod.InputMethodManagerServiceProto.SHOW_FORCED;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.Display.INVALID_DISPLAY;
import static android.view.WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED;
import static android.view.WindowManager.LayoutParams.SoftInputModeFlags;

import static com.android.internal.inputmethod.InputMethodDebug.softInputModeToString;
import static com.android.server.inputmethod.InputMethodManagerService.computeImeDisplayIdForTarget;

import android.accessibilityservice.AccessibilityService;
import android.annotation.IntDef;
@@ -59,6 +61,8 @@ public final class ImeVisibilityStateComputer {
    private final InputMethodManagerService mService;
    private final WindowManagerInternal mWindowManagerInternal;

    final InputMethodManagerService.ImeDisplayValidator mImeDisplayValidator;

    /**
     * A map used to track the requested IME target window and its state. The key represents the
     * token of the window and the value is the corresponding IME window state.
@@ -118,6 +122,7 @@ public final class ImeVisibilityStateComputer {
    public ImeVisibilityStateComputer(InputMethodManagerService service) {
        mService = service;
        mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
        mImeDisplayValidator = mWindowManagerInternal::getDisplayImePolicy;
        mPolicy = new ImeVisibilityPolicy();
    }

@@ -183,6 +188,14 @@ public final class ImeVisibilityStateComputer {
        mShowForced = false;
    }

    int computeImeDisplayId(@NonNull ImeTargetWindowState state, int displayId) {
        final int displayToShowIme = computeImeDisplayIdForTarget(displayId, mImeDisplayValidator);
        state.setImeDisplayId(displayToShowIme);
        final boolean imeHiddenByPolicy = displayToShowIme == INVALID_DISPLAY;
        mPolicy.setImeHiddenByDisplayPolicy(imeHiddenByPolicy);
        return displayToShowIme;
    }

    /**
     * Request to show/hide IME from the given window.
     *
+8 −8
Original line number Diff line number Diff line
@@ -691,8 +691,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
     */
    private static final int FALLBACK_DISPLAY_ID = DEFAULT_DISPLAY;

    final ImeDisplayValidator mImeDisplayValidator;

    /**
     * If non-null, this is the input method service we are currently connected
     * to.
@@ -1686,7 +1684,6 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
        mInputManagerInternal = LocalServices.getService(InputManagerInternal.class);
        mImePlatformCompatUtils = new ImePlatformCompatUtils();
        mInputMethodDeviceConfigs = new InputMethodDeviceConfigs();
        mImeDisplayValidator = mWindowManagerInternal::getDisplayImePolicy;
        mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
        mUserManagerInternal = LocalServices.getService(UserManagerInternal.class);

@@ -2464,12 +2461,15 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub

        // Compute the final shown display ID with validated cs.selfReportedDisplayId for this
        // session & other conditions.
        mDisplayIdToShowIme = computeImeDisplayIdForTarget(cs.mSelfReportedDisplayId,
                mImeDisplayValidator);
        final boolean imeHiddenByPolicy = mDisplayIdToShowIme == INVALID_DISPLAY;
        mVisibilityStateComputer.getImePolicy().setImeHiddenByDisplayPolicy(imeHiddenByPolicy);
        ImeTargetWindowState winState = mVisibilityStateComputer.getWindowStateOrNull(
                mCurFocusedWindow);
        if (winState == null) {
            return InputBindResult.NOT_IME_TARGET_WINDOW;
        }
        final int csDisplayId = cs.mSelfReportedDisplayId;
        mDisplayIdToShowIme = mVisibilityStateComputer.computeImeDisplayId(winState, csDisplayId);

        if (imeHiddenByPolicy) {
        if (mVisibilityStateComputer.getImePolicy().isImeHiddenByDisplayPolicy()) {
            hideCurrentInputLocked(mCurFocusedWindow, null /* statsToken */, 0 /* flags */,
                    null /* resultReceiver */,
                    SoftInputShowHideReason.HIDE_DISPLAY_IME_POLICY_HIDE);