summaryrefslogtreecommitdiff
path: root/libs/input
diff options
context:
space:
mode:
author Siarhei Vishniakou <svv@google.com> 2019-11-25 11:44:11 -0800
committer Siarhei Vishniakou <svv@google.com> 2019-11-26 13:03:54 -0800
commit10fe676bf6423dfb17104e8f1fdacdaf1d1983da (patch)
tree1374b58a5ae1269c7de134abe86a18906bb813fe /libs/input
parent3b37f9a0b60464ec89b530e6cebc2c3236d0cebc (diff)
Add static asserts for InputMessage sizes
We currently don't test the total size of InputMessage. But that's still important, to ensure it doesn't extend further than expected. Add asserts for the sizes of Header and Body. Bug: none Test: presubmit Change-Id: I2dbda2136186b22a9247fde058a9c356b07c808d
Diffstat (limited to 'libs/input')
-rw-r--r--libs/input/InputTransport.cpp4
-rw-r--r--libs/input/tests/StructLayout_test.cpp16
2 files changed, 18 insertions, 2 deletions
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp
index 8d1dd639bb..b7937dc95e 100644
--- a/libs/input/InputTransport.cpp
+++ b/libs/input/InputTransport.cpp
@@ -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;
}
@@ -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);
}
diff --git a/libs/input/tests/StructLayout_test.cpp b/libs/input/tests/StructLayout_test.cpp
index 8d8cf06c91..0fb6cfc204 100644
--- a/libs/input/tests/StructLayout_test.cpp
+++ b/libs/input/tests/StructLayout_test.cpp
@@ -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