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
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 5158220..005e5b6 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -5918,14 +5918,16 @@
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,36 +5936,38 @@
<< " in window: " << windowPtr->dump();
return BAD_VALUE;
}
- const int32_t deviceId = *deviceIds.begin();
- TouchState& state = *statePtr;
- TouchedWindow& window = *windowPtr;
- // Send cancel events to all the input channels we're stealing from.
- CancelationOptions options(CancelationOptions::Mode::CANCEL_POINTER_EVENTS,
- "input channel stole pointer stream");
- options.deviceId = deviceId;
- options.displayId = displayId;
- std::bitset<MAX_POINTER_ID + 1> pointerIds = window.getTouchingPointers(deviceId);
- options.pointerIds = pointerIds;
- std::string canceledWindows;
- for (const TouchedWindow& w : state.windows) {
- const std::shared_ptr<InputChannel> channel =
- getInputChannelLocked(w.windowHandle->getToken());
- if (channel != nullptr && channel->getConnectionToken() != token) {
- synthesizeCancelationEventsForInputChannelLocked(channel, options);
- canceledWindows += canceledWindows.empty() ? "[" : ", ";
- canceledWindows += channel->getName();
+ for (const DeviceId deviceId : deviceIds) {
+ TouchState& state = *statePtr;
+ TouchedWindow& window = *windowPtr;
+ // Send cancel events to all the input channels we're stealing from.
+ CancelationOptions options(CancelationOptions::Mode::CANCEL_POINTER_EVENTS,
+ "input channel stole pointer stream");
+ options.deviceId = deviceId;
+ options.displayId = displayId;
+ std::bitset<MAX_POINTER_ID + 1> pointerIds = window.getTouchingPointers(deviceId);
+ options.pointerIds = pointerIds;
+ std::string canceledWindows;
+ for (const TouchedWindow& w : state.windows) {
+ const std::shared_ptr<InputChannel> channel =
+ getInputChannelLocked(w.windowHandle->getToken());
+ if (channel != nullptr && channel->getConnectionToken() != token) {
+ synthesizeCancelationEventsForInputChannelLocked(channel, options);
+ canceledWindows += canceledWindows.empty() ? "[" : ", ";
+ canceledWindows += channel->getName();
+ }
}
+ canceledWindows += canceledWindows.empty() ? "[]" : "]";
+ 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);
}
- canceledWindows += canceledWindows.empty() ? "[]" : "]";
- ALOGI("Channel %s is stealing touch from %s", requestingChannel->getName().c_str(),
- canceledWindows.c_str());
-
- // 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;
}