@@ -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
192194std::list<NotifyArgs> InputReader::processEventsLocked (const RawEvent* rawEvents, size_t count) {
0 commit comments