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

Commit 05a8fe28 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Add DisplayViewport native tests

The strategy for finding DisplayViewport has changed in ag/4723479.
Add native tests for the new lookup logic here.

The matching is done by uniqueId if it is specified, and by type only if it is not.

Some additional refactors:
- Return std::optional from getDisplayViewport
- Make internal viewport optional. Expect normal operation if internal
viewport is not present at all.

Bug: 111108021
Test: atest -a inputflinger_tests
Change-Id: I7d7d698438d0d691f5f07fef2da80e792a504978
parent 7371fedb
Loading
Loading
Loading
Loading
+17 −16
Original line number Diff line number Diff line
@@ -256,18 +256,17 @@ static void synthesizeButtonKeys(InputReaderContext* context, int32_t action,

// --- InputReaderConfiguration ---

bool InputReaderConfiguration::getDisplayViewport(ViewportType viewportType,
        const std::string& uniqueDisplayId, DisplayViewport* outViewport) const {
std::optional<DisplayViewport> InputReaderConfiguration::getDisplayViewport(
        ViewportType viewportType, const std::string& uniqueDisplayId) const {
    for (const DisplayViewport& currentViewport : mDisplays) {
        if (currentViewport.type == viewportType) {
            if (uniqueDisplayId.empty() ||
                    (!uniqueDisplayId.empty() && uniqueDisplayId == currentViewport.uniqueId)) {
                *outViewport = currentViewport;
                return true;
                return std::make_optional(currentViewport);
            }
        }
    }
    return false;
    return std::nullopt;
}

void InputReaderConfiguration::setDisplayViewports(const std::vector<DisplayViewport>& viewports) {
@@ -2249,7 +2248,6 @@ void KeyboardInputMapper::dump(std::string& dump) {
    dump += StringPrintf(INDENT3 "DownTime: %" PRId64 "\n", mDownTime);
}


void KeyboardInputMapper::configure(nsecs_t when,
        const InputReaderConfiguration* config, uint32_t changes) {
    InputMapper::configure(when, config, changes);
@@ -2261,9 +2259,7 @@ void KeyboardInputMapper::configure(nsecs_t when,

    if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
        if (mParameters.orientationAware) {
            DisplayViewport dvp;
            config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, "", &dvp);
            mViewport = dvp;
            mViewport = config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, "");
        }
    }
}
@@ -2672,9 +2668,10 @@ void CursorInputMapper::configure(nsecs_t when,
    if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
        mOrientation = DISPLAY_ORIENTATION_0;
        if (mParameters.orientationAware && mParameters.hasAssociatedDisplay) {
            DisplayViewport v;
            if (config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, "", &v)) {
                mOrientation = v.orientation;
            std::optional<DisplayViewport> internalViewport =
                    config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, "");
            if (internalViewport) {
                mOrientation = internalViewport->orientation;
            }
        }
        bumpGeneration();
@@ -2987,9 +2984,10 @@ void RotaryEncoderInputMapper::configure(nsecs_t when,
        mRotaryEncoderScrollAccumulator.configure(getDevice());
    }
    if (!changes || (changes & InputReaderConfiguration::CHANGE_DISPLAY_INFO)) {
        DisplayViewport v;
        if (config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, "", &v)) {
            mOrientation = v.orientation;
        std::optional<DisplayViewport> internalViewport =
                config->getDisplayViewport(ViewportType::VIEWPORT_INTERNAL, "");
        if (internalViewport) {
            mOrientation = internalViewport->orientation;
        } else {
            mOrientation = DISPLAY_ORIENTATION_0;
        }
@@ -3502,7 +3500,9 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
            viewportTypeToUse = ViewportType::VIEWPORT_INTERNAL;
        }

        if (!mConfig.getDisplayViewport(viewportTypeToUse, uniqueDisplayId, &newViewport)) {
        std::optional<DisplayViewport> viewportToUse =
                mConfig.getDisplayViewport(viewportTypeToUse, uniqueDisplayId);
        if (!viewportToUse) {
            ALOGI(INDENT "Touch device '%s' could not query the properties of its associated "
                    "display.  The device will be inoperable until the display size "
                    "becomes available.",
@@ -3510,6 +3510,7 @@ void TouchInputMapper::configureSurface(nsecs_t when, bool* outResetNeeded) {
            mDeviceMode = DEVICE_MODE_DISABLED;
            return;
        }
        newViewport = *viewportToUse;
    } else {
        newViewport.setNonDisplayViewport(rawWidth, rawHeight);
    }
+2 −2
Original line number Diff line number Diff line
@@ -202,8 +202,8 @@ struct InputReaderConfiguration {
            pointerGestureZoomSpeedRatio(0.3f),
            showTouches(false) { }

    bool getDisplayViewport(ViewportType viewportType, const std::string& uniqueDisplayId,
            DisplayViewport* outViewport) const;
    std::optional<DisplayViewport> getDisplayViewport(ViewportType viewportType,
            const std::string& uniqueDisplayId) const;
    void setDisplayViewports(const std::vector<DisplayViewport>& viewports);


+1 −0
Original line number Diff line number Diff line
@@ -10,6 +10,7 @@ cc_test {
    cflags: [
        "-Wall",
        "-Werror",
        "-Wextra",
        "-Wno-unused-parameter",
    ],
    shared_libs: [
+209 −54

File changed.

Preview size limit exceeded, changes collapsed.