Skip to content

Commit c95ea81

Browse files
author
Arpit Singh
committed
[18/n Dispatcher refactor] Move pilferPointers
In this CL we move pilferPointers to the DispatcherTouchStates subclass. Bug: 367661487 Bug: 245989146 Test: atest inputflinger_tests Flag: EXEMPT refactor Change-Id: I49c5760b79e6feab101fc381ec83bd91288bde4c
1 parent c2a4d0f commit c95ea81

2 files changed

Lines changed: 47 additions & 24 deletions

File tree

services/inputflinger/dispatcher/InputDispatcher.cpp

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5528,7 +5528,7 @@ InputDispatcher::DispatcherTouchState::eraseRemovedWindowsFromWindowInfo(
55285528
LOG(INFO) << "Touched window was removed: " << touchedWindow.windowHandle->getName()
55295529
<< " in display %" << displayId;
55305530
cancellations.emplace_back(touchedWindow.windowHandle,
5531-
CancelationOptions::Mode::CANCEL_POINTER_EVENTS, std::nullopt);
5531+
CancelationOptions::Mode::CANCEL_POINTER_EVENTS);
55325532
// Since we are about to drop the touch, cancel the events for the wallpaper as well.
55335533
if (touchedWindow.targetFlags.test(InputTarget::Flags::FOREGROUND) &&
55345534
touchedWindow.windowHandle->getInfo()->inputConfig.test(
@@ -5941,7 +5941,7 @@ InputDispatcher::DispatcherTouchState::transferTouchGesture(const sp<android::IB
59415941
if (fromConnection != nullptr && toConnection != nullptr) {
59425942
fromConnection->inputState.mergePointerStateTo(toConnection->inputState);
59435943
cancellations.emplace_back(fromWindowHandle,
5944-
CancelationOptions::Mode::CANCEL_POINTER_EVENTS, std::nullopt);
5944+
CancelationOptions::Mode::CANCEL_POINTER_EVENTS);
59455945

59465946
// Check if the wallpaper window should deliver the corresponding event.
59475947
auto [wallpaperCancellations, wallpaperPointerDowns] =
@@ -6293,43 +6293,62 @@ status_t InputDispatcher::pilferPointersLocked(const sp<IBinder>& token) {
62936293
return BAD_VALUE;
62946294
}
62956295

6296-
auto [statePtr, windowPtr, displayId] =
6297-
findTouchStateWindowAndDisplay(token, mTouchStates.mTouchStatesByDisplay);
6298-
if (statePtr == nullptr || windowPtr == nullptr) {
6296+
ScopedSyntheticEventTracer traceContext(mTracer);
6297+
CancelationOptions options(CancelationOptions::Mode::CANCEL_POINTER_EVENTS,
6298+
"input channel stole pointer stream", traceContext.getTracker());
6299+
const auto result = mTouchStates.pilferPointers(token, *requestingConnection);
6300+
if (!result.ok()) {
6301+
return result.error().code();
6302+
}
6303+
6304+
const auto cancellations = *result;
6305+
for (const auto& cancellationArgs : cancellations) {
6306+
LOG_ALWAYS_FATAL_IF(cancellationArgs.mode !=
6307+
CancelationOptions::Mode::CANCEL_POINTER_EVENTS);
6308+
options.displayId = cancellationArgs.displayId;
6309+
options.deviceId = cancellationArgs.deviceId;
6310+
options.pointerIds = cancellationArgs.pointerIds;
6311+
synthesizeCancelationEventsForWindowLocked(cancellationArgs.windowHandle, options);
6312+
}
6313+
return OK;
6314+
}
6315+
6316+
base::Result<std::list<InputDispatcher::DispatcherTouchState::CancellationArgs>, status_t>
6317+
InputDispatcher::DispatcherTouchState::pilferPointers(const sp<IBinder>& token,
6318+
const Connection& requestingConnection) {
6319+
auto touchStateWindowAndDisplay = findTouchStateWindowAndDisplay(token);
6320+
if (!touchStateWindowAndDisplay.has_value()) {
62996321
LOG(WARNING)
63006322
<< "Attempted to pilfer points from a channel without any on-going pointer streams."
63016323
" Ignoring.";
6302-
return BAD_VALUE;
6324+
return Error(BAD_VALUE);
63036325
}
6304-
std::set<int32_t> deviceIds = windowPtr->getTouchingDeviceIds();
6326+
6327+
auto [state, window, displayId] = touchStateWindowAndDisplay.value();
6328+
6329+
std::set<int32_t> deviceIds = window.getTouchingDeviceIds();
63056330
if (deviceIds.empty()) {
6306-
LOG(WARNING) << "Can't pilfer: no touching devices in window: " << windowPtr->dump();
6307-
return BAD_VALUE;
6331+
LOG(WARNING) << "Can't pilfer: no touching devices in window: " << window.dump();
6332+
return Error(BAD_VALUE);
63086333
}
63096334

6310-
ScopedSyntheticEventTracer traceContext(mTracer);
6335+
std::list<CancellationArgs> cancellations;
63116336
for (const DeviceId deviceId : deviceIds) {
6312-
TouchState& state = *statePtr;
6313-
TouchedWindow& window = *windowPtr;
63146337
// Send cancel events to all the input channels we're stealing from.
6315-
CancelationOptions options(CancelationOptions::Mode::CANCEL_POINTER_EVENTS,
6316-
"input channel stole pointer stream", traceContext.getTracker());
6317-
options.deviceId = deviceId;
6318-
options.displayId = displayId;
63196338
std::vector<PointerProperties> pointers = window.getTouchingPointers(deviceId);
63206339
std::bitset<MAX_POINTER_ID + 1> pointerIds = getPointerIds(pointers);
6321-
options.pointerIds = pointerIds;
6322-
63236340
std::string canceledWindows;
63246341
for (const TouchedWindow& w : state.windows) {
63256342
if (w.windowHandle->getToken() != token) {
6326-
synthesizeCancelationEventsForWindowLocked(w.windowHandle, options);
6343+
cancellations.emplace_back(w.windowHandle,
6344+
CancelationOptions::Mode::CANCEL_POINTER_EVENTS,
6345+
deviceId, displayId, pointerIds);
63276346
canceledWindows += canceledWindows.empty() ? "[" : ", ";
63286347
canceledWindows += w.windowHandle->getName();
63296348
}
63306349
}
63316350
canceledWindows += canceledWindows.empty() ? "[]" : "]";
6332-
LOG(INFO) << "Channel " << requestingConnection->getInputChannelName()
6351+
LOG(INFO) << "Channel " << requestingConnection.getInputChannelName()
63336352
<< " is stealing input gesture for device " << deviceId << " from "
63346353
<< canceledWindows;
63356354

@@ -6339,7 +6358,7 @@ status_t InputDispatcher::pilferPointersLocked(const sp<IBinder>& token) {
63396358

63406359
state.cancelPointersForWindowsExcept(deviceId, pointerIds, token);
63416360
}
6342-
return OK;
6361+
return cancellations;
63436362
}
63446363

63456364
void InputDispatcher::requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) {
@@ -7220,8 +7239,7 @@ InputDispatcher::DispatcherTouchState::transferWallpaperTouch(
72207239
std::list<PointerDownArgs> pointerDowns;
72217240
if (oldWallpaper != nullptr) {
72227241
state.removeWindowByToken(oldWallpaper->getToken());
7223-
cancellations.emplace_back(oldWallpaper, CancelationOptions::Mode::CANCEL_POINTER_EVENTS,
7224-
/*deviceId*/ std::nullopt);
7242+
cancellations.emplace_back(oldWallpaper, CancelationOptions::Mode::CANCEL_POINTER_EVENTS);
72257243
}
72267244

72277245
if (newWallpaper != nullptr) {

services/inputflinger/dispatcher/InputDispatcher.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,9 @@ class InputDispatcher : public android::InputDispatcherInterface {
355355
struct CancellationArgs {
356356
const sp<gui::WindowInfoHandle> windowHandle;
357357
CancelationOptions::Mode mode;
358-
std::optional<DeviceId> deviceId;
358+
std::optional<DeviceId> deviceId{std::nullopt};
359+
ui::LogicalDisplayId displayId{ui::LogicalDisplayId::INVALID};
360+
std::bitset<MAX_POINTER_ID + 1> pointerIds{};
359361
};
360362

361363
struct PointerDownArgs {
@@ -408,6 +410,9 @@ class InputDispatcher : public android::InputDispatcherInterface {
408410
const DispatcherWindowInfo& windowInfos,
409411
const ConnectionManager& connections);
410412

413+
base::Result<std::list<CancellationArgs>, status_t> pilferPointers(
414+
const sp<IBinder>& token, const Connection& requestingConnection);
415+
411416
void clear();
412417

413418
std::unordered_map<ui::LogicalDisplayId, TouchState> mTouchStatesByDisplay;

0 commit comments

Comments
 (0)