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

Commit 8384e0d7 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Iterate over vector in pilferPointersLocked

No behaviour change in this CL.
We are currently returning early from the function where there isn't
exactly one device active.

To future-proof this code, iterate over the entire vector of devices,
knowing that currently, only 1 iteration will occur.
This will simplify the future CL for multi-device support.

Bug: 211379801
Test: atest inputflinger_tests
Change-Id: Ie58ecde47f6dccd4cb45e1d8264af59376c27683
parent 06405fc7
Loading
Loading
Loading
Loading
+37 −33
Original line number Diff line number Diff line
@@ -5918,14 +5918,16 @@ status_t InputDispatcher::pilferPointers(const sp<IBinder>& token) {
status_t InputDispatcher::pilferPointersLocked(const sp<IBinder>& token) {
    const std::shared_ptr<InputChannel> requestingChannel = getInputChannelLocked(token);
    if (!requestingChannel) {
        ALOGW("Attempted to pilfer pointers from an un-registered channel or invalid token");
        LOG(WARNING)
                << "Attempted to pilfer pointers from an un-registered channel or invalid token";
        return BAD_VALUE;
    }

    auto [statePtr, windowPtr, displayId] = findTouchStateWindowAndDisplayLocked(token);
    if (statePtr == nullptr || windowPtr == nullptr) {
        ALOGW("Attempted to pilfer points from a channel without any on-going pointer streams."
              " Ignoring.");
        LOG(WARNING)
                << "Attempted to pilfer points from a channel without any on-going pointer streams."
                   " Ignoring.";
        return BAD_VALUE;
    }
    std::set<int32_t> deviceIds = windowPtr->getTouchingDeviceIds();
@@ -5934,8 +5936,8 @@ status_t InputDispatcher::pilferPointersLocked(const sp<IBinder>& token) {
                     << " in window: " << windowPtr->dump();
        return BAD_VALUE;
    }
    const int32_t deviceId = *deviceIds.begin();

    for (const DeviceId deviceId : deviceIds) {
        TouchState& state = *statePtr;
        TouchedWindow& window = *windowPtr;
        // Send cancel events to all the input channels we're stealing from.
@@ -5956,14 +5958,16 @@ status_t InputDispatcher::pilferPointersLocked(const sp<IBinder>& token) {
            }
        }
        canceledWindows += canceledWindows.empty() ? "[]" : "]";
    ALOGI("Channel %s is stealing touch from %s", requestingChannel->getName().c_str(),
          canceledWindows.c_str());
        LOG(INFO) << "Channel " << requestingChannel->getName()
                  << " is stealing input gesture for device " << deviceId << " from "
                  << canceledWindows;

        // Prevent the gesture from being sent to any other windows.
        // This only blocks relevant pointers to be sent to other windows
        window.addPilferingPointers(deviceId, pointerIds);

        state.cancelPointersForWindowsExcept(deviceId, pointerIds, token);
    }
    return OK;
}