diff options
| author | 2023-11-01 18:41:03 +0000 | |
|---|---|---|
| committer | 2023-11-01 18:41:03 +0000 | |
| commit | df57c05624a65f2c080b0d105ed64d53a3321025 (patch) | |
| tree | 513fcb59e904896a6eac285bfb938e7ab7dcbbfb | |
| parent | 15b1df58569adc80b8af82a17396b8f3d4e38ec7 (diff) | |
| parent | 96e4fad0a291c7600a5a010e9f855fec126d7f6f (diff) | |
Merge "InputDispatcher: check consistency of filtered injected events" into main
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 26 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.h | 3 |
2 files changed, 28 insertions, 1 deletions
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index ab23893d8d..47b9a0c62f 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -4551,6 +4551,7 @@ void InputDispatcher::notifySwitch(const NotifySwitchArgs& args) { } void InputDispatcher::notifyDeviceReset(const NotifyDeviceResetArgs& args) { + // TODO(b/308677868) Remove device reset from the InputListener interface if (debugInboundEventDetails()) { ALOGD("notifyDeviceReset - eventTime=%" PRId64 ", deviceId=%d", args.eventTime, args.deviceId); @@ -4692,6 +4693,30 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev } mLock.lock(); + + if (policyFlags & POLICY_FLAG_FILTERED) { + // The events from InputFilter impersonate real hardware devices. Check these + // events for consistency and print an error. An inconsistent event sent from + // InputFilter could cause a crash in the later stages of dispatching pipeline. + auto [it, _] = + mInputFilterVerifiersByDisplay + .try_emplace(displayId, + StringPrintf("Injection on %" PRId32, displayId)); + InputVerifier& verifier = it->second; + + Result<void> result = + verifier.processMovement(resolvedDeviceId, motionEvent.getSource(), + motionEvent.getAction(), + motionEvent.getPointerCount(), + motionEvent.getPointerProperties(), + motionEvent.getSamplePointerCoords(), flags); + if (!result.ok()) { + logDispatchStateLocked(); + LOG(ERROR) << "Inconsistent event: " << motionEvent + << ", reason: " << result.error(); + } + } + const nsecs_t* sampleEventTimes = motionEvent.getSampleEventTimes(); const size_t pointerCount = motionEvent.getPointerCount(); const std::vector<PointerProperties> @@ -6756,6 +6781,7 @@ void InputDispatcher::displayRemoved(int32_t displayId) { // Remove the associated touch mode state. mTouchModePerDisplay.erase(displayId); mVerifiersByDisplay.erase(displayId); + mInputFilterVerifiersByDisplay.erase(displayId); } // release lock // Wake up poll loop since it may need to make new input dispatching choices. diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index 1be85f7868..e428c4e915 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -286,7 +286,8 @@ private: void transformMotionEntryForInjectionLocked(MotionEntry&, const ui::Transform& injectedTransform) const REQUIRES(mLock); - + // Per-display correction of injected events + std::map</*displayId*/ int32_t, InputVerifier> mInputFilterVerifiersByDisplay GUARDED_BY(mLock); std::condition_variable mInjectionSyncFinished; void incrementPendingForegroundDispatches(EventEntry& entry); void decrementPendingForegroundDispatches(EventEntry& entry); |