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

Commit b8e9586d authored by Siarhei Vishniakou's avatar Siarhei Vishniakou Committed by Android (Google) Code Review
Browse files

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

parents 94091d03 dbdb6736
Loading
Loading
Loading
Loading
+35 −23
Original line number Original line Diff line number Diff line
@@ -96,28 +96,42 @@ inline static const char* toString(bool value) {
// --- InputMessage ---
// --- InputMessage ---


bool InputMessage::isValid(size_t actualSize) const {
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) {
    switch (header.type) {
        case Type::KEY:
        case Type::KEY:
            return true;
            return true;
            case Type::MOTION:
        case Type::MOTION: {
                return body.motion.pointerCount > 0 && body.motion.pointerCount <= MAX_POINTERS;
            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::FINISHED:
                return true;
        case Type::FOCUS:
        case Type::FOCUS:
                return true;
        case Type::CAPTURE:
        case Type::CAPTURE:
                return true;
        case Type::DRAG:
        case Type::DRAG:
            return true;
            return true;
            case Type::TIMELINE:
        case Type::TIMELINE: {
            const nsecs_t gpuCompletedTime =
            const nsecs_t gpuCompletedTime =
                    body.timeline.graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME];
                    body.timeline.graphicsTimeline[GraphicsTimeline::GPU_COMPLETED_TIME];
            const nsecs_t presentTime =
            const nsecs_t presentTime =
                    body.timeline.graphicsTimeline[GraphicsTimeline::PRESENT_TIME];
                    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;
    return false;
}
}


@@ -404,9 +418,7 @@ status_t InputChannel::receiveMessage(InputMessage* msg) {
    }
    }


    if (!msg->isValid(nRead)) {
    if (!msg->isValid(nRead)) {
#if DEBUG_CHANNEL_MESSAGES
        ALOGE("channel '%s' ~ received invalid message of size %zd", mName.c_str(), nRead);
        ALOGD("channel '%s' ~ received invalid message", mName.c_str());
#endif
        return BAD_VALUE;
        return BAD_VALUE;
    }
    }


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