Skip to content

Commit d77e913

Browse files
Treehugger Robotandroid-build-merge-worker-robot
authored andcommitted
Merge "Still send motion events to window which already be touched" into main am: 902c67a am: 2439c80
Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/3431763 Change-Id: I92f616a262ba81731f4bdc8ca838cd78d97804d3 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2 parents dfc9f67 + 2439c80 commit d77e913

2 files changed

Lines changed: 67 additions & 0 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4878,6 +4878,19 @@ InputEventInjectionResult InputDispatcher::injectInputEvent(const InputEvent* ev
48784878
return InputEventInjectionResult::FAILED;
48794879
}
48804880

4881+
if (!(policyFlags & POLICY_FLAG_PASS_TO_USER)) {
4882+
// Set the flag anyway if we already have an ongoing motion gesture. That
4883+
// would allow us to complete the processing of the current stroke.
4884+
const auto touchStateIt = mTouchStatesByDisplay.find(displayId);
4885+
if (touchStateIt != mTouchStatesByDisplay.end()) {
4886+
const TouchState& touchState = touchStateIt->second;
4887+
if (touchState.hasTouchingPointers(resolvedDeviceId) ||
4888+
touchState.hasHoveringPointers(resolvedDeviceId)) {
4889+
policyFlags |= POLICY_FLAG_PASS_TO_USER;
4890+
}
4891+
}
4892+
}
4893+
48814894
const nsecs_t* sampleEventTimes = motionEvent.getSampleEventTimes();
48824895
const size_t pointerCount = motionEvent.getPointerCount();
48834896
const std::vector<PointerProperties>

services/inputflinger/tests/InputDispatcher_test.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)