@@ -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
63456364void 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 ) {
0 commit comments