Make EventEntry const throughout the Dispatcher pipieline
This will help ensure that parts of the event do not change throughout
the dispatching pipieline after they are traced, and that the parts that
do change during dispatch are explicitly tracked.
Bug: 210460522
Test: atest inputflinger_tests
Change-Id: I2738d1a37da7ce72525d59c65f910a6fec09f862
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index e9d52cd..9f8cd6e 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -170,9 +170,9 @@
sp<Looper> mLooper;
- std::shared_ptr<EventEntry> mPendingEvent GUARDED_BY(mLock);
- std::deque<std::shared_ptr<EventEntry>> mInboundQueue GUARDED_BY(mLock);
- std::deque<std::shared_ptr<EventEntry>> mRecentQueue GUARDED_BY(mLock);
+ std::shared_ptr<const EventEntry> mPendingEvent GUARDED_BY(mLock);
+ std::deque<std::shared_ptr<const EventEntry>> mInboundQueue GUARDED_BY(mLock);
+ std::deque<std::shared_ptr<const EventEntry>> mRecentQueue GUARDED_BY(mLock);
// A command entry captures state and behavior for an action to be performed in the
// dispatch loop after the initial processing has taken place. It is essentially
@@ -222,7 +222,7 @@
REQUIRES(mLock);
// Adds an event to a queue of recent events for debugging purposes.
- void addRecentEventLocked(std::shared_ptr<EventEntry> entry) REQUIRES(mLock);
+ void addRecentEventLocked(std::shared_ptr<const EventEntry> entry) REQUIRES(mLock);
// App switch latency optimization.
bool mAppSwitchSawKeyDown GUARDED_BY(mLock);
@@ -234,7 +234,7 @@
// Blocked event latency optimization. Drops old events when the user intends
// to transfer focus to a new application.
- std::shared_ptr<EventEntry> mNextUnblockedEvent GUARDED_BY(mLock);
+ std::shared_ptr<const EventEntry> mNextUnblockedEvent GUARDED_BY(mLock);
sp<android::gui::WindowInfoHandle> findTouchedWindowAtLocked(
int32_t displayId, float x, float y, bool isStylus = false,
@@ -281,19 +281,19 @@
// Event injection and synchronization.
std::condition_variable mInjectionResultAvailable;
- void setInjectionResult(EventEntry& entry,
+ void setInjectionResult(const EventEntry& entry,
android::os::InputEventInjectionResult injectionResult);
void transformMotionEntryForInjectionLocked(MotionEntry&,
const ui::Transform& injectedTransform) const
REQUIRES(mLock);
std::condition_variable mInjectionSyncFinished;
- void incrementPendingForegroundDispatches(EventEntry& entry);
- void decrementPendingForegroundDispatches(EventEntry& entry);
+ void incrementPendingForegroundDispatches(const EventEntry& entry);
+ void decrementPendingForegroundDispatches(const EventEntry& entry);
// Key repeat tracking.
struct KeyRepeatState {
- std::shared_ptr<KeyEntry> lastKeyEntry; // or null if no repeat
+ std::shared_ptr<const KeyEntry> lastKeyEntry; // or null if no repeat
nsecs_t nextRepeatTime;
} mKeyRepeatState GUARDED_BY(mLock);
@@ -319,7 +319,7 @@
// Inbound event processing.
void drainInboundQueueLocked() REQUIRES(mLock);
void releasePendingEventLocked() REQUIRES(mLock);
- void releaseInboundEventLocked(std::shared_ptr<EventEntry> entry) REQUIRES(mLock);
+ void releaseInboundEventLocked(std::shared_ptr<const EventEntry> entry) REQUIRES(mLock);
// Dispatch state.
bool mDispatchEnabled GUARDED_BY(mLock);
@@ -430,23 +430,24 @@
const ConfigurationChangedEntry& entry) REQUIRES(mLock);
bool dispatchDeviceResetLocked(nsecs_t currentTime, const DeviceResetEntry& entry)
REQUIRES(mLock);
- bool dispatchKeyLocked(nsecs_t currentTime, std::shared_ptr<KeyEntry> entry,
+ bool dispatchKeyLocked(nsecs_t currentTime, std::shared_ptr<const KeyEntry> entry,
DropReason* dropReason, nsecs_t* nextWakeupTime) REQUIRES(mLock);
- bool dispatchMotionLocked(nsecs_t currentTime, std::shared_ptr<MotionEntry> entry,
+ bool dispatchMotionLocked(nsecs_t currentTime, std::shared_ptr<const MotionEntry> entry,
DropReason* dropReason, nsecs_t* nextWakeupTime) REQUIRES(mLock);
- void dispatchFocusLocked(nsecs_t currentTime, std::shared_ptr<FocusEntry> entry)
+ void dispatchFocusLocked(nsecs_t currentTime, std::shared_ptr<const FocusEntry> entry)
REQUIRES(mLock);
void dispatchPointerCaptureChangedLocked(
- nsecs_t currentTime, const std::shared_ptr<PointerCaptureChangedEntry>& entry,
+ nsecs_t currentTime, const std::shared_ptr<const PointerCaptureChangedEntry>& entry,
DropReason& dropReason) REQUIRES(mLock);
void dispatchTouchModeChangeLocked(nsecs_t currentTime,
- const std::shared_ptr<TouchModeEntry>& entry)
+ const std::shared_ptr<const TouchModeEntry>& entry)
REQUIRES(mLock);
- void dispatchEventLocked(nsecs_t currentTime, std::shared_ptr<EventEntry> entry,
+ void dispatchEventLocked(nsecs_t currentTime, std::shared_ptr<const EventEntry> entry,
const std::vector<InputTarget>& inputTargets) REQUIRES(mLock);
- void dispatchSensorLocked(nsecs_t currentTime, const std::shared_ptr<SensorEntry>& entry,
+ void dispatchSensorLocked(nsecs_t currentTime, const std::shared_ptr<const SensorEntry>& entry,
DropReason* dropReason, nsecs_t* nextWakeupTime) REQUIRES(mLock);
- void dispatchDragLocked(nsecs_t currentTime, std::shared_ptr<DragEntry> entry) REQUIRES(mLock);
+ void dispatchDragLocked(nsecs_t currentTime, std::shared_ptr<const DragEntry> entry)
+ REQUIRES(mLock);
void logOutboundKeyDetails(const char* prefix, const KeyEntry& entry);
void logOutboundMotionDetails(const char* prefix, const MotionEntry& entry);
@@ -576,14 +577,15 @@
// If needed, the methods post commands to run later once the critical bits are done.
void prepareDispatchCycleLocked(nsecs_t currentTime,
const std::shared_ptr<Connection>& connection,
- std::shared_ptr<EventEntry>, const InputTarget& inputTarget)
- REQUIRES(mLock);
+ std::shared_ptr<const EventEntry>,
+ const InputTarget& inputTarget) REQUIRES(mLock);
void enqueueDispatchEntriesLocked(nsecs_t currentTime,
const std::shared_ptr<Connection>& connection,
- std::shared_ptr<EventEntry>, const InputTarget& inputTarget)
- REQUIRES(mLock);
+ std::shared_ptr<const EventEntry>,
+ const InputTarget& inputTarget) REQUIRES(mLock);
void enqueueDispatchEntryLocked(const std::shared_ptr<Connection>& connection,
- std::shared_ptr<EventEntry>, const InputTarget& inputTarget,
+ std::shared_ptr<const EventEntry>,
+ const InputTarget& inputTarget,
ftl::Flags<InputTarget::Flags> dispatchMode) REQUIRES(mLock);
status_t publishMotionEvent(Connection& connection, DispatchEntry& dispatchEntry) const;
void startDispatchCycleLocked(nsecs_t currentTime,
@@ -645,7 +647,7 @@
const std::shared_ptr<Connection>& connection, uint32_t seq,
bool handled, nsecs_t consumeTime) REQUIRES(mLock);
void doInterceptKeyBeforeDispatchingCommand(const sp<IBinder>& focusedWindowToken,
- KeyEntry& entry) REQUIRES(mLock);
+ const KeyEntry& entry) REQUIRES(mLock);
void onFocusChangedLocked(const FocusResolver::FocusChanges& changes) REQUIRES(mLock);
void sendFocusChangedCommandLocked(const sp<IBinder>& oldToken, const sp<IBinder>& newToken)
REQUIRES(mLock);
@@ -660,7 +662,7 @@
REQUIRES(mLock);
std::map<int32_t /*displayId*/, InputVerifier> mVerifiersByDisplay;
// Returns a fallback KeyEntry that should be sent to the connection, if required.
- std::unique_ptr<KeyEntry> afterKeyEventLockedInterruptable(
+ std::unique_ptr<const KeyEntry> afterKeyEventLockedInterruptable(
const std::shared_ptr<Connection>& connection, DispatchEntry& dispatchEntry,
const KeyEntry& keyEntry, bool handled) REQUIRES(mLock);