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

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

Move some methods from InputMethodClient to InputMethodDebug

This is the first step to split InputMethodClient into multiple
classes.

With this CL, utility methods to convert integer constants to String
messages will be moved from InputMethodClient to InputMethodDebug,
which I believe is a bit more descriptive class name than
InputMethodClient.

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/InputMethodDebug.java
Change-Id: I83f4795e95bc2e8ae325ad6e28d3a42317414e8d
parent 4afd9335
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@ import android.view.WindowManager.LayoutParams.SoftInputModeFlags;
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.os.SomeArgs;
import com.android.internal.view.IInputConnectionWrapper;
@@ -550,7 +551,7 @@ public final class InputMethodManager {
                    final int reason = msg.arg2;
                    if (DEBUG) {
                        Log.i(TAG, "handleMessage: MSG_UNBIND " + sequence +
                                " reason=" + InputMethodClient.getUnbindReason(reason));
                                " reason=" + InputMethodDebug.unbindReasonToString(reason));
                    }
                    final boolean startInput;
                    synchronized (mH) {
@@ -1400,7 +1401,7 @@ public final class InputMethodManager {
            // Make sure we have a window token for the served view.
            if (DEBUG) {
                Log.v(TAG, "Starting input: view=" + dumpViewInfo(view) +
                        " reason=" + InputMethodClient.getStartInputReason(startInputReason));
                        " reason=" + InputMethodDebug.startInputReasonToString(startInputReason));
            }
            if (view == null) {
                if (DEBUG) Log.v(TAG, "ABORT input: no served view!");
@@ -1519,7 +1520,7 @@ public final class InputMethodManager {
                if (res == null) {
                    Log.wtf(TAG, "startInputOrWindowGainedFocus must not return"
                            + " null. startInputReason="
                            + InputMethodClient.getStartInputReason(startInputReason)
                            + InputMethodDebug.startInputReasonToString(startInputReason)
                            + " editorInfo=" + tba
                            + " controlFlags=#" + Integer.toHexString(controlFlags));
                    return false;
@@ -1717,7 +1718,7 @@ public final class InputMethodManager {
        boolean forceNewFocus = false;
        synchronized (mH) {
            if (DEBUG) Log.v(TAG, "onWindowFocus: " + focusedView
                    + " softInputMode=" + InputMethodClient.softInputModeToString(softInputMode)
                    + " softInputMode=" + InputMethodDebug.softInputModeToString(softInputMode)
                    + " first=" + first + " flags=#"
                    + Integer.toHexString(windowFlags));
            if (mRestartOnNextWindowFocus) {
+162 −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 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;

/**
 * Provides useful methods for debugging.
 */
public final class InputMethodDebug {
    /**
     * Not intended to be instantiated.
     */
    private InputMethodDebug() {
    }

    /**
     * Converts {@link StartInputReason} to {@link String} for debug logging.
     *
     * @param reason integer constant for {@link StartInputReason}.
     * @return {@link String} message corresponds for the given {@code reason}.
     */
    public static String startInputReasonToString(@StartInputReason int reason) {
        switch (reason) {
            case InputMethodClient.START_INPUT_REASON_UNSPECIFIED:
                return "UNSPECIFIED";
            case InputMethodClient.START_INPUT_REASON_WINDOW_FOCUS_GAIN:
                return "WINDOW_FOCUS_GAIN";
            case InputMethodClient.START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY:
                return "WINDOW_FOCUS_GAIN_REPORT_ONLY";
            case InputMethodClient.START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API:
                return "APP_CALLED_RESTART_INPUT_API";
            case InputMethodClient.START_INPUT_REASON_CHECK_FOCUS:
                return "CHECK_FOCUS";
            case InputMethodClient.START_INPUT_REASON_BOUND_TO_IMMS:
                return "BOUND_TO_IMMS";
            case InputMethodClient.START_INPUT_REASON_UNBOUND_FROM_IMMS:
                return "UNBOUND_FROM_IMMS";
            case InputMethodClient.START_INPUT_REASON_ACTIVATED_BY_IMMS:
                return "ACTIVATED_BY_IMMS";
            case InputMethodClient.START_INPUT_REASON_DEACTIVATED_BY_IMMS:
                return "DEACTIVATED_BY_IMMS";
            case InputMethodClient.START_INPUT_REASON_SESSION_CREATED_BY_IME:
                return "SESSION_CREATED_BY_IME";
            default:
                return "Unknown=" + reason;
        }
    }

    /**
     * Converts {@link UnbindReason} to {@link String} for debug logging.
     *
     * @param reason integer constant for {@link UnbindReason}.
     * @return {@link String} message corresponds for the given {@code reason}.
     */
    public static String unbindReasonToString(@UnbindReason int reason) {
        switch (reason) {
            case InputMethodClient.UNBIND_REASON_UNSPECIFIED:
                return "UNSPECIFIED";
            case InputMethodClient.UNBIND_REASON_SWITCH_CLIENT:
                return "SWITCH_CLIENT";
            case InputMethodClient.UNBIND_REASON_SWITCH_IME:
                return "SWITCH_IME";
            case InputMethodClient.UNBIND_REASON_DISCONNECT_IME:
                return "DISCONNECT_IME";
            case InputMethodClient.UNBIND_REASON_NO_IME:
                return "NO_IME";
            case InputMethodClient.UNBIND_REASON_SWITCH_IME_FAILED:
                return "SWITCH_IME_FAILED";
            case InputMethodClient.UNBIND_REASON_SWITCH_USER:
                return "SWITCH_USER";
            default:
                return "Unknown=" + reason;
        }
    }

    /**
     * Converts {@link SoftInputModeFlags} to {@link String} for debug logging.
     *
     * @param softInputMode integer constant for {@link SoftInputModeFlags}.
     * @return {@link String} message corresponds for the given {@code softInputMode}.
     */
    public static String softInputModeToString(@SoftInputModeFlags int softInputMode) {
        final StringBuilder sb = new StringBuilder();
        final int state = softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_STATE;
        final int adjust = softInputMode & WindowManager.LayoutParams.SOFT_INPUT_MASK_ADJUST;
        final boolean isForwardNav =
                (softInputMode & WindowManager.LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0;

        switch (state) {
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
                sb.append("STATE_UNSPECIFIED");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
                sb.append("STATE_UNCHANGED");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN:
                sb.append("STATE_HIDDEN");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN:
                sb.append("STATE_ALWAYS_HIDDEN");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE:
                sb.append("STATE_VISIBLE");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
                sb.append("STATE_ALWAYS_VISIBLE");
                break;
            default:
                sb.append("STATE_UNKNOWN(");
                sb.append(state);
                sb.append(")");
                break;
        }

        switch (adjust) {
            case WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED:
                sb.append("|ADJUST_UNSPECIFIED");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE:
                sb.append("|ADJUST_RESIZE");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN:
                sb.append("|ADJUST_PAN");
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING:
                sb.append("|ADJUST_NOTHING");
                break;
            default:
                sb.append("|ADJUST_UNKNOWN(");
                sb.append(adjust);
                sb.append(")");
                break;
        }

        if (isForwardNav) {
            // This is a special bit that is set by the system only during the window navigation.
            sb.append("|IS_FORWARD_NAVIGATION");
        }

        return sb.toString();
    }
}
+0 −111
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@
package com.android.internal.view;

import android.annotation.IntDef;
import android.view.WindowManager.LayoutParams;
import android.view.WindowManager.LayoutParams.SoftInputModeFlags;

import java.lang.annotation.Retention;

@@ -44,33 +42,6 @@ public final class InputMethodClient {
            START_INPUT_REASON_DEACTIVATED_BY_IMMS, START_INPUT_REASON_SESSION_CREATED_BY_IME})
    public @interface StartInputReason {}

    public static String getStartInputReason(@StartInputReason final int reason) {
        switch (reason) {
            case START_INPUT_REASON_UNSPECIFIED:
                return "UNSPECIFIED";
            case START_INPUT_REASON_WINDOW_FOCUS_GAIN:
                return "WINDOW_FOCUS_GAIN";
            case START_INPUT_REASON_WINDOW_FOCUS_GAIN_REPORT_ONLY:
                return "WINDOW_FOCUS_GAIN_REPORT_ONLY";
            case START_INPUT_REASON_APP_CALLED_RESTART_INPUT_API:
                return "APP_CALLED_RESTART_INPUT_API";
            case START_INPUT_REASON_CHECK_FOCUS:
                return "CHECK_FOCUS";
            case START_INPUT_REASON_BOUND_TO_IMMS:
                return "BOUND_TO_IMMS";
            case START_INPUT_REASON_UNBOUND_FROM_IMMS:
                return "UNBOUND_FROM_IMMS";
            case START_INPUT_REASON_ACTIVATED_BY_IMMS:
                return "ACTIVATED_BY_IMMS";
            case START_INPUT_REASON_DEACTIVATED_BY_IMMS:
                return "DEACTIVATED_BY_IMMS";
            case START_INPUT_REASON_SESSION_CREATED_BY_IME:
                return "SESSION_CREATED_BY_IME";
            default:
                return "Unknown=" + reason;
        }
    }

    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;
@@ -84,86 +55,4 @@ public final class InputMethodClient {
            UNBIND_REASON_DISCONNECT_IME, UNBIND_REASON_NO_IME, UNBIND_REASON_SWITCH_IME_FAILED,
            UNBIND_REASON_SWITCH_USER})
    public @interface UnbindReason {}

    public static String getUnbindReason(@UnbindReason final int reason) {
        switch (reason) {
            case UNBIND_REASON_UNSPECIFIED:
                return "UNSPECIFIED";
            case UNBIND_REASON_SWITCH_CLIENT:
                return "SWITCH_CLIENT";
            case UNBIND_REASON_SWITCH_IME:
                return "SWITCH_IME";
            case UNBIND_REASON_DISCONNECT_IME:
                return "DISCONNECT_IME";
            case UNBIND_REASON_NO_IME:
                return "NO_IME";
            case UNBIND_REASON_SWITCH_IME_FAILED:
                return "SWITCH_IME_FAILED";
            case UNBIND_REASON_SWITCH_USER:
                return "SWITCH_USER";
            default:
                return "Unknown=" + reason;
        }
    }

    public static String softInputModeToString(@SoftInputModeFlags final int softInputMode) {
        final StringBuilder sb = new StringBuilder();
        final int state = softInputMode & LayoutParams.SOFT_INPUT_MASK_STATE;
        final int adjust = softInputMode & LayoutParams.SOFT_INPUT_MASK_ADJUST;
        final boolean isForwardNav =
                (softInputMode & LayoutParams.SOFT_INPUT_IS_FORWARD_NAVIGATION) != 0;

        switch (state) {
            case LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED:
                sb.append("STATE_UNSPECIFIED");
                break;
            case LayoutParams.SOFT_INPUT_STATE_UNCHANGED:
                sb.append("STATE_UNCHANGED");
                break;
            case LayoutParams.SOFT_INPUT_STATE_HIDDEN:
                sb.append("STATE_HIDDEN");
                break;
            case LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN:
                sb.append("STATE_ALWAYS_HIDDEN");
                break;
            case LayoutParams.SOFT_INPUT_STATE_VISIBLE:
                sb.append("STATE_VISIBLE");
                break;
            case LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
                sb.append("STATE_ALWAYS_VISIBLE");
                break;
            default:
                sb.append("STATE_UNKNOWN(");
                sb.append(state);
                sb.append(")");
                break;
        }

        switch (adjust) {
            case LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED:
                sb.append("|ADJUST_UNSPECIFIED");
                break;
            case LayoutParams.SOFT_INPUT_ADJUST_RESIZE:
                sb.append("|ADJUST_RESIZE");
                break;
            case LayoutParams.SOFT_INPUT_ADJUST_PAN:
                sb.append("|ADJUST_PAN");
                break;
            case LayoutParams.SOFT_INPUT_ADJUST_NOTHING:
                sb.append("|ADJUST_NOTHING");
                break;
            default:
                sb.append("|ADJUST_UNKNOWN(");
                sb.append(adjust);
                sb.append(")");
                break;
        }

        if (isForwardNav) {
            // This is a special bit that is set by the system only during the window navigation.
            sb.append("|IS_FORWARD_NAVIGATION");
        }

        return sb.toString();
    }
}
+7 −6
Original line number Diff line number Diff line
@@ -131,6 +131,7 @@ import com.android.internal.annotations.GuardedBy;
import com.android.internal.content.PackageMonitor;
import com.android.internal.inputmethod.IInputContentUriToken;
import com.android.internal.inputmethod.IInputMethodPrivilegedOperations;
import com.android.internal.inputmethod.InputMethodDebug;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.internal.notification.SystemNotificationChannels;
import com.android.internal.os.HandlerCaller;
@@ -842,7 +843,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                pw.println(" time=" + dataFormat.format(new Date(entry.mWallTime))
                        + " (timestamp=" + entry.mTimestamp + ")"
                        + " reason="
                        + InputMethodClient.getStartInputReason(entry.mStartInputReason)
                        + InputMethodDebug.startInputReasonToString(entry.mStartInputReason)
                        + " restarting=" + entry.mRestarting);

                pw.print(prefix);
@@ -854,7 +855,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                        + " clientBindSeq=" + entry.mClientBindSequenceNumber);

                pw.print(prefix);
                pw.println(" softInputMode=" + InputMethodClient.softInputModeToString(
                pw.println(" softInputMode=" + InputMethodDebug.softInputModeToString(
                                entry.mTargetWindowSoftInputMode));

                pw.print(prefix);
@@ -2752,7 +2753,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
        if (result == null) {
            // This must never happen, but just in case.
            Slog.wtf(TAG, "InputBindResult is @NonNull. startInputReason="
                    + InputMethodClient.getStartInputReason(startInputReason)
                    + InputMethodDebug.startInputReasonToString(startInputReason)
                    + " windowFlags=#" + Integer.toHexString(windowFlags)
                    + " editorInfo=" + attribute);
            return InputBindResult.NULL;
@@ -2775,14 +2776,14 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
                    mWindowManagerInternal.getDisplayIdForWindow(windowToken);
            synchronized (mMethodMap) {
                if (DEBUG) Slog.v(TAG, "startInputOrWindowGainedFocusInternal: reason="
                        + InputMethodClient.getStartInputReason(startInputReason)
                        + InputMethodDebug.startInputReasonToString(startInputReason)
                        + " client=" + client.asBinder()
                        + " inputContext=" + inputContext
                        + " missingMethods="
                        + InputConnectionInspector.getMissingMethodFlagsAsString(missingMethods)
                        + " attribute=" + attribute
                        + " controlFlags=#" + Integer.toHexString(controlFlags)
                        + " softInputMode=" + InputMethodClient.softInputModeToString(softInputMode)
                        + " softInputMode=" + InputMethodDebug.softInputModeToString(softInputMode)
                        + " windowFlags=#" + Integer.toHexString(windowFlags)
                        + " unverifiedTargetSdkVersion=" + unverifiedTargetSdkVersion);

@@ -4580,7 +4581,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
            p.println("  mCurClient=" + client + " mCurSeq=" + mCurSeq);
            p.println("  mCurFocusedWindow=" + mCurFocusedWindow
                    + " softInputMode=" +
                    InputMethodClient.softInputModeToString(mCurFocusedWindowSoftInputMode)
                    InputMethodDebug.softInputModeToString(mCurFocusedWindowSoftInputMode)
                    + " client=" + mCurFocusedWindowClient);
            focusedWindowClient = mCurFocusedWindowClient;
            p.println("  mCurId=" + mCurId + " mHaveConnection=" + mHaveConnection