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

Commit b20ee4ee authored by Wilson Wu's avatar Wilson Wu
Browse files

Simplify InputMethodManager#startInputInner

Wrap the createInputConnection logic into a
private method to simplify this complex method.

This is a mechanical restructuring without user
visible changes.

Bug: 236937383
Bug: 236920321
Test: presubmit
Change-Id: I21207d22b7f5d55e84cbfde91969e59bb94b3043
parent 425a324a
Loading
Loading
Loading
Loading
+28 −18
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.annotation.RequiresFeature;
import android.annotation.RequiresPermission;
import android.annotation.SystemService;
import android.annotation.TestApi;
import android.annotation.UiThread;
import android.annotation.UserIdInt;
import android.app.ActivityThread;
import android.compat.annotation.ChangeId;
@@ -78,6 +79,7 @@ import android.provider.Settings;
import android.text.TextUtils;
import android.text.style.SuggestionSpan;
import android.util.Log;
import android.util.Pair;
import android.util.Pools.Pool;
import android.util.Pools.SimplePool;
import android.util.PrintWriterPrinter;
@@ -2472,24 +2474,9 @@ public final class InputMethodManager {
        // Okay we are now ready to call into the served view and have it
        // do its stuff.
        // Life is good: let's hook everything up!
        EditorInfo editorInfo = new EditorInfo();
        // Note: Use Context#getOpPackageName() rather than Context#getPackageName() so that the
        // system can verify the consistency between the uid of this process and package name passed
        // from here. See comment of Context#getOpPackageName() for details.
        editorInfo.packageName = view.getContext().getOpPackageName();
        editorInfo.autofillId = view.getAutofillId();
        editorInfo.fieldId = view.getId();
        InputConnection ic = view.onCreateInputConnection(editorInfo);
        if (DEBUG) Log.v(TAG, "Starting input: editorInfo=" + editorInfo + " ic=" + ic);

        // Clear autofill and field ids if a connection could not be established.
        // This ensures that even disconnected EditorInfos have well-defined attributes,
        // making them consistently and straightforwardly comparable.
        if (ic == null) {
            editorInfo.autofillId = AutofillId.NO_AUTOFILL_ID;
            editorInfo.fieldId = 0;
        }

        final Pair<InputConnection, EditorInfo> connectionPair = createInputConnection(view);
        final InputConnection ic = connectionPair.first;
        final EditorInfo editorInfo = connectionPair.second;
        final Handler icHandler;
        InputBindResult res = null;
        synchronized (mH) {
@@ -4030,4 +4017,27 @@ public final class InputMethodManager {
            consumer.accept(mAccessibilityInputMethodSession.valueAt(i));
        }
    }

    @UiThread
    private static Pair<InputConnection, EditorInfo> createInputConnection(
            @NonNull View servedView) {
        final EditorInfo editorInfo = new EditorInfo();
        // Note: Use Context#getOpPackageName() rather than Context#getPackageName() so that the
        // system can verify the consistency between the uid of this process and package name passed
        // from here. See comment of Context#getOpPackageName() for details.
        editorInfo.packageName = servedView.getContext().getOpPackageName();
        editorInfo.autofillId = servedView.getAutofillId();
        editorInfo.fieldId = servedView.getId();
        final InputConnection ic = servedView.onCreateInputConnection(editorInfo);
        if (DEBUG) Log.v(TAG, "Starting input: editorInfo=" + editorInfo + " ic=" + ic);

        // Clear autofill and field ids if a connection could not be established.
        // This ensures that even disconnected EditorInfos have well-defined attributes,
        // making them consistently and straightforwardly comparable.
        if (ic == null) {
            editorInfo.autofillId = AutofillId.NO_AUTOFILL_ID;
            editorInfo.fieldId = 0;
        }
        return new Pair<>(ic, editorInfo);
    }
}