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

Commit 2c7a22e2 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Improve logging of evdev events by using labels for recognized values"...

Merge "Improve logging of evdev events by using labels for recognized values" into udc-dev am: b02c8901

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



Change-Id: Icc2b203102076bdc5339a9b1d10b9fd9059933b8
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 0b81d3b2 b02c8901
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -30,6 +30,12 @@ struct InputEventLabel {
    int value;
};

struct EvdevEventLabel {
    std::string type;
    std::string code;
    std::string value;
};

//   NOTE: If you want a new key code, axis code, led code or flag code in keylayout file,
//   then you must add it to InputEventLabels.cpp.

@@ -52,6 +58,8 @@ public:

    static std::optional<int> getLedByLabel(const char* label);

    static EvdevEventLabel getLinuxEvdevLabel(int32_t type, int32_t code, int32_t value);

private:
    static const std::unordered_map<std::string, int> KEYCODES;

+4 −0
Original line number Diff line number Diff line
@@ -69,6 +69,10 @@ cc_library {
    ],
    export_header_lib_headers: ["jni_headers"],

    generated_headers: [
        "toolbox_input_labels",
    ],

    shared_libs: [
        "libbase",
        "libcutils",
+84 −0
Original line number Diff line number Diff line
@@ -16,6 +16,9 @@

#include <input/InputEventLabels.h>

#include <linux/input-event-codes.h>
#include <linux/input.h>

#define DEFINE_KEYCODE(key) { #key, AKEYCODE_##key }
#define DEFINE_AXIS(axis) { #axis, AMOTION_EVENT_AXIS_##axis }
#define DEFINE_LED(led) { #led, ALED_##led }
@@ -480,4 +483,85 @@ std::optional<int> InputEventLookup::getLedByLabel(const char* label) {
    return lookupValueByLabel(LEDS, label);
}

namespace {

struct label {
    const char* name;
    int value;
};

#define LABEL(constant) \
    { #constant, constant }
#define LABEL_END \
    { nullptr, -1 }

static struct label ev_key_value_labels[] = {
        {"UP", 0},
        {"DOWN", 1},
        {"REPEAT", 2},
        LABEL_END,
};

#include "input.h-labels.h"

#undef LABEL
#undef LABEL_END

std::string getLabel(const label* labels, int value) {
    if (labels == nullptr) return std::to_string(value);
    while (labels->name != nullptr && value != labels->value) {
        labels++;
    }
    return labels->name != nullptr ? labels->name : std::to_string(value);
}

const label* getCodeLabelsForType(int32_t type) {
    switch (type) {
        case EV_SYN:
            return syn_labels;
        case EV_KEY:
            return key_labels;
        case EV_REL:
            return rel_labels;
        case EV_ABS:
            return abs_labels;
        case EV_SW:
            return sw_labels;
        case EV_MSC:
            return msc_labels;
        case EV_LED:
            return led_labels;
        case EV_REP:
            return rep_labels;
        case EV_SND:
            return snd_labels;
        case EV_FF:
            return ff_labels;
        case EV_FF_STATUS:
            return ff_status_labels;
        default:
            return nullptr;
    }
}

const label* getValueLabelsForTypeAndCode(int32_t type, int32_t code) {
    if (type == EV_KEY) {
        return ev_key_value_labels;
    }
    if (type == EV_MSC && code == ABS_MT_TOOL_TYPE) {
        return mt_tool_labels;
    }
    return nullptr;
}

} // namespace

EvdevEventLabel InputEventLookup::getLinuxEvdevLabel(int32_t type, int32_t code, int32_t value) {
    return {
            .type = getLabel(ev_labels, type),
            .code = getLabel(getCodeLabelsForType(type), code),
            .value = getLabel(getValueLabelsForTypeAndCode(type, code), value),
    };
}

} // namespace android
+8 −9
Original line number Diff line number Diff line
@@ -417,21 +417,20 @@ std::list<NotifyArgs> InputDevice::process(const RawEvent* rawEvents, size_t cou
    std::list<NotifyArgs> out;
    for (const RawEvent* rawEvent = rawEvents; count != 0; rawEvent++) {
        if (debugRawEvents()) {
            ALOGD("Input event: device=%d type=0x%04x code=0x%04x value=0x%08x when=%" PRId64,
                  rawEvent->deviceId, rawEvent->type, rawEvent->code, rawEvent->value,
                  rawEvent->when);
            const auto [type, code, value] =
                    InputEventLookup::getLinuxEvdevLabel(rawEvent->type, rawEvent->code,
                                                         rawEvent->value);
            ALOGD("Input event: eventHubDevice=%d type=%s code=%s value=%s when=%" PRId64,
                  rawEvent->deviceId, type.c_str(), code.c_str(), value.c_str(), rawEvent->when);
        }

        if (mDropUntilNextSync) {
            if (rawEvent->type == EV_SYN && rawEvent->code == SYN_REPORT) {
                mDropUntilNextSync = false;
                if (debugRawEvents()) {
                    ALOGD("Recovered from input event buffer overrun.");
                }
                ALOGD_IF(debugRawEvents(), "Recovered from input event buffer overrun.");
            } else {
                if (debugRawEvents()) {
                    ALOGD("Dropped input event while waiting for next input sync.");
                }
                ALOGD_IF(debugRawEvents(),
                         "Dropped input event while waiting for next input sync.");
            }
        } else if (rawEvent->type == EV_SYN && rawEvent->code == SYN_DROPPED) {
            ALOGI("Detected input event buffer overrun for device %s.", getName().c_str());