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

Commit 35fa6d58 authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Extract IMM internal flags into StartInputFlags

This is a mechanical refactoring like we did to split
InputMethodClient for Bug 118040692.

So-called "controlFlags" in InputMethodManager (IMM) was originally
introduced for IMM#startInput()/windowGainedFocus() [1] to carry
additional client information then reused when we unify startInput()
and windowGainedFocus() into startInputOrWindowGainedFocus() [2].

This CL mechanically moves the location where those flags are defined,
from InputMethodManager.java to a newly created file
StartInputFlags.java.

This is still just a mechanical refacotring / renaming.  There should
be no user-visible behavior change.

 [1]: Icb58bef75ef4bf9979f3e2ba88cea20db2e2c3fb
      7663d80f
 [2]: I56934f18e30d90fcdf77bcbb0c35a92a5feb1b82
      05c25f8a

Test: atest CtsInputMethodTestCases CtsInputMethodServiceHostTestCases
Test: atest FrameworksCoreTests:com.android.internal.inputmethod.InputMethodDebugTest
Change-Id: If5a4810dece852edcff0d1119463711249bb7ef2
parent 5e46a66c
Loading
Loading
Loading
Loading
+19 −41
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ import android.view.autofill.AutofillManager;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.inputmethod.InputMethodDebug;
import com.android.internal.inputmethod.InputMethodPrivilegedOperationsRegistry;
import com.android.internal.inputmethod.StartInputFlags;
import com.android.internal.inputmethod.StartInputReason;
import com.android.internal.inputmethod.UnbindReason;
import com.android.internal.os.SomeArgs;
@@ -293,30 +294,6 @@ public final class InputMethodManager {
    @GuardedBy("sLock")
    private static final SparseArray<InputMethodManager> sInstanceMap = new SparseArray<>();

    /**
     * @hide Flag for IInputMethodManager.windowGainedFocus: a view in
     * the window has input focus.
     */
    public static final int CONTROL_WINDOW_VIEW_HAS_FOCUS = 1<<0;

    /**
     * @hide Flag for IInputMethodManager.windowGainedFocus: the focus
     * is a text editor.
     */
    public static final int CONTROL_WINDOW_IS_TEXT_EDITOR = 1<<1;

    /**
     * @hide Flag for IInputMethodManager.windowGainedFocus: this is the first
     * time the window has gotten focus.
     */
    public static final int CONTROL_WINDOW_FIRST = 1<<2;

    /**
     * @hide Flag for IInputMethodManager.startInput: this is the first
     * time the window has gotten focus.
     */
    public static final int CONTROL_START_INITIAL = 1<<8;

    /**
     * Timeout in milliseconds for delivering a key to an IME.
     */
@@ -1446,8 +1423,8 @@ public final class InputMethodManager {
    }

    boolean startInputInner(@StartInputReason int startInputReason,
            @Nullable IBinder windowGainingFocus, int controlFlags, int softInputMode,
            int windowFlags) {
            @Nullable IBinder windowGainingFocus, @StartInputFlags int startInputFlags,
            @SoftInputModeFlags int softInputMode, int windowFlags) {
        final View view;
        synchronized (mH) {
            view = mServedView;
@@ -1469,9 +1446,9 @@ public final class InputMethodManager {
                Log.e(TAG, "ABORT input: ServedView must be attached to a Window");
                return false;
            }
            controlFlags |= CONTROL_WINDOW_VIEW_HAS_FOCUS;
            startInputFlags |= StartInputFlags.VIEW_HAS_FOCUS;
            if (view.onCheckIsTextEditor()) {
                controlFlags |= CONTROL_WINDOW_IS_TEXT_EDITOR;
                startInputFlags |= StartInputFlags.IS_TEXT_EDITOR;
            }
            softInputMode = view.getViewRootImpl().mWindowAttributes.softInputMode;
            windowFlags = view.getViewRootImpl().mWindowAttributes.flags;
@@ -1526,7 +1503,7 @@ public final class InputMethodManager {
            // If we already have a text box, then this view is already
            // connected so we want to restart it.
            if (mCurrentTextBoxAttribute == null) {
                controlFlags |= CONTROL_START_INITIAL;
                startInputFlags |= StartInputFlags.INITIAL_CONNECTION;
            }

            // Hook 'em up and let 'er rip.
@@ -1564,11 +1541,11 @@ public final class InputMethodManager {

            try {
                if (DEBUG) Log.v(TAG, "START INPUT: view=" + dumpViewInfo(view) + " ic="
                        + ic + " tba=" + tba + " controlFlags=#"
                        + Integer.toHexString(controlFlags));
                        + ic + " tba=" + tba + " startInputFlags="
                        + InputMethodDebug.startInputFlagsToString(startInputFlags));
                final InputBindResult res = mService.startInputOrWindowGainedFocus(
                        startInputReason, mClient, windowGainingFocus, controlFlags, softInputMode,
                        windowFlags, tba, servedContext, missingMethodFlags,
                        startInputReason, mClient, windowGainingFocus, startInputFlags,
                        softInputMode, windowFlags, tba, servedContext, missingMethodFlags,
                        view.getContext().getApplicationInfo().targetSdkVersion);
                if (DEBUG) Log.v(TAG, "Starting input: Bind result=" + res);
                if (res == null) {
@@ -1576,7 +1553,8 @@ public final class InputMethodManager {
                            + " null. startInputReason="
                            + InputMethodDebug.startInputReasonToString(startInputReason)
                            + " editorInfo=" + tba
                            + " controlFlags=#" + Integer.toHexString(controlFlags));
                            + " startInputFlags="
                            + InputMethodDebug.startInputFlagsToString(startInputFlags));
                    return false;
                }
                if (res.id != null) {
@@ -1783,15 +1761,15 @@ public final class InputMethodManager {
            focusInLocked(focusedView != null ? focusedView : rootView);
        }

        int controlFlags = 0;
        int startInputFlags = 0;
        if (focusedView != null) {
            controlFlags |= CONTROL_WINDOW_VIEW_HAS_FOCUS;
            startInputFlags |= StartInputFlags.VIEW_HAS_FOCUS;
            if (focusedView.onCheckIsTextEditor()) {
                controlFlags |= CONTROL_WINDOW_IS_TEXT_EDITOR;
                startInputFlags |= StartInputFlags.IS_TEXT_EDITOR;
            }
        }
        if (first) {
            controlFlags |= CONTROL_WINDOW_FIRST;
            startInputFlags |= StartInputFlags.FIRST_WINDOW_FOCUS_GAIN;
        }

        if (checkFocusNoStartInput(forceNewFocus)) {
@@ -1800,7 +1778,7 @@ public final class InputMethodManager {
            // about the window gaining focus, to help make the transition
            // smooth.
            if (startInputInner(StartInputReason.WINDOW_FOCUS_GAIN, rootView.getWindowToken(),
                    controlFlags, softInputMode, windowFlags)) {
                    startInputFlags, softInputMode, windowFlags)) {
                return;
            }
        }
@@ -1812,8 +1790,8 @@ public final class InputMethodManager {
                if (DEBUG) Log.v(TAG, "Reporting focus gain, without startInput");
                mService.startInputOrWindowGainedFocus(
                        StartInputReason.WINDOW_FOCUS_GAIN_REPORT_ONLY, mClient,
                        rootView.getWindowToken(), controlFlags, softInputMode, windowFlags, null,
                        null, 0 /* missingMethodFlags */,
                        rootView.getWindowToken(), startInputFlags, softInputMode, windowFlags,
                        null, null, 0 /* missingMethodFlags */,
                        rootView.getContext().getApplicationInfo().targetSdkVersion);
            } catch (RemoteException e) {
                throw e.rethrowFromSystemServer();
+24 −0
Original line number Diff line number Diff line
@@ -153,4 +153,28 @@ public final class InputMethodDebug {

        return joiner.setEmptyValue("(none)").toString();
    }

    /**
     * Converts {@link StartInputFlags} to {@link String} for debug logging.
     *
     * @param startInputFlags integer constant for {@link StartInputFlags}.
     * @return {@link String} message corresponds for the given {@code startInputFlags}.
     */
    public static String startInputFlagsToString(@StartInputFlags int startInputFlags) {
        final StringJoiner joiner = new StringJoiner("|");
        if ((startInputFlags & StartInputFlags.VIEW_HAS_FOCUS) != 0) {
            joiner.add("VIEW_HAS_FOCUS");
        }
        if ((startInputFlags & StartInputFlags.IS_TEXT_EDITOR) != 0) {
            joiner.add("IS_TEXT_EDITOR");
        }
        if ((startInputFlags & StartInputFlags.FIRST_WINDOW_FOCUS_GAIN) != 0) {
            joiner.add("FIRST_WINDOW_FOCUS_GAIN");
        }
        if ((startInputFlags & StartInputFlags.INITIAL_CONNECTION) != 0) {
            joiner.add("INITIAL_CONNECTION");
        }

        return joiner.setEmptyValue("(none)").toString();
    }
}
+56 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.internal.inputmethod;

import static java.lang.annotation.RetentionPolicy.SOURCE;

import android.annotation.IntDef;

import java.lang.annotation.Retention;

/**
 * Describes additional info in
 * {@link com.android.internal.view.IInputMethodManager#startInputOrWindowGainedFocus}.
 */
@Retention(SOURCE)
@IntDef(flag = true, value = {
        StartInputFlags.VIEW_HAS_FOCUS,
        StartInputFlags.IS_TEXT_EDITOR,
        StartInputFlags.FIRST_WINDOW_FOCUS_GAIN,
        StartInputFlags.INITIAL_CONNECTION})
public @interface StartInputFlags {
    /**
     * There is a focused view in the focused window.
     */
    int VIEW_HAS_FOCUS = 1;

    /**
     * The focused view is a text editor.
     */
    int IS_TEXT_EDITOR = 2;

    /**
     * This is the first time the window has gotten focus.
     */
    int FIRST_WINDOW_FOCUS_GAIN = 4;

    /**
     * An internal concept to distinguish "start" and "restart". This concept doesn't look well
     * documented hence we probably need to revisit this though.
     */
    int INITIAL_CONNECTION = 8;
}
+2 −1
Original line number Diff line number Diff line
@@ -55,7 +55,8 @@ interface IInputMethodManager {
    // @NonNull
    InputBindResult startInputOrWindowGainedFocus(
            /* @StartInputReason */ int startInputReason,
            in IInputMethodClient client, in IBinder windowToken, int controlFlags,
            in IInputMethodClient client, in IBinder windowToken,
            /* @StartInputFlags */ int startInputFlags,
            /* @android.view.WindowManager.LayoutParams.SoftInputModeFlags */ int softInputMode,
            int windowFlags, in EditorInfo attribute, IInputContext inputContext,
            /* @InputConnectionInspector.MissingMethodFlags */ int missingMethodFlags,
+11 −0
Original line number Diff line number Diff line
@@ -53,4 +53,15 @@ public class InputMethodDebugTest {
                                | LayoutParams.SOFT_INPUT_ADJUST_RESIZE
                                | LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION));
    }

    @Test
    public void testStartInputFlagsToString() {
        // TODO: add more tests
        assertEquals("(none)", InputMethodDebug.startInputFlagsToString(0));
        assertEquals("IS_TEXT_EDITOR",
                InputMethodDebug.startInputFlagsToString(StartInputFlags.IS_TEXT_EDITOR));
        assertEquals("VIEW_HAS_FOCUS|INITIAL_CONNECTION",
                InputMethodDebug.startInputFlagsToString(
                        StartInputFlags.VIEW_HAS_FOCUS | StartInputFlags.INITIAL_CONNECTION));
    }
}
Loading