Loading include/input/Input.h +5 −0 Original line number Diff line number Diff line Loading @@ -241,6 +241,11 @@ enum class MotionClassification : uint8_t { DEEP_PRESS = 2, }; /** * String representation of MotionClassification */ const char* motionClassificationToString(MotionClassification classification); /* * Pointer coordinate data. */ Loading include/input/InputTransport.h +3 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -271,6 +272,7 @@ public: int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xOffset, float yOffset, float xPrecision, Loading libs/input/Input.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading libs/input/InputTransport.cpp +8 −4 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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, Loading @@ -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) { Loading @@ -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; Loading Loading @@ -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, Loading libs/input/tests/InputChannel_test.cpp +34 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ * limitations under the License. */ #include <array> #include "TestHelpers.h" #include <unistd.h> Loading Loading @@ -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
include/input/Input.h +5 −0 Original line number Diff line number Diff line Loading @@ -241,6 +241,11 @@ enum class MotionClassification : uint8_t { DEEP_PRESS = 2, }; /** * String representation of MotionClassification */ const char* motionClassificationToString(MotionClassification classification); /* * Pointer coordinate data. */ Loading
include/input/InputTransport.h +3 −1 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -271,6 +272,7 @@ public: int32_t edgeFlags, int32_t metaState, int32_t buttonState, MotionClassification classification, float xOffset, float yOffset, float xPrecision, Loading
libs/input/Input.cpp +11 −0 Original line number Diff line number Diff line Loading @@ -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) { Loading
libs/input/InputTransport.cpp +8 −4 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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, Loading @@ -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) { Loading @@ -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; Loading Loading @@ -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, Loading
libs/input/tests/InputChannel_test.cpp +34 −0 Original line number Diff line number Diff line Loading @@ -14,6 +14,8 @@ * limitations under the License. */ #include <array> #include "TestHelpers.h" #include <unistd.h> Loading Loading @@ -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