Fix input injection with zero coords
In the native MotionEvent class, setting an axis value to 0 is
equivalent to removing the axis from the bitfield of valid axes. This is
because getting an axis value that is not set in the bitfield will
return 0 by default.
This means that we cannot rely on the bitfield of valid axes to know
exactly which axes are valid, since all axes are always valid with a
default value of 0.
Rather than transforming only the axies that are set in the bitfield, we
add a helper function to MotionEvent to transform the entire
PointerCoords.
Bug: 219711163
Test: manual, see bug: adb shell input draganddrop 665 531 0 531 1000
Change-Id: I335beebf8263a38f180f2f4c6a788fbd69d15a6f
Merged-In: I335beebf8263a38f180f2f4c6a788fbd69d15a6f
(cherry picked from commit 890532e49c0e329c0c462fb2733c5ae27a395b7b)
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 58c9303..2eb9bd3 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -4426,19 +4426,9 @@
const auto& transformToDisplay = it->second.transform.inverse() * injectedTransform;
for (uint32_t i = 0; i < entry.pointerCount; i++) {
- PointerCoords& pc = entry.pointerCoords[i];
- // Make a copy of the injected coords. We cannot change them in place because some of them
- // are interdependent (for example, X coordinate might depend on the Y coordinate).
- PointerCoords injectedCoords = entry.pointerCoords[i];
-
- BitSet64 bits(injectedCoords.bits);
- while (!bits.isEmpty()) {
- const auto axis = static_cast<int32_t>(bits.clearFirstMarkedBit());
- const float value =
- MotionEvent::calculateTransformedAxisValue(axis, entry.source,
- transformToDisplay, injectedCoords);
- pc.setAxisValue(axis, value);
- }
+ entry.pointerCoords[i] =
+ MotionEvent::calculateTransformedCoords(entry.source, transformToDisplay,
+ entry.pointerCoords[i]);
}
}