From 134d218f787fbfea3b64df8528c81c0a5baa0493 Mon Sep 17 00:00:00 2001 From: Vishnu Nair Date: Thu, 29 Oct 2020 17:32:00 -0700 Subject: [PATCH] Add logs to track focus changes Adds an entry to the input event log when WM requests a focus change and to logcat when a request is dropped. Bug: 171130500 Test: adb logcat -b events | grep input_focus Change-Id: I48f434de1f6992a9c3dbf83f7782cd3e9b57b5af --- .../java/com/android/server/wm/InputMonitor.java | 9 ++++++--- .../android/server/wm/WindowManagerService.java | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java index 470c2b1581d09..4a54196b71de9 100644 --- a/services/core/java/com/android/server/wm/InputMonitor.java +++ b/services/core/java/com/android/server/wm/InputMonitor.java @@ -45,6 +45,7 @@ import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER; import static com.android.internal.protolog.ProtoLogGroup.WM_DEBUG_FOCUS_LIGHT; import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_INPUT; import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM; +import static com.android.server.wm.WindowManagerService.LOGTAG_INPUT_FOCUS; import android.graphics.Rect; import android.os.Handler; @@ -54,6 +55,7 @@ import android.os.Process; import android.os.Trace; import android.os.UserHandle; import android.util.ArrayMap; +import android.util.EventLog; import android.util.Slog; import android.view.InputApplicationHandle; import android.view.InputChannel; @@ -503,13 +505,14 @@ final class InputMonitor { } if (!focus.mWinAnimator.hasSurface()) { - ProtoLog.d(WM_DEBUG_FOCUS_LIGHT, - "Focus not requested for window=%s because it has no surface", - focus); + Slog.v(TAG_WM, "Focus not requested for window=%" + focus + + " because it has no surface."); return; } mInputTransaction.setFocusedWindow(focus.mInputWindowHandle.token, mDisplayId); + EventLog.writeEvent(LOGTAG_INPUT_FOCUS, + "Focus request " + focus, "reason=UpdateInputWindows"); mDisplayContent.mLastRequestedFocus = focus; ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "Focus requested for window=%s", focus); } diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 5bbd24918ec75..410b22a155ac6 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -206,6 +206,7 @@ import android.text.format.DateUtils; import android.util.ArrayMap; import android.util.ArraySet; import android.util.DisplayMetrics; +import android.util.EventLog; import android.util.MergedConfiguration; import android.util.Slog; import android.util.SparseArray; @@ -407,6 +408,7 @@ public class WindowManagerService extends IWindowManager.Stub */ private static final String DISABLE_CUSTOM_TASK_ANIMATION_PROPERTY = "persist.wm.disable_custom_task_animation"; + static final int LOGTAG_INPUT_FOCUS = 62001; /** * @see #DISABLE_CUSTOM_TASK_ANIMATION_PROPERTY @@ -8345,6 +8347,9 @@ public class WindowManagerService extends IWindowManager.Stub final int displayId = embeddedWindow.mDisplayId; if (grantFocus) { t.setFocusedWindow(targetInputToken, displayId).apply(); + EventLog.writeEvent(LOGTAG_INPUT_FOCUS, + "Focus request " + embeddedWindow.getName(), + "reason=grantEmbeddedWindowFocus(true)"); } else { // Search for a new focus target DisplayContent displayContent = mRoot.getDisplayContent(displayId); @@ -8358,6 +8363,9 @@ public class WindowManagerService extends IWindowManager.Stub } t.requestFocusTransfer(newFocusTarget.mInputWindowHandle.token, targetInputToken, displayId).apply(); + EventLog.writeEvent(LOGTAG_INPUT_FOCUS, + "Transfer focus request " + newFocusTarget, + "reason=grantEmbeddedWindowFocus(false)"); } ProtoLog.v(WM_DEBUG_FOCUS, "grantEmbeddedWindowFocus win=%s grantFocus=%s", embeddedWindow.getName(), grantFocus); @@ -8391,9 +8399,15 @@ public class WindowManagerService extends IWindowManager.Stub if (grantFocus) { t.requestFocusTransfer(targetInputToken, hostWindow.mInputChannel.getToken(), hostWindow.getDisplayId()).apply(); + EventLog.writeEvent(LOGTAG_INPUT_FOCUS, + "Transfer focus request " + embeddedWindow.getName(), + "reason=grantEmbeddedWindowFocus(true)"); } else { t.requestFocusTransfer(hostWindow.mInputChannel.getToken(), targetInputToken, hostWindow.getDisplayId()).apply(); + EventLog.writeEvent(LOGTAG_INPUT_FOCUS, + "Transfer focus request " + hostWindow, + "reason=grantEmbeddedWindowFocus(false)"); } ProtoLog.v(WM_DEBUG_FOCUS, "grantEmbeddedWindowFocus win=%s grantFocus=%s", embeddedWindow.getName(), grantFocus);