VerifiedMotionEvent: Sign transformed raw values
The values for axes X/Y that are stored in MotionEvent are
transformed to values used for its getRaw API based on the source.
This is because non-pointer sources should not have translation applied
to them.
We need to ensure that we use the same raw coordinates when we sign a
VerifiedMotionEvent in InputDispatcher that we would get with the
MotionEvent#getRaw API. To do this, we re-use the same logic used to
transform the raw coordinates in MotionEvent in InputDispatcher.
Bug: 179274888
Test: atest inputflinger_tests
Test: atest VerifyInputEventTest
Change-Id: I552f94064f15573ddda8f7c0b588cd3b984b6a94
diff --git a/services/inputflinger/dispatcher/Entry.cpp b/services/inputflinger/dispatcher/Entry.cpp
index bcb0071..c03581d 100644
--- a/services/inputflinger/dispatcher/Entry.cpp
+++ b/services/inputflinger/dispatcher/Entry.cpp
@@ -40,14 +40,15 @@
entry.repeatCount};
}
-VerifiedMotionEvent verifiedMotionEventFromMotionEntry(const MotionEntry& entry) {
- const float rawX = entry.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_X);
- const float rawY = entry.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_Y);
+VerifiedMotionEvent verifiedMotionEventFromMotionEntry(const MotionEntry& entry,
+ const ui::Transform& rawTransform) {
+ const vec2 rawXY = MotionEvent::calculateTransformedXY(entry.source, rawTransform,
+ entry.pointerCoords[0].getXYValue());
const int actionMasked = entry.action & AMOTION_EVENT_ACTION_MASK;
return {{VerifiedInputEvent::Type::MOTION, entry.deviceId, entry.eventTime, entry.source,
entry.displayId},
- rawX,
- rawY,
+ rawXY.x,
+ rawXY.y,
actionMasked,
entry.downTime,
entry.flags & VERIFIED_MOTION_EVENT_FLAGS,
diff --git a/services/inputflinger/dispatcher/Entry.h b/services/inputflinger/dispatcher/Entry.h
index 7a121ce..477781a 100644
--- a/services/inputflinger/dispatcher/Entry.h
+++ b/services/inputflinger/dispatcher/Entry.h
@@ -254,7 +254,8 @@
};
VerifiedKeyEvent verifiedKeyEventFromKeyEntry(const KeyEntry& entry);
-VerifiedMotionEvent verifiedMotionEventFromMotionEntry(const MotionEntry& entry);
+VerifiedMotionEvent verifiedMotionEventFromMotionEntry(const MotionEntry& entry,
+ const ui::Transform& rawTransform);
} // namespace android::inputdispatcher
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 695dd17..52a88d7 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -3360,16 +3360,18 @@
const std::array<uint8_t, 32> InputDispatcher::getSignature(
const MotionEntry& motionEntry, const DispatchEntry& dispatchEntry) const {
- int32_t actionMasked = dispatchEntry.resolvedAction & AMOTION_EVENT_ACTION_MASK;
- if ((actionMasked == AMOTION_EVENT_ACTION_UP) || (actionMasked == AMOTION_EVENT_ACTION_DOWN)) {
+ const int32_t actionMasked = dispatchEntry.resolvedAction & AMOTION_EVENT_ACTION_MASK;
+ if (actionMasked != AMOTION_EVENT_ACTION_UP && actionMasked != AMOTION_EVENT_ACTION_DOWN) {
// Only sign events up and down events as the purely move events
// are tied to their up/down counterparts so signing would be redundant.
- VerifiedMotionEvent verifiedEvent = verifiedMotionEventFromMotionEntry(motionEntry);
- verifiedEvent.actionMasked = actionMasked;
- verifiedEvent.flags = dispatchEntry.resolvedFlags & VERIFIED_MOTION_EVENT_FLAGS;
- return sign(verifiedEvent);
+ return INVALID_HMAC;
}
- return INVALID_HMAC;
+
+ VerifiedMotionEvent verifiedEvent =
+ verifiedMotionEventFromMotionEntry(motionEntry, dispatchEntry.rawTransform);
+ verifiedEvent.actionMasked = actionMasked;
+ verifiedEvent.flags = dispatchEntry.resolvedFlags & VERIFIED_MOTION_EVENT_FLAGS;
+ return sign(verifiedEvent);
}
const std::array<uint8_t, 32> InputDispatcher::getSignature(