Skip to content

Commit c3a9247

Browse files
committed
InputReader: Notify policy of device changes after flushing events
...so that the rest of the listeners are synchonized with the device changes (through NotifyInputDevicesChangedArgs) before the policy can react to the changes. Bug: 324061913 Bug: 293587049 Test: atest inputflinger_tests Test: atest VirtualDeviceMirrorDisplayTest#virtualMouse_buttonEvent --rerun-until-failure Change-Id: I818b1e688565d30867295019c5baae29cb5bdbf2
1 parent 6c8661a commit c3a9247

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)