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

Commit 0686f0c4 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Reset touch state when device resets

At any point in time, an input device may be reset. We already generate
cancel events to handle this situation.
However, that's not sufficient.

In this CL, touch state is cleared of all pointers for the device that
is getting reset.

Bug: 273376858
Test: m inputflinger_tests && $ANDROID_HOST_OUT/nativetest64/inputflinger_tests/inputflinger_tests --gtest_filter="*NotifyDeviceResetCancelsHoveringStream*"
Change-Id: I66da4f3eec125a6b260ed1478bca00164bb40c9e
parent c03813b7
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -1461,6 +1461,11 @@ bool InputDispatcher::dispatchDeviceResetLocked(nsecs_t currentTime,
    CancelationOptions options(CancelationOptions::Mode::CANCEL_ALL_EVENTS, "device was reset");
    options.deviceId = entry.deviceId;
    synthesizeCancelationEventsForAllConnectionsLocked(options);

    // Remove all active pointers from this device
    for (auto& [_, touchState] : mTouchStatesByDisplay) {
        touchState.removeAllPointersForDevice(entry.deviceId);
    }
    return true;
}

+12 −0
Original line number Diff line number Diff line
@@ -242,6 +242,18 @@ void TouchState::removeHoveringPointer(int32_t hoveringDeviceId, int32_t hoverin
    clearWindowsWithoutPointers();
}

void TouchState::removeAllPointersForDevice(int32_t removedDeviceId) {
    for (TouchedWindow& window : windows) {
        window.removeAllHoveringPointersForDevice(removedDeviceId);
    }
    if (deviceId == removedDeviceId) {
        for (TouchedWindow& window : windows) {
            window.removeAllTouchingPointers();
        }
    }
    clearWindowsWithoutPointers();
}

std::string TouchState::dump() const {
    std::string out;
    out += StringPrintf("deviceId=%d, source=%s\n", deviceId,
+2 −0
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ struct TouchState {
                                    int32_t deviceId, int32_t hoveringPointerId);
    void removeHoveringPointer(int32_t deviceId, int32_t hoveringPointerId);
    void clearHoveringPointers();

    void removeAllPointersForDevice(int32_t removedDeviceId);
    void removeWindowByToken(const sp<IBinder>& token);
    void filterNonAsIsTouchWindows();

+8 −0
Original line number Diff line number Diff line
@@ -58,6 +58,10 @@ void TouchedWindow::removeTouchingPointer(int32_t pointerId) {
    }
}

void TouchedWindow::removeAllTouchingPointers() {
    pointerIds.reset();
}

void TouchedWindow::removeHoveringPointer(int32_t deviceId, int32_t pointerId) {
    const auto it = mHoveringPointerIdsByDevice.find(deviceId);
    if (it == mHoveringPointerIdsByDevice.end()) {
@@ -70,6 +74,10 @@ void TouchedWindow::removeHoveringPointer(int32_t deviceId, int32_t pointerId) {
    }
}

void TouchedWindow::removeAllHoveringPointersForDevice(int32_t deviceId) {
    mHoveringPointerIdsByDevice.erase(deviceId);
}

std::string TouchedWindow::dump() const {
    std::string out;
    std::string hoveringPointers =
+3 −0
Original line number Diff line number Diff line
@@ -44,6 +44,9 @@ struct TouchedWindow {
    void addHoveringPointer(int32_t deviceId, int32_t pointerId);
    void removeHoveringPointer(int32_t deviceId, int32_t pointerId);
    void removeTouchingPointer(int32_t pointerId);

    void removeAllTouchingPointers();
    void removeAllHoveringPointersForDevice(int32_t deviceId);
    void clearHoveringPointers();
    std::string dump() const;

Loading