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

Commit 6cd19a42 authored by Arthur Hung's avatar Arthur Hung
Browse files

Make sure that touches are within the surface.

Changed TouchInputMapper::isPointInsideSurface should check the
surface range instead of physical frame range.

Test: atest inputflinger_tests
Test: enable emulator, open second display with landscape mode, try
      YouTube and changed it to portrait mode.
Bug: 139805619

Change-Id: Id4ad7053acac33f49363442bd5f710f8023d5190
parent d071a9dc
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -3621,9 +3621,9 @@ bool TouchInputMapper::isPointInsideSurface(int32_t x, int32_t y) {
    const float scaledX = x * mXScale;
    const float scaledY = y * mYScale;
    return x >= mRawPointerAxes.x.minValue && x <= mRawPointerAxes.x.maxValue &&
            scaledX >= mPhysicalLeft && scaledX <= mPhysicalLeft + mPhysicalWidth &&
            scaledX >= mSurfaceLeft && scaledX <= mSurfaceLeft + mSurfaceWidth &&
            y >= mRawPointerAxes.y.minValue && y <= mRawPointerAxes.y.maxValue &&
            scaledY >= mPhysicalTop && scaledY <= mPhysicalTop + mPhysicalHeight;
            scaledY >= mSurfaceTop && scaledY <= mSurfaceTop + mSurfaceHeight;
}

const TouchInputMapper::VirtualKey* TouchInputMapper::findVirtualKeyHit(int32_t x, int32_t y) {
+40 −0
Original line number Diff line number Diff line
@@ -202,6 +202,20 @@ public:
        mConfig.setDisplayViewports(mViewports);
    }

    bool updateViewport(const DisplayViewport& viewport) {
        size_t count = mViewports.size();
        for (size_t i = 0; i < count; i++) {
            const DisplayViewport& currentViewport = mViewports[i];
            if (currentViewport.displayId == viewport.displayId) {
                mViewports[i] = viewport;
                mConfig.setDisplayViewports(mViewports);
                return true;
            }
        }
        // no viewport found.
        return false;
    }

    void addExcludedDeviceName(const std::string& deviceName) {
        mConfig.excludedDeviceNames.push_back(deviceName);
    }
@@ -6593,4 +6607,30 @@ TEST_F(MultiTouchInputMapperTest, Configure_EnabledForAssociatedDisplay) {
    ASSERT_EQ(SECONDARY_DISPLAY_ID, args.displayId);
}

/**
 * Test touch should not work if outside of surface.
 */
TEST_F(MultiTouchInputMapperTest, Viewports_SurfaceRange) {
    MultiTouchInputMapper* mapper = new MultiTouchInputMapper(mDevice);
    addConfigurationProperty("touch.deviceType", "touchScreen");
    prepareDisplay(DISPLAY_ORIENTATION_0);
    // Let surface be different from physical display.
    std::optional<DisplayViewport> internalViewport =
            mFakePolicy->getDisplayViewportByType(ViewportType::VIEWPORT_INTERNAL);
    internalViewport->logicalLeft = internalViewport->physicalTop + 20;
    internalViewport->logicalTop = internalViewport->physicalRight + 20;
    internalViewport->logicalRight = internalViewport->physicalRight - 20;
    internalViewport->logicalBottom = internalViewport->physicalBottom - 20;
    mFakePolicy->updateViewport(internalViewport.value());

    prepareAxes(POSITION);
    addMapperAndConfigure(mapper);

    int32_t rawX = 10;
    int32_t rawY = 10;
    processPosition(mapper, rawX, rawY);
    processSync(mapper);
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
}

} // namespace android