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

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

Remove redundant IMM#mServedInputConnection.

Following two fields have basically the same lifetime.
 - InputMethodManager#mServedInputConnection
 - InputMethodManager#mServedInputConnectionWrapper
Hence we do not need to maintain both of them.

This is a preparation CL for Bug 25332806 and does not change any
user-visible behavior.

Bug: 25332806
Change-Id: I1181e067aa5bedbdf0c7ec1bcec479257aea511c
parent c57fc478
Loading
Loading
Loading
Loading
+31 −20
Original line number Diff line number Diff line
@@ -317,7 +317,6 @@ public final class InputMethodManager {
    /**
     * The InputConnection that was last retrieved from the served view.
     */
    InputConnection mServedInputConnection;
    ControlledInputConnectionWrapper mServedInputConnectionWrapper;
    /**
     * The completions that were last provided by the served view.
@@ -498,7 +497,7 @@ public final class InputMethodManager {
                            // from a thread that created mServedView. That could happen
                            // the current activity is running in the system process.
                            // In that case, we really should not call
                            // mServedInputConnection.finishComposingText.
                            // mServedInputConnectionWrapper.finishComposingText().
                            if (checkFocusNoStartInput(mHasBeenInactive, false)) {
                                final int reason = active ?
                                        InputMethodClient.START_INPUT_REASON_ACTIVATED_BY_IMMS :
@@ -562,7 +561,9 @@ public final class InputMethodManager {

        @Override
        public String toString() {
            return "ControlledInputConnectionWrapper{mActive=" + mActive
            return "ControlledInputConnectionWrapper{"
                    + "connection=" + getInputConnection()
                    + " mActive=" + mActive
                    + " mParentInputMethodManager.mActive=" + mParentInputMethodManager.mActive
                    + "}";
        }
@@ -780,7 +781,8 @@ public final class InputMethodManager {
     */
    public boolean isAcceptingText() {
        checkFocus();
        return mServedInputConnection != null;
        return mServedInputConnectionWrapper != null &&
                mServedInputConnectionWrapper.getInputConnection() != null;
    }

    /**
@@ -815,7 +817,6 @@ public final class InputMethodManager {
     */
    void clearConnectionLocked() {
        mCurrentTextBoxAttribute = null;
        mServedInputConnection = null;
        if (mServedInputConnectionWrapper != null) {
            mServedInputConnectionWrapper.deactivate();
            mServedInputConnectionWrapper = null;
@@ -848,7 +849,13 @@ public final class InputMethodManager {
     * Notifies the served view that the current InputConnection will no longer be used.
     */
    private void notifyInputConnectionFinished() {
        if (mServedView != null && mServedInputConnection != null) {
        if (mServedView == null || mServedInputConnectionWrapper == null) {
            return;
        }
        final InputConnection inputConnection = mServedInputConnectionWrapper.getInputConnection();
        if (inputConnection == null) {
            return;
        }
        // We need to tell the previously served view that it is no
        // longer the input target, so it can reset its state.  Schedule
        // this call on its window's Handler so it will be on the correct
@@ -856,8 +863,7 @@ public final class InputMethodManager {
        ViewRootImpl viewRootImpl = mServedView.getViewRootImpl();
        if (viewRootImpl != null) {
            // This will result in a call to reportFinishInputConnection() below.
                viewRootImpl.dispatchFinishInputConnection(mServedInputConnection);
            }
            viewRootImpl.dispatchFinishInputConnection(inputConnection);
        }
    }

@@ -866,7 +872,13 @@ public final class InputMethodManager {
     * @hide
     */
    public void reportFinishInputConnection(InputConnection ic) {
        if (mServedInputConnection != ic) {
        final InputConnection currentConnection;
        if (mServedInputConnectionWrapper == null) {
            currentConnection = null;
        } else {
            currentConnection = mServedInputConnectionWrapper.getInputConnection();
        }
        if (currentConnection != ic) {
            ic.finishComposingText();
            // To avoid modifying the public InputConnection interface
            if (ic instanceof BaseInputConnection) {
@@ -1222,7 +1234,6 @@ public final class InputMethodManager {
            mServedConnecting = false;
            // Notify the served view that its previous input connection is finished
            notifyInputConnectionFinished();
            mServedInputConnection = ic;
            ControlledInputConnectionWrapper servedContext;
            final int missingMethodFlags;
            if (ic != null) {
@@ -1393,7 +1404,7 @@ public final class InputMethodManager {
            return false;
        }

        InputConnection ic = null;
        final ControlledInputConnectionWrapper ic;
        synchronized (mH) {
            if (mServedView == mNextServedView && !forceNewFocus) {
                return false;
@@ -1413,7 +1424,7 @@ public final class InputMethodManager {
                return false;
            }

            ic = mServedInputConnection;
            ic = mServedInputConnectionWrapper;

            mServedView = mNextServedView;
            mCurrentTextBoxAttribute = null;
@@ -2262,7 +2273,7 @@ public final class InputMethodManager {
        } else {
            p.println("  mCurrentTextBoxAttribute: null");
        }
        p.println("  mServedInputConnection=" + mServedInputConnection);
        p.println("  mServedInputConnectionWrapper=" + mServedInputConnectionWrapper);
        p.println("  mCompletions=" + Arrays.toString(mCompletions));
        p.println("  mCursorRect=" + mCursorRect);
        p.println("  mCursorSelStart=" + mCursorSelStart
+9 −1
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.internal.view;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
@@ -57,7 +59,8 @@ public abstract class IInputConnectionWrapper extends IInputContext.Stub {
    private static final int DO_CLEAR_META_KEY_STATES = 130;
    private static final int DO_REQUEST_UPDATE_CURSOR_ANCHOR_INFO = 140;

    private WeakReference<InputConnection> mInputConnection;
    @NonNull
    private final WeakReference<InputConnection> mInputConnection;

    private Looper mMainLooper;
    private Handler mH;
@@ -86,6 +89,11 @@ public abstract class IInputConnectionWrapper extends IInputContext.Stub {
        mH = new MyHandler(mMainLooper);
    }

    @Nullable
    public InputConnection getInputConnection() {
        return mInputConnection.get();
    }

    abstract protected boolean isActive();

    /**