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

Commit f56c8ffc authored by Felix Stern's avatar Felix Stern
Browse files

Replace build time only Slog's in state computer and visibilityApplier with protolog

Currently, there are many Slog.d logs which are compiled out, if
DEBUG=false. To be able to enable logs without recompiling, this CL
replaces those logs with protologs.

Bug: 393561240
Flag: EXEMPT logs only
Test: Enable logs manually via: adb shell cmd protolog logcat enable IME_VIS_STATE_COMPUTER_DEBUG
Change-Id: Id939dffe69e96a1f3d7b3ab3096f497c3590084d
parent 0a40deba
Loading
Loading
Loading
Loading
+10 −14
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import static com.android.internal.inputmethod.SoftInputShowHideReason.REMOVE_IM
import static com.android.internal.inputmethod.SoftInputShowHideReason.SHOW_IME_SCREENSHOT_FROM_IMMS;
import static com.android.server.EventLogTags.IMF_HIDE_IME;
import static com.android.server.EventLogTags.IMF_SHOW_IME;
import static com.android.server.inputmethod.ImeProtoLogGroup.IME_VISIBILITY_APPLIER_DEBUG;
import static com.android.server.inputmethod.ImeVisibilityStateComputer.STATE_HIDE_IME;
import static com.android.server.inputmethod.ImeVisibilityStateComputer.STATE_HIDE_IME_EXPLICIT;
import static com.android.server.inputmethod.ImeVisibilityStateComputer.STATE_HIDE_IME_NOT_ALWAYS;
@@ -36,7 +37,6 @@ import android.annotation.UserIdInt;
import android.os.IBinder;
import android.os.ResultReceiver;
import android.util.EventLog;
import android.util.Slog;
import android.view.MotionEvent;
import android.view.inputmethod.Flags;
import android.view.inputmethod.ImeTracker;
@@ -46,6 +46,7 @@ import android.view.inputmethod.InputMethodManager;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.inputmethod.InputMethodDebug;
import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.internal.protolog.ProtoLog;
import com.android.server.LocalServices;
import com.android.server.wm.ImeTargetVisibilityPolicy;
import com.android.server.wm.WindowManagerInternal;
@@ -58,9 +59,7 @@ import java.util.Objects;
 */
final class DefaultImeVisibilityApplier {

    private static final String TAG = "DefaultImeVisibilityApplier";

    private static final boolean DEBUG = InputMethodManagerService.DEBUG;
    static final String TAG = "DefaultImeVisibilityApplier";

    private InputMethodManagerService mService;

@@ -93,11 +92,10 @@ final class DefaultImeVisibilityApplier {
        final var bindingController = userData.mBindingController;
        final IInputMethodInvoker curMethod = bindingController.getCurMethod();
        if (curMethod != null) {
            if (DEBUG) {
                Slog.v(TAG, "Calling " + curMethod + ".showSoftInput(" + showInputToken
                        + ", " + showFlags + ", " + resultReceiver + ") for reason: "
                        + InputMethodDebug.softInputDisplayReasonToString(reason));
            }
            ProtoLog.v(IME_VISIBILITY_APPLIER_DEBUG,
                    "Calling %s.showSoftInput(%s, %s, %s) for reason: %s", curMethod,
                    showInputToken, showFlags, resultReceiver,
                    InputMethodDebug.softInputDisplayReasonToString(reason));
            // TODO(b/192412909): Check if we can always call onShowHideSoftInputRequested() or not.
            if (curMethod.showSoftInput(showInputToken, statsToken, showFlags, resultReceiver)) {
                if (DEBUG_IME_VISIBILITY) {
@@ -136,11 +134,9 @@ final class DefaultImeVisibilityApplier {
            // delivered to the IME process as an IPC.  Hence the inconsistency between
            // IMMS#mInputShown and IMMS#mImeWindowVis should be resolved spontaneously in
            // the final state.
            if (DEBUG) {
                Slog.v(TAG, "Calling " + curMethod + ".hideSoftInput(0, " + hideInputToken
                        + ", " + resultReceiver + ") for reason: "
                        + InputMethodDebug.softInputDisplayReasonToString(reason));
            }
            ProtoLog.v(IME_VISIBILITY_APPLIER_DEBUG,
                    "Calling %s.hideSoftInput(0, %s, %s) for reason: %s", curMethod, hideInputToken,
                    resultReceiver, InputMethodDebug.softInputDisplayReasonToString(reason));
            // TODO(b/192412909): Check if we can always call onShowHideSoftInputRequested() or not.
            if (curMethod.hideSoftInput(hideInputToken, statsToken, 0, resultReceiver)) {
                if (DEBUG_IME_VISIBILITY) {
+5 −1
Original line number Diff line number Diff line
@@ -23,7 +23,11 @@ import java.util.UUID;
public enum ImeProtoLogGroup implements IProtoLogGroup {
    // TODO(b/393561240): add info/warn/error log level and replace in IMMS
    IMMS_DEBUG(Consts.ENABLE_DEBUG, false, false,
            InputMethodManagerService.TAG);
            InputMethodManagerService.TAG),
    IME_VISIBILITY_APPLIER_DEBUG(Consts.ENABLE_DEBUG, false, false,
            DefaultImeVisibilityApplier.TAG),
    IME_VIS_STATE_COMPUTER_DEBUG(Consts.ENABLE_DEBUG, false, false,
            ImeVisibilityStateComputer.TAG);

    private final boolean mEnabled;
    private volatile boolean mLogToProto;
+22 −16
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static android.view.WindowManager.LayoutParams.SoftInputModeFlags;
import static com.android.internal.inputmethod.InputMethodDebug.softInputModeToString;
import static com.android.internal.inputmethod.SoftInputShowHideReason.REMOVE_IME_SCREENSHOT_FROM_IMMS;
import static com.android.internal.inputmethod.SoftInputShowHideReason.SHOW_IME_SCREENSHOT_FROM_IMMS;
import static com.android.server.inputmethod.ImeProtoLogGroup.IME_VIS_STATE_COMPUTER_DEBUG;
import static com.android.server.inputmethod.InputMethodManagerService.computeImeDisplayIdForTarget;

import android.accessibilityservice.AccessibilityService;
@@ -58,6 +59,7 @@ import android.view.inputmethod.InputMethodManager;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.inputmethod.SoftInputShowHideReason;
import com.android.internal.protolog.ProtoLog;
import com.android.server.LocalServices;
import com.android.server.pm.UserManagerInternal;
import com.android.server.wm.WindowManagerInternal;
@@ -72,9 +74,7 @@ import java.util.WeakHashMap;
 */
public final class ImeVisibilityStateComputer {

    private static final String TAG = "ImeVisibilityStateComputer";

    private static final boolean DEBUG = InputMethodManagerService.DEBUG;
    static final String TAG = "ImeVisibilityStateComputer";

    @UserIdInt
    private final int mUserId;
@@ -292,12 +292,14 @@ public final class ImeVisibilityStateComputer {
            @InputMethodManager.HideFlags int hideFlags) {
        if ((hideFlags & InputMethodManager.HIDE_IMPLICIT_ONLY) != 0
                && (mRequestedShowExplicitly || mShowForced)) {
            if (DEBUG) Slog.v(TAG, "Not hiding: explicit show not cancelled by non-explicit hide");
            ProtoLog.v(IME_VIS_STATE_COMPUTER_DEBUG,
                    "Not hiding: explicit show not cancelled by non-explicit hide");
            ImeTracker.forLogging().onFailed(statsToken, ImeTracker.PHASE_SERVER_HIDE_IMPLICIT);
            return false;
        }
        if (mShowForced && (hideFlags & InputMethodManager.HIDE_NOT_ALWAYS) != 0) {
            if (DEBUG) Slog.v(TAG, "Not hiding: forced show not cancelled by not-always hide");
            ProtoLog.v(IME_VIS_STATE_COMPUTER_DEBUG,
                    "Not hiding: forced show not cancelled by not-always hide");
            ImeTracker.forLogging().onFailed(statsToken, ImeTracker.PHASE_SERVER_HIDE_NOT_ALWAYS);
            return false;
        }
@@ -417,8 +419,8 @@ public final class ImeVisibilityStateComputer {

    @GuardedBy("ImfLock.class")
    private void setWindowStateInner(IBinder windowToken, @NonNull ImeTargetWindowState newState) {
        if (DEBUG) Slog.d(TAG, "setWindowStateInner, windowToken=" + windowToken
                + ", state=" + newState);
        ProtoLog.v(IME_VIS_STATE_COMPUTER_DEBUG, "setWindowStateInner, windowToken=%s, state=%s",
                windowToken, newState);
        mRequestWindowStateMap.put(windowToken, newState);
    }

@@ -466,7 +468,7 @@ public final class ImeVisibilityStateComputer {
        // Because the app might leverage these flags to hide soft-keyboard with showing their own
        // UI for input.
        if (state.hasEditorFocused() && shouldRestoreImeVisibility(state)) {
            if (DEBUG) Slog.v(TAG, "Will show input to restore visibility");
            ProtoLog.v(IME_VIS_STATE_COMPUTER_DEBUG, "Will show input to restore visibility");
            // Inherit the last requested IME visible state when the target window is still
            // focused with an editor.
            state.setRequestedImeVisible(true);
@@ -483,7 +485,8 @@ public final class ImeVisibilityStateComputer {
                        // There is no focus view, and this window will
                        // be behind any soft input window, so hide the
                        // soft input window if it is shown.
                        if (DEBUG) Slog.v(TAG, "Unspecified window will hide input");
                        ProtoLog.v(IME_VIS_STATE_COMPUTER_DEBUG,
                                "Unspecified window will hide input");
                        return new ImeVisibilityResult(STATE_HIDE_IME_NOT_ALWAYS,
                                SoftInputShowHideReason.HIDE_UNSPECIFIED_WINDOW);
                    }
@@ -495,7 +498,7 @@ public final class ImeVisibilityStateComputer {
                    // them good context without input information being obscured
                    // by the IME) or if running on a large screen where there
                    // is more room for the target window + IME.
                    if (DEBUG) Slog.v(TAG, "Unspecified window will show input");
                    ProtoLog.v(IME_VIS_STATE_COMPUTER_DEBUG, "Unspecified window will show input");
                    return new ImeVisibilityResult(STATE_SHOW_IME_IMPLICIT,
                            SoftInputShowHideReason.SHOW_AUTO_EDITOR_FORWARD_NAV);
                }
@@ -513,7 +516,8 @@ public final class ImeVisibilityStateComputer {
                    // the WindowState, as they're already in the correct state
                    break;
                } else if (isForwardNavigation) {
                    if (DEBUG) Slog.v(TAG, "Window asks to hide input going forward");
                    ProtoLog.v(IME_VIS_STATE_COMPUTER_DEBUG,
                            "Window asks to hide input going forward");
                    return new ImeVisibilityResult(STATE_HIDE_IME_EXPLICIT,
                            SoftInputShowHideReason.HIDE_STATE_HIDDEN_FORWARD_NAV);
                }
@@ -524,7 +528,7 @@ public final class ImeVisibilityStateComputer {
                    // the WindowState, as they're already in the correct state
                    break;
                } else if (state.hasImeFocusChanged()) {
                    if (DEBUG) Slog.v(TAG, "Window asks to hide input");
                    ProtoLog.v(IME_VIS_STATE_COMPUTER_DEBUG, "Window asks to hide input");
                    return new ImeVisibilityResult(STATE_HIDE_IME_EXPLICIT,
                            SoftInputShowHideReason.HIDE_ALWAYS_HIDDEN_STATE);
                }
@@ -532,7 +536,8 @@ public final class ImeVisibilityStateComputer {
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE:
                if (isForwardNavigation) {
                    if (allowVisible) {
                        if (DEBUG) Slog.v(TAG, "Window asks to show input going forward");
                        ProtoLog.v(IME_VIS_STATE_COMPUTER_DEBUG,
                                "Window asks to show input going forward");
                        return new ImeVisibilityResult(STATE_SHOW_IME_IMPLICIT,
                                SoftInputShowHideReason.SHOW_STATE_VISIBLE_FORWARD_NAV);
                    } else {
@@ -543,7 +548,7 @@ public final class ImeVisibilityStateComputer {
                }
                break;
            case WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE:
                if (DEBUG) Slog.v(TAG, "Window asks to always show input");
                ProtoLog.v(IME_VIS_STATE_COMPUTER_DEBUG, "Window asks to always show input");
                if (allowVisible) {
                    if (state.hasImeFocusChanged()) {
                        return new ImeVisibilityResult(STATE_SHOW_IME_IMPLICIT,
@@ -565,7 +570,8 @@ public final class ImeVisibilityStateComputer {
            // To maintain compatibility, we are now hiding the IME when we don't have
            // an editor upon refocusing a window.
            if (state.isStartInputByGainFocus()) {
                if (DEBUG) Slog.v(TAG, "Same window without editor will hide input");
                ProtoLog.v(IME_VIS_STATE_COMPUTER_DEBUG,
                        "Same window without editor will hide input");
                return new ImeVisibilityResult(STATE_HIDE_IME_EXPLICIT,
                        SoftInputShowHideReason.HIDE_SAME_WINDOW_FOCUSED_WITHOUT_EDITOR);
            }
@@ -579,7 +585,7 @@ public final class ImeVisibilityStateComputer {
            // 1) SOFT_INPUT_STATE_UNCHANGED state without an editor
            // 2) SOFT_INPUT_STATE_VISIBLE state without an editor
            // 3) SOFT_INPUT_STATE_ALWAYS_VISIBLE state without an editor
            if (DEBUG) Slog.v(TAG, "Window without editor will hide input");
            ProtoLog.v(IME_VIS_STATE_COMPUTER_DEBUG, "Window without editor will hide input");
            if (Flags.refactorInsetsController()) {
                state.setRequestedImeVisible(false);
            }