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

Commit 9da14733 authored by Arthur Hung's avatar Arthur Hung
Browse files

Fix touch can't work after enabled the associated viewport

If a device has associated port but there is no viewport found, it would
be expeced to be disabled. But for some devices, such as touch screen or
joystick, they have to read the axis ranges info in InputMapper at first
time configuration changed. So we have to defer disabling the device after
info has been read when the device plugged.

Bug: 140205788
Test: atest inputflinger_tests
Change-Id: I9dd55e0016b6a020aab211dada45880195aec8dd
parent bfd9c008
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -1141,13 +1141,24 @@ void InputDevice::configure(nsecs_t when, const InputReaderConfiguration* config
                }
            }

            if (changes) {
                // For first-time configuration, only allow device to be disabled after mappers have
                // finished configuring. This is because we need to read some of the properties from
                // the device's open fd.
                setEnabled(enabled, when);
            }
        }

        for (InputMapper* mapper : mMappers) {
            mapper->configure(when, config, changes);
            mSources |= mapper->getSources();
        }

        // If a device is just plugged but it might be disabled, we need to update some info like
        // axis range of touch from each InputMapper first, then disable it.
        if (!changes) {
            setEnabled(config->disabledDevices.find(mId) == config->disabledDevices.end(), when);
        }
    }
}

+32 −1
Original line number Diff line number Diff line
@@ -527,7 +527,7 @@ private:
    virtual status_t getAbsoluteAxisInfo(int32_t deviceId, int axis,
            RawAbsoluteAxisInfo* outAxisInfo) const {
        Device* device = getDevice(deviceId);
        if (device) {
        if (device && device->enabled) {
            ssize_t index = device->absoluteAxes.indexOfKey(axis);
            if (index >= 0) {
                *outAxisInfo = device->absoluteAxes.valueAt(index);
@@ -6554,4 +6554,35 @@ TEST_F(MultiTouchInputMapperTest, VideoFrames_MultipleFramesAreRotated) {
    ASSERT_EQ(frames, motionArgs.videoFrames);
}

/**
 * If we had defined port associations, but the viewport is not ready, the touch device would be
 * expected to be disabled, and it should be enabled after the viewport has found.
 */
TEST_F(MultiTouchInputMapperTest, Configure_EnabledForAssociatedDisplay) {
    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
    constexpr uint8_t hdmi2 = 1;
    const std::string secondaryUniqueId = "uniqueId2";
    constexpr ViewportType type = ViewportType::VIEWPORT_EXTERNAL;

    mFakePolicy->addInputPortAssociation(DEVICE_LOCATION, hdmi2);

    addConfigurationProperty("touch.deviceType", "touchScreen");
    prepareAxes(POSITION);
    addMapperAndConfigure(mapper);

    ASSERT_EQ(mDevice->isEnabled(), false);

    // Add display on hdmi2, the device should be enabled and can receive touch event.
    prepareSecondaryDisplay(type, hdmi2);
    ASSERT_EQ(mDevice->isEnabled(), true);

    // Send a touch event.
    processPosition(mapper, 100, 100);
    processSync(mapper);

    NotifyMotionArgs args;
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(&args));
    ASSERT_EQ(SECONDARY_DISPLAY_ID, args.displayId);
}

} // namespace android