@@ -5907,8 +5907,24 @@ bool InputDispatcher::transferTouchGesture(const sp<IBinder>& fromToken, const s
59075907 synthesizeCancelationEventsForWindowLocked (fromWindowHandle, options, fromConnection);
59085908
59095909 // Check if the wallpaper window should deliver the corresponding event.
5910- transferWallpaperTouch (oldTargetFlags, newTargetFlags, fromWindowHandle, toWindowHandle,
5911- *state, deviceId, pointers, traceContext.getTracker ());
5910+ const auto [cancellations, pointerDowns] =
5911+ mTouchStates .transferWallpaperTouch (fromWindowHandle, toWindowHandle, displayId,
5912+ deviceId, pointers, oldTargetFlags,
5913+ newTargetFlags, mWindowInfos ,
5914+ mConnectionManager );
5915+ for (const auto & cancellationArgs : cancellations) {
5916+ // touch should be cancelled for old wallpaper window
5917+ LOG_ALWAYS_FATAL_IF (cancellationArgs.mode !=
5918+ CancelationOptions::Mode::CANCEL_POINTER_EVENTS);
5919+ synthesizeCancelationEventsForWindowLocked (cancellationArgs.windowHandle , options);
5920+ }
5921+ for (const auto & pointerDownArgs : pointerDowns) {
5922+ // expect pointer down on new the wallpaper window
5923+ synthesizePointerDownEventsForConnectionLocked (pointerDownArgs.downTimeInTarget ,
5924+ pointerDownArgs.connection ,
5925+ pointerDownArgs.targetFlags ,
5926+ traceContext.getTracker ());
5927+ }
59125928
59135929 // Because new window may have a wallpaper window, it will merge input state from it
59145930 // parent window, after this the firstNewPointerIdx in input state will be reset, then
@@ -7156,12 +7172,17 @@ void InputDispatcher::DispatcherTouchState::slipWallpaperTouch(
71567172 }
71577173}
71587174
7159- void InputDispatcher::transferWallpaperTouch (
7175+ std::pair<std::list<InputDispatcher::DispatcherTouchState::CancellationArgs>,
7176+ std::list<InputDispatcher::DispatcherTouchState::PointerDownArgs>>
7177+ InputDispatcher::DispatcherTouchState::transferWallpaperTouch (
7178+ const sp<gui::WindowInfoHandle> fromWindowHandle,
7179+ const sp<gui::WindowInfoHandle> toWindowHandle, ui::LogicalDisplayId displayId,
7180+ android::DeviceId deviceId, const std::vector<PointerProperties>& pointers,
71607181 ftl::Flags<InputTarget::Flags> oldTargetFlags,
7161- ftl::Flags<InputTarget::Flags> newTargetFlags, const sp<WindowInfoHandle> fromWindowHandle ,
7162- const sp<WindowInfoHandle> toWindowHandle, TouchState& state, DeviceId deviceId,
7163- const std::vector<PointerProperties>& pointers,
7164- const std::unique_ptr<trace::EventTrackerInterface>& traceTracker) {
7182+ ftl::Flags<InputTarget::Flags> newTargetFlags, const DispatcherWindowInfo& windowInfos ,
7183+ const ConnectionManager& connections) {
7184+ TouchState& state = getTouchState (displayId);
7185+
71657186 const bool oldHasWallpaper = oldTargetFlags.test (InputTarget::Flags::FOREGROUND) &&
71667187 fromWindowHandle->getInfo ()->inputConfig .test (
71677188 gui::WindowInfo::InputConfig::DUPLICATE_TOUCH_TO_WALLPAPER);
@@ -7172,16 +7193,17 @@ void InputDispatcher::transferWallpaperTouch(
71727193 const sp<WindowInfoHandle> oldWallpaper =
71737194 oldHasWallpaper ? state.getWallpaperWindow (deviceId) : nullptr ;
71747195 const sp<WindowInfoHandle> newWallpaper =
7175- newHasWallpaper ? mWindowInfos .findWallpaperWindowBelow (toWindowHandle) : nullptr ;
7196+ newHasWallpaper ? windowInfos .findWallpaperWindowBelow (toWindowHandle) : nullptr ;
71767197 if (oldWallpaper == newWallpaper) {
7177- return ;
7198+ return {} ;
71787199 }
71797200
7201+ std::list<CancellationArgs> cancellations;
7202+ std::list<PointerDownArgs> pointerDowns;
71807203 if (oldWallpaper != nullptr ) {
7181- CancelationOptions options (CancelationOptions::Mode::CANCEL_POINTER_EVENTS,
7182- " transferring touch focus to another window" , traceTracker);
71837204 state.removeWindowByToken (oldWallpaper->getToken ());
7184- synthesizeCancelationEventsForWindowLocked (oldWallpaper, options);
7205+ cancellations.emplace_back (oldWallpaper, CancelationOptions::Mode::CANCEL_POINTER_EVENTS,
7206+ /* deviceId*/ std::nullopt );
71857207 }
71867208
71877209 if (newWallpaper != nullptr ) {
@@ -7193,15 +7215,16 @@ void InputDispatcher::transferWallpaperTouch(
71937215 state.addOrUpdateWindow (newWallpaper, InputTarget::DispatchMode::AS_IS, wallpaperFlags,
71947216 deviceId, pointers, downTimeInTarget);
71957217 std::shared_ptr<Connection> wallpaperConnection =
7196- mConnectionManager .getConnection (newWallpaper->getToken ());
7218+ connections .getConnection (newWallpaper->getToken ());
71977219 if (wallpaperConnection != nullptr ) {
71987220 std::shared_ptr<Connection> toConnection =
7199- mConnectionManager .getConnection (toWindowHandle->getToken ());
7221+ connections .getConnection (toWindowHandle->getToken ());
72007222 toConnection->inputState .mergePointerStateTo (wallpaperConnection->inputState );
7201- synthesizePointerDownEventsForConnectionLocked (downTimeInTarget, wallpaperConnection,
7202- wallpaperFlags, traceTracker);
7223+ pointerDowns.emplace_back (downTimeInTarget, wallpaperConnection, wallpaperFlags);
72037224 }
7225+ pointerDowns.emplace_back (downTimeInTarget, wallpaperConnection, wallpaperFlags);
72047226 }
7227+ return {cancellations, pointerDowns};
72057228}
72067229
72077230sp<WindowInfoHandle> InputDispatcher::DispatcherWindowInfo::findWallpaperWindowBelow (
@@ -7455,4 +7478,10 @@ void InputDispatcher::DispatcherTouchState::clear() {
74557478 mTouchStatesByDisplay .clear ();
74567479}
74577480
7481+ TouchState& InputDispatcher::DispatcherTouchState::getTouchState (ui::LogicalDisplayId displayId) {
7482+ auto touchStateIt = mTouchStatesByDisplay .find (displayId);
7483+ LOG_ALWAYS_FATAL_IF (touchStateIt == mTouchStatesByDisplay .end ());
7484+ return touchStateIt->second ;
7485+ }
7486+
74587487} // namespace android::inputdispatcher
0 commit comments