From 9a9897d154f9230325113d18c8d6f4cee7ca72d7 Mon Sep 17 00:00:00 2001 From: Prabir Pradhan Date: Thu, 21 Mar 2024 21:52:57 +0000 Subject: 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 --- services/inputflinger/InputCommonConverter.cpp | 30 ++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'services/inputflinger/InputCommonConverter.cpp') 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 kInvalidHmac{}; + static common::Source getSource(uint32_t source) { static_assert(static_cast(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* 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* 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 -- cgit v1.2.3-59-g8ed1b