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

Commit ddecabc7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Log dispatch state when addPointers hits unexpected state" into main

parents a31e51ca e535f979
Loading
Loading
Loading
Loading
+13 −5
Original line number Diff line number Diff line
@@ -2539,11 +2539,19 @@ std::vector<InputTarget> InputDispatcher::findTouchedWindowTargetsLocked(
            if (!isHoverAction) {
                const bool isDownOrPointerDown = maskedAction == AMOTION_EVENT_ACTION_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},
                                                         isDownOrPointerDown
                                                         ? std::make_optional(entry.eventTime)
                                                                 ? std::make_optional(
                                                                           entry.eventTime)
                                                                 : 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
                // 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
+10 −8
Original line number Diff line number Diff line
@@ -70,14 +70,14 @@ void TouchState::clearWindowsWithoutPointers() {
    });
}

void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle,
                                   InputTarget::DispatchMode dispatchMode,
android::base::Result<void> TouchState::addOrUpdateWindow(
        const sp<WindowInfoHandle>& windowHandle, InputTarget::DispatchMode dispatchMode,
        ftl::Flags<InputTarget::Flags> targetFlags, DeviceId deviceId,
        const std::vector<PointerProperties>& touchingPointers,
        std::optional<nsecs_t> firstDownTimeInTarget) {
    if (touchingPointers.empty()) {
        LOG(FATAL) << __func__ << "No pointers specified for " << windowHandle->getName();
        return;
        return android::base::Error();
    }
    for (TouchedWindow& touchedWindow : windows) {
        // 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
            // downTime set initially. Need to update existing window when a pointer is down for the
            // window.
            android::base::Result<void> addResult =
                    touchedWindow.addTouchingPointers(deviceId, touchingPointers);
            if (firstDownTimeInTarget) {
                touchedWindow.trySetDownTimeInTarget(deviceId, *firstDownTimeInTarget);
            }
            return;
            return addResult;
        }
    }
    TouchedWindow touchedWindow;
@@ -107,6 +108,7 @@ void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle,
        touchedWindow.trySetDownTimeInTarget(deviceId, *firstDownTimeInTarget);
    }
    windows.push_back(touchedWindow);
    return {};
}

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

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

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

void TouchedWindow::addTouchingPointers(DeviceId deviceId,
Result<void> TouchedWindow::addTouchingPointers(DeviceId deviceId,
                                                const std::vector<PointerProperties>& pointers) {
    std::vector<PointerProperties>& touchingPointers = mDeviceStates[deviceId].touchingPointers;
    const size_t initialSize = touchingPointers.size();
@@ -98,11 +99,14 @@ void TouchedWindow::addTouchingPointers(DeviceId deviceId,
            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 "
                   << deviceId << " already in " << *this;
        return android::base::Error();
    }
    touchingPointers.insert(touchingPointers.end(), pointers.begin(), pointers.end());
    return {};
}

bool TouchedWindow::hasTouchingPointers() const {
+2 −1
Original line number Diff line number Diff line
@@ -46,7 +46,8 @@ struct TouchedWindow {
    bool hasTouchingPointers() const;
    bool hasTouchingPointers(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 removeTouchingPointers(DeviceId deviceId, std::bitset<MAX_POINTER_ID + 1> pointers);
    bool hasActiveStylus() const;