From a307ac7c6afc35099f3ab8dff180843fe8795d84 Mon Sep 17 00:00:00 2001 From: Wilson Wu Date: Wed, 30 Nov 2022 17:03:34 +0800 Subject: [PATCH] Improve IMF visibility log (1/N) Add event log to record the show/hide IME request InputMethodManagerService. The log includes focused window, visibility reason, soft input mode, and use the tag of ImeTracker.Token for identification. The log is only enabled for debug builds. Bug: 239501597 Test: presubmit Change-Id: I3b4d16ae441ce0628febfb6e18a54aae86cdab4a --- .../java/android/view/inputmethod/ImeTracker.java | 6 ++++++ .../java/com/android/server/EventLogTags.logtags | 4 ++++ .../inputmethod/InputMethodManagerService.java | 15 +++++++++++++++ .../server/wm/WindowManagerDebugConfig.java | 3 +++ 4 files changed, 28 insertions(+) diff --git a/core/java/android/view/inputmethod/ImeTracker.java b/core/java/android/view/inputmethod/ImeTracker.java index f4ecdff12c7a0..927d7698985bf 100644 --- a/core/java/android/view/inputmethod/ImeTracker.java +++ b/core/java/android/view/inputmethod/ImeTracker.java @@ -423,6 +423,12 @@ public interface ImeTracker { mTag = tag; } + /** Returns the {@link Token#mTag} */ + @NonNull + public String getTag() { + return mTag; + } + /** For Parcelable, no special marshalled objects. */ @Override public int describeContents() { diff --git a/services/core/java/com/android/server/EventLogTags.logtags b/services/core/java/com/android/server/EventLogTags.logtags index 68fd0c12bea84..274370e371518 100644 --- a/services/core/java/com/android/server/EventLogTags.logtags +++ b/services/core/java/com/android/server/EventLogTags.logtags @@ -185,6 +185,10 @@ option java_package com.android.server # --------------------------- # Re-connecting to input method service because we haven't received its interface 32000 imf_force_reconnect_ime (IME|4),(Time Since Connect|2|3),(Showing|1|1) +# Indicates server show input method +32001 imf_show_ime (token|3),(window|3),(reason|3),(softInputMode|3) +# Indicates server hide input method +32002 imf_hide_ime (token|3),(window|3),(reason|3),(softInputMode|3) # --------------------------- diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 080d5829f9d91..97c8305f546f0 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -49,8 +49,11 @@ import static android.view.Display.INVALID_DISPLAY; import static android.view.WindowManager.DISPLAY_IME_POLICY_HIDE; import static android.view.WindowManager.DISPLAY_IME_POLICY_LOCAL; +import static com.android.server.EventLogTags.IMF_HIDE_IME; +import static com.android.server.EventLogTags.IMF_SHOW_IME; import static com.android.server.inputmethod.InputMethodBindingController.TIME_TO_RECONNECT; import static com.android.server.inputmethod.InputMethodUtils.isSoftInputModeStateVisibleAllowed; +import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_IME_VISIBILITY; import static java.lang.annotation.RetentionPolicy.SOURCE; @@ -3439,6 +3442,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub } // TODO(b/192412909): Check if we can always call onShowHideSoftInputRequested() or not. if (curMethod.showSoftInput(showInputToken, statsToken, showFlags, resultReceiver)) { + if (DEBUG_IME_VISIBILITY) { + EventLog.writeEvent(IMF_SHOW_IME, statsToken.getTag(), + Objects.toString(mCurFocusedWindow), + InputMethodDebug.softInputDisplayReasonToString(reason), + InputMethodDebug.softInputModeToString(mCurFocusedWindowSoftInputMode)); + } onShowHideSoftInputRequested(true /* show */, windowToken, reason); } mInputShown = true; @@ -3537,6 +3546,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub // TODO(b/192412909): Check if we can always call onShowHideSoftInputRequested() or not. if (curMethod.hideSoftInput(hideInputToken, statsToken, 0 /* flags */, resultReceiver)) { + if (DEBUG_IME_VISIBILITY) { + EventLog.writeEvent(IMF_HIDE_IME, statsToken.getTag(), + Objects.toString(mCurFocusedWindow), + InputMethodDebug.softInputDisplayReasonToString(reason), + InputMethodDebug.softInputModeToString(mCurFocusedWindowSoftInputMode)); + } onShowHideSoftInputRequested(false /* show */, windowToken, reason); } res = true; diff --git a/services/core/java/com/android/server/wm/WindowManagerDebugConfig.java b/services/core/java/com/android/server/wm/WindowManagerDebugConfig.java index 42b556f77ab61..6abb8fdfca6cc 100644 --- a/services/core/java/com/android/server/wm/WindowManagerDebugConfig.java +++ b/services/core/java/com/android/server/wm/WindowManagerDebugConfig.java @@ -56,4 +56,7 @@ public class WindowManagerDebugConfig { static final boolean SHOW_STACK_CRAWLS = false; static final boolean DEBUG_WINDOW_CROP = false; static final boolean DEBUG_UNKNOWN_APP_VISIBILITY = false; + + // TODO(b/239501597) : Have a system property to control this flag. + public static final boolean DEBUG_IME_VISIBILITY = false; }