diff options
author | 2023-01-16 17:55:46 +0000 | |
---|---|---|
committer | 2023-01-20 11:44:48 +0000 | |
commit | ea73eaa7cb640654d6cd5b423196a7beeb781416 (patch) | |
tree | 6311c08d1330e1664b2b0ddef5e03781ddfd1248 | |
parent | 1b217913fbc80d3b8042a628d1a3eb7a3842e7ff (diff) |
TouchpadInputMapper: add dump method
This dumps the state from the gesture converter, and a list of gesture
properties, which is useful for debugging settings.
Bug: 251196347
Test: run dumpsys input with touchpad connected, check output
Change-Id: I036d0251b06489b645b883a239ff345a98448497
10 files changed, 113 insertions, 7 deletions
diff --git a/include/input/PrintTools.h b/include/input/PrintTools.h index e24344b3f1..ce8717009e 100644 --- a/include/input/PrintTools.h +++ b/include/input/PrintTools.h @@ -20,6 +20,7 @@ #include <optional> #include <set> #include <string> +#include <vector> namespace android { @@ -28,6 +29,16 @@ inline std::string constToString(const T& v) { return std::to_string(v); } +template <> +inline std::string constToString(const bool& value) { + return value ? "true" : "false"; +} + +template <> +inline std::string constToString(const std::vector<bool>::reference& value) { + return value ? "true" : "false"; +} + inline std::string constToString(const std::string& s) { return s; } @@ -70,6 +81,19 @@ std::string dumpMap(const std::map<K, V>& map, std::string (*keyToString)(const return out; } +/** + * Convert a vector to a string. The values of the vector should be of a type supported by + * constToString. + */ +template <typename T> +std::string dumpVector(std::vector<T> values) { + std::string dump = constToString(values[0]); + for (size_t i = 1; i < values.size(); i++) { + dump += ", " + constToString(values[i]); + } + return dump; +} + const char* toString(bool value); /** @@ -81,4 +105,4 @@ const char* toString(bool value); */ std::string addLinePrefix(std::string str, const std::string& prefix); -} // namespace android
\ No newline at end of file +} // namespace android diff --git a/services/inputflinger/reader/EventHub.cpp b/services/inputflinger/reader/EventHub.cpp index 43b67cae8b..f7b38a1b9e 100644 --- a/services/inputflinger/reader/EventHub.cpp +++ b/services/inputflinger/reader/EventHub.cpp @@ -515,6 +515,18 @@ ftl::Flags<InputDeviceClass> getAbsAxisUsage(int32_t axis, return deviceClasses & InputDeviceClass::JOYSTICK; } +// --- RawAbsoluteAxisInfo --- + +std::ostream& operator<<(std::ostream& out, const RawAbsoluteAxisInfo& info) { + if (info.valid) { + out << "min=" << info.minValue << ", max=" << info.maxValue << ", flat=" << info.flat + << ", fuzz=" << info.fuzz << ", resolution=" << info.resolution; + } else { + out << "unknown range"; + } + return out; +} + // --- EventHub::Device --- EventHub::Device::Device(int fd, int32_t id, std::string path, InputDeviceIdentifier identifier, diff --git a/services/inputflinger/reader/include/EventHub.h b/services/inputflinger/reader/include/EventHub.h index a3ecf418bb..86acadb428 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 <ostream> +#include <string> #include <unordered_map> #include <utility> #include <vector> @@ -77,6 +79,8 @@ struct RawAbsoluteAxisInfo { inline void clear() { *this = RawAbsoluteAxisInfo(); } }; +std::ostream& operator<<(std::ostream& out, const RawAbsoluteAxisInfo& info); + /* * Input device classes. */ diff --git a/services/inputflinger/reader/mapper/InputMapper.cpp b/services/inputflinger/reader/mapper/InputMapper.cpp index 8e3539c3a6..ba2ea998b5 100644 --- a/services/inputflinger/reader/mapper/InputMapper.cpp +++ b/services/inputflinger/reader/mapper/InputMapper.cpp @@ -18,6 +18,8 @@ #include "InputMapper.h" +#include <sstream> + #include "InputDevice.h" #include "input/PrintTools.h" @@ -120,12 +122,9 @@ void InputMapper::bumpGeneration() { void InputMapper::dumpRawAbsoluteAxisInfo(std::string& dump, const RawAbsoluteAxisInfo& axis, const char* name) { - if (axis.valid) { - dump += StringPrintf(INDENT4 "%s: min=%d, max=%d, flat=%d, fuzz=%d, resolution=%d\n", name, - axis.minValue, axis.maxValue, axis.flat, axis.fuzz, axis.resolution); - } else { - dump += StringPrintf(INDENT4 "%s: unknown range\n", name); - } + std::stringstream out; + out << INDENT4 << name << ": " << axis << "\n"; + dump += out.str(); } void InputMapper::dumpStylusState(std::string& dump, const StylusState& state) { diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp index 89ba07ea9b..b6313a1049 100644 --- a/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.cpp @@ -19,6 +19,7 @@ #include <optional> #include <android/input.h> +#include <input/PrintTools.h> #include <linux/input-event-codes.h> #include <log/log_main.h> #include "TouchCursorInputMapperCommon.h" @@ -124,6 +125,14 @@ uint32_t TouchpadInputMapper::getSources() const { return AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_TOUCHPAD; } +void TouchpadInputMapper::dump(std::string& dump) { + dump += INDENT2 "Touchpad Input Mapper:\n"; + dump += INDENT3 "Gesture converter:\n"; + dump += addLinePrefix(mGestureConverter.dump(), INDENT4); + dump += INDENT3 "Gesture properties:\n"; + dump += addLinePrefix(mPropertyProvider.dump(), INDENT4); +} + std::list<NotifyArgs> TouchpadInputMapper::configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes) { diff --git a/services/inputflinger/reader/mapper/TouchpadInputMapper.h b/services/inputflinger/reader/mapper/TouchpadInputMapper.h index 8ffc8a0b39..d693bcaf30 100644 --- a/services/inputflinger/reader/mapper/TouchpadInputMapper.h +++ b/services/inputflinger/reader/mapper/TouchpadInputMapper.h @@ -41,6 +41,8 @@ public: ~TouchpadInputMapper(); uint32_t getSources() const override; + void dump(std::string& dump) override; + [[nodiscard]] std::list<NotifyArgs> configure(nsecs_t when, const InputReaderConfiguration* config, uint32_t changes) override; diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp index 11ffd286dd..561b1f819a 100644 --- a/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp +++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.cpp @@ -16,7 +16,11 @@ #include "gestures/GestureConverter.h" +#include <sstream> + +#include <android-base/stringprintf.h> #include <android/input.h> +#include <ftl/enum.h> #include <linux/input-event-codes.h> #include <log/log_main.h> @@ -55,6 +59,18 @@ GestureConverter::GestureConverter(InputReaderContext& readerContext, deviceContext.getAbsoluteAxisInfo(ABS_MT_POSITION_Y, &mYAxisInfo); } +std::string GestureConverter::dump() const { + std::stringstream out; + out << "Orientation: " << ftl::enum_string(mOrientation) << "\n"; + out << "Axis info:\n"; + out << " X: " << mXAxisInfo << "\n"; + out << " Y: " << mYAxisInfo << "\n"; + out << StringPrintf("Button state: 0x%08x\n", mButtonState); + out << "Down time: " << mDownTime << "\n"; + out << "Current classification: " << ftl::enum_string(mCurrentClassification) << "\n"; + return out.str(); +} + void GestureConverter::reset() { mButtonState = 0; } diff --git a/services/inputflinger/reader/mapper/gestures/GestureConverter.h b/services/inputflinger/reader/mapper/gestures/GestureConverter.h index 8e8e3d9de3..2ec5841fe0 100644 --- a/services/inputflinger/reader/mapper/gestures/GestureConverter.h +++ b/services/inputflinger/reader/mapper/gestures/GestureConverter.h @@ -40,6 +40,8 @@ public: GestureConverter(InputReaderContext& readerContext, const InputDeviceContext& deviceContext, int32_t deviceId); + std::string dump() const; + void setOrientation(ui::Rotation orientation) { mOrientation = orientation; } void reset(); diff --git a/services/inputflinger/reader/mapper/gestures/PropertyProvider.cpp b/services/inputflinger/reader/mapper/gestures/PropertyProvider.cpp index 2e128540d8..cd18cd3e35 100644 --- a/services/inputflinger/reader/mapper/gestures/PropertyProvider.cpp +++ b/services/inputflinger/reader/mapper/gestures/PropertyProvider.cpp @@ -21,7 +21,9 @@ #include <algorithm> #include <utility> +#include <android-base/stringprintf.h> #include <ftl/enum.h> +#include <input/PrintTools.h> #include <log/log_main.h> namespace android { @@ -74,6 +76,14 @@ GesturesProp& PropertyProvider::getProperty(const std::string name) { return mProperties.at(name); } +std::string PropertyProvider::dump() const { + std::string dump; + for (const auto& [name, property] : mProperties) { + dump += property.dump() + "\n"; + } + return dump; +} + GesturesProp* PropertyProvider::createIntArrayProperty(const std::string name, int* loc, size_t count, const int* init) { const auto [it, inserted] = @@ -124,6 +134,31 @@ GesturesProp::GesturesProp(std::string name, const char** dataPointer, *(std::get<const char**>(mDataPointer)) = initialValue; } +std::string GesturesProp::dump() const { + using android::base::StringPrintf; + std::string type, values; + switch (mDataPointer.index()) { + case 0: + type = "integer"; + values = android::dumpVector(getIntValues()); + break; + case 1: + type = "boolean"; + values = android::dumpVector(getBoolValues()); + break; + case 2: + type = "string"; + values = getStringValue(); + break; + case 3: + type = "real"; + values = android::dumpVector(getRealValues()); + break; + } + std::string typeAndSize = mCount == 1 ? type : std::to_string(mCount) + " " + type + "s"; + return StringPrintf("%s (%s): %s", mName.c_str(), typeAndSize.c_str(), values.c_str()); +} + void GesturesProp::registerHandlers(void* handlerData, GesturesPropGetHandler getter, GesturesPropSetHandler setter) { mHandlerData = handlerData; diff --git a/services/inputflinger/reader/mapper/gestures/PropertyProvider.h b/services/inputflinger/reader/mapper/gestures/PropertyProvider.h index 4bebd469b2..c21260f6c2 100644 --- a/services/inputflinger/reader/mapper/gestures/PropertyProvider.h +++ b/services/inputflinger/reader/mapper/gestures/PropertyProvider.h @@ -33,6 +33,7 @@ class PropertyProvider { public: bool hasProperty(const std::string name) const; GesturesProp& getProperty(const std::string name); + std::string dump() const; // Methods to be called by the gestures library: GesturesProp* createIntArrayProperty(const std::string name, int* loc, size_t count, @@ -62,6 +63,8 @@ public: GesturesProp(std::string name, T* dataPointer, size_t count, const T* initialValues); GesturesProp(std::string name, const char** dataPointer, const char* const initialValue); + std::string dump() const; + std::string getName() const { return mName; } size_t getCount() const { return mCount; } |