Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fbed16bf authored by Arpit Singh's avatar Arpit Singh
Browse files

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
parent adcbb982
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -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<EventEntry>& downEventEntry : downEvents) {
@@ -7397,8 +7392,8 @@ bool InputDispatcher::DispatcherTouchState::isPointerInWindow(const sp<android::
    return false;
}

std::optional<std::tuple<const sp<gui::WindowInfoHandle>&, ui::LogicalDisplayId>>
InputDispatcher::DispatcherTouchState::findTouchedWindowHandleAndDisplay(
std::tuple<const sp<gui::WindowInfoHandle>&, ui::LogicalDisplayId>
InputDispatcher::DispatcherTouchState::findExistingTouchedWindowHandleAndDisplay(
        const sp<android::IBinder>& 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(
+3 −3
Original line number Diff line number Diff line
@@ -396,9 +396,9 @@ private:
        bool isPointerInWindow(const sp<android::IBinder>& token, ui::LogicalDisplayId displayId,
                               DeviceId deviceId, int32_t pointerId) const;

        // Find touched windowHandle and display by token.
        std::optional<std::tuple<const sp<gui::WindowInfoHandle>&, ui::LogicalDisplayId>>
        findTouchedWindowHandleAndDisplay(const sp<IBinder>& token) const;
        // Find an existing touched windowHandle and display by token.
        std::tuple<const sp<gui::WindowInfoHandle>&, ui::LogicalDisplayId>
        findExistingTouchedWindowHandleAndDisplay(const sp<IBinder>& token) const;

        void forAllTouchedWindows(std::function<void(const sp<gui::WindowInfoHandle>&)> f) const;