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

Commit 49e59220 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Add classification to MotionEvent

The classification will be used to categorize the
current motion event stream. The classification may change from ambiguous to deep press,
for example.

Test: integration tested by printing to logcat whenever CLASSIFICATION_DEEP_PRESS
is present.
Test: atest libinput_tests inputflinger_tests
Bug: 62940136

Change-Id: I2d93583bab42162e1fd1e95ebf624ef3ab9a58ec
parent bcb4be70
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -220,6 +220,27 @@ enum {
    POLICY_FLAG_PASS_TO_USER = 0x40000000,
};

/**
 * Classifications of the current gesture, if available.
 *
 * The following values must be kept in sync with MotionEvent.java
 */
enum class MotionClassification : uint8_t {
    /**
     * No classification is available.
     */
    NONE = 0,
    /**
     * Too early to classify the current gesture. Need more events. Look for changes in the
     * upcoming motion events.
     */
    AMBIGUOUS_GESTURE = 1,
    /**
     * The current gesture likely represents a user intentionally exerting force on the touchscreen.
     */
    DEEP_PRESS = 2,
};

/*
 * Pointer coordinate data.
 */
@@ -419,6 +440,8 @@ public:

    inline void setButtonState(int32_t buttonState) { mButtonState = buttonState; }

    inline MotionClassification getClassification() const { return mClassification; }

    inline int32_t getActionButton() const { return mActionButton; }

    inline void setActionButton(int32_t button) { mActionButton = button; }
@@ -582,6 +605,7 @@ public:
            int32_t edgeFlags,
            int32_t metaState,
            int32_t buttonState,
            MotionClassification classification,
            float xOffset,
            float yOffset,
            float xPrecision,
@@ -635,6 +659,7 @@ protected:
    int32_t mEdgeFlags;
    int32_t mMetaState;
    int32_t mButtonState;
    MotionClassification mClassification;
    float mXOffset;
    float mYOffset;
    float mXPrecision;
+5 −0
Original line number Diff line number Diff line
@@ -234,6 +234,7 @@ void MotionEvent::initialize(
        int32_t edgeFlags,
        int32_t metaState,
        int32_t buttonState,
        MotionClassification classification,
        float xOffset,
        float yOffset,
        float xPrecision,
@@ -250,6 +251,7 @@ void MotionEvent::initialize(
    mEdgeFlags = edgeFlags;
    mMetaState = metaState;
    mButtonState = buttonState;
    mClassification = classification;
    mXOffset = xOffset;
    mYOffset = yOffset;
    mXPrecision = xPrecision;
@@ -270,6 +272,7 @@ void MotionEvent::copyFrom(const MotionEvent* other, bool keepHistory) {
    mEdgeFlags = other->mEdgeFlags;
    mMetaState = other->mMetaState;
    mButtonState = other->mButtonState;
    mClassification = other->mClassification;
    mXOffset = other->mXOffset;
    mYOffset = other->mYOffset;
    mXPrecision = other->mXPrecision;
@@ -451,6 +454,7 @@ status_t MotionEvent::readFromParcel(Parcel* parcel) {
    mEdgeFlags = parcel->readInt32();
    mMetaState = parcel->readInt32();
    mButtonState = parcel->readInt32();
    mClassification = static_cast<MotionClassification>(parcel->readByte());
    mXOffset = parcel->readFloat();
    mYOffset = parcel->readFloat();
    mXPrecision = parcel->readFloat();
@@ -501,6 +505,7 @@ status_t MotionEvent::writeToParcel(Parcel* parcel) const {
    parcel->writeInt32(mEdgeFlags);
    parcel->writeInt32(mMetaState);
    parcel->writeInt32(mButtonState);
    parcel->writeByte(static_cast<int8_t>(mClassification));
    parcel->writeFloat(mXOffset);
    parcel->writeFloat(mYOffset);
    parcel->writeFloat(mXPrecision);
+1 −0
Original line number Diff line number Diff line
@@ -1112,6 +1112,7 @@ void InputConsumer::initializeMotionEvent(MotionEvent* event, const InputMessage
            msg->body.motion.edgeFlags,
            msg->body.motion.metaState,
            msg->body.motion.buttonState,
            MotionClassification::NONE,
            msg->body.motion.xOffset,
            msg->body.motion.yOffset,
            msg->body.motion.xPrecision,
+6 −3
Original line number Diff line number Diff line
@@ -260,7 +260,7 @@ void MotionEventTest::initializeEventWithHistory(MotionEvent* event) {
    event->initialize(2, AINPUT_SOURCE_TOUCHSCREEN, DISPLAY_ID, AMOTION_EVENT_ACTION_MOVE, 0,
            AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED,
            AMOTION_EVENT_EDGE_FLAG_TOP, AMETA_ALT_ON, AMOTION_EVENT_BUTTON_PRIMARY,
            X_OFFSET, Y_OFFSET, 2.0f, 2.1f,
            MotionClassification::NONE, X_OFFSET, Y_OFFSET, 2.0f, 2.1f,
            ARBITRARY_DOWN_TIME, ARBITRARY_EVENT_TIME,
            2, pointerProperties, pointerCoords);

@@ -572,8 +572,11 @@ TEST_F(MotionEventTest, Transform) {
        pointerCoords[i].setAxisValue(AMOTION_EVENT_AXIS_ORIENTATION, angle);
    }
    MotionEvent event;
    event.initialize(0, 0, DISPLAY_ID, AMOTION_EVENT_ACTION_MOVE, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, pointerCount, pointerProperties, pointerCoords);
    event.initialize(0 /*deviceId*/, AINPUT_SOURCE_UNKNOWN, DISPLAY_ID, AMOTION_EVENT_ACTION_MOVE,
            0 /*actionButton*/, 0 /*flags*/, AMOTION_EVENT_EDGE_FLAG_NONE,
            AMETA_NONE, 0 /*buttonState*/, MotionClassification::NONE,
            0 /*xOffset*/, 0 /*yOffset*/, 0 /*xPrecision*/, 0 /*yPrecision*/,
            0 /*downTime*/, 0 /*eventTime*/, pointerCount, pointerProperties, pointerCoords);
    float originalRawX = 0 + 3;
    float originalRawY = -RADIUS + 2;

+7 −3
Original line number Diff line number Diff line
@@ -90,7 +90,8 @@ MotionEvent* createSimpleMotionEvent(const Position* positions, size_t numSample

    MotionEvent* event = new MotionEvent();
    PointerCoords coords;
    PointerProperties properties[1];
    constexpr size_t pointerCount = 1;
    PointerProperties properties[pointerCount];

    properties[0].id = DEFAULT_POINTER_ID;
    properties[0].toolType = AMOTION_EVENT_TOOL_TYPE_FINGER;
@@ -98,8 +99,11 @@ MotionEvent* createSimpleMotionEvent(const Position* positions, size_t numSample
    // First sample added separately with initialize
    coords.setAxisValue(AMOTION_EVENT_AXIS_X, positions[0].x);
    coords.setAxisValue(AMOTION_EVENT_AXIS_Y, positions[0].y);
    event->initialize(0, AINPUT_SOURCE_TOUCHSCREEN, DISPLAY_ID, AMOTION_EVENT_ACTION_MOVE,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, positions[0].time, 1, properties, &coords);
    event->initialize(0 /*deviceId*/, AINPUT_SOURCE_TOUCHSCREEN, DISPLAY_ID,
            AMOTION_EVENT_ACTION_MOVE, 0 /*actionButton*/, 0 /*flags*/,
            AMOTION_EVENT_EDGE_FLAG_NONE, AMETA_NONE, 0 /*buttonState*/, MotionClassification::NONE,
            0 /*xOffset*/, 0 /*yOffset*/, 0 /*xPrecision*/, 0 /*yPrecision*/,
            0 /*downTime*/, positions[0].time, pointerCount, properties, &coords);

    for (size_t i = 1; i < numSamples; i++) {
        coords.setAxisValue(AMOTION_EVENT_AXIS_X, positions[i].x);
Loading