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

Commit ce1cd88c authored by Prabir Pradhan's avatar Prabir Pradhan Committed by Android (Google) Code Review
Browse files

Merge "Do not assume we are in POINTER mode when canceling pointer gestures"

parents fc424b0a b80b6c0e
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -3556,6 +3556,8 @@ std::list<NotifyArgs> TouchInputMapper::abortPointerMouse(nsecs_t when, nsecs_t
std::list<NotifyArgs> TouchInputMapper::dispatchPointerSimple(nsecs_t when, nsecs_t readTime,
                                                              uint32_t policyFlags, bool down,
                                                              bool hovering) {
    LOG_ALWAYS_FATAL_IF(mDeviceMode != DeviceMode::POINTER,
                        "%s cannot be used when the device is not in POINTER mode.", __func__);
    std::list<NotifyArgs> out;
    int32_t metaState = getContext()->getGlobalMetaState();

@@ -3682,6 +3684,10 @@ std::list<NotifyArgs> TouchInputMapper::dispatchPointerSimple(nsecs_t when, nsec
    if (down || hovering) {
        mPointerSimple.lastCoords.copyFrom(mPointerSimple.currentCoords);
        mPointerSimple.lastProperties.copyFrom(mPointerSimple.currentProperties);
        mPointerSimple.displayId = displayId;
        mPointerSimple.source = mSource;
        mPointerSimple.lastCursorX = xCursorPosition;
        mPointerSimple.lastCursorY = yCursorPosition;
    } else {
        mPointerSimple.reset();
    }
@@ -3690,10 +3696,25 @@ std::list<NotifyArgs> TouchInputMapper::dispatchPointerSimple(nsecs_t when, nsec

std::list<NotifyArgs> TouchInputMapper::abortPointerSimple(nsecs_t when, nsecs_t readTime,
                                                           uint32_t policyFlags) {
    mPointerSimple.currentCoords.clear();
    mPointerSimple.currentProperties.clear();

    return dispatchPointerSimple(when, readTime, policyFlags, false, false);
    std::list<NotifyArgs> out;
    if (mPointerSimple.down || mPointerSimple.hovering) {
        int32_t metaState = getContext()->getGlobalMetaState();
        out.push_back(NotifyMotionArgs(getContext()->getNextId(), when, readTime, getDeviceId(),
                                       mPointerSimple.source, mPointerSimple.displayId, policyFlags,
                                       AMOTION_EVENT_ACTION_CANCEL, 0, AMOTION_EVENT_FLAG_CANCELED,
                                       metaState, mLastRawState.buttonState,
                                       MotionClassification::NONE, AMOTION_EVENT_EDGE_FLAG_NONE, 1,
                                       &mPointerSimple.lastProperties, &mPointerSimple.lastCoords,
                                       mOrientedXPrecision, mOrientedYPrecision,
                                       mPointerSimple.lastCursorX, mPointerSimple.lastCursorY,
                                       mPointerSimple.downTime,
                                       /* videoFrames */ {}));
        if (mPointerController != nullptr) {
            mPointerController->fade(PointerControllerInterface::Transition::GRADUAL);
        }
    }
    mPointerSimple.reset();
    return out;
}

NotifyMotionArgs TouchInputMapper::dispatchMotion(
+10 −0
Original line number Diff line number Diff line
@@ -678,6 +678,12 @@ private:
        // Time the pointer last went down.
        nsecs_t downTime;

        // Values reported for the last pointer event.
        uint32_t source;
        int32_t displayId;
        float lastCursorX;
        float lastCursorY;

        void reset() {
            currentCoords.clear();
            currentProperties.clear();
@@ -686,6 +692,10 @@ private:
            down = false;
            hovering = false;
            downTime = 0;
            source = 0;
            displayId = ADISPLAY_ID_NONE;
            lastCursorX = 0.f;
            lastCursorY = 0.f;
        }
    } mPointerSimple;

+40 −0
Original line number Diff line number Diff line
@@ -10420,6 +10420,46 @@ TEST_F(MultiTouchPointerModeTest, TwoFingerSwipeOffsets) {
    ASSERT_GT(motionArgs.pointerCoords[0].getAxisValue(AMOTION_EVENT_AXIS_GESTURE_Y_OFFSET), 0);
}

TEST_F(MultiTouchPointerModeTest, WhenViewportActiveStatusChanged_PointerGestureIsReset) {
    preparePointerMode(25 /*xResolution*/, 25 /*yResolution*/);
    mFakeEventHub->addKey(EVENTHUB_ID, BTN_TOOL_PEN, 0, AKEYCODE_UNKNOWN, 0);
    MultiTouchInputMapper& mapper = addMapperAndConfigure<MultiTouchInputMapper>();
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyDeviceResetWasCalled());

    // Start a stylus gesture.
    processKey(mapper, BTN_TOOL_PEN, 1);
    processId(mapper, FIRST_TRACKING_ID);
    processPosition(mapper, 100, 200);
    processSync(mapper);
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(
            AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN),
                  WithSource(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS),
                  WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS))));
    // TODO(b/257078296): Pointer mode generates extra event.
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(
            AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE),
                  WithSource(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS),
                  WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS))));
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());

    // Make the viewport inactive. This will put the device in disabled mode, and the ongoing stylus
    // gesture should be disabled.
    auto viewport = mFakePolicy->getDisplayViewportByType(ViewportType::INTERNAL);
    viewport->isActive = false;
    mFakePolicy->updateViewport(*viewport);
    configureDevice(InputReaderConfiguration::CHANGE_DISPLAY_INFO);
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(
            AllOf(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL),
                  WithSource(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS),
                  WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS))));
    // TODO(b/257078296): Pointer mode generates extra event.
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasCalled(
            AllOf(WithMotionAction(AMOTION_EVENT_ACTION_CANCEL),
                  WithSource(AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS),
                  WithToolType(AMOTION_EVENT_TOOL_TYPE_STYLUS))));
    ASSERT_NO_FATAL_FAILURE(mFakeListener->assertNotifyMotionWasNotCalled());
}

// --- JoystickInputMapperTest ---

class JoystickInputMapperTest : public InputMapperTest {