@@ -1571,6 +1571,60 @@ TEST_F(InputDispatcherTest, HoverEventInconsistentPolicy) {
15711571 window->consumeMotionEvent(WithMotionAction(ACTION_HOVER_EXIT));
15721572}
15731573
1574+ // Still send inject motion events to window which already be touched.
1575+ TEST_F(InputDispatcherTest, AlwaysDispatchInjectMotionEventWhenAlreadyDownForWindow) {
1576+ std::shared_ptr<FakeApplicationHandle> application1 = std::make_shared<FakeApplicationHandle>();
1577+ sp<FakeWindowHandle> window1 =
1578+ sp<FakeWindowHandle>::make(application1, mDispatcher, "window1",
1579+ ui::LogicalDisplayId::DEFAULT);
1580+ window1->setFrame(Rect(0, 0, 100, 100));
1581+ window1->setWatchOutsideTouch(false);
1582+
1583+ std::shared_ptr<FakeApplicationHandle> application2 = std::make_shared<FakeApplicationHandle>();
1584+ sp<FakeWindowHandle> window2 =
1585+ sp<FakeWindowHandle>::make(application2, mDispatcher, "window2",
1586+ ui::LogicalDisplayId::DEFAULT);
1587+ window2->setFrame(Rect(50, 50, 100, 100));
1588+ window2->setWatchOutsideTouch(true);
1589+ mDispatcher->onWindowInfosChanged({{*window2->getInfo(), *window1->getInfo()}, {}, 0, 0});
1590+
1591+ std::chrono::milliseconds injectionTimeout = INJECT_EVENT_TIMEOUT;
1592+ InputEventInjectionSync injectionMode = InputEventInjectionSync::WAIT_FOR_RESULT;
1593+ std::optional<gui::Uid> targetUid = {};
1594+ uint32_t policyFlags = DEFAULT_POLICY_FLAGS;
1595+
1596+ const MotionEvent eventDown1 = MotionEventBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
1597+ .pointer(PointerBuilder(0, ToolType::FINGER).x(60).y(60)).deviceId(-1)
1598+ .build();
1599+ injectMotionEvent(*mDispatcher, eventDown1, injectionTimeout, injectionMode, targetUid,
1600+ policyFlags);
1601+ window2->consumeMotionEvent(WithMotionAction(ACTION_DOWN));
1602+
1603+ const MotionEvent eventUp1 = MotionEventBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN)
1604+ .pointer(PointerBuilder(0, ToolType::FINGER).x(60).y(60)).deviceId(-1)
1605+ .downTime(eventDown1.getDownTime()).build();
1606+ // Inject UP event, without the POLICY_FLAG_PASS_TO_USER (to simulate policy behaviour
1607+ // when screen is off).
1608+ injectMotionEvent(*mDispatcher, eventUp1, injectionTimeout, injectionMode, targetUid,
1609+ /*policyFlags=*/0);
1610+ window2->consumeMotionEvent(WithMotionAction(ACTION_UP));
1611+ const MotionEvent eventDown2 = MotionEventBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
1612+ .pointer(PointerBuilder(0, ToolType::FINGER).x(40).y(40)).deviceId(-1)
1613+ .build();
1614+ injectMotionEvent(*mDispatcher, eventDown2, injectionTimeout, injectionMode, targetUid,
1615+ policyFlags);
1616+ window1->consumeMotionEvent(WithMotionAction(ACTION_DOWN));
1617+ window2->consumeMotionEvent(WithMotionAction(ACTION_OUTSIDE));
1618+
1619+ const MotionEvent eventUp2 = MotionEventBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN)
1620+ .pointer(PointerBuilder(0, ToolType::FINGER).x(60).y(60)).deviceId(-1)
1621+ .downTime(eventDown2.getDownTime()).build();
1622+ injectMotionEvent(*mDispatcher, eventUp2, injectionTimeout, injectionMode, targetUid,
1623+ /*policyFlags=*/0);
1624+ window1->consumeMotionEvent(WithMotionAction(ACTION_UP));
1625+ window2->assertNoEvents();
1626+ }
1627+
15741628/**
15751629 * Two windows: a window on the left and a window on the right.
15761630 * Mouse is hovered from the right window into the left window.
0 commit comments