Merge "Add error logging when channel receives an invalid message" into sc-dev
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp
index de75691..dd1c462 100644
--- a/libs/input/InputTransport.cpp
+++ b/libs/input/InputTransport.cpp
@@ -96,28 +96,42 @@
// --- InputMessage ---
bool InputMessage::isValid(size_t actualSize) const {
- if (size() == actualSize) {
- switch (header.type) {
- case Type::KEY:
- return true;
- case Type::MOTION:
- return body.motion.pointerCount > 0 && body.motion.pointerCount <= MAX_POINTERS;
- case Type::FINISHED:
- return true;
- case Type::FOCUS:
- return true;
- case Type::CAPTURE:
- return true;
- case Type::DRAG:
- return true;
- case Type::TIMELINE:
- const nsecs_t gpuCompletedTime =
- body.timeline.graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME];
- const nsecs_t presentTime =
- body.timeline.graphicsTimeline[GraphicsTimeline::PRESENT_TIME];
- return presentTime > gpuCompletedTime;
+ if (size() != actualSize) {
+ ALOGE("Received message of incorrect size %zu (expected %zu)", actualSize, size());
+ return false;
+ }
+
+ switch (header.type) {
+ case Type::KEY:
+ return true;
+ case Type::MOTION: {
+ const bool valid =
+ body.motion.pointerCount > 0 && body.motion.pointerCount <= MAX_POINTERS;
+ if (!valid) {
+ ALOGE("Received invalid MOTION: pointerCount = %" PRIu32, body.motion.pointerCount);
+ }
+ return valid;
+ }
+ case Type::FINISHED:
+ case Type::FOCUS:
+ case Type::CAPTURE:
+ case Type::DRAG:
+ return true;
+ case Type::TIMELINE: {
+ const nsecs_t gpuCompletedTime =
+ body.timeline.graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME];
+ const nsecs_t presentTime =
+ body.timeline.graphicsTimeline[GraphicsTimeline::PRESENT_TIME];
+ const bool valid = presentTime > gpuCompletedTime;
+ if (!valid) {
+ ALOGE("Received invalid TIMELINE: gpuCompletedTime = %" PRId64
+ " presentTime = %" PRId64,
+ gpuCompletedTime, presentTime);
+ }
+ return valid;
}
}
+ ALOGE("Invalid message type: %" PRIu32, header.type);
return false;
}
@@ -404,9 +418,7 @@
}
if (!msg->isValid(nRead)) {
-#if DEBUG_CHANNEL_MESSAGES
- ALOGD("channel '%s' ~ received invalid message", mName.c_str());
-#endif
+ ALOGE("channel '%s' ~ received invalid message of size %zd", mName.c_str(), nRead);
return BAD_VALUE;
}
diff --git a/libs/input/tests/Android.bp b/libs/input/tests/Android.bp
index fe8a567..767878b 100644
--- a/libs/input/tests/Android.bp
+++ b/libs/input/tests/Android.bp
@@ -49,8 +49,8 @@
cc_library_static {
name: "StructLayout_test",
srcs: ["StructLayout_test.cpp"],
+ compile_multilib: "both",
cflags: [
- "-O0",
"-Wall",
"-Werror",
"-Wextra",