diff options
| -rw-r--r-- | services/inputflinger/reader/EventHub.cpp | 25 | ||||
| -rw-r--r-- | services/inputflinger/reader/include/EventHub.h | 18 |
2 files changed, 42 insertions, 1 deletions
diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp index 9a1273301b..bc4cdd1192 100644 --- a/services/inputflinger/reader/EventHub.cpp +++ b/services/inputflinger/reader/EventHub.cpp @@ -2863,6 +2863,31 @@ void EventHub::dump(std::string& dump) const { device->associatedDevice ? device->associatedDevice->sysfsRootPath.c_str() : "<none>"); + if (device->keyBitmask.any(0, KEY_MAX + 1)) { + const auto pressedKeys = device->keyState.dumpSetIndices(", ", [](int i) { + return InputEventLookup::getLinuxEvdevLabel(EV_KEY, i, 1).code; + }); + dump += StringPrintf(INDENT3 "KeyState (pressed): %s\n", pressedKeys.c_str()); + } + if (device->swBitmask.any(0, SW_MAX + 1)) { + const auto pressedSwitches = device->swState.dumpSetIndices(", ", [](int i) { + return InputEventLookup::getLinuxEvdevLabel(EV_SW, i, 1).code; + }); + dump += StringPrintf(INDENT3 "SwState (pressed): %s\n", pressedSwitches.c_str()); + } + if (!device->absState.empty()) { + std::string axisValues; + for (const auto& [axis, state] : device->absState) { + if (!axisValues.empty()) { + axisValues += ", "; + } + axisValues += StringPrintf("%s=%d", + InputEventLookup::getLinuxEvdevLabel(EV_ABS, axis, 0) + .code.c_str(), + state.value); + } + dump += INDENT3 "AbsState: " + axisValues + "\n"; + } } dump += INDENT "Unattached video devices:\n"; diff --git a/services/inputflinger/reader/include/EventHub.h b/services/inputflinger/reader/include/EventHub.h index 09c5e947d8..8347df8bdc 100644 --- a/services/inputflinger/reader/include/EventHub.h +++ b/services/inputflinger/reader/include/EventHub.h @@ -19,6 +19,8 @@ #include <bitset> #include <climits> #include <filesystem> +#include <functional> +#include <map> #include <ostream> #include <string> #include <unordered_map> @@ -469,6 +471,20 @@ public: mData[i] = std::bitset<WIDTH>(buffer[i]); } } + /* Dump the indices in the bit array that are set. */ + inline std::string dumpSetIndices(std::string separator, + std::function<std::string(size_t /*index*/)> format) { + std::string dmp; + for (size_t i = 0; i < BITS; i++) { + if (test(i)) { + if (!dmp.empty()) { + dmp += separator; + } + dmp += format(i); + } + } + return dmp.empty() ? "<none>" : dmp; + } private: std::array<std::bitset<WIDTH>, COUNT> mData; @@ -624,7 +640,7 @@ private: RawAbsoluteAxisInfo info; int value; }; - std::unordered_map<int /*axis*/, AxisState> absState; + std::map<int /*axis*/, AxisState> absState; std::string configurationFile; std::unique_ptr<PropertyMap> configuration; |