From 7965f957e752737c31bae6d9e0c6f1ee3ff80496 Mon Sep 17 00:00:00 2001 From: HQ Liu Date: Wed, 4 May 2022 09:50:03 -0700 Subject: [PATCH] Prevent to revoke input focus from recentsAnimationInputConsumer During recents animation, there are increasing number of ANR, that is because the input focus is suppose to be on the recents_animation_input_consumer, but the focus is revoked falsely. To fix the issue, stop sending requet to remove focus when the focus is on the input consumer. Bug: 222232784 Bug: 223750399 Test: manual Change-Id: Id19d64d8027a07dc9a1236d10b9e1185ebc717c4 --- core/jni/android_view_SurfaceControl.cpp | 1 + .../java/com/android/server/wm/InputMonitor.java | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/core/jni/android_view_SurfaceControl.cpp b/core/jni/android_view_SurfaceControl.cpp index c769da57eecc4..4044c579a57fd 100644 --- a/core/jni/android_view_SurfaceControl.cpp +++ b/core/jni/android_view_SurfaceControl.cpp @@ -1921,6 +1921,7 @@ static void nativeRemoveCurrentInputFocus(JNIEnv* env, jclass clazz, jlong trans FocusRequest request; request.timestamp = systemTime(SYSTEM_TIME_MONOTONIC); request.displayId = displayId; + request.windowName = ""; transaction->setFocusedWindow(request); } diff --git a/services/core/java/com/android/server/wm/InputMonitor.java b/services/core/java/com/android/server/wm/InputMonitor.java index 65062e576d550..1ddd0b2e2c957 100644 --- a/services/core/java/com/android/server/wm/InputMonitor.java +++ b/services/core/java/com/android/server/wm/InputMonitor.java @@ -416,8 +416,22 @@ final class InputMonitor { final IBinder focusToken = focus != null ? focus.mInputChannelToken : null; if (focusToken == null) { + if (recentsAnimationInputConsumer != null + && recentsAnimationInputConsumer.mWindowHandle != null + && mInputFocus == recentsAnimationInputConsumer.mWindowHandle.token) { + // Avoid removing input focus from recentsAnimationInputConsumer. + // When the recents animation input consumer has the input focus, + // mInputFocus does not match to mDisplayContent.mCurrentFocus. Making it to be + // a special case, that do not remove the input focus from it when + // mDisplayContent.mCurrentFocus is null. This special case should be removed + // once recentAnimationInputConsumer is removed. + return; + } // When an app is focused, but its window is not showing yet, remove the input focus - // from the current window. + // from the current window. This enforces the input focus to match + // mDisplayContent.mCurrentFocus. However, if more special cases are discovered that + // the input focus and mDisplayContent.mCurrentFocus are expected to mismatch, + // the whole logic of how and when to revoke focus needs to be checked. if (mDisplayContent.mFocusedApp != null && mInputFocus != null) { ProtoLog.v(WM_DEBUG_FOCUS_LIGHT, "App %s is focused," + " but the window is not ready. Start a transaction to remove focus from"