summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Prabir Pradhan <prabirmsp@google.com> 2024-02-06 20:08:05 +0000
committer Prabir Pradhan <prabirmsp@google.com> 2024-02-06 20:24:44 +0000
commitc3a924740c152bc6ff45ad255bed28bf619230e4 (patch)
treef15ae33bce9f3b1745ce5720c472241fbffa38fd
parent6c8661ac9cf6c96d9deeacc87acbf9bdaef24fae (diff)
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
-rw-r--r--services/inputflinger/reader/InputReader.cpp28
1 files changed, 15 insertions, 13 deletions
diff --git a/services/inputflinger/reader/InputReader.cpp b/services/inputflinger/reader/InputReader.cpp
index 0582649d38..9608210ca0 100644
--- a/services/inputflinger/reader/InputReader.cpp
+++ b/services/inputflinger/reader/InputReader.cpp
@@ -164,19 +164,6 @@ void InputReader::loopOnce() {
std::swap(notifyArgs, mPendingArgs);
} // release lock
- // Send out a message that the describes the changed input devices.
- if (inputDevicesChanged) {
- mPolicy->notifyInputDevicesChanged(inputDevices);
- }
-
- // Notify the policy of the start of every new stylus gesture outside the lock.
- for (const auto& args : notifyArgs) {
- const auto* motionArgs = std::get_if<NotifyMotionArgs>(&args);
- if (motionArgs != nullptr && isStylusPointerGestureStart(*motionArgs)) {
- mPolicy->notifyStylusGestureStarted(motionArgs->deviceId, motionArgs->eventTime);
- }
- }
-
// Flush queued events out to the listener.
// This must happen outside of the lock because the listener could potentially call
// back into the InputReader's methods, such as getScanCodeState, or become blocked
@@ -187,6 +174,21 @@ void InputReader::loopOnce() {
for (const NotifyArgs& args : notifyArgs) {
mNextListener.notify(args);
}
+
+ // Notify the policy that input devices have changed.
+ // This must be done after flushing events down the listener chain to ensure that the rest of
+ // the listeners are synchronized with the changes before the policy reacts to them.
+ if (inputDevicesChanged) {
+ mPolicy->notifyInputDevicesChanged(inputDevices);
+ }
+
+ // Notify the policy of the start of every new stylus gesture.
+ for (const auto& args : notifyArgs) {
+ const auto* motionArgs = std::get_if<NotifyMotionArgs>(&args);
+ if (motionArgs != nullptr && isStylusPointerGestureStart(*motionArgs)) {
+ mPolicy->notifyStylusGestureStarted(motionArgs->deviceId, motionArgs->eventTime);
+ }
+ }
}
std::list<NotifyArgs> InputReader::processEventsLocked(const RawEvent* rawEvents, size_t count) {