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

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

Extract StartInputReason from InputMethodClient

This is another step to split InputMethodClient into multiple classes.

With this CL, StartInputReason will be extracted from
InputMethodClient.java into a dedicated file.

This is a mechanical refactoring. There should be no user-visible
behavior change.

Bug: 118040692
Test: atest CtsInputMethodTestCases CtsInputMethodServiceHostTestCases
Test: atest FrameworksCoreTests:android.view.inputmethod.InputMethodManagerTest
Test: prebuilts/checkstyle/checkstyle.py -f \
      frameworks/base/core/java/com/android/internal/inputmethod/StartInputReason.java
Change-Id: I0cc2588c97239a004720f74cbf356bda4c735d53
parent a468d70e
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -61,6 +61,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.StartInputReason;
import com.android.internal.os.SomeArgs;
import com.android.internal.view.IInputConnectionWrapper;
import com.android.internal.view.IInputContext;
@@ -541,7 +542,7 @@ public final class InputMethodManager {
                        mCurId = res.id;
                        mBindSequence = res.sequence;
                    }
                    startInputInner(InputMethodClient.START_INPUT_REASON_BOUND_TO_IMMS,
                    startInputInner(StartInputReason.START_INPUT_REASON_BOUND_TO_IMMS,
                            null, 0, 0, 0);
                    return;
                }
@@ -568,7 +569,7 @@ public final class InputMethodManager {
                    }
                    if (startInput) {
                        startInputInner(
                                InputMethodClient.START_INPUT_REASON_UNBOUND_FROM_IMMS, null, 0, 0,
                                StartInputReason.START_INPUT_REASON_UNBOUND_FROM_IMMS, null, 0, 0,
                                0);
                    }
                    return;
@@ -599,8 +600,8 @@ public final class InputMethodManager {
                        if (mServedView != null && canStartInput(mServedView)) {
                            if (checkFocusNoStartInput(mRestartOnNextWindowFocus)) {
                                final int reason = active ?
                                        InputMethodClient.START_INPUT_REASON_ACTIVATED_BY_IMMS :
                                        InputMethodClient.START_INPUT_REASON_DEACTIVATED_BY_IMMS;
                                        StartInputReason.START_INPUT_REASON_ACTIVATED_BY_IMMS :
                                        StartInputReason.START_INPUT_REASON_DEACTIVATED_BY_IMMS;
                                startInputInner(reason, null, 0, 0, 0);
                            }
                        }
@@ -1387,11 +1388,11 @@ public final class InputMethodManager {
            mServedConnecting = true;
        }

        startInputInner(InputMethodClient.START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API, null, 0,
        startInputInner(StartInputReason.START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API, null, 0,
                0, 0);
    }

    boolean startInputInner(@InputMethodClient.StartInputReason final int startInputReason,
    boolean startInputInner(@StartInputReason int startInputReason,
            @Nullable IBinder windowGainingFocus, int controlFlags, int softInputMode,
            int windowFlags) {
        final View view;
@@ -1655,7 +1656,7 @@ public final class InputMethodManager {
    @UnsupportedAppUsage
    public void checkFocus() {
        if (checkFocusNoStartInput(false)) {
            startInputInner(InputMethodClient.START_INPUT_REASON_CHECK_FOCUS, null, 0, 0, 0);
            startInputInner(StartInputReason.START_INPUT_REASON_CHECK_FOCUS, null, 0, 0, 0);
        }
    }

@@ -1745,7 +1746,7 @@ public final class InputMethodManager {
            // should be done in conjunction with telling the system service
            // about the window gaining focus, to help make the transition
            // smooth.
            if (startInputInner(InputMethodClient.START_INPUT_REASON_WINDOW_FOCUS_GAIN,
            if (startInputInner(StartInputReason.START_INPUT_REASON_WINDOW_FOCUS_GAIN,
                    rootView.getWindowToken(), controlFlags, softInputMode, windowFlags)) {
                return;
            }
@@ -1757,7 +1758,7 @@ public final class InputMethodManager {
            try {
                if (DEBUG) Log.v(TAG, "Reporting focus gain, without startInput");
                mService.startInputOrWindowGainedFocus(
                        InputMethodClient.START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY, mClient,
                        StartInputReason.START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY, mClient,
                        rootView.getWindowToken(), controlFlags, softInputMode, windowFlags, null,
                        null, 0 /* missingMethodFlags */,
                        rootView.getContext().getApplicationInfo().targetSdkVersion);
+10 −11
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import android.view.WindowManager;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;

import com.android.internal.view.InputMethodClient;
import com.android.internal.view.InputMethodClient.StartInputReason;
import com.android.internal.view.InputMethodClient.UnbindReason;

/**
@@ -41,25 +40,25 @@ public final class InputMethodDebug {
     */
    public static String startInputReasonToString(@StartInputReason int reason) {
        switch (reason) {
            case InputMethodClient.START_INPUT_REASON_UNSPECIFIED:
            case StartInputReason.START_INPUT_REASON_UNSPECIFIED:
                return "UNSPECIFIED";
            case InputMethodClient.START_INPUT_REASON_WINDOW_FOCUS_GAIN:
            case StartInputReason.START_INPUT_REASON_WINDOW_FOCUS_GAIN:
                return "WINDOW_FOCUS_GAIN";
            case InputMethodClient.START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY:
            case StartInputReason.START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY:
                return "WINDOW_FOCUS_GAIN_REPORT_ONLY";
            case InputMethodClient.START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API:
            case StartInputReason.START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API:
                return "APP_CALLED_RESTART_INPUT_API";
            case InputMethodClient.START_INPUT_REASON_CHECK_FOCUS:
            case StartInputReason.START_INPUT_REASON_CHECK_FOCUS:
                return "CHECK_FOCUS";
            case InputMethodClient.START_INPUT_REASON_BOUND_TO_IMMS:
            case StartInputReason.START_INPUT_REASON_BOUND_TO_IMMS:
                return "BOUND_TO_IMMS";
            case InputMethodClient.START_INPUT_REASON_UNBOUND_FROM_IMMS:
            case StartInputReason.START_INPUT_REASON_UNBOUND_FROM_IMMS:
                return "UNBOUND_FROM_IMMS";
            case InputMethodClient.START_INPUT_REASON_ACTIVATED_BY_IMMS:
            case StartInputReason.START_INPUT_REASON_ACTIVATED_BY_IMMS:
                return "ACTIVATED_BY_IMMS";
            case InputMethodClient.START_INPUT_REASON_DEACTIVATED_BY_IMMS:
            case StartInputReason.START_INPUT_REASON_DEACTIVATED_BY_IMMS:
                return "DEACTIVATED_BY_IMMS";
            case InputMethodClient.START_INPUT_REASON_SESSION_CREATED_BY_IME:
            case StartInputReason.START_INPUT_REASON_SESSION_CREATED_BY_IME:
                return "SESSION_CREATED_BY_IME";
            default:
                return "Unknown=" + reason;
+92 −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 the reason why {@link android.view.inputmethod.InputMethodManager} is calling
 * {@link com.android.internal.view.IInputMethodManager#startInputOrWindowGainedFocus}.
 */
@Retention(SOURCE)
@IntDef(prefix = "START_INPUT_REASON_", value = {
        StartInputReason.START_INPUT_REASON_UNSPECIFIED,
        StartInputReason.START_INPUT_REASON_WINDOW_FOCUS_GAIN,
        StartInputReason.START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY,
        StartInputReason.START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API,
        StartInputReason.START_INPUT_REASON_CHECK_FOCUS,
        StartInputReason.START_INPUT_REASON_BOUND_TO_IMMS,
        StartInputReason.START_INPUT_REASON_UNBOUND_FROM_IMMS,
        StartInputReason.START_INPUT_REASON_ACTIVATED_BY_IMMS,
        StartInputReason.START_INPUT_REASON_DEACTIVATED_BY_IMMS,
        StartInputReason.START_INPUT_REASON_SESSION_CREATED_BY_IME})
public @interface StartInputReason {
    /**
     * Reason is not specified.
     */
    int START_INPUT_REASON_UNSPECIFIED = 0;
    /**
     * {@link android.view.Window} gained focus and it made the focused {@link android.view.View}
     * to (re)start a new connection.
     */
    int START_INPUT_REASON_WINDOW_FOCUS_GAIN = 1;
    /**
     * {@link android.view.Window} gained focus but there is no {@link android.view.View} that is
     * eligible to have IME focus. {@link android.view.inputmethod.InputMethodManager} just reports
     * this window focus change event.
     */
    int START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY = 2;
    /**
     * {@link android.view.inputmethod.InputMethodManager#restartInput(android.view.View)} is
     * either explicitly called by the application or indirectly called by some Framework class
     * (e.g. {@link android.widget.EditText}).
     */
    int START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API = 3;
    /**
     * {@link android.view.View} requested a new connection because of view focus change.
     */
    int START_INPUT_REASON_CHECK_FOCUS = 4;
    /**
     * {@link android.view.inputmethod.InputMethodManager} is responding to
     * {@link com.android.internal.view.IInputMethodClient#onBindMethod}.
     */
    int START_INPUT_REASON_BOUND_TO_IMMS = 5;
    /**
     * {@link android.view.inputmethod.InputMethodManager} is responding to
     * {@link com.android.internal.view.IInputMethodClient#onUnbindMethod}.
     */
    int START_INPUT_REASON_UNBOUND_FROM_IMMS = 6;
    /**
     * {@link android.view.inputmethod.InputMethodManager} is responding to
     * {@link com.android.internal.view.IInputMethodClient#setActive}.
     */
    int START_INPUT_REASON_ACTIVATED_BY_IMMS = 7;
    /**
     * {@link android.view.inputmethod.InputMethodManager} is responding to
     * {@link com.android.internal.view.IInputMethodClient#setActive}.
     */
    int START_INPUT_REASON_DEACTIVATED_BY_IMMS = 8;
    /**
     * {@link com.android.server.inputmethod.InputMethodManagerService} is responding to
     * {@link com.android.internal.view.IInputSessionCallback#sessionCreated}.
     */
    int START_INPUT_REASON_SESSION_CREATED_BY_IME = 9;
}
+1 −1
Original line number Diff line number Diff line
@@ -54,7 +54,7 @@ interface IInputMethodManager {
    // has gained focus, and if 'attribute' is non-null then also does startInput.
    // @NonNull
    InputBindResult startInputOrWindowGainedFocus(
            /* @InputMethodClient.StartInputReason */ int startInputReason,
            /* @StartInputReason */ int startInputReason,
            in IInputMethodClient client, in IBinder windowToken, int controlFlags,
            /* @android.view.WindowManager.LayoutParams.SoftInputModeFlags */ int softInputMode,
            int windowFlags, in EditorInfo attribute, IInputContext inputContext,
+0 −19
Original line number Diff line number Diff line
@@ -23,25 +23,6 @@ import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.SOURCE;

public final class InputMethodClient {
    public static final int START_INPUT_REASON_UNSPECIFIED = 0;
    public static final int START_INPUT_REASON_WINDOW_FOCUS_GAIN = 1;
    public static final int START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY = 2;
    public static final int START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API = 3;
    public static final int START_INPUT_REASON_CHECK_FOCUS = 4;
    public static final int START_INPUT_REASON_BOUND_TO_IMMS = 5;
    public static final int START_INPUT_REASON_UNBOUND_FROM_IMMS = 6;
    public static final int START_INPUT_REASON_ACTIVATED_BY_IMMS = 7;
    public static final int START_INPUT_REASON_DEACTIVATED_BY_IMMS = 8;
    public static final int START_INPUT_REASON_SESSION_CREATED_BY_IME = 9;

    @Retention(SOURCE)
    @IntDef({START_INPUT_REASON_UNSPECIFIED, START_INPUT_REASON_WINDOW_FOCUS_GAIN,
            START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY,
            START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API, START_INPUT_REASON_CHECK_FOCUS,
            START_INPUT_REASON_BOUND_TO_IMMS, START_INPUT_REASON_ACTIVATED_BY_IMMS,
            START_INPUT_REASON_DEACTIVATED_BY_IMMS, START_INPUT_REASON_SESSION_CREATED_BY_IME})
    public @interface StartInputReason {}

    public static final int UNBIND_REASON_UNSPECIFIED = 0;
    public static final int UNBIND_REASON_SWITCH_CLIENT = 1;
    public static final int UNBIND_REASON_SWITCH_IME = 2;
Loading