Move input event verify for publish to back of sendMessage
Currently, in InputTransport, we support verifying events intended to
be published. This verification occurs before sendMessage. If the
application processes events too slowly at this time, it can lead to an
excessive number of events in the pipeline, preventing further sending.
In such cases, we return a status to the dispatcher to allow it to send
the event later. If the action of this event is DOWN or UP, the
InputVerifier will receive multiple events with action DOWN or UP,
which can cause problems with event verification, leading to abnormal
device crashes.
Here, we move the verification of the event to after sendMessage
succeeds. This resolves the issue because we only verify events that
have been successfully sent. Although this may cause the original logic
to change (potentially sending an incorrect stream of events to the
application), in reality, when an error occurs, the device has already
rebooted, so there is no impact.
Bug: 373764868
Flag: EXEMPT bugfix
Test: presubmit
Signed-off-by: Linnan Li <lilinnan@xiaomi.corp-partner.google.com>
(cherry picked from https://partner-android-review.googlesource.com/q/commit:586c7ba1af39fd81190e977fd8ecc570144d37da)
Merged-In: I74003e5d0eece9007db09cd98a60f616e0e7e22a
Change-Id: I74003e5d0eece9007db09cd98a60f616e0e7e22a
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp
index 77dcaa9..6a55726 100644
--- a/libs/input/InputTransport.cpp
+++ b/libs/input/InputTransport.cpp
@@ -583,15 +583,6 @@
StringPrintf("publishMotionEvent(inputChannel=%s, action=%s)",
mChannel->getName().c_str(),
MotionEvent::actionToString(action).c_str()));
- if (verifyEvents()) {
- Result<void> result =
- mInputVerifier.processMovement(deviceId, source, action, pointerCount,
- pointerProperties, pointerCoords, flags);
- if (!result.ok()) {
- LOG(ERROR) << "Bad stream: " << result.error();
- return BAD_VALUE;
- }
- }
if (debugTransportPublisher()) {
std::string transformString;
transform.dump(transformString, "transform", " ");
@@ -657,8 +648,18 @@
msg.body.motion.pointers[i].properties = pointerProperties[i];
msg.body.motion.pointers[i].coords = pointerCoords[i];
}
+ const status_t status = mChannel->sendMessage(&msg);
- return mChannel->sendMessage(&msg);
+ if (status == OK && verifyEvents()) {
+ Result<void> result =
+ mInputVerifier.processMovement(deviceId, source, action, pointerCount,
+ pointerProperties, pointerCoords, flags);
+ if (!result.ok()) {
+ LOG(ERROR) << "Bad stream: " << result.error();
+ return BAD_VALUE;
+ }
+ }
+ return status;
}
status_t InputPublisher::publishFocusEvent(uint32_t seq, int32_t eventId, bool hasFocus) {