Loading include/input/InputTransport.h +8 −3 Original line number Diff line number Diff line Loading @@ -121,11 +121,16 @@ struct InputMessage { float yCursorPosition; uint32_t pointerCount; uint32_t empty3; // Note that PointerCoords requires 8 byte alignment. /** * The "pointers" field must be the last field of the struct InputMessage. * When we send the struct InputMessage across the socket, we are not * writing the entire "pointers" array, but only the pointerCount portion * of it as an optimization. Adding a field after "pointers" would break this. */ struct Pointer { PointerProperties properties; PointerCoords coords; } pointers[MAX_POINTERS]; } pointers[MAX_POINTERS] __attribute__((aligned(8))); int32_t getActionId() const { uint32_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) Loading @@ -141,7 +146,7 @@ struct InputMessage { struct Finished { uint32_t seq; bool handled; uint32_t handled; // actually a bool, but we must maintain 8-byte alignment inline size_t size() const { return sizeof(Finished); Loading libs/input/InputTransport.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -547,7 +547,7 @@ status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandle return UNKNOWN_ERROR; } *outSeq = msg.body.finished.seq; *outHandled = msg.body.finished.handled; *outHandled = msg.body.finished.handled == 1; return OK; } Loading Loading @@ -1065,7 +1065,7 @@ status_t InputConsumer::sendUnchainedFinishedSignal(uint32_t seq, bool handled) InputMessage msg; msg.header.type = InputMessage::Type::FINISHED; msg.body.finished.seq = seq; msg.body.finished.handled = handled; msg.body.finished.handled = handled ? 1 : 0; return mChannel->sendMessage(&msg); } Loading libs/input/tests/StructLayout_test.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -73,4 +73,20 @@ void TestInputMessageAlignment() { CHECK_OFFSET(InputMessage::Body::Finished, handled, 4); } void TestHeaderSize() { static_assert(sizeof(InputMessage::Header) == 8); } /** * We cannot use the Body::size() method here because it is not static for * the Motion type, where "pointerCount" variable affects the size and can change at runtime. */ void TestBodySize() { static_assert(sizeof(InputMessage::Body::Key) == 64); static_assert(sizeof(InputMessage::Body::Motion) == offsetof(InputMessage::Body::Motion, pointers) + sizeof(InputMessage::Body::Motion::Pointer) * MAX_POINTERS); static_assert(sizeof(InputMessage::Body::Finished) == 8); } } // namespace android Loading
include/input/InputTransport.h +8 −3 Original line number Diff line number Diff line Loading @@ -121,11 +121,16 @@ struct InputMessage { float yCursorPosition; uint32_t pointerCount; uint32_t empty3; // Note that PointerCoords requires 8 byte alignment. /** * The "pointers" field must be the last field of the struct InputMessage. * When we send the struct InputMessage across the socket, we are not * writing the entire "pointers" array, but only the pointerCount portion * of it as an optimization. Adding a field after "pointers" would break this. */ struct Pointer { PointerProperties properties; PointerCoords coords; } pointers[MAX_POINTERS]; } pointers[MAX_POINTERS] __attribute__((aligned(8))); int32_t getActionId() const { uint32_t index = (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) Loading @@ -141,7 +146,7 @@ struct InputMessage { struct Finished { uint32_t seq; bool handled; uint32_t handled; // actually a bool, but we must maintain 8-byte alignment inline size_t size() const { return sizeof(Finished); Loading
libs/input/InputTransport.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -547,7 +547,7 @@ status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandle return UNKNOWN_ERROR; } *outSeq = msg.body.finished.seq; *outHandled = msg.body.finished.handled; *outHandled = msg.body.finished.handled == 1; return OK; } Loading Loading @@ -1065,7 +1065,7 @@ status_t InputConsumer::sendUnchainedFinishedSignal(uint32_t seq, bool handled) InputMessage msg; msg.header.type = InputMessage::Type::FINISHED; msg.body.finished.seq = seq; msg.body.finished.handled = handled; msg.body.finished.handled = handled ? 1 : 0; return mChannel->sendMessage(&msg); } Loading
libs/input/tests/StructLayout_test.cpp +16 −0 Original line number Diff line number Diff line Loading @@ -73,4 +73,20 @@ void TestInputMessageAlignment() { CHECK_OFFSET(InputMessage::Body::Finished, handled, 4); } void TestHeaderSize() { static_assert(sizeof(InputMessage::Header) == 8); } /** * We cannot use the Body::size() method here because it is not static for * the Motion type, where "pointerCount" variable affects the size and can change at runtime. */ void TestBodySize() { static_assert(sizeof(InputMessage::Body::Key) == 64); static_assert(sizeof(InputMessage::Body::Motion) == offsetof(InputMessage::Body::Motion, pointers) + sizeof(InputMessage::Body::Motion::Pointer) * MAX_POINTERS); static_assert(sizeof(InputMessage::Body::Finished) == 8); } } // namespace android