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

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

Migrate applyImeVsibility to ImeVisibilityApplier

To abstract the application of IME visiblity without any behavior
change.

Bug: 246309664
Test: atest CtsInputMethodTestCases
Change-Id: I6e137a6e14f4fd7101322f54fda32ddcb5ccd017
parent 537a99fc
Loading
Loading
Loading
Loading
+41 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ import static android.view.inputmethod.ImeTracker.DEBUG_IME_VISIBILITY;

import static com.android.server.EventLogTags.IMF_HIDE_IME;
import static com.android.server.EventLogTags.IMF_SHOW_IME;
import static com.android.server.inputmethod.ImeVisibilityStateComputer.STATE_HIDE_IME;
import static com.android.server.inputmethod.ImeVisibilityStateComputer.STATE_SHOW_IME;

import android.annotation.Nullable;
import android.os.Binder;
@@ -32,6 +34,8 @@ import android.view.inputmethod.ImeTracker;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.inputmethod.InputMethodDebug;
import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.server.LocalServices;
import com.android.server.wm.WindowManagerInternal;

import java.util.Objects;

@@ -47,8 +51,12 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier {

    private InputMethodManagerService mService;

    private final WindowManagerInternal mWindowManagerInternal;


    DefaultImeVisibilityApplier(InputMethodManagerService service) {
        mService = service;
        mWindowManagerInternal = LocalServices.getService(WindowManagerInternal.class);
    }

    @GuardedBy("ImfLock.class")
@@ -111,4 +119,37 @@ final class DefaultImeVisibilityApplier implements ImeVisibilityApplier {
            }
        }
    }

    @GuardedBy("ImfLock.class")
    @Override
    public void applyImeVisibility(IBinder windowToken, @Nullable ImeTracker.Token statsToken,
            @ImeVisibilityStateComputer.VisibilityState int state) {
        switch (state) {
            case STATE_SHOW_IME:
                ImeTracker.get().onProgress(statsToken,
                        ImeTracker.PHASE_SERVER_APPLY_IME_VISIBILITY);
                // Send to window manager to show IME after IME layout finishes.
                mWindowManagerInternal.showImePostLayout(windowToken, statsToken);
                break;
            case STATE_HIDE_IME:
                if (mService.mCurFocusedWindowClient != null) {
                    ImeTracker.get().onProgress(statsToken,
                            ImeTracker.PHASE_SERVER_APPLY_IME_VISIBILITY);
                    // IMMS only knows of focused window, not the actual IME target.
                    // e.g. it isn't aware of any window that has both
                    // NOT_FOCUSABLE, ALT_FOCUSABLE_IM flags set and can the IME target.
                    // Send it to window manager to hide IME from IME target window.
                    // TODO(b/139861270): send to mCurClient.client once IMMS is aware of
                    // actual IME target.
                    mWindowManagerInternal.hideIme(windowToken,
                            mService.mCurFocusedWindowClient.mSelfReportedDisplayId, statsToken);
                } else {
                    ImeTracker.get().onFailed(statsToken,
                            ImeTracker.PHASE_SERVER_APPLY_IME_VISIBILITY);
                }
                break;
            default:
                throw new IllegalArgumentException("Invalid IME visibility state: " + state);
        }
    }
}
+4 −5
Original line number Diff line number Diff line
@@ -58,12 +58,11 @@ interface ImeVisibilityApplier {
     * according to the given visibility state.
     *
     * @param windowToken The token of a window for applying the IME visibility
     * @param statsToken  A token that tracks the progress of an IME request.
     * @param state       The new IME visibility state for the applier to handle
     */
    default void applyImeVisibility(IBinder windowToken,
            @ImeVisibilityStateComputer.VisibilityState int state) {
        // TODO: migrate IMMS#applyImeVisibility logic to here.
    }
    default void applyImeVisibility(IBinder windowToken, @Nullable ImeTracker.Token statsToken,
            @ImeVisibilityStateComputer.VisibilityState int state) {}

    /**
     * Updates the IME Z-ordering relative to the given window.
+3 −16
Original line number Diff line number Diff line
@@ -4699,22 +4699,9 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub
                return;
            }
            final IBinder requestToken = mVisibilityStateComputer.getWindowTokenFrom(windowToken);
            if (!setVisible) {
                if (mCurClient != null) {
                    ImeTracker.get().onProgress(statsToken,
                            ImeTracker.PHASE_SERVER_APPLY_IME_VISIBILITY);
                    mWindowManagerInternal.hideIme(requestToken, mCurClient.mSelfReportedDisplayId,
                            statsToken);
                } else {
                    ImeTracker.get().onFailed(statsToken,
                            ImeTracker.PHASE_SERVER_APPLY_IME_VISIBILITY);
                }
            } else {
                ImeTracker.get().onProgress(statsToken,
                        ImeTracker.PHASE_SERVER_APPLY_IME_VISIBILITY);
                // Send to window manager to show IME after IME layout finishes.
                mWindowManagerInternal.showImePostLayout(requestToken, statsToken);
            }
            mVisibilityApplier.applyImeVisibility(requestToken, statsToken,
                    setVisible ? ImeVisibilityStateComputer.STATE_SHOW_IME
                            : ImeVisibilityStateComputer.STATE_HIDE_IME);
        }
        Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER);
    }