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