Add error logging when channel receives an invalid message

When an InputChannel receives an invalid message today, it produces a
BAD_VALUE status. This status later causes the InputChannel to get
completely closed. But the error messages today are only showing up when
the channel debugging is on.

Since the closure of an input channel is a pretty catastrophic failure,
always log these messages. This could have helped identify the root
cause of b/185015591 immediately.

Sample logs after this change, and before the bug fix:
E InputTransport: Received invalid TIMELINE: gpuCompletedTime = 245454055433239 presentTime = 245453214298812
E InputTransport: channel '1a77725 com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity (server)' ~ received invalid message of size 32
E InputDispatcher: channel '1a77725 com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity (server)' ~ Failed to receive finished signal.  status=BAD_VALUE(-22)
E InputDispatcher: channel '1a77725 com.google.android.apps.nexuslauncher/com.google.android.apps.nexuslauncher.NexusLauncherActivity (server)' ~ Channel is unrecoverably broken and will be disposed!

Separately, ensure that the StructLayout_test is getting built for both
32-bit and 64-bit applications. This was missed in the last refactor of
this test in
https://googleplex-android-review.git.corp.google.com/c/platform/frameworks/native/+/1433165/1/libs/input/tests/Android.mk#b35
when the build files were getting converted from mk to bp.

Also, remove the "-O0" option from StructLayout_test. The struct layout
that we actually care about resides (and is getting built) in libinput.
When libinput is being built, we do not specify "-O0". Therefore, we
should compile StructLayout_test using the same compiler options as we
use for libinput. Otherwise, these asserts are not representative of the
real-world usage.

Bug: 185015591
Test: atest libinput_tests
Test: m StructLayout_test StructLayout_test_32
Change-Id: I854c829151636e0906fca1e3a3ac389e07980faf
diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp
index 56a064b..c68cd9e 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;
 }
 
@@ -400,9 +414,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;
     }