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

Commit 955b6137 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

EventHub: Dump tracked EV_KEY, EV_SW, and EV_ABS states

Dump the pressed keys and switches, and the current value of all axes to
ensure EventHub is tracking the input device state correctly.

Bug: 290938220
Bug: 261025260
Test: manual, adb shell dumpsys input
Change-Id: I443692cfddcd3a2f19576076cde3b8a35a4c4a40
parent 341d0787
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
@@ -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";
+17 −1
Original line number Diff line number Diff line
@@ -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;