diff options
| author | 2024-03-21 21:52:57 +0000 | |
|---|---|---|
| committer | 2024-04-03 21:20:46 +0000 | |
| commit | 9a9897d154f9230325113d18c8d6f4cee7ca72d7 (patch) | |
| tree | 538baa0c027f85f610dfe27e772a27960ed8b48e /services/inputflinger/InputCommonConverter.cpp | |
| parent | efd55b1a397b8a87cbed4d87cda878640f3e29eb (diff) | |
InputTracer: Add tests for perfetto backend
Add a new InputTraceSession class that encapsulates the logic to take
and decode a perfetto input trace for testing.
Then, use it to add new tests to verify the behavior of entire tracing
framework, using InputDispatcher as the interface.
Bug: 210460522
Test: atest inputflinger_tests
Change-Id: I5a9b47e831c5c30e5d7f2b60c9b8075b7d330e9e
Diffstat (limited to 'services/inputflinger/InputCommonConverter.cpp')
| -rw-r--r-- | services/inputflinger/InputCommonConverter.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/services/inputflinger/InputCommonConverter.cpp b/services/inputflinger/InputCommonConverter.cpp index 6ccd9e7697..417c1f333b 100644 --- a/services/inputflinger/InputCommonConverter.cpp +++ b/services/inputflinger/InputCommonConverter.cpp @@ -20,6 +20,9 @@ using namespace ::aidl::android::hardware::input; namespace android { +const static ui::Transform kIdentityTransform; +const static std::array<uint8_t, 32> kInvalidHmac{}; + static common::Source getSource(uint32_t source) { static_assert(static_cast<common::Source>(AINPUT_SOURCE_UNKNOWN) == common::Source::UNKNOWN, "SOURCE_UNKNOWN mismatch"); @@ -337,4 +340,31 @@ common::MotionEvent notifyMotionArgsToHalMotionEvent(const NotifyMotionArgs& arg return event; } +MotionEvent toMotionEvent(const NotifyMotionArgs& args, const ui::Transform* transform, + const ui::Transform* rawTransform, const std::array<uint8_t, 32>* hmac) { + if (transform == nullptr) transform = &kIdentityTransform; + if (rawTransform == nullptr) rawTransform = &kIdentityTransform; + if (hmac == nullptr) hmac = &kInvalidHmac; + + MotionEvent event; + event.initialize(args.id, args.deviceId, args.source, args.displayId, *hmac, args.action, + args.actionButton, args.flags, args.edgeFlags, args.metaState, + args.buttonState, args.classification, *transform, args.xPrecision, + args.yPrecision, args.xCursorPosition, args.yCursorPosition, *rawTransform, + args.downTime, args.eventTime, args.getPointerCount(), + args.pointerProperties.data(), args.pointerCoords.data()); + return event; +} + +KeyEvent toKeyEvent(const NotifyKeyArgs& args, int32_t repeatCount, + const std::array<uint8_t, 32>* hmac) { + if (hmac == nullptr) hmac = &kInvalidHmac; + + KeyEvent event; + event.initialize(args.id, args.deviceId, args.source, args.displayId, *hmac, args.action, + args.flags, args.keyCode, args.scanCode, args.metaState, repeatCount, + args.downTime, args.eventTime); + return event; +} + } // namespace android |