Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a2293c8 authored by Christine Franks's avatar Christine Franks
Browse files

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
parent e1d18723
Loading
Loading
Loading
Loading
+8 −8
Original line number Diff line number Diff line
@@ -309,15 +309,15 @@ void InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config
                const auto& displayPort = ports.find(inputPort);
                if (displayPort != ports.end()) {
                    mAssociatedDisplayPort = std::make_optional(displayPort->second);
                }
            }
            const std::string& inputDeviceName = mIdentifier.name;
            const std::unordered_map<std::string, std::string>& names =
                } else {
                    const std::unordered_map<std::string, std::string>& displayUniqueIds =
                            config->uniqueIdAssociations;
            const auto& displayUniqueId = names.find(inputDeviceName);
            if (displayUniqueId != names.end()) {
                    const auto& displayUniqueId = displayUniqueIds.find(inputPort);
                    if (displayUniqueId != displayUniqueIds.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 @@ void InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config
                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;
                }
            }
+6 −0
Original line number Diff line number Diff line
@@ -61,6 +61,9 @@ public:
    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 @@ public:
    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();
    }
+6 −0
Original line number Diff line number Diff line
@@ -565,6 +565,12 @@ std::optional<DisplayViewport> TouchInputMapper::findViewport() {
            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);
+16 −1
Original line number Diff line number Diff line
@@ -2862,7 +2862,7 @@ TEST_F(InputDeviceTest, Configure_AssignsDisplayUniqueId) {
    // 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 @@ TEST_F(InputDeviceTest, Configure_AssignsDisplayUniqueId) {
    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 {