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

Commit 16a2e306 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Propagate MotionClassification to InputDispatcher

We added MotionClassification to MotionEvent and NotifyMotionArgs, but
the two have not yet been connected. Connect them here, to ensure that
apps can receive the classification.

Bug: 111480215
Test: atest -a libinput_tests inputflinger_tests
Change-Id: I67dda22d9ee8a2d89abf40dbd01200ec37a65737
parent b6d0623b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -241,6 +241,11 @@ enum class MotionClassification : uint8_t {
    DEEP_PRESS = 2,
};

/**
 * String representation of MotionClassification
 */
const char* motionClassificationToString(MotionClassification classification);

/*
 * Pointer coordinate data.
 */
+3 −1
Original line number Diff line number Diff line
@@ -105,8 +105,9 @@ struct InputMessage {
            int32_t flags;
            int32_t metaState;
            int32_t buttonState;
            MotionClassification classification; // base type: uint8_t
            uint8_t empty2[3];
            int32_t edgeFlags;
            uint32_t empty2;
            nsecs_t downTime __attribute__((aligned(8)));
            float xOffset;
            float yOffset;
@@ -271,6 +272,7 @@ public:
            int32_t edgeFlags,
            int32_t metaState,
            int32_t buttonState,
            MotionClassification classification,
            float xOffset,
            float yOffset,
            float xPrecision,
+11 −0
Original line number Diff line number Diff line
@@ -29,6 +29,17 @@

namespace android {

const char* motionClassificationToString(MotionClassification classification) {
    switch (classification) {
        case MotionClassification::NONE:
            return "NONE";
        case MotionClassification::AMBIGUOUS_GESTURE:
            return "AMBIGUOUS_GESTURE";
        case MotionClassification::DEEP_PRESS:
            return "DEEP_PRESS";
    }
}

// --- InputEvent ---

void InputEvent::initialize(int32_t deviceId, int32_t source, int32_t displayId) {
+8 −4
Original line number Diff line number Diff line
@@ -157,6 +157,8 @@ void InputMessage::getSanitizedCopy(InputMessage* msg) const {
            msg->body.motion.metaState = body.motion.metaState;
            // int32_t buttonState
            msg->body.motion.buttonState = body.motion.buttonState;
            // MotionClassification classification
            msg->body.motion.classification = body.motion.classification;
            // int32_t edgeFlags
            msg->body.motion.edgeFlags = body.motion.edgeFlags;
            // nsecs_t downTime
@@ -448,6 +450,7 @@ status_t InputPublisher::publishMotionEvent(
        int32_t edgeFlags,
        int32_t metaState,
        int32_t buttonState,
        MotionClassification classification,
        float xOffset,
        float yOffset,
        float xPrecision,
@@ -461,13 +464,13 @@ status_t InputPublisher::publishMotionEvent(
    ALOGD("channel '%s' publisher ~ publishMotionEvent: seq=%u, deviceId=%d, source=0x%x, "
            "displayId=%" PRId32 ", "
            "action=0x%x, actionButton=0x%08x, flags=0x%x, edgeFlags=0x%x, "
            "metaState=0x%x, buttonState=0x%x, xOffset=%f, yOffset=%f, "
            "metaState=0x%x, buttonState=0x%x, classification=%s, xOffset=%f, yOffset=%f, "
            "xPrecision=%f, yPrecision=%f, downTime=%" PRId64 ", eventTime=%" PRId64 ", "
            "pointerCount=%" PRIu32,
            mChannel->getName().c_str(), seq,
            deviceId, source, displayId, action, actionButton, flags, edgeFlags, metaState,
            buttonState, xOffset, yOffset, xPrecision, yPrecision, downTime, eventTime,
            pointerCount);
            buttonState, motionClassificationToString(classification),
            xOffset, yOffset, xPrecision, yPrecision, downTime, eventTime, pointerCount);
#endif

    if (!seq) {
@@ -493,6 +496,7 @@ status_t InputPublisher::publishMotionEvent(
    msg.body.motion.edgeFlags = edgeFlags;
    msg.body.motion.metaState = metaState;
    msg.body.motion.buttonState = buttonState;
    msg.body.motion.classification = classification;
    msg.body.motion.xOffset = xOffset;
    msg.body.motion.yOffset = yOffset;
    msg.body.motion.xPrecision = xPrecision;
@@ -1112,7 +1116,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.classification,
            msg->body.motion.xOffset,
            msg->body.motion.yOffset,
            msg->body.motion.xPrecision,
+34 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
 * limitations under the License.
 */

#include <array>

#include "TestHelpers.h"

#include <unistd.h>
@@ -155,5 +157,37 @@ TEST_F(InputChannelTest, SendSignal_WhenPeerClosed_ReturnsAnError) {
            << "sendMessage should have returned DEAD_OBJECT";
}

TEST_F(InputChannelTest, SendAndReceive_MotionClassification) {
    sp<InputChannel> serverChannel, clientChannel;
    status_t result = InputChannel::openInputChannelPair("channel name",
            serverChannel, clientChannel);
    ASSERT_EQ(OK, result)
            << "should have successfully opened a channel pair";

    std::array<MotionClassification, 3> classifications = {
        MotionClassification::NONE,
        MotionClassification::AMBIGUOUS_GESTURE,
        MotionClassification::DEEP_PRESS,
    };

    InputMessage serverMsg = {}, clientMsg;
    serverMsg.header.type = InputMessage::TYPE_MOTION;
    serverMsg.body.motion.seq = 1;
    serverMsg.body.motion.pointerCount = 1;

    for (MotionClassification classification : classifications) {
        // Send and receive a message with classification
        serverMsg.body.motion.classification = classification;
        EXPECT_EQ(OK, serverChannel->sendMessage(&serverMsg))
                << "server channel should be able to send message to client channel";

        EXPECT_EQ(OK, clientChannel->receiveMessage(&clientMsg))
                << "client channel should be able to receive message from server channel";
        EXPECT_EQ(serverMsg.header.type, clientMsg.header.type);
        EXPECT_EQ(classification, clientMsg.body.motion.classification) <<
                "Expected to receive " << motionClassificationToString(classification);
    }
}


} // namespace android
Loading