From fbed16bfa7b50cb85cecd1ae8868aa6d3c58ea4e Mon Sep 17 00:00:00 2001 From: Arpit Singh Date: Tue, 11 Feb 2025 15:47:37 +0000 Subject: Use ALWAYS_FATAL if touchState is out of sync Converting an existing LOG(FATAL) to LOG_ALWAYS_FATAL. This methods is always called with tokens that hvae been added to touchstate. So in this CL we 1. Rename the method accordingly. 2. Add a LOG_ALWAYS_FATAL for cases this expectation is not met. This is a followup from ag/31432556. Test: atest inputflinger_tests Bug: 245989146 Flag: EXEMPT TEST_ONLY Change-Id: I18daa7a0086495b3a64df5286f94406d9c2c9ccb --- services/inputflinger/dispatcher/InputDispatcher.cpp | 15 +++++---------- services/inputflinger/dispatcher/InputDispatcher.h | 6 +++--- 2 files changed, 8 insertions(+), 13 deletions(-) (limited to 'services/inputflinger') diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index 4c8147df2c..9efe74de6c 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -4235,13 +4235,8 @@ void InputDispatcher::synthesizePointerDownEventsForConnectionLocked( << "channel '" << connection->getInputChannelName() << "' ~ Synthesized " << downEvents.size() << " down events to ensure consistent event stream."; - auto touchedWindowHandleAndDisplay = - mTouchStates.findTouchedWindowHandleAndDisplay(connection->getToken()); - if (!touchedWindowHandleAndDisplay.has_value()) { - LOG(FATAL) << __func__ << ": Touch state is out of sync: No touched window for token"; - } - - const auto [windowHandle, displayId] = touchedWindowHandleAndDisplay.value(); + const auto [windowHandle, displayId] = + mTouchStates.findExistingTouchedWindowHandleAndDisplay(connection->getToken()); const bool wasEmpty = connection->outboundQueue.empty(); for (std::unique_ptr& downEventEntry : downEvents) { @@ -7397,8 +7392,8 @@ bool InputDispatcher::DispatcherTouchState::isPointerInWindow(const sp&, ui::LogicalDisplayId>> -InputDispatcher::DispatcherTouchState::findTouchedWindowHandleAndDisplay( +std::tuple&, ui::LogicalDisplayId> +InputDispatcher::DispatcherTouchState::findExistingTouchedWindowHandleAndDisplay( const sp& token) const { for (const auto& [displayId, state] : mTouchStatesByDisplay) { for (const TouchedWindow& w : state.windows) { @@ -7407,7 +7402,7 @@ InputDispatcher::DispatcherTouchState::findTouchedWindowHandleAndDisplay( } } } - return std::nullopt; + LOG_ALWAYS_FATAL("%s : Touch state is out of sync: No touched window for token", __func__); } void InputDispatcher::DispatcherTouchState::forAllTouchedWindows( diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index e76bd8970f..db7ebfd4e3 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -396,9 +396,9 @@ private: bool isPointerInWindow(const sp& token, ui::LogicalDisplayId displayId, DeviceId deviceId, int32_t pointerId) const; - // Find touched windowHandle and display by token. - std::optional&, ui::LogicalDisplayId>> - findTouchedWindowHandleAndDisplay(const sp& token) const; + // Find an existing touched windowHandle and display by token. + std::tuple&, ui::LogicalDisplayId> + findExistingTouchedWindowHandleAndDisplay(const sp& token) const; void forAllTouchedWindows(std::function&)> f) const; -- cgit v1.2.3-59-g8ed1b