Skip to content

Commit 2561547

Browse files
Nergi RahardiAndroid (Google) Code Review
authored andcommitted
Merge "[CD Cursor] Fix invalid displayId set when topology is not yet set" into main
2 parents 515b2e4 + 1396c8f commit 2561547

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

services/inputflinger/PointerChoreographer.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,13 @@ ui::LogicalDisplayId PointerChoreographer::getTargetMouseDisplayLocked(
677677
mTopology.graph.find(associatedDisplayId) == mTopology.graph.end()) {
678678
return associatedDisplayId;
679679
}
680-
return mCurrentMouseDisplayId.isValid() ? mCurrentMouseDisplayId : mTopology.primaryDisplayId;
680+
if (mCurrentMouseDisplayId.isValid()) {
681+
return mCurrentMouseDisplayId;
682+
}
683+
if (mTopology.primaryDisplayId.isValid()) {
684+
return mTopology.primaryDisplayId;
685+
}
686+
return ui::LogicalDisplayId::DEFAULT;
681687
}
682688

683689
std::pair<ui::LogicalDisplayId, PointerControllerInterface&>
@@ -786,7 +792,8 @@ PointerChoreographer::PointerDisplayChange
786792
PointerChoreographer::calculatePointerDisplayChangeToNotify() {
787793
ui::LogicalDisplayId displayIdToNotify = ui::LogicalDisplayId::INVALID;
788794
vec2 cursorPosition = {0, 0};
789-
if (const auto it = mMousePointersByDisplay.find(mCurrentMouseDisplayId);
795+
if (const auto it =
796+
mMousePointersByDisplay.find(getTargetMouseDisplayLocked(mCurrentMouseDisplayId));
790797
it != mMousePointersByDisplay.end()) {
791798
const auto& pointerController = it->second;
792799
// Use the displayId from the pointerController, because it accurately reflects whether

services/inputflinger/tests/PointerChoreographer_test.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,17 @@ TEST_F(PointerChoreographerTest, CallsNotifyPointerDisplayIdChanged) {
361361
assertPointerDisplayIdNotified(DISPLAY_ID);
362362
}
363363

364+
TEST_F(PointerChoreographerTest, NoDefaultMouseSetFallbackToDefaultDisplayId) {
365+
mChoreographer.setDisplayViewports(createViewports({ui::LogicalDisplayId::DEFAULT}));
366+
mChoreographer.notifyInputDevicesChanged(
367+
{/*id=*/0,
368+
{generateTestDeviceInfo(DEVICE_ID, AINPUT_SOURCE_MOUSE,
369+
ui::LogicalDisplayId::INVALID)}});
370+
assertPointerControllerCreated(ControllerType::MOUSE);
371+
372+
assertPointerDisplayIdNotified(ui::LogicalDisplayId::DEFAULT);
373+
}
374+
364375
TEST_F(PointerChoreographerTest, WhenViewportIsSetLaterCallsNotifyPointerDisplayIdChanged) {
365376
setDefaultMouseDisplayId(DISPLAY_ID);
366377
mChoreographer.notifyInputDevicesChanged(

0 commit comments

Comments
 (0)