From 55c5ee21ac21cbbc3b4f8b2faf9ffae126ada33c Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Wed, 14 Feb 2024 06:03:02 +0000 Subject: InputReader: Bump generation when associated display changes When the display association changes, we need to bump the device generation because the associated display is part of the java InputDevice, so we need to notify listeners about changes in the associated display. Bug: 324299318 Test: atest VirtualDpadTest --iterations Change-Id: Id5da99804b3e170d03fb1ca4c126b782a7587c7c --- services/inputflinger/reader/InputDevice.cpp | 6 ++++++ services/inputflinger/tests/InputReader_test.cpp | 3 +++ 2 files changed, 9 insertions(+) diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp index f3f15df151..2baf576903 100644 --- a/services/inputflinger/reader/InputDevice.cpp +++ b/services/inputflinger/reader/InputDevice.cpp @@ -265,6 +265,8 @@ std::list InputDevice::configureInternal(nsecs_t when, } if (!changes.any() || changes.test(Change::DISPLAY_INFO)) { + const auto oldAssociatedDisplayId = getAssociatedDisplayId(); + // In most situations, no port or name will be specified. mAssociatedDisplayPort = std::nullopt; mAssociatedDisplayUniqueId = std::nullopt; @@ -306,6 +308,10 @@ std::list InputDevice::configureInternal(nsecs_t when, getName().c_str(), mAssociatedDisplayUniqueId->c_str()); } } + + if (getAssociatedDisplayId() != oldAssociatedDisplayId) { + bumpGeneration(); + } } for_each_mapper([this, when, &readerConfig, changes, &out](InputMapper& mapper) { diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index c1dc7ffcfb..476f755bae 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -2893,9 +2893,12 @@ TEST_F(InputDeviceTest, Configure_UniqueId_CorrectlyMatches) { mFakePolicy->addDisplayViewport(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, /* isActive= */ true, DISPLAY_UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); + const auto initialGeneration = mDevice->getGeneration(); unused += mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), InputReaderConfiguration::Change::DISPLAY_INFO); ASSERT_EQ(DISPLAY_UNIQUE_ID, mDevice->getAssociatedDisplayUniqueId()); + ASSERT_GT(mDevice->getGeneration(), initialGeneration); + ASSERT_EQ(mDevice->getDeviceInfo().getAssociatedDisplayId(), SECONDARY_DISPLAY_ID); } /** -- cgit v1.2.3-59-g8ed1b