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

Commit e535f979 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Log dispatch state when addPointers hits unexpected state

Propagate errors from TouchedWindow's addTouchingPointers to the
InputDispatcher, so that we can look at the event history. Currently,
this condition is not getting triggered in the dispatcher tests, but it
seems achievable in the libgui_test, according to the logs.

Once we figure out the failure mode, we can remove this error reporting
to simplify the code.

Bug: 331747627
Test: TEST=inputflinger_tests; m $TEST && $ANDROID_HOST_OUT/nativetest64/$TEST/$TEST
Change-Id: I668b2db8c3d20b7af81ad89e85608783db631309
parent 686b965e
Loading
Loading
Loading
Loading
+13 −5
Original line number Original line Diff line number Diff line
@@ -2539,11 +2539,19 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
            if (!isHoverAction) {
            if (!isHoverAction) {
                const bool isDownOrPointerDown = maskedAction == AMOTION_EVENT_ACTION_DOWN ||
                const bool isDownOrPointerDown = maskedAction == AMOTION_EVENT_ACTION_DOWN ||
                        maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN;
                        maskedAction == AMOTION_EVENT_ACTION_POINTER_DOWN;
                tempTouchState.addOrUpdateWindow(windowHandle, InputTarget::DispatchMode::AS_IS,
                Result<void> addResult =
                        tempTouchState.addOrUpdateWindow(windowHandle,
                                                         InputTarget::DispatchMode::AS_IS,
                                                         targetFlags, entry.deviceId, {pointer},
                                                         targetFlags, entry.deviceId, {pointer},
                                                         isDownOrPointerDown
                                                         isDownOrPointerDown
                                                         ? std::make_optional(entry.eventTime)
                                                                 ? std::make_optional(
                                                                           entry.eventTime)
                                                                 : std::nullopt);
                                                                 : std::nullopt);
                if (!addResult.ok()) {
                    LOG(ERROR) << "Error while processing " << entry << " for "
                               << windowHandle->getName();
                    logDispatchStateLocked();
                }
                // If this is the pointer going down and the touched window has a wallpaper
                // If this is the pointer going down and the touched window has a wallpaper
                // then also add the touched wallpaper windows so they are locked in for the
                // then also add the touched wallpaper windows so they are locked in for the
                // duration of the touch gesture. We do not collect wallpapers during HOVER_MOVE or
                // duration of the touch gesture. We do not collect wallpapers during HOVER_MOVE or
+10 −8
Original line number Original line Diff line number Diff line
@@ -70,14 +70,14 @@ void TouchState::clearWindowsWithoutPointers() {
    });
    });
}
}


void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle,
android::base::Result<void> TouchState::addOrUpdateWindow(
                                   InputTarget::DispatchMode dispatchMode,
        const sp<WindowInfoHandle>& windowHandle, InputTarget::DispatchMode dispatchMode,
        ftl::Flags<InputTarget::Flags> targetFlags, DeviceId deviceId,
        ftl::Flags<InputTarget::Flags> targetFlags, DeviceId deviceId,
        const std::vector<PointerProperties>& touchingPointers,
        const std::vector<PointerProperties>& touchingPointers,
        std::optional<nsecs_t> firstDownTimeInTarget) {
        std::optional<nsecs_t> firstDownTimeInTarget) {
    if (touchingPointers.empty()) {
    if (touchingPointers.empty()) {
        LOG(FATAL) << __func__ << "No pointers specified for " << windowHandle->getName();
        LOG(FATAL) << __func__ << "No pointers specified for " << windowHandle->getName();
        return;
        return android::base::Error();
    }
    }
    for (TouchedWindow& touchedWindow : windows) {
    for (TouchedWindow& touchedWindow : windows) {
        // We do not compare windows by token here because two windows that share the same token
        // We do not compare windows by token here because two windows that share the same token
@@ -91,11 +91,12 @@ void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle,
            // For cases like hover enter/exit or DISPATCH_AS_OUTSIDE a touch window might not have
            // For cases like hover enter/exit or DISPATCH_AS_OUTSIDE a touch window might not have
            // downTime set initially. Need to update existing window when a pointer is down for the
            // downTime set initially. Need to update existing window when a pointer is down for the
            // window.
            // window.
            android::base::Result<void> addResult =
                    touchedWindow.addTouchingPointers(deviceId, touchingPointers);
                    touchedWindow.addTouchingPointers(deviceId, touchingPointers);
            if (firstDownTimeInTarget) {
            if (firstDownTimeInTarget) {
                touchedWindow.trySetDownTimeInTarget(deviceId, *firstDownTimeInTarget);
                touchedWindow.trySetDownTimeInTarget(deviceId, *firstDownTimeInTarget);
            }
            }
            return;
            return addResult;
        }
        }
    }
    }
    TouchedWindow touchedWindow;
    TouchedWindow touchedWindow;
@@ -107,6 +108,7 @@ void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle,
        touchedWindow.trySetDownTimeInTarget(deviceId, *firstDownTimeInTarget);
        touchedWindow.trySetDownTimeInTarget(deviceId, *firstDownTimeInTarget);
    }
    }
    windows.push_back(touchedWindow);
    windows.push_back(touchedWindow);
    return {};
}
}


void TouchState::addHoveringPointerToWindow(const sp<WindowInfoHandle>& windowHandle,
void TouchState::addHoveringPointerToWindow(const sp<WindowInfoHandle>& windowHandle,
+5 −5
Original line number Original line Diff line number Diff line
@@ -43,10 +43,10 @@ struct TouchState {
    void removeTouchingPointer(DeviceId deviceId, int32_t pointerId);
    void removeTouchingPointer(DeviceId deviceId, int32_t pointerId);
    void removeTouchingPointerFromWindow(DeviceId deviceId, int32_t pointerId,
    void removeTouchingPointerFromWindow(DeviceId deviceId, int32_t pointerId,
                                         const sp<android::gui::WindowInfoHandle>& windowHandle);
                                         const sp<android::gui::WindowInfoHandle>& windowHandle);
    void addOrUpdateWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
    android::base::Result<void> addOrUpdateWindow(
                           InputTarget::DispatchMode dispatchMode,
            const sp<android::gui::WindowInfoHandle>& windowHandle,
                           ftl::Flags<InputTarget::Flags> targetFlags, DeviceId deviceId,
            InputTarget::DispatchMode dispatchMode, ftl::Flags<InputTarget::Flags> targetFlags,
                           const std::vector<PointerProperties>& touchingPointers,
            DeviceId deviceId, const std::vector<PointerProperties>& touchingPointers,
            std::optional<nsecs_t> firstDownTimeInTarget = std::nullopt);
            std::optional<nsecs_t> firstDownTimeInTarget = std::nullopt);
    void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
    void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
                                    DeviceId deviceId, const PointerProperties& pointer);
                                    DeviceId deviceId, const PointerProperties& pointer);
+8 −4
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@
#include <android-base/stringprintf.h>
#include <android-base/stringprintf.h>
#include <input/PrintTools.h>
#include <input/PrintTools.h>


using android::base::Result;
using android::base::StringPrintf;
using android::base::StringPrintf;


namespace android {
namespace android {
@@ -89,7 +90,7 @@ void TouchedWindow::addHoveringPointer(DeviceId deviceId, const PointerPropertie
    hoveringPointers.push_back(pointer);
    hoveringPointers.push_back(pointer);
}
}


void TouchedWindow::addTouchingPointers(DeviceId deviceId,
Result<void> TouchedWindow::addTouchingPointers(DeviceId deviceId,
                                                const std::vector<PointerProperties>& pointers) {
                                                const std::vector<PointerProperties>& pointers) {
    std::vector<PointerProperties>& touchingPointers = mDeviceStates[deviceId].touchingPointers;
    std::vector<PointerProperties>& touchingPointers = mDeviceStates[deviceId].touchingPointers;
    const size_t initialSize = touchingPointers.size();
    const size_t initialSize = touchingPointers.size();
@@ -98,11 +99,14 @@ void TouchedWindow::addTouchingPointers(DeviceId deviceId,
            return properties.id == pointer.id;
            return properties.id == pointer.id;
        });
        });
    }
    }
    if (touchingPointers.size() != initialSize) {
    const bool foundInconsistentState = touchingPointers.size() != initialSize;
    touchingPointers.insert(touchingPointers.end(), pointers.begin(), pointers.end());
    if (foundInconsistentState) {
        LOG(ERROR) << __func__ << ": " << dumpVector(pointers, streamableToString) << ", device "
        LOG(ERROR) << __func__ << ": " << dumpVector(pointers, streamableToString) << ", device "
                   << deviceId << " already in " << *this;
                   << deviceId << " already in " << *this;
        return android::base::Error();
    }
    }
    touchingPointers.insert(touchingPointers.end(), pointers.begin(), pointers.end());
    return {};
}
}


bool TouchedWindow::hasTouchingPointers() const {
bool TouchedWindow::hasTouchingPointers() const {
+2 −1
Original line number Original line Diff line number Diff line
@@ -46,7 +46,8 @@ struct TouchedWindow {
    bool hasTouchingPointers() const;
    bool hasTouchingPointers() const;
    bool hasTouchingPointers(DeviceId deviceId) const;
    bool hasTouchingPointers(DeviceId deviceId) const;
    std::vector<PointerProperties> getTouchingPointers(DeviceId deviceId) const;
    std::vector<PointerProperties> getTouchingPointers(DeviceId deviceId) const;
    void addTouchingPointers(DeviceId deviceId, const std::vector<PointerProperties>& pointers);
    android::base::Result<void> addTouchingPointers(DeviceId deviceId,
                                                    const std::vector<PointerProperties>& pointers);
    void removeTouchingPointer(DeviceId deviceId, int32_t pointerId);
    void removeTouchingPointer(DeviceId deviceId, int32_t pointerId);
    void removeTouchingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointers);
    void removeTouchingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointers);
    bool hasActiveStylus() const;
    bool hasActiveStylus() const;