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

Commit d074638d authored by Josep del Rio's avatar Josep del Rio Committed by Josep del Río
Browse files

Allow touchpads to expose associated display

After landing ag/24209603, a touchpad test started failing; the
reason is that the device never exposed the associated display id,
even though it became associated to a viewport. This CL makes the
necessary changes so the associated display id is properly
propagated.

Bug: 293488187
Test: atest of the failing test
Change-Id: Ia1480012bd339de92abd284c6d00f7ac93505735
parent 65c0b693
Loading
Loading
Loading
Loading
+32 −7
Original line number Original line Diff line number Diff line
@@ -350,6 +350,7 @@ void TouchpadInputMapper::dump(std::string& dump) {
    dump += addLinePrefix(mPropertyProvider.dump(), INDENT4);
    dump += addLinePrefix(mPropertyProvider.dump(), INDENT4);
    dump += INDENT3 "Captured event converter:\n";
    dump += INDENT3 "Captured event converter:\n";
    dump += addLinePrefix(mCapturedEventConverter.dump(), INDENT4);
    dump += addLinePrefix(mCapturedEventConverter.dump(), INDENT4);
    dump += StringPrintf(INDENT3 "DisplayId: %s\n", toString(mDisplayId).c_str());
}
}


std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when,
std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when,
@@ -361,13 +362,31 @@ std::list<NotifyArgs> TouchpadInputMapper::reconfigure(nsecs_t when,
    }
    }


    if (!changes.any() || changes.test(InputReaderConfiguration::Change::DISPLAY_INFO)) {
    if (!changes.any() || changes.test(InputReaderConfiguration::Change::DISPLAY_INFO)) {
        std::optional<int32_t> displayId = mPointerController->getDisplayId();
        mDisplayId = ADISPLAY_ID_NONE;
        if (auto viewport = mDeviceContext.getAssociatedViewport(); viewport) {
            // This InputDevice is associated with a viewport.
            // Only generate events for the associated display.
            const bool mismatchedPointerDisplay =
                    (viewport->displayId != mPointerController->getDisplayId());
            if (mismatchedPointerDisplay) {
                ALOGW("Touchpad \"%s\" associated viewport display does not match pointer "
                      "controller",
                      mDeviceContext.getName().c_str());
            }
            mDisplayId = mismatchedPointerDisplay ? std::nullopt
                                                  : std::make_optional(viewport->displayId);
        } else {
            // The InputDevice is not associated with a viewport, but it controls the mouse pointer.
            mDisplayId = mPointerController->getDisplayId();
        }

        ui::Rotation orientation = ui::ROTATION_0;
        ui::Rotation orientation = ui::ROTATION_0;
        if (displayId.has_value()) {
        if (mDisplayId.has_value()) {
            if (auto viewport = config.getDisplayViewportById(*displayId); viewport) {
            if (auto viewport = config.getDisplayViewportById(*mDisplayId); viewport) {
                orientation = getInverseRotation(viewport->orientation);
                orientation = getInverseRotation(viewport->orientation);
            }
            }
        }
        }
        mGestureConverter.setDisplayId(mDisplayId);
        mGestureConverter.setOrientation(orientation);
        mGestureConverter.setOrientation(orientation);
    }
    }
    if (!changes.any() || changes.test(InputReaderConfiguration::Change::TOUCHPAD_SETTINGS)) {
    if (!changes.any() || changes.test(InputReaderConfiguration::Change::TOUCHPAD_SETTINGS)) {
@@ -497,13 +516,19 @@ void TouchpadInputMapper::consumeGesture(const Gesture* gesture) {


std::list<NotifyArgs> TouchpadInputMapper::processGestures(nsecs_t when, nsecs_t readTime) {
std::list<NotifyArgs> TouchpadInputMapper::processGestures(nsecs_t when, nsecs_t readTime) {
    std::list<NotifyArgs> out = {};
    std::list<NotifyArgs> out = {};
    if (mDisplayId) {
        MetricsAccumulator& metricsAccumulator = MetricsAccumulator::getInstance();
        MetricsAccumulator& metricsAccumulator = MetricsAccumulator::getInstance();
        for (Gesture& gesture : mGesturesToProcess) {
        for (Gesture& gesture : mGesturesToProcess) {
            out += mGestureConverter.handleGesture(when, readTime, gesture);
            out += mGestureConverter.handleGesture(when, readTime, gesture);
            metricsAccumulator.processGesture(mMetricsId, gesture);
            metricsAccumulator.processGesture(mMetricsId, gesture);
        }
        }
    }
    mGesturesToProcess.clear();
    mGesturesToProcess.clear();
    return out;
    return out;
}
}


std::optional<int32_t> TouchpadInputMapper::getAssociatedDisplayId() {
    return mDisplayId;
}

} // namespace android
} // namespace android
+7 −0
Original line number Original line Diff line number Diff line
@@ -64,6 +64,8 @@ public:
    using MetricsIdentifier = std::tuple<uint16_t /*busId*/, uint16_t /*vendorId*/,
    using MetricsIdentifier = std::tuple<uint16_t /*busId*/, uint16_t /*vendorId*/,
                                         uint16_t /*productId*/, uint16_t /*version*/>;
                                         uint16_t /*productId*/, uint16_t /*version*/>;


    std::optional<int32_t> getAssociatedDisplayId() override;

private:
private:
    void resetGestureInterpreter(nsecs_t when);
    void resetGestureInterpreter(nsecs_t when);
    explicit TouchpadInputMapper(InputDeviceContext& deviceContext,
    explicit TouchpadInputMapper(InputDeviceContext& deviceContext,
@@ -102,6 +104,11 @@ private:
    std::set<int32_t> mLastFrameTrackingIds;
    std::set<int32_t> mLastFrameTrackingIds;
    // Tracking IDs for touches that have at some point been reported as palms by the touchpad.
    // Tracking IDs for touches that have at some point been reported as palms by the touchpad.
    std::set<int32_t> mPalmTrackingIds;
    std::set<int32_t> mPalmTrackingIds;

    // The display that events generated by this mapper should target. This can be set to
    // ADISPLAY_ID_NONE to target the focused display. If there is no display target (i.e.
    // std::nullopt), all events will be ignored.
    std::optional<int32_t> mDisplayId;
};
};


} // namespace android
} // namespace android
+6 −1
Original line number Original line Diff line number Diff line
@@ -124,6 +124,11 @@ void GestureConverter::populateMotionRanges(InputDeviceInfo& info) const {


std::list<NotifyArgs> GestureConverter::handleGesture(nsecs_t when, nsecs_t readTime,
std::list<NotifyArgs> GestureConverter::handleGesture(nsecs_t when, nsecs_t readTime,
                                                      const Gesture& gesture) {
                                                      const Gesture& gesture) {
    if (!mDisplayId) {
        // Ignore gestures when there is no target display configured.
        return {};
    }

    switch (gesture.type) {
    switch (gesture.type) {
        case kGestureTypeMove:
        case kGestureTypeMove:
            return {handleMove(when, readTime, gesture)};
            return {handleMove(when, readTime, gesture)};
@@ -556,7 +561,7 @@ NotifyMotionArgs GestureConverter::makeMotionArgs(nsecs_t when, nsecs_t readTime
            readTime,
            readTime,
            mDeviceId,
            mDeviceId,
            SOURCE,
            SOURCE,
            mPointerController->getDisplayId(),
            *mDisplayId,
            /* policyFlags= */ POLICY_FLAG_WAKE,
            /* policyFlags= */ POLICY_FLAG_WAKE,
            action,
            action,
            /* actionButton= */ actionButton,
            /* actionButton= */ actionButton,
+3 −0
Original line number Original line Diff line number Diff line
@@ -46,6 +46,8 @@ public:
    void setOrientation(ui::Rotation orientation) { mOrientation = orientation; }
    void setOrientation(ui::Rotation orientation) { mOrientation = orientation; }
    [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);
    [[nodiscard]] std::list<NotifyArgs> reset(nsecs_t when);


    void setDisplayId(std::optional<int32_t> displayId) { mDisplayId = displayId; }

    void populateMotionRanges(InputDeviceInfo& info) const;
    void populateMotionRanges(InputDeviceInfo& info) const;


    [[nodiscard]] std::list<NotifyArgs> handleGesture(nsecs_t when, nsecs_t readTime,
    [[nodiscard]] std::list<NotifyArgs> handleGesture(nsecs_t when, nsecs_t readTime,
@@ -84,6 +86,7 @@ private:
    InputReaderContext& mReaderContext;
    InputReaderContext& mReaderContext;
    std::shared_ptr<PointerControllerInterface> mPointerController;
    std::shared_ptr<PointerControllerInterface> mPointerController;


    std::optional<int32_t> mDisplayId;
    ui::Rotation mOrientation = ui::ROTATION_0;
    ui::Rotation mOrientation = ui::ROTATION_0;
    RawAbsoluteAxisInfo mXAxisInfo;
    RawAbsoluteAxisInfo mXAxisInfo;
    RawAbsoluteAxisInfo mYAxisInfo;
    RawAbsoluteAxisInfo mYAxisInfo;
+185 −106

File changed.

Preview size limit exceeded, changes collapsed.