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

Commit 8bdeee1a authored by Nikolas Havrikov's avatar Nikolas Havrikov
Browse files

Extract adding new window token in own method

Bug: 205676419
Test: make
Change-Id: I90374ed05682057bd56ec44c78be4b56bb10b625
parent 430e1722
Loading
Loading
Loading
Loading
+22 −14
Original line number Diff line number Diff line
@@ -2513,20 +2513,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        setCurIntent(intent);

        if (bindCurrentInputMethodServiceLocked(intent, this, mImeConnectionBindFlags)) {
            setLastBindTime(SystemClock.uptimeMillis());
            setHasConnection(true);
            setCurId(info.getId());
            setCurToken(new Binder());
            mCurTokenDisplayId = displayIdToShowIme;
            try {
                if (DEBUG) {
                    Slog.v(TAG, "Adding window token: " + getCurToken() + " for display: "
                            + mCurTokenDisplayId);
                }
                mIWindowManager.addWindowToken(getCurToken(), LayoutParams.TYPE_INPUT_METHOD,
                        mCurTokenDisplayId, null /* options */);
            } catch (RemoteException e) {
            }
            addFreshWindowTokenLocked(displayIdToShowIme, info.getId());
            return new InputBindResult(
                    InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING,
                    null, null, getCurId(), getSequenceNumber(), false);
@@ -2548,6 +2535,27 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        return intent;
    }

    @GuardedBy("mMethodMap")
    private void addFreshWindowTokenLocked(int displayIdToShowIme, String methodId) {
        Binder token = new Binder();
        setCurToken(token);
        setLastBindTime(SystemClock.uptimeMillis());
        setHasConnection(true);
        setCurId(methodId);
        mCurTokenDisplayId = displayIdToShowIme;
        try {
            if (DEBUG) {
                Slog.v(TAG, "Adding window token: " + token + " for display: "
                        + displayIdToShowIme);
            }
            mIWindowManager.addWindowToken(token, LayoutParams.TYPE_INPUT_METHOD,
                    displayIdToShowIme, null /* options */);
        } catch (RemoteException e) {
            Slog.e(TAG, "Could not add window token " + token + " for display "
                    + displayIdToShowIme, e);
        }
    }

    @FunctionalInterface
    interface ImeDisplayValidator {
        @DisplayImePolicy int getDisplayImePolicy(int displayId);