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

Commit 11bd57de 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 am: b8e9586d

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

Change-Id: Ib04e38f8c9cba9bb981b42d611709edf14ab0dad
parents 85edcd85 b8e9586d
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",