@@ -4794,6 +4794,39 @@ void InputDispatcher::notifyPointerCaptureChanged(const NotifyPointerCaptureChan
47944794 }
47954795}
47964796
4797+ bool InputDispatcher::shouldRejectInjectedMotionLocked (const MotionEvent& motionEvent,
4798+ DeviceId deviceId,
4799+ ui::LogicalDisplayId displayId,
4800+ std::optional<gui::Uid> targetUid,
4801+ int32_t flags) {
4802+ // Don't verify targeted injection, since it will only affect the caller's
4803+ // window, and the windows are typically destroyed at the end of the test.
4804+ if (targetUid.has_value ()) {
4805+ return false ;
4806+ }
4807+
4808+ // Verify all other injected streams, whether the injection is coming from apps or from
4809+ // input filter. Print an error if the stream becomes inconsistent with this event.
4810+ // An inconsistent injected event sent could cause a crash in the later stages of
4811+ // dispatching pipeline.
4812+ auto [it, _] = mInputFilterVerifiersByDisplay .try_emplace (displayId,
4813+ std::string (" Injection on " ) +
4814+ displayId.toString ());
4815+ InputVerifier& verifier = it->second ;
4816+
4817+ Result<void > result =
4818+ verifier.processMovement (deviceId, motionEvent.getSource (), motionEvent.getAction (),
4819+ motionEvent.getPointerCount (),
4820+ motionEvent.getPointerProperties (),
4821+ motionEvent.getSamplePointerCoords (), flags);
4822+ if (!result.ok ()) {
4823+ logDispatchStateLocked ();
4824+ LOG (ERROR) << " Inconsistent event: " << motionEvent << " , reason: " << result.error ();
4825+ return true ;
4826+ }
4827+ return false ;
4828+ }
4829+
47974830InputEventInjectionResult InputDispatcher::injectInputEvent (const InputEvent* event,
47984831 std::optional<gui::Uid> targetUid,
47994832 InputEventInjectionSync syncMode,
@@ -4904,32 +4937,10 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev
49044937
49054938 mLock .lock ();
49064939
4907- {
4908- // Verify all injected streams, whether the injection is coming from apps or from
4909- // input filter. Print an error if the stream becomes inconsistent with this event.
4910- // An inconsistent injected event sent could cause a crash in the later stages of
4911- // dispatching pipeline.
4912- auto [it, _] =
4913- mInputFilterVerifiersByDisplay .try_emplace (displayId,
4914- std::string (" Injection on " ) +
4915- displayId.toString ());
4916- InputVerifier& verifier = it->second ;
4917-
4918- Result<void > result =
4919- verifier.processMovement (resolvedDeviceId, motionEvent.getSource (),
4920- motionEvent.getAction (),
4921- motionEvent.getPointerCount (),
4922- motionEvent.getPointerProperties (),
4923- motionEvent.getSamplePointerCoords (), flags);
4924- if (!result.ok ()) {
4925- logDispatchStateLocked ();
4926- LOG (ERROR) << " Inconsistent event: " << motionEvent
4927- << " , reason: " << result.error ();
4928- if (policyFlags & POLICY_FLAG_INJECTED_FROM_ACCESSIBILITY) {
4929- mLock .unlock ();
4930- return InputEventInjectionResult::FAILED;
4931- }
4932- }
4940+ if (shouldRejectInjectedMotionLocked (motionEvent, resolvedDeviceId, displayId,
4941+ targetUid, flags)) {
4942+ mLock .unlock ();
4943+ return InputEventInjectionResult::FAILED;
49334944 }
49344945
49354946 const nsecs_t * sampleEventTimes = motionEvent.getSampleEventTimes ();
0 commit comments