Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ef7a1b38 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou Committed by Automerger Merge Worker
Browse files

Merge "Add error logging when channel receives an invalid message" into sc-dev...

Merge "Add error logging when channel receives an invalid message" into sc-dev am: b8e9586d am: 8b0d5403

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/14313777

Change-Id: I7a7f6a921b0f8b68c0d025c132629868a883c74f
parents 4c0180eb 8b0d5403
Loading
Loading
Loading
Loading
+35 −23
Original line number Diff line number Diff line
@@ -96,28 +96,42 @@ inline static const char* toString(bool value) {
// --- InputMessage ---

bool InputMessage::isValid(size_t actualSize) const {
    if (size() == actualSize) {
    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:
                return body.motion.pointerCount > 0 && body.motion.pointerCount <= MAX_POINTERS;
        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:
                return true;
        case Type::FOCUS:
                return true;
        case Type::CAPTURE:
                return true;
        case Type::DRAG:
            return true;
            case Type::TIMELINE:
        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;
            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 @@ status_t InputChannel::receiveMessage(InputMessage* msg) {
    }

    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;
    }

+1 −1
Original line number Diff line number Diff line
@@ -49,8 +49,8 @@ cc_test {
cc_library_static {
    name: "StructLayout_test",
    srcs: ["StructLayout_test.cpp"],
    compile_multilib: "both",
    cflags: [
        "-O0",
        "-Wall",
        "-Werror",
        "-Wextra",