Update uniqueId association native methods
Change the association mechanism from names to physical port locations
(PHYS). In addtion, read and match the associations for touchscreens as
well as for cursor input devices.
Bug: 202273865
Test: atest inputflinger_tests
Change-Id: I4ed2f140d2125833f239ffcb16f5efff9d342acf
diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp
index 3e95fa9..a050963 100644
--- a/services/inputflinger/reader/InputDevice.cpp
+++ b/services/inputflinger/reader/InputDevice.cpp
@@ -309,15 +309,15 @@
const auto& displayPort = ports.find(inputPort);
if (displayPort != ports.end()) {
mAssociatedDisplayPort = std::make_optional(displayPort->second);
+ } else {
+ const std::unordered_map<std::string, std::string>& displayUniqueIds =
+ config->uniqueIdAssociations;
+ const auto& displayUniqueId = displayUniqueIds.find(inputPort);
+ if (displayUniqueId != displayUniqueIds.end()) {
+ mAssociatedDisplayUniqueId = displayUniqueId->second;
+ }
}
}
- const std::string& inputDeviceName = mIdentifier.name;
- const std::unordered_map<std::string, std::string>& names =
- config->uniqueIdAssociations;
- const auto& displayUniqueId = names.find(inputDeviceName);
- if (displayUniqueId != names.end()) {
- mAssociatedDisplayUniqueId = displayUniqueId->second;
- }
// If the device was explicitly disabled by the user, it would be present in the
// "disabledDevices" list. If it is associated with a specific display, and it was not
@@ -338,7 +338,7 @@
if (!mAssociatedViewport) {
ALOGW("Input device %s should be associated with display %s but the "
"corresponding viewport cannot be found",
- inputDeviceName.c_str(), mAssociatedDisplayUniqueId->c_str());
+ getName().c_str(), mAssociatedDisplayUniqueId->c_str());
enabled = false;
}
}
diff --git a/services/inputflinger/reader/include/InputDevice.h b/services/inputflinger/reader/include/InputDevice.h
index 11c074a..694daa9 100644
--- a/services/inputflinger/reader/include/InputDevice.h
+++ b/services/inputflinger/reader/include/InputDevice.h
@@ -61,6 +61,9 @@
inline std::optional<uint8_t> getAssociatedDisplayPort() const {
return mAssociatedDisplayPort;
}
+ inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
+ return mAssociatedDisplayUniqueId;
+ }
inline std::optional<DisplayViewport> getAssociatedViewport() const {
return mAssociatedViewport;
}
@@ -386,6 +389,9 @@
inline std::optional<uint8_t> getAssociatedDisplayPort() const {
return mDevice.getAssociatedDisplayPort();
}
+ inline std::optional<std::string> getAssociatedDisplayUniqueId() const {
+ return mDevice.getAssociatedDisplayUniqueId();
+ }
inline std::optional<DisplayViewport> getAssociatedViewport() const {
return mDevice.getAssociatedViewport();
}
diff --git a/services/inputflinger/reader/mapper/TouchInputMapper.cpp b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
index 4772beb..f729ba9 100644
--- a/services/inputflinger/reader/mapper/TouchInputMapper.cpp
+++ b/services/inputflinger/reader/mapper/TouchInputMapper.cpp
@@ -565,6 +565,12 @@
return getDeviceContext().getAssociatedViewport();
}
+ const std::optional<std::string> associatedDisplayUniqueId =
+ getDeviceContext().getAssociatedDisplayUniqueId();
+ if (associatedDisplayUniqueId) {
+ return getDeviceContext().getAssociatedViewport();
+ }
+
if (mDeviceMode == DeviceMode::POINTER) {
std::optional<DisplayViewport> viewport =
mConfig.getDisplayViewportById(mConfig.defaultPointerDisplayId);
diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp
index e2596f0..54cf15d 100644
--- a/services/inputflinger/tests/InputReader_test.cpp
+++ b/services/inputflinger/tests/InputReader_test.cpp
@@ -2862,7 +2862,7 @@
// Device should be disabled because it is associated with a specific display, but the
// corresponding display is not found.
const std::string DISPLAY_UNIQUE_ID = "displayUniqueId";
- mFakePolicy->addInputUniqueIdAssociation(DEVICE_NAME, DISPLAY_UNIQUE_ID);
+ mFakePolicy->addInputUniqueIdAssociation(DEVICE_LOCATION, DISPLAY_UNIQUE_ID);
mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
InputReaderConfiguration::CHANGE_DISPLAY_INFO);
ASSERT_FALSE(mDevice->isEnabled());
@@ -2887,6 +2887,21 @@
ASSERT_FALSE(mDevice->isEnabled());
}
+TEST_F(InputDeviceTest, Configure_UniqueId_CorrectlyMatches) {
+ mFakePolicy->clearViewports();
+ mDevice->addMapper<FakeInputMapper>(EVENTHUB_ID, AINPUT_SOURCE_KEYBOARD);
+ mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), 0);
+
+ const std::string DISPLAY_UNIQUE_ID = "displayUniqueId";
+ mFakePolicy->addInputUniqueIdAssociation(DEVICE_LOCATION, DISPLAY_UNIQUE_ID);
+ mFakePolicy->addDisplayViewport(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT,
+ DISPLAY_ORIENTATION_0, /* isActive= */ true, DISPLAY_UNIQUE_ID,
+ NO_PORT, ViewportType::INTERNAL);
+ mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(),
+ InputReaderConfiguration::CHANGE_DISPLAY_INFO);
+ ASSERT_EQ(DISPLAY_UNIQUE_ID, mDevice->getAssociatedDisplayUniqueId());
+}
+
// --- InputMapperTest ---
class InputMapperTest : public testing::Test {