Loading include/input/InputConsumerNoResampling.h +6 −6 Original line number Original line Diff line number Diff line Loading @@ -29,8 +29,8 @@ namespace android { class InputConsumerCallbacks { class InputConsumerCallbacks { public: public: virtual ~InputConsumerCallbacks(){}; virtual ~InputConsumerCallbacks(){}; virtual void onKeyEvent(KeyEvent&& event, uint32_t seq) = 0; virtual void onKeyEvent(std::unique_ptr<KeyEvent> event, uint32_t seq) = 0; virtual void onMotionEvent(MotionEvent&& event, uint32_t seq) = 0; virtual void onMotionEvent(std::unique_ptr<MotionEvent> event, uint32_t seq) = 0; /** /** * When you receive this callback, you must (eventually) call "consumeBatchedInputEvents". * When you receive this callback, you must (eventually) call "consumeBatchedInputEvents". * If you don't want batching, then call "consumeBatchedInputEvents" immediately with * If you don't want batching, then call "consumeBatchedInputEvents" immediately with Loading @@ -38,10 +38,10 @@ public: * @param pendingBatchSource the source of the pending batch. * @param pendingBatchSource the source of the pending batch. */ */ virtual void onBatchedInputEventPending(int32_t pendingBatchSource) = 0; virtual void onBatchedInputEventPending(int32_t pendingBatchSource) = 0; virtual void onFocusEvent(FocusEvent&& event, uint32_t seq) = 0; virtual void onFocusEvent(std::unique_ptr<FocusEvent> event, uint32_t seq) = 0; virtual void onCaptureEvent(CaptureEvent&& event, uint32_t seq) = 0; virtual void onCaptureEvent(std::unique_ptr<CaptureEvent> event, uint32_t seq) = 0; virtual void onDragEvent(DragEvent&& event, uint32_t seq) = 0; virtual void onDragEvent(std::unique_ptr<DragEvent> event, uint32_t seq) = 0; virtual void onTouchModeEvent(TouchModeEvent&& event, uint32_t seq) = 0; virtual void onTouchModeEvent(std::unique_ptr<TouchModeEvent> event, uint32_t seq) = 0; }; }; /** /** Loading libs/input/InputConsumerNoResampling.cpp +51 −45 Original line number Original line Diff line number Diff line Loading @@ -44,28 +44,37 @@ namespace { const bool DEBUG_TRANSPORT_CONSUMER = const bool DEBUG_TRANSPORT_CONSUMER = __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Consumer", ANDROID_LOG_INFO); __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Consumer", ANDROID_LOG_INFO); void initializeKeyEvent(KeyEvent& event, const InputMessage& msg) { std::unique_ptr<KeyEvent> createKeyEvent(const InputMessage& msg) { event.initialize(msg.body.key.eventId, msg.body.key.deviceId, msg.body.key.source, std::unique_ptr<KeyEvent> event = std::make_unique<KeyEvent>(); event->initialize(msg.body.key.eventId, msg.body.key.deviceId, msg.body.key.source, msg.body.key.displayId, msg.body.key.hmac, msg.body.key.action, msg.body.key.displayId, msg.body.key.hmac, msg.body.key.action, msg.body.key.flags, msg.body.key.keyCode, msg.body.key.scanCode, msg.body.key.flags, msg.body.key.keyCode, msg.body.key.scanCode, msg.body.key.metaState, msg.body.key.repeatCount, msg.body.key.downTime, msg.body.key.metaState, msg.body.key.repeatCount, msg.body.key.downTime, msg.body.key.eventTime); msg.body.key.eventTime); return event; } } void initializeFocusEvent(FocusEvent& event, const InputMessage& msg) { std::unique_ptr<FocusEvent> createFocusEvent(const InputMessage& msg) { event.initialize(msg.body.focus.eventId, msg.body.focus.hasFocus); std::unique_ptr<FocusEvent> event = std::make_unique<FocusEvent>(); event->initialize(msg.body.focus.eventId, msg.body.focus.hasFocus); return event; } } void initializeCaptureEvent(CaptureEvent& event, const InputMessage& msg) { std::unique_ptr<CaptureEvent> createCaptureEvent(const InputMessage& msg) { event.initialize(msg.body.capture.eventId, msg.body.capture.pointerCaptureEnabled); std::unique_ptr<CaptureEvent> event = std::make_unique<CaptureEvent>(); event->initialize(msg.body.capture.eventId, msg.body.capture.pointerCaptureEnabled); return event; } } void initializeDragEvent(DragEvent& event, const InputMessage& msg) { std::unique_ptr<DragEvent> createDragEvent(const InputMessage& msg) { event.initialize(msg.body.drag.eventId, msg.body.drag.x, msg.body.drag.y, std::unique_ptr<DragEvent> event = std::make_unique<DragEvent>(); event->initialize(msg.body.drag.eventId, msg.body.drag.x, msg.body.drag.y, msg.body.drag.isExiting); msg.body.drag.isExiting); return event; } } void initializeMotionEvent(MotionEvent& event, const InputMessage& msg) { std::unique_ptr<MotionEvent> createMotionEvent(const InputMessage& msg) { std::unique_ptr<MotionEvent> event = std::make_unique<MotionEvent>(); const uint32_t pointerCount = msg.body.motion.pointerCount; const uint32_t pointerCount = msg.body.motion.pointerCount; std::vector<PointerProperties> pointerProperties; std::vector<PointerProperties> pointerProperties; pointerProperties.reserve(pointerCount); pointerProperties.reserve(pointerCount); Loading @@ -83,15 +92,16 @@ void initializeMotionEvent(MotionEvent& event, const InputMessage& msg) { displayTransform.set({msg.body.motion.dsdxRaw, msg.body.motion.dtdxRaw, msg.body.motion.txRaw, displayTransform.set({msg.body.motion.dsdxRaw, msg.body.motion.dtdxRaw, msg.body.motion.txRaw, msg.body.motion.dtdyRaw, msg.body.motion.dsdyRaw, msg.body.motion.tyRaw, msg.body.motion.dtdyRaw, msg.body.motion.dsdyRaw, msg.body.motion.tyRaw, 0, 0, 1}); 0, 0, 1}); event.initialize(msg.body.motion.eventId, msg.body.motion.deviceId, msg.body.motion.source, event->initialize(msg.body.motion.eventId, msg.body.motion.deviceId, msg.body.motion.source, msg.body.motion.displayId, msg.body.motion.hmac, msg.body.motion.action, msg.body.motion.displayId, msg.body.motion.hmac, msg.body.motion.action, msg.body.motion.actionButton, msg.body.motion.flags, msg.body.motion.edgeFlags, msg.body.motion.actionButton, msg.body.motion.flags, msg.body.motion.metaState, msg.body.motion.buttonState, msg.body.motion.edgeFlags, msg.body.motion.metaState, msg.body.motion.classification, transform, msg.body.motion.xPrecision, msg.body.motion.buttonState, msg.body.motion.classification, transform, msg.body.motion.yPrecision, msg.body.motion.xCursorPosition, msg.body.motion.xPrecision, msg.body.motion.yPrecision, msg.body.motion.yCursorPosition, displayTransform, msg.body.motion.downTime, msg.body.motion.xCursorPosition, msg.body.motion.yCursorPosition, msg.body.motion.eventTime, pointerCount, pointerProperties.data(), displayTransform, msg.body.motion.downTime, msg.body.motion.eventTime, pointerCoords.data()); pointerCount, pointerProperties.data(), pointerCoords.data()); return event; } } void addSample(MotionEvent& event, const InputMessage& msg) { void addSample(MotionEvent& event, const InputMessage& msg) { Loading @@ -107,8 +117,10 @@ void addSample(MotionEvent& event, const InputMessage& msg) { event.addSample(msg.body.motion.eventTime, pointerCoords.data()); event.addSample(msg.body.motion.eventTime, pointerCoords.data()); } } void initializeTouchModeEvent(TouchModeEvent& event, const InputMessage& msg) { std::unique_ptr<TouchModeEvent> createTouchModeEvent(const InputMessage& msg) { event.initialize(msg.body.touchMode.eventId, msg.body.touchMode.isInTouchMode); std::unique_ptr<TouchModeEvent> event = std::make_unique<TouchModeEvent>(); event->initialize(msg.body.touchMode.eventId, msg.body.touchMode.isInTouchMode); return event; } } std::string outboundMessageToString(const InputMessage& outboundMsg) { std::string outboundMessageToString(const InputMessage& outboundMsg) { Loading Loading @@ -388,15 +400,13 @@ std::vector<InputMessage> InputConsumerNoResampling::readAllMessages() { void InputConsumerNoResampling::handleMessage(const InputMessage& msg) const { void InputConsumerNoResampling::handleMessage(const InputMessage& msg) const { switch (msg.header.type) { switch (msg.header.type) { case InputMessage::Type::KEY: { case InputMessage::Type::KEY: { KeyEvent keyEvent; std::unique_ptr<KeyEvent> keyEvent = createKeyEvent(msg); initializeKeyEvent(keyEvent, msg); mCallbacks.onKeyEvent(std::move(keyEvent), msg.header.seq); mCallbacks.onKeyEvent(std::move(keyEvent), msg.header.seq); break; break; } } case InputMessage::Type::MOTION: { case InputMessage::Type::MOTION: { MotionEvent motionEvent; std::unique_ptr<MotionEvent> motionEvent = createMotionEvent(msg); initializeMotionEvent(motionEvent, msg); mCallbacks.onMotionEvent(std::move(motionEvent), msg.header.seq); mCallbacks.onMotionEvent(std::move(motionEvent), msg.header.seq); break; break; } } Loading @@ -411,29 +421,25 @@ void InputConsumerNoResampling::handleMessage(const InputMessage& msg) const { } } case InputMessage::Type::FOCUS: { case InputMessage::Type::FOCUS: { FocusEvent focusEvent; std::unique_ptr<FocusEvent> focusEvent = createFocusEvent(msg); initializeFocusEvent(focusEvent, msg); mCallbacks.onFocusEvent(std::move(focusEvent), msg.header.seq); mCallbacks.onFocusEvent(std::move(focusEvent), msg.header.seq); break; break; } } case InputMessage::Type::CAPTURE: { case InputMessage::Type::CAPTURE: { CaptureEvent captureEvent; std::unique_ptr<CaptureEvent> captureEvent = createCaptureEvent(msg); initializeCaptureEvent(captureEvent, msg); mCallbacks.onCaptureEvent(std::move(captureEvent), msg.header.seq); mCallbacks.onCaptureEvent(std::move(captureEvent), msg.header.seq); break; break; } } case InputMessage::Type::DRAG: { case InputMessage::Type::DRAG: { DragEvent dragEvent; std::unique_ptr<DragEvent> dragEvent = createDragEvent(msg); initializeDragEvent(dragEvent, msg); mCallbacks.onDragEvent(std::move(dragEvent), msg.header.seq); mCallbacks.onDragEvent(std::move(dragEvent), msg.header.seq); break; break; } } case InputMessage::Type::TOUCH_MODE: { case InputMessage::Type::TOUCH_MODE: { TouchModeEvent touchModeEvent; std::unique_ptr<TouchModeEvent> touchModeEvent = createTouchModeEvent(msg); initializeTouchModeEvent(touchModeEvent, msg); mCallbacks.onTouchModeEvent(std::move(touchModeEvent), msg.header.seq); mCallbacks.onTouchModeEvent(std::move(touchModeEvent), msg.header.seq); break; break; } } Loading @@ -448,7 +454,7 @@ bool InputConsumerNoResampling::consumeBatchedInputEvents( const nsecs_t frameTime = requestedFrameTime.value_or(std::numeric_limits<nsecs_t>::max()); const nsecs_t frameTime = requestedFrameTime.value_or(std::numeric_limits<nsecs_t>::max()); bool producedEvents = false; bool producedEvents = false; for (auto& [deviceId, messages] : mBatches) { for (auto& [deviceId, messages] : mBatches) { MotionEvent motion; std::unique_ptr<MotionEvent> motion; std::optional<uint32_t> firstSeqForBatch; std::optional<uint32_t> firstSeqForBatch; std::vector<uint32_t> sequences; std::vector<uint32_t> sequences; while (!messages.empty()) { while (!messages.empty()) { Loading @@ -456,20 +462,21 @@ bool InputConsumerNoResampling::consumeBatchedInputEvents( if (msg.body.motion.eventTime > frameTime) { if (msg.body.motion.eventTime > frameTime) { break; break; } } if (!firstSeqForBatch.has_value()) { if (motion == nullptr) { initializeMotionEvent(motion, msg); motion = createMotionEvent(msg); firstSeqForBatch = msg.header.seq; firstSeqForBatch = msg.header.seq; const auto [_, inserted] = mBatchedSequenceNumbers.insert({*firstSeqForBatch, {}}); const auto [_, inserted] = mBatchedSequenceNumbers.insert({*firstSeqForBatch, {}}); if (!inserted) { if (!inserted) { LOG(FATAL) << "The sequence " << msg.header.seq << " was already present!"; LOG(FATAL) << "The sequence " << msg.header.seq << " was already present!"; } } } else { } else { addSample(motion, msg); addSample(*motion, msg); mBatchedSequenceNumbers[*firstSeqForBatch].push_back(msg.header.seq); mBatchedSequenceNumbers[*firstSeqForBatch].push_back(msg.header.seq); } } messages.pop(); messages.pop(); } } if (firstSeqForBatch.has_value()) { if (motion != nullptr) { LOG_ALWAYS_FATAL_IF(!firstSeqForBatch.has_value()); mCallbacks.onMotionEvent(std::move(motion), *firstSeqForBatch); mCallbacks.onMotionEvent(std::move(motion), *firstSeqForBatch); producedEvents = true; producedEvents = true; } else { } else { Loading Loading @@ -520,9 +527,8 @@ std::string InputConsumerNoResampling::dump() const { std::queue<InputMessage> tmpQueue = messages; std::queue<InputMessage> tmpQueue = messages; while (!tmpQueue.empty()) { while (!tmpQueue.empty()) { LOG_ALWAYS_FATAL_IF(tmpQueue.front().header.type != InputMessage::Type::MOTION); LOG_ALWAYS_FATAL_IF(tmpQueue.front().header.type != InputMessage::Type::MOTION); MotionEvent motion; std::unique_ptr<MotionEvent> motion = createMotionEvent(tmpQueue.front()); initializeMotionEvent(motion, tmpQueue.front()); out += std::string(" ") + streamableToString(*motion) + "\n"; out += std::string(" ") + streamableToString(motion) + "\n"; tmpQueue.pop(); tmpQueue.pop(); } } } } Loading libs/input/tests/InputPublisherAndConsumerNoResampling_test.cpp +36 −30 Original line number Original line Diff line number Diff line Loading @@ -341,19 +341,19 @@ private: // The sequence number to use when publishing the next event // The sequence number to use when publishing the next event uint32_t mSeq = 1; uint32_t mSeq = 1; BlockingQueue<KeyEvent> mKeyEvents; BlockingQueue<std::unique_ptr<KeyEvent>> mKeyEvents; BlockingQueue<MotionEvent> mMotionEvents; BlockingQueue<std::unique_ptr<MotionEvent>> mMotionEvents; BlockingQueue<FocusEvent> mFocusEvents; BlockingQueue<std::unique_ptr<FocusEvent>> mFocusEvents; BlockingQueue<CaptureEvent> mCaptureEvents; BlockingQueue<std::unique_ptr<CaptureEvent>> mCaptureEvents; BlockingQueue<DragEvent> mDragEvents; BlockingQueue<std::unique_ptr<DragEvent>> mDragEvents; BlockingQueue<TouchModeEvent> mTouchModeEvents; BlockingQueue<std::unique_ptr<TouchModeEvent>> mTouchModeEvents; // InputConsumerCallbacks interface // InputConsumerCallbacks interface void onKeyEvent(KeyEvent&& event, uint32_t seq) override { void onKeyEvent(std::unique_ptr<KeyEvent> event, uint32_t seq) override { mKeyEvents.push(std::move(event)); mKeyEvents.push(std::move(event)); mConsumer->finishInputEvent(seq, true); mConsumer->finishInputEvent(seq, true); } } void onMotionEvent(MotionEvent&& event, uint32_t seq) override { void onMotionEvent(std::unique_ptr<MotionEvent> event, uint32_t seq) override { mMotionEvents.push(std::move(event)); mMotionEvents.push(std::move(event)); mConsumer->finishInputEvent(seq, true); mConsumer->finishInputEvent(seq, true); } } Loading @@ -363,19 +363,19 @@ private: } } mConsumer->consumeBatchedInputEvents(std::nullopt); mConsumer->consumeBatchedInputEvents(std::nullopt); }; }; void onFocusEvent(FocusEvent&& event, uint32_t seq) override { void onFocusEvent(std::unique_ptr<FocusEvent> event, uint32_t seq) override { mFocusEvents.push(std::move(event)); mFocusEvents.push(std::move(event)); mConsumer->finishInputEvent(seq, true); mConsumer->finishInputEvent(seq, true); }; }; void onCaptureEvent(CaptureEvent&& event, uint32_t seq) override { void onCaptureEvent(std::unique_ptr<CaptureEvent> event, uint32_t seq) override { mCaptureEvents.push(std::move(event)); mCaptureEvents.push(std::move(event)); mConsumer->finishInputEvent(seq, true); mConsumer->finishInputEvent(seq, true); }; }; void onDragEvent(DragEvent&& event, uint32_t seq) override { void onDragEvent(std::unique_ptr<DragEvent> event, uint32_t seq) override { mDragEvents.push(std::move(event)); mDragEvents.push(std::move(event)); mConsumer->finishInputEvent(seq, true); mConsumer->finishInputEvent(seq, true); } } void onTouchModeEvent(TouchModeEvent&& event, uint32_t seq) override { void onTouchModeEvent(std::unique_ptr<TouchModeEvent> event, uint32_t seq) override { mTouchModeEvents.push(std::move(event)); mTouchModeEvents.push(std::move(event)); mConsumer->finishInputEvent(seq, true); mConsumer->finishInputEvent(seq, true); }; }; Loading Loading @@ -465,15 +465,15 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeKeyEvent() { eventTime); eventTime); ASSERT_EQ(OK, status) << "publisher publishKeyEvent should return OK"; ASSERT_EQ(OK, status) << "publisher publishKeyEvent should return OK"; std::optional<KeyEvent> keyEvent = mKeyEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<KeyEvent>> optKeyEvent = mKeyEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(optKeyEvent.has_value()) << "consumer should have returned non-NULL event"; std::unique_ptr<KeyEvent> keyEvent = std::move(*optKeyEvent); sendMessage(LooperMessage::CALL_PROBABLY_HAS_INPUT); sendMessage(LooperMessage::CALL_PROBABLY_HAS_INPUT); std::optional<bool> probablyHasInput = mProbablyHasInputResponses.popWithTimeout(TIMEOUT); std::optional<bool> probablyHasInput = mProbablyHasInputResponses.popWithTimeout(TIMEOUT); ASSERT_TRUE(probablyHasInput.has_value()); ASSERT_TRUE(probablyHasInput.has_value()); ASSERT_FALSE(probablyHasInput.value()) << "no events should be waiting after being consumed"; ASSERT_FALSE(probablyHasInput.value()) << "no events should be waiting after being consumed"; ASSERT_TRUE(keyEvent.has_value()) << "consumer should have returned non-NULL event"; EXPECT_EQ(eventId, keyEvent->getId()); EXPECT_EQ(eventId, keyEvent->getId()); EXPECT_EQ(deviceId, keyEvent->getDeviceId()); EXPECT_EQ(deviceId, keyEvent->getDeviceId()); EXPECT_EQ(source, keyEvent->getSource()); EXPECT_EQ(source, keyEvent->getSource()); Loading Loading @@ -540,7 +540,8 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeBatchedMotionMo publishMotionEvent(*mPublisher, args); publishMotionEvent(*mPublisher, args); // Ensure no event arrives because the UI thread is blocked // Ensure no event arrives because the UI thread is blocked std::optional<MotionEvent> noEvent = mMotionEvents.popWithTimeout(NO_EVENT_TIMEOUT); std::optional<std::unique_ptr<MotionEvent>> noEvent = mMotionEvents.popWithTimeout(NO_EVENT_TIMEOUT); ASSERT_FALSE(noEvent.has_value()) << "Got unexpected event: " << *noEvent; ASSERT_FALSE(noEvent.has_value()) << "Got unexpected event: " << *noEvent; Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse(); Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse(); Loading @@ -559,8 +560,9 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeBatchedMotionMo } } mNotifyLooperMayProceed.notify_all(); mNotifyLooperMayProceed.notify_all(); std::optional<MotionEvent> motion = mMotionEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<MotionEvent>> optMotion = mMotionEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(motion.has_value()); ASSERT_TRUE(optMotion.has_value()); std::unique_ptr<MotionEvent> motion = std::move(*optMotion); ASSERT_EQ(ACTION_MOVE, motion->getAction()); ASSERT_EQ(ACTION_MOVE, motion->getAction()); verifyFinishedSignal(*mPublisher, seq, publishTime); verifyFinishedSignal(*mPublisher, seq, publishTime); Loading @@ -573,8 +575,9 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeMotionEvent( nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC); nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC); publishMotionEvent(*mPublisher, args); publishMotionEvent(*mPublisher, args); std::optional<MotionEvent> event = mMotionEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<MotionEvent>> optMotion = mMotionEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(event.has_value()) << "consumer should have returned non-NULL event"; ASSERT_TRUE(optMotion.has_value()); std::unique_ptr<MotionEvent> event = std::move(*optMotion); verifyArgsEqualToEvent(args, *event); verifyArgsEqualToEvent(args, *event); Loading @@ -592,8 +595,9 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeFocusEvent() { status = mPublisher->publishFocusEvent(seq, eventId, hasFocus); status = mPublisher->publishFocusEvent(seq, eventId, hasFocus); ASSERT_EQ(OK, status) << "publisher publishFocusEvent should return OK"; ASSERT_EQ(OK, status) << "publisher publishFocusEvent should return OK"; std::optional<FocusEvent> focusEvent = mFocusEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<FocusEvent>> optFocusEvent = mFocusEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(focusEvent.has_value()) << "consumer should have returned non-NULL event"; ASSERT_TRUE(optFocusEvent.has_value()) << "consumer should have returned non-NULL event"; std::unique_ptr<FocusEvent> focusEvent = std::move(*optFocusEvent); EXPECT_EQ(eventId, focusEvent->getId()); EXPECT_EQ(eventId, focusEvent->getId()); EXPECT_EQ(hasFocus, focusEvent->getHasFocus()); EXPECT_EQ(hasFocus, focusEvent->getHasFocus()); Loading @@ -611,9 +615,9 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeCaptureEvent() status = mPublisher->publishCaptureEvent(seq, eventId, captureEnabled); status = mPublisher->publishCaptureEvent(seq, eventId, captureEnabled); ASSERT_EQ(OK, status) << "publisher publishCaptureEvent should return OK"; ASSERT_EQ(OK, status) << "publisher publishCaptureEvent should return OK"; std::optional<CaptureEvent> event = mCaptureEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<CaptureEvent>> optEvent = mCaptureEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(optEvent.has_value()) << "consumer should have returned non-NULL event"; ASSERT_TRUE(event.has_value()) << "consumer should have returned non-NULL event"; std::unique_ptr<CaptureEvent> event = std::move(*optEvent); const CaptureEvent& captureEvent = *event; const CaptureEvent& captureEvent = *event; EXPECT_EQ(eventId, captureEvent.getId()); EXPECT_EQ(eventId, captureEvent.getId()); Loading @@ -635,9 +639,9 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeDragEvent() { status = mPublisher->publishDragEvent(seq, eventId, x, y, isExiting); status = mPublisher->publishDragEvent(seq, eventId, x, y, isExiting); ASSERT_EQ(OK, status) << "publisher publishDragEvent should return OK"; ASSERT_EQ(OK, status) << "publisher publishDragEvent should return OK"; std::optional<DragEvent> event = mDragEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<DragEvent>> optEvent = mDragEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(optEvent.has_value()) << "consumer should have returned non-NULL event"; ASSERT_TRUE(event.has_value()) << "consumer should have returned non-NULL event"; std::unique_ptr<DragEvent> event = std::move(*optEvent); const DragEvent& dragEvent = *event; const DragEvent& dragEvent = *event; EXPECT_EQ(eventId, dragEvent.getId()); EXPECT_EQ(eventId, dragEvent.getId()); Loading @@ -659,8 +663,10 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeTouchModeEvent( status = mPublisher->publishTouchModeEvent(seq, eventId, touchModeEnabled); status = mPublisher->publishTouchModeEvent(seq, eventId, touchModeEnabled); ASSERT_EQ(OK, status) << "publisher publishTouchModeEvent should return OK"; ASSERT_EQ(OK, status) << "publisher publishTouchModeEvent should return OK"; std::optional<TouchModeEvent> event = mTouchModeEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<TouchModeEvent>> optEvent = ASSERT_NE(std::nullopt, event); mTouchModeEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(optEvent.has_value()); std::unique_ptr<TouchModeEvent> event = std::move(*optEvent); const TouchModeEvent& touchModeEvent = *event; const TouchModeEvent& touchModeEvent = *event; EXPECT_EQ(eventId, touchModeEvent.getId()); EXPECT_EQ(eventId, touchModeEvent.getId()); Loading Loading
include/input/InputConsumerNoResampling.h +6 −6 Original line number Original line Diff line number Diff line Loading @@ -29,8 +29,8 @@ namespace android { class InputConsumerCallbacks { class InputConsumerCallbacks { public: public: virtual ~InputConsumerCallbacks(){}; virtual ~InputConsumerCallbacks(){}; virtual void onKeyEvent(KeyEvent&& event, uint32_t seq) = 0; virtual void onKeyEvent(std::unique_ptr<KeyEvent> event, uint32_t seq) = 0; virtual void onMotionEvent(MotionEvent&& event, uint32_t seq) = 0; virtual void onMotionEvent(std::unique_ptr<MotionEvent> event, uint32_t seq) = 0; /** /** * When you receive this callback, you must (eventually) call "consumeBatchedInputEvents". * When you receive this callback, you must (eventually) call "consumeBatchedInputEvents". * If you don't want batching, then call "consumeBatchedInputEvents" immediately with * If you don't want batching, then call "consumeBatchedInputEvents" immediately with Loading @@ -38,10 +38,10 @@ public: * @param pendingBatchSource the source of the pending batch. * @param pendingBatchSource the source of the pending batch. */ */ virtual void onBatchedInputEventPending(int32_t pendingBatchSource) = 0; virtual void onBatchedInputEventPending(int32_t pendingBatchSource) = 0; virtual void onFocusEvent(FocusEvent&& event, uint32_t seq) = 0; virtual void onFocusEvent(std::unique_ptr<FocusEvent> event, uint32_t seq) = 0; virtual void onCaptureEvent(CaptureEvent&& event, uint32_t seq) = 0; virtual void onCaptureEvent(std::unique_ptr<CaptureEvent> event, uint32_t seq) = 0; virtual void onDragEvent(DragEvent&& event, uint32_t seq) = 0; virtual void onDragEvent(std::unique_ptr<DragEvent> event, uint32_t seq) = 0; virtual void onTouchModeEvent(TouchModeEvent&& event, uint32_t seq) = 0; virtual void onTouchModeEvent(std::unique_ptr<TouchModeEvent> event, uint32_t seq) = 0; }; }; /** /** Loading
libs/input/InputConsumerNoResampling.cpp +51 −45 Original line number Original line Diff line number Diff line Loading @@ -44,28 +44,37 @@ namespace { const bool DEBUG_TRANSPORT_CONSUMER = const bool DEBUG_TRANSPORT_CONSUMER = __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Consumer", ANDROID_LOG_INFO); __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG "Consumer", ANDROID_LOG_INFO); void initializeKeyEvent(KeyEvent& event, const InputMessage& msg) { std::unique_ptr<KeyEvent> createKeyEvent(const InputMessage& msg) { event.initialize(msg.body.key.eventId, msg.body.key.deviceId, msg.body.key.source, std::unique_ptr<KeyEvent> event = std::make_unique<KeyEvent>(); event->initialize(msg.body.key.eventId, msg.body.key.deviceId, msg.body.key.source, msg.body.key.displayId, msg.body.key.hmac, msg.body.key.action, msg.body.key.displayId, msg.body.key.hmac, msg.body.key.action, msg.body.key.flags, msg.body.key.keyCode, msg.body.key.scanCode, msg.body.key.flags, msg.body.key.keyCode, msg.body.key.scanCode, msg.body.key.metaState, msg.body.key.repeatCount, msg.body.key.downTime, msg.body.key.metaState, msg.body.key.repeatCount, msg.body.key.downTime, msg.body.key.eventTime); msg.body.key.eventTime); return event; } } void initializeFocusEvent(FocusEvent& event, const InputMessage& msg) { std::unique_ptr<FocusEvent> createFocusEvent(const InputMessage& msg) { event.initialize(msg.body.focus.eventId, msg.body.focus.hasFocus); std::unique_ptr<FocusEvent> event = std::make_unique<FocusEvent>(); event->initialize(msg.body.focus.eventId, msg.body.focus.hasFocus); return event; } } void initializeCaptureEvent(CaptureEvent& event, const InputMessage& msg) { std::unique_ptr<CaptureEvent> createCaptureEvent(const InputMessage& msg) { event.initialize(msg.body.capture.eventId, msg.body.capture.pointerCaptureEnabled); std::unique_ptr<CaptureEvent> event = std::make_unique<CaptureEvent>(); event->initialize(msg.body.capture.eventId, msg.body.capture.pointerCaptureEnabled); return event; } } void initializeDragEvent(DragEvent& event, const InputMessage& msg) { std::unique_ptr<DragEvent> createDragEvent(const InputMessage& msg) { event.initialize(msg.body.drag.eventId, msg.body.drag.x, msg.body.drag.y, std::unique_ptr<DragEvent> event = std::make_unique<DragEvent>(); event->initialize(msg.body.drag.eventId, msg.body.drag.x, msg.body.drag.y, msg.body.drag.isExiting); msg.body.drag.isExiting); return event; } } void initializeMotionEvent(MotionEvent& event, const InputMessage& msg) { std::unique_ptr<MotionEvent> createMotionEvent(const InputMessage& msg) { std::unique_ptr<MotionEvent> event = std::make_unique<MotionEvent>(); const uint32_t pointerCount = msg.body.motion.pointerCount; const uint32_t pointerCount = msg.body.motion.pointerCount; std::vector<PointerProperties> pointerProperties; std::vector<PointerProperties> pointerProperties; pointerProperties.reserve(pointerCount); pointerProperties.reserve(pointerCount); Loading @@ -83,15 +92,16 @@ void initializeMotionEvent(MotionEvent& event, const InputMessage& msg) { displayTransform.set({msg.body.motion.dsdxRaw, msg.body.motion.dtdxRaw, msg.body.motion.txRaw, displayTransform.set({msg.body.motion.dsdxRaw, msg.body.motion.dtdxRaw, msg.body.motion.txRaw, msg.body.motion.dtdyRaw, msg.body.motion.dsdyRaw, msg.body.motion.tyRaw, msg.body.motion.dtdyRaw, msg.body.motion.dsdyRaw, msg.body.motion.tyRaw, 0, 0, 1}); 0, 0, 1}); event.initialize(msg.body.motion.eventId, msg.body.motion.deviceId, msg.body.motion.source, event->initialize(msg.body.motion.eventId, msg.body.motion.deviceId, msg.body.motion.source, msg.body.motion.displayId, msg.body.motion.hmac, msg.body.motion.action, msg.body.motion.displayId, msg.body.motion.hmac, msg.body.motion.action, msg.body.motion.actionButton, msg.body.motion.flags, msg.body.motion.edgeFlags, msg.body.motion.actionButton, msg.body.motion.flags, msg.body.motion.metaState, msg.body.motion.buttonState, msg.body.motion.edgeFlags, msg.body.motion.metaState, msg.body.motion.classification, transform, msg.body.motion.xPrecision, msg.body.motion.buttonState, msg.body.motion.classification, transform, msg.body.motion.yPrecision, msg.body.motion.xCursorPosition, msg.body.motion.xPrecision, msg.body.motion.yPrecision, msg.body.motion.yCursorPosition, displayTransform, msg.body.motion.downTime, msg.body.motion.xCursorPosition, msg.body.motion.yCursorPosition, msg.body.motion.eventTime, pointerCount, pointerProperties.data(), displayTransform, msg.body.motion.downTime, msg.body.motion.eventTime, pointerCoords.data()); pointerCount, pointerProperties.data(), pointerCoords.data()); return event; } } void addSample(MotionEvent& event, const InputMessage& msg) { void addSample(MotionEvent& event, const InputMessage& msg) { Loading @@ -107,8 +117,10 @@ void addSample(MotionEvent& event, const InputMessage& msg) { event.addSample(msg.body.motion.eventTime, pointerCoords.data()); event.addSample(msg.body.motion.eventTime, pointerCoords.data()); } } void initializeTouchModeEvent(TouchModeEvent& event, const InputMessage& msg) { std::unique_ptr<TouchModeEvent> createTouchModeEvent(const InputMessage& msg) { event.initialize(msg.body.touchMode.eventId, msg.body.touchMode.isInTouchMode); std::unique_ptr<TouchModeEvent> event = std::make_unique<TouchModeEvent>(); event->initialize(msg.body.touchMode.eventId, msg.body.touchMode.isInTouchMode); return event; } } std::string outboundMessageToString(const InputMessage& outboundMsg) { std::string outboundMessageToString(const InputMessage& outboundMsg) { Loading Loading @@ -388,15 +400,13 @@ std::vector<InputMessage> InputConsumerNoResampling::readAllMessages() { void InputConsumerNoResampling::handleMessage(const InputMessage& msg) const { void InputConsumerNoResampling::handleMessage(const InputMessage& msg) const { switch (msg.header.type) { switch (msg.header.type) { case InputMessage::Type::KEY: { case InputMessage::Type::KEY: { KeyEvent keyEvent; std::unique_ptr<KeyEvent> keyEvent = createKeyEvent(msg); initializeKeyEvent(keyEvent, msg); mCallbacks.onKeyEvent(std::move(keyEvent), msg.header.seq); mCallbacks.onKeyEvent(std::move(keyEvent), msg.header.seq); break; break; } } case InputMessage::Type::MOTION: { case InputMessage::Type::MOTION: { MotionEvent motionEvent; std::unique_ptr<MotionEvent> motionEvent = createMotionEvent(msg); initializeMotionEvent(motionEvent, msg); mCallbacks.onMotionEvent(std::move(motionEvent), msg.header.seq); mCallbacks.onMotionEvent(std::move(motionEvent), msg.header.seq); break; break; } } Loading @@ -411,29 +421,25 @@ void InputConsumerNoResampling::handleMessage(const InputMessage& msg) const { } } case InputMessage::Type::FOCUS: { case InputMessage::Type::FOCUS: { FocusEvent focusEvent; std::unique_ptr<FocusEvent> focusEvent = createFocusEvent(msg); initializeFocusEvent(focusEvent, msg); mCallbacks.onFocusEvent(std::move(focusEvent), msg.header.seq); mCallbacks.onFocusEvent(std::move(focusEvent), msg.header.seq); break; break; } } case InputMessage::Type::CAPTURE: { case InputMessage::Type::CAPTURE: { CaptureEvent captureEvent; std::unique_ptr<CaptureEvent> captureEvent = createCaptureEvent(msg); initializeCaptureEvent(captureEvent, msg); mCallbacks.onCaptureEvent(std::move(captureEvent), msg.header.seq); mCallbacks.onCaptureEvent(std::move(captureEvent), msg.header.seq); break; break; } } case InputMessage::Type::DRAG: { case InputMessage::Type::DRAG: { DragEvent dragEvent; std::unique_ptr<DragEvent> dragEvent = createDragEvent(msg); initializeDragEvent(dragEvent, msg); mCallbacks.onDragEvent(std::move(dragEvent), msg.header.seq); mCallbacks.onDragEvent(std::move(dragEvent), msg.header.seq); break; break; } } case InputMessage::Type::TOUCH_MODE: { case InputMessage::Type::TOUCH_MODE: { TouchModeEvent touchModeEvent; std::unique_ptr<TouchModeEvent> touchModeEvent = createTouchModeEvent(msg); initializeTouchModeEvent(touchModeEvent, msg); mCallbacks.onTouchModeEvent(std::move(touchModeEvent), msg.header.seq); mCallbacks.onTouchModeEvent(std::move(touchModeEvent), msg.header.seq); break; break; } } Loading @@ -448,7 +454,7 @@ bool InputConsumerNoResampling::consumeBatchedInputEvents( const nsecs_t frameTime = requestedFrameTime.value_or(std::numeric_limits<nsecs_t>::max()); const nsecs_t frameTime = requestedFrameTime.value_or(std::numeric_limits<nsecs_t>::max()); bool producedEvents = false; bool producedEvents = false; for (auto& [deviceId, messages] : mBatches) { for (auto& [deviceId, messages] : mBatches) { MotionEvent motion; std::unique_ptr<MotionEvent> motion; std::optional<uint32_t> firstSeqForBatch; std::optional<uint32_t> firstSeqForBatch; std::vector<uint32_t> sequences; std::vector<uint32_t> sequences; while (!messages.empty()) { while (!messages.empty()) { Loading @@ -456,20 +462,21 @@ bool InputConsumerNoResampling::consumeBatchedInputEvents( if (msg.body.motion.eventTime > frameTime) { if (msg.body.motion.eventTime > frameTime) { break; break; } } if (!firstSeqForBatch.has_value()) { if (motion == nullptr) { initializeMotionEvent(motion, msg); motion = createMotionEvent(msg); firstSeqForBatch = msg.header.seq; firstSeqForBatch = msg.header.seq; const auto [_, inserted] = mBatchedSequenceNumbers.insert({*firstSeqForBatch, {}}); const auto [_, inserted] = mBatchedSequenceNumbers.insert({*firstSeqForBatch, {}}); if (!inserted) { if (!inserted) { LOG(FATAL) << "The sequence " << msg.header.seq << " was already present!"; LOG(FATAL) << "The sequence " << msg.header.seq << " was already present!"; } } } else { } else { addSample(motion, msg); addSample(*motion, msg); mBatchedSequenceNumbers[*firstSeqForBatch].push_back(msg.header.seq); mBatchedSequenceNumbers[*firstSeqForBatch].push_back(msg.header.seq); } } messages.pop(); messages.pop(); } } if (firstSeqForBatch.has_value()) { if (motion != nullptr) { LOG_ALWAYS_FATAL_IF(!firstSeqForBatch.has_value()); mCallbacks.onMotionEvent(std::move(motion), *firstSeqForBatch); mCallbacks.onMotionEvent(std::move(motion), *firstSeqForBatch); producedEvents = true; producedEvents = true; } else { } else { Loading Loading @@ -520,9 +527,8 @@ std::string InputConsumerNoResampling::dump() const { std::queue<InputMessage> tmpQueue = messages; std::queue<InputMessage> tmpQueue = messages; while (!tmpQueue.empty()) { while (!tmpQueue.empty()) { LOG_ALWAYS_FATAL_IF(tmpQueue.front().header.type != InputMessage::Type::MOTION); LOG_ALWAYS_FATAL_IF(tmpQueue.front().header.type != InputMessage::Type::MOTION); MotionEvent motion; std::unique_ptr<MotionEvent> motion = createMotionEvent(tmpQueue.front()); initializeMotionEvent(motion, tmpQueue.front()); out += std::string(" ") + streamableToString(*motion) + "\n"; out += std::string(" ") + streamableToString(motion) + "\n"; tmpQueue.pop(); tmpQueue.pop(); } } } } Loading
libs/input/tests/InputPublisherAndConsumerNoResampling_test.cpp +36 −30 Original line number Original line Diff line number Diff line Loading @@ -341,19 +341,19 @@ private: // The sequence number to use when publishing the next event // The sequence number to use when publishing the next event uint32_t mSeq = 1; uint32_t mSeq = 1; BlockingQueue<KeyEvent> mKeyEvents; BlockingQueue<std::unique_ptr<KeyEvent>> mKeyEvents; BlockingQueue<MotionEvent> mMotionEvents; BlockingQueue<std::unique_ptr<MotionEvent>> mMotionEvents; BlockingQueue<FocusEvent> mFocusEvents; BlockingQueue<std::unique_ptr<FocusEvent>> mFocusEvents; BlockingQueue<CaptureEvent> mCaptureEvents; BlockingQueue<std::unique_ptr<CaptureEvent>> mCaptureEvents; BlockingQueue<DragEvent> mDragEvents; BlockingQueue<std::unique_ptr<DragEvent>> mDragEvents; BlockingQueue<TouchModeEvent> mTouchModeEvents; BlockingQueue<std::unique_ptr<TouchModeEvent>> mTouchModeEvents; // InputConsumerCallbacks interface // InputConsumerCallbacks interface void onKeyEvent(KeyEvent&& event, uint32_t seq) override { void onKeyEvent(std::unique_ptr<KeyEvent> event, uint32_t seq) override { mKeyEvents.push(std::move(event)); mKeyEvents.push(std::move(event)); mConsumer->finishInputEvent(seq, true); mConsumer->finishInputEvent(seq, true); } } void onMotionEvent(MotionEvent&& event, uint32_t seq) override { void onMotionEvent(std::unique_ptr<MotionEvent> event, uint32_t seq) override { mMotionEvents.push(std::move(event)); mMotionEvents.push(std::move(event)); mConsumer->finishInputEvent(seq, true); mConsumer->finishInputEvent(seq, true); } } Loading @@ -363,19 +363,19 @@ private: } } mConsumer->consumeBatchedInputEvents(std::nullopt); mConsumer->consumeBatchedInputEvents(std::nullopt); }; }; void onFocusEvent(FocusEvent&& event, uint32_t seq) override { void onFocusEvent(std::unique_ptr<FocusEvent> event, uint32_t seq) override { mFocusEvents.push(std::move(event)); mFocusEvents.push(std::move(event)); mConsumer->finishInputEvent(seq, true); mConsumer->finishInputEvent(seq, true); }; }; void onCaptureEvent(CaptureEvent&& event, uint32_t seq) override { void onCaptureEvent(std::unique_ptr<CaptureEvent> event, uint32_t seq) override { mCaptureEvents.push(std::move(event)); mCaptureEvents.push(std::move(event)); mConsumer->finishInputEvent(seq, true); mConsumer->finishInputEvent(seq, true); }; }; void onDragEvent(DragEvent&& event, uint32_t seq) override { void onDragEvent(std::unique_ptr<DragEvent> event, uint32_t seq) override { mDragEvents.push(std::move(event)); mDragEvents.push(std::move(event)); mConsumer->finishInputEvent(seq, true); mConsumer->finishInputEvent(seq, true); } } void onTouchModeEvent(TouchModeEvent&& event, uint32_t seq) override { void onTouchModeEvent(std::unique_ptr<TouchModeEvent> event, uint32_t seq) override { mTouchModeEvents.push(std::move(event)); mTouchModeEvents.push(std::move(event)); mConsumer->finishInputEvent(seq, true); mConsumer->finishInputEvent(seq, true); }; }; Loading Loading @@ -465,15 +465,15 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeKeyEvent() { eventTime); eventTime); ASSERT_EQ(OK, status) << "publisher publishKeyEvent should return OK"; ASSERT_EQ(OK, status) << "publisher publishKeyEvent should return OK"; std::optional<KeyEvent> keyEvent = mKeyEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<KeyEvent>> optKeyEvent = mKeyEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(optKeyEvent.has_value()) << "consumer should have returned non-NULL event"; std::unique_ptr<KeyEvent> keyEvent = std::move(*optKeyEvent); sendMessage(LooperMessage::CALL_PROBABLY_HAS_INPUT); sendMessage(LooperMessage::CALL_PROBABLY_HAS_INPUT); std::optional<bool> probablyHasInput = mProbablyHasInputResponses.popWithTimeout(TIMEOUT); std::optional<bool> probablyHasInput = mProbablyHasInputResponses.popWithTimeout(TIMEOUT); ASSERT_TRUE(probablyHasInput.has_value()); ASSERT_TRUE(probablyHasInput.has_value()); ASSERT_FALSE(probablyHasInput.value()) << "no events should be waiting after being consumed"; ASSERT_FALSE(probablyHasInput.value()) << "no events should be waiting after being consumed"; ASSERT_TRUE(keyEvent.has_value()) << "consumer should have returned non-NULL event"; EXPECT_EQ(eventId, keyEvent->getId()); EXPECT_EQ(eventId, keyEvent->getId()); EXPECT_EQ(deviceId, keyEvent->getDeviceId()); EXPECT_EQ(deviceId, keyEvent->getDeviceId()); EXPECT_EQ(source, keyEvent->getSource()); EXPECT_EQ(source, keyEvent->getSource()); Loading Loading @@ -540,7 +540,8 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeBatchedMotionMo publishMotionEvent(*mPublisher, args); publishMotionEvent(*mPublisher, args); // Ensure no event arrives because the UI thread is blocked // Ensure no event arrives because the UI thread is blocked std::optional<MotionEvent> noEvent = mMotionEvents.popWithTimeout(NO_EVENT_TIMEOUT); std::optional<std::unique_ptr<MotionEvent>> noEvent = mMotionEvents.popWithTimeout(NO_EVENT_TIMEOUT); ASSERT_FALSE(noEvent.has_value()) << "Got unexpected event: " << *noEvent; ASSERT_FALSE(noEvent.has_value()) << "Got unexpected event: " << *noEvent; Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse(); Result<InputPublisher::ConsumerResponse> result = mPublisher->receiveConsumerResponse(); Loading @@ -559,8 +560,9 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeBatchedMotionMo } } mNotifyLooperMayProceed.notify_all(); mNotifyLooperMayProceed.notify_all(); std::optional<MotionEvent> motion = mMotionEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<MotionEvent>> optMotion = mMotionEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(motion.has_value()); ASSERT_TRUE(optMotion.has_value()); std::unique_ptr<MotionEvent> motion = std::move(*optMotion); ASSERT_EQ(ACTION_MOVE, motion->getAction()); ASSERT_EQ(ACTION_MOVE, motion->getAction()); verifyFinishedSignal(*mPublisher, seq, publishTime); verifyFinishedSignal(*mPublisher, seq, publishTime); Loading @@ -573,8 +575,9 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeMotionEvent( nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC); nsecs_t publishTime = systemTime(SYSTEM_TIME_MONOTONIC); publishMotionEvent(*mPublisher, args); publishMotionEvent(*mPublisher, args); std::optional<MotionEvent> event = mMotionEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<MotionEvent>> optMotion = mMotionEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(event.has_value()) << "consumer should have returned non-NULL event"; ASSERT_TRUE(optMotion.has_value()); std::unique_ptr<MotionEvent> event = std::move(*optMotion); verifyArgsEqualToEvent(args, *event); verifyArgsEqualToEvent(args, *event); Loading @@ -592,8 +595,9 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeFocusEvent() { status = mPublisher->publishFocusEvent(seq, eventId, hasFocus); status = mPublisher->publishFocusEvent(seq, eventId, hasFocus); ASSERT_EQ(OK, status) << "publisher publishFocusEvent should return OK"; ASSERT_EQ(OK, status) << "publisher publishFocusEvent should return OK"; std::optional<FocusEvent> focusEvent = mFocusEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<FocusEvent>> optFocusEvent = mFocusEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(focusEvent.has_value()) << "consumer should have returned non-NULL event"; ASSERT_TRUE(optFocusEvent.has_value()) << "consumer should have returned non-NULL event"; std::unique_ptr<FocusEvent> focusEvent = std::move(*optFocusEvent); EXPECT_EQ(eventId, focusEvent->getId()); EXPECT_EQ(eventId, focusEvent->getId()); EXPECT_EQ(hasFocus, focusEvent->getHasFocus()); EXPECT_EQ(hasFocus, focusEvent->getHasFocus()); Loading @@ -611,9 +615,9 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeCaptureEvent() status = mPublisher->publishCaptureEvent(seq, eventId, captureEnabled); status = mPublisher->publishCaptureEvent(seq, eventId, captureEnabled); ASSERT_EQ(OK, status) << "publisher publishCaptureEvent should return OK"; ASSERT_EQ(OK, status) << "publisher publishCaptureEvent should return OK"; std::optional<CaptureEvent> event = mCaptureEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<CaptureEvent>> optEvent = mCaptureEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(optEvent.has_value()) << "consumer should have returned non-NULL event"; ASSERT_TRUE(event.has_value()) << "consumer should have returned non-NULL event"; std::unique_ptr<CaptureEvent> event = std::move(*optEvent); const CaptureEvent& captureEvent = *event; const CaptureEvent& captureEvent = *event; EXPECT_EQ(eventId, captureEvent.getId()); EXPECT_EQ(eventId, captureEvent.getId()); Loading @@ -635,9 +639,9 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeDragEvent() { status = mPublisher->publishDragEvent(seq, eventId, x, y, isExiting); status = mPublisher->publishDragEvent(seq, eventId, x, y, isExiting); ASSERT_EQ(OK, status) << "publisher publishDragEvent should return OK"; ASSERT_EQ(OK, status) << "publisher publishDragEvent should return OK"; std::optional<DragEvent> event = mDragEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<DragEvent>> optEvent = mDragEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(optEvent.has_value()) << "consumer should have returned non-NULL event"; ASSERT_TRUE(event.has_value()) << "consumer should have returned non-NULL event"; std::unique_ptr<DragEvent> event = std::move(*optEvent); const DragEvent& dragEvent = *event; const DragEvent& dragEvent = *event; EXPECT_EQ(eventId, dragEvent.getId()); EXPECT_EQ(eventId, dragEvent.getId()); Loading @@ -659,8 +663,10 @@ void InputPublisherAndConsumerNoResamplingTest::publishAndConsumeTouchModeEvent( status = mPublisher->publishTouchModeEvent(seq, eventId, touchModeEnabled); status = mPublisher->publishTouchModeEvent(seq, eventId, touchModeEnabled); ASSERT_EQ(OK, status) << "publisher publishTouchModeEvent should return OK"; ASSERT_EQ(OK, status) << "publisher publishTouchModeEvent should return OK"; std::optional<TouchModeEvent> event = mTouchModeEvents.popWithTimeout(TIMEOUT); std::optional<std::unique_ptr<TouchModeEvent>> optEvent = ASSERT_NE(std::nullopt, event); mTouchModeEvents.popWithTimeout(TIMEOUT); ASSERT_TRUE(optEvent.has_value()); std::unique_ptr<TouchModeEvent> event = std::move(*optEvent); const TouchModeEvent& touchModeEvent = *event; const TouchModeEvent& touchModeEvent = *event; EXPECT_EQ(eventId, touchModeEvent.getId()); EXPECT_EQ(eventId, touchModeEvent.getId()); Loading