InputDispatcher: Do not change focus when using transferTouch
Since window focus requests are not fully synchronized between
InputDispatcher and WM, there can be adverse impacts of rapid gesture
transfers on the focused window. This is because when transferring
touch, we synthesize a pointer DOWN, and if that event id directed to a
non-focused window, Dispatcher will notify the policy that
onPointerDownOutsideFocus to get WM to change the focused window.
We want the concepts of touched windows and focused windows to be
orthogonal. To support this, change the behavior of the transferTouch
API to ensure that transfering touches don't result in changes in focus.
Bug: 324265767
Test: atest inputflinger_tests
Change-Id: I07607c6ac6c91a1a5ad4433b451aa8dfb23f42a7
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 6719006..3a18f25 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -3422,6 +3422,9 @@
InputTarget::Flags::WINDOW_IS_PARTIALLY_OBSCURED)) {
resolvedFlags |= AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED;
}
+ if (dispatchEntry->targetFlags.test(InputTarget::Flags::NO_FOCUS_CHANGE)) {
+ resolvedFlags |= AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE;
+ }
dispatchEntry->resolvedFlags = resolvedFlags;
if (resolvedAction != motionEntry.action) {
@@ -3496,8 +3499,7 @@
<< "~ dropping inconsistent event: " << *dispatchEntry;
return; // skip the inconsistent event
}
-
- if ((resolvedMotion->flags & AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE) &&
+ if ((dispatchEntry->resolvedFlags & AMOTION_EVENT_FLAG_NO_FOCUS_CHANGE) &&
(resolvedMotion->policyFlags & POLICY_FLAG_TRUSTED)) {
// Skip reporting pointer down outside focus to the policy.
break;
@@ -5612,6 +5614,8 @@
if (canReceiveForegroundTouches(*toWindowHandle->getInfo())) {
newTargetFlags |= InputTarget::Flags::FOREGROUND;
}
+ // Transferring touch focus using this API should not effect the focused window.
+ newTargetFlags |= InputTarget::Flags::NO_FOCUS_CHANGE;
state->addOrUpdateWindow(toWindowHandle, InputTarget::DispatchMode::AS_IS, newTargetFlags,
deviceId, pointers, downTimeInTarget);
@@ -7000,7 +7004,8 @@
if (newWallpaper != nullptr) {
nsecs_t downTimeInTarget = now();
- ftl::Flags<InputTarget::Flags> wallpaperFlags = oldTargetFlags & InputTarget::Flags::SPLIT;
+ ftl::Flags<InputTarget::Flags> wallpaperFlags = newTargetFlags;
+ wallpaperFlags |= oldTargetFlags & InputTarget::Flags::SPLIT;
wallpaperFlags |= InputTarget::Flags::WINDOW_IS_OBSCURED |
InputTarget::Flags::WINDOW_IS_PARTIALLY_OBSCURED;
state.addOrUpdateWindow(newWallpaper, InputTarget::DispatchMode::AS_IS, wallpaperFlags,