Skip to content

Commit fc66a3a

Browse files
author
Arpit Singh
committed
[CD Cursor] Fix cursorState lookup for non-primary displays
In connected display scenario touchstate display for mouse is always identified by primary display. At present DispatcherTouchState::forTouchAndCursorStatesOnDisplay is the only API in TouchStates that does not adhere to this mapping. This can cause the lookup for cursorState to fail. IsPointerInWindow is the only public API in dispatcher that uses this and fails. This Cl updates the lookup and adds tests for API called with the non-primary display in topology. Test: inputflinger_tests with the flag enabled/disabled Bug: 395033854 Flag: com.android.input.flags.connected_displays_cursor Change-Id: I1515171802478a7132206562e41a7586b8ca8559
1 parent 3c769a4 commit fc66a3a

2 files changed

Lines changed: 47 additions & 3 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7553,9 +7553,10 @@ void InputDispatcher::DispatcherTouchState::forTouchAndCursorStatesOnDisplay(
75537553
return;
75547554
}
75557555

7556-
// TODO(b/383092013): This is currently not accounting for the "topology group" concept.
7557-
// Proper implementation requires looking tghrough all the displays in the topology group.
7558-
const auto cursorStateIt = mCursorStateByDisplay.find(displayId);
7556+
// DisplayId for the Cursor state may not be same as supplied displayId if display is part of
7557+
// topology. Instead we should to check from the topology's primary display.
7558+
const auto cursorStateIt =
7559+
mCursorStateByDisplay.find(mWindowInfos.getPrimaryDisplayId(displayId));
75597560
if (cursorStateIt != mCursorStateByDisplay.end()) {
75607561
f(cursorStateIt->second);
75617562
}

services/inputflinger/tests/InputDispatcher_test.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15403,4 +15403,47 @@ TEST_F(InputDispatcherConnectedDisplayTest, MultiDisplayMouseDragAndDropFromNonP
1540315403
mWindowOnSecondDisplay->assertNoEvents();
1540415404
}
1540515405

15406+
using InputDispatcherConnectedDisplayPointerInWindowTest = InputDispatcherConnectedDisplayTest;
15407+
15408+
TEST_F(InputDispatcherConnectedDisplayPointerInWindowTest, MouseOnWindowOnPrimaryDisplay) {
15409+
SCOPED_FLAG_OVERRIDE(connected_displays_cursor, true);
15410+
15411+
mDispatcher->notifyMotion(
15412+
MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE)
15413+
.pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE).x(50).y(50))
15414+
.build());
15415+
15416+
mWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER));
15417+
mSpyWindow->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER));
15418+
mWindowOnSecondDisplay->assertNoEvents();
15419+
15420+
ASSERT_TRUE(mDispatcher->isPointerInWindow(mWindow->getToken(), DISPLAY_ID, DEVICE_ID,
15421+
/*pointerId=*/0));
15422+
ASSERT_TRUE(mDispatcher->isPointerInWindow(mSpyWindow->getToken(), DISPLAY_ID, DEVICE_ID,
15423+
/*pointerId=*/0));
15424+
ASSERT_FALSE(mDispatcher->isPointerInWindow(mWindowOnSecondDisplay->getToken(),
15425+
SECOND_DISPLAY_ID, DEVICE_ID, /*pointerId=*/0));
15426+
}
15427+
15428+
TEST_F(InputDispatcherConnectedDisplayPointerInWindowTest, MouseOnWindowOnNonPrimaryDisplay) {
15429+
SCOPED_FLAG_OVERRIDE(connected_displays_cursor, true);
15430+
15431+
mDispatcher->notifyMotion(
15432+
MotionArgsBuilder(ACTION_HOVER_ENTER, AINPUT_SOURCE_MOUSE)
15433+
.displayId(SECOND_DISPLAY_ID)
15434+
.pointer(PointerBuilder(/*id=*/0, ToolType::MOUSE).x(50).y(50))
15435+
.build());
15436+
15437+
mWindow->assertNoEvents();
15438+
mSpyWindow->assertNoEvents();
15439+
mWindowOnSecondDisplay->consumeMotionEvent(WithMotionAction(ACTION_HOVER_ENTER));
15440+
15441+
ASSERT_FALSE(mDispatcher->isPointerInWindow(mWindow->getToken(), DISPLAY_ID, DEVICE_ID,
15442+
/*pointerId=*/0));
15443+
ASSERT_FALSE(mDispatcher->isPointerInWindow(mSpyWindow->getToken(), DISPLAY_ID, DEVICE_ID,
15444+
/*pointerId=*/0));
15445+
ASSERT_TRUE(mDispatcher->isPointerInWindow(mWindowOnSecondDisplay->getToken(),
15446+
SECOND_DISPLAY_ID, DEVICE_ID, /*pointerId=*/0));
15447+
}
15448+
1540615449
} // namespace android::inputdispatcher

0 commit comments

Comments
 (0)