Skip to content

Commit 9edb922

Browse files
prabirmspAndroid (Google) Code Review
authored andcommitted
Merge "InputReader: Notify policy of device changes after flushing events" into main
2 parents 77b0a49 + c3a9247 commit 9edb922

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

services/inputflinger/reader/InputReader.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,6 @@ void InputReader::loopOnce() {
164164
std::swap(notifyArgs, mPendingArgs);
165165
} // release lock
166166

167-
// Send out a message that the describes the changed input devices.
168-
if (inputDevicesChanged) {
169-
mPolicy->notifyInputDevicesChanged(inputDevices);
170-
}
171-
172-
// Notify the policy of the start of every new stylus gesture outside the lock.
173-
for (const auto& args : notifyArgs) {
174-
const auto* motionArgs = std::get_if<NotifyMotionArgs>(&args);
175-
if (motionArgs != nullptr && isStylusPointerGestureStart(*motionArgs)) {
176-
mPolicy->notifyStylusGestureStarted(motionArgs->deviceId, motionArgs->eventTime);
177-
}
178-
}
179-
180167
// Flush queued events out to the listener.
181168
// This must happen outside of the lock because the listener could potentially call
182169
// back into the InputReader's methods, such as getScanCodeState, or become blocked
@@ -187,6 +174,21 @@ void InputReader::loopOnce() {
187174
for (const NotifyArgs& args : notifyArgs) {
188175
mNextListener.notify(args);
189176
}
177+
178+
// Notify the policy that input devices have changed.
179+
// This must be done after flushing events down the listener chain to ensure that the rest of
180+
// the listeners are synchronized with the changes before the policy reacts to them.
181+
if (inputDevicesChanged) {
182+
mPolicy->notifyInputDevicesChanged(inputDevices);
183+
}
184+
185+
// Notify the policy of the start of every new stylus gesture.
186+
for (const auto& args : notifyArgs) {
187+
const auto* motionArgs = std::get_if<NotifyMotionArgs>(&args);
188+
if (motionArgs != nullptr && isStylusPointerGestureStart(*motionArgs)) {
189+
mPolicy->notifyStylusGestureStarted(motionArgs->deviceId, motionArgs->eventTime);
190+
}
191+
}
190192
}
191193

192194
std::list<NotifyArgs> InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) {

0 commit comments

Comments
 (0)