Do not re-use the same EventEntry and DispatchEntry for fallback keys
Re-using the same EventEntry and DispatchEntry for fallbacks is
incorrect. A fallback can be thought of as a completely new event
generated for a channel, in which case it should not share the same
eventId as the original event.
Re-using the same DispatchEntry leads to the incorrect behavior, since
the expected flags in the event will be overridden by the the
resolvedFlags (and other resolved fields) from the old DispatchEntry.
This CL also fixed this incorrect behavior, which is verified with the
new tests added in the following CL.
Bug: 210460522
Test: atest inputflinger_tests
Change-Id: I30fd72a7da85043ea19fedaace41e79b20c85645
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index e428c4e..f0f6772 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -660,12 +660,10 @@
void updateLastAnrStateLocked(const std::string& windowLabel, const std::string& reason)
REQUIRES(mLock);
std::map<int32_t /*displayId*/, InputVerifier> mVerifiersByDisplay;
- bool afterKeyEventLockedInterruptable(const std::shared_ptr<Connection>& connection,
- DispatchEntry& dispatchEntry, KeyEntry& keyEntry,
- bool handled) REQUIRES(mLock);
- bool afterMotionEventLockedInterruptable(const std::shared_ptr<Connection>& connection,
- DispatchEntry& dispatchEntry, MotionEntry& motionEntry,
- bool handled) REQUIRES(mLock);
+ // Returns a fallback KeyEntry that should be sent to the connection, if required.
+ std::unique_ptr<KeyEntry> afterKeyEventLockedInterruptable(
+ const std::shared_ptr<Connection>& connection, DispatchEntry& dispatchEntry,
+ const KeyEntry& keyEntry, bool handled) REQUIRES(mLock);
// Find touched state and touched window by token.
std::tuple<TouchState*, TouchedWindow*, int32_t /*displayId*/>