diff options
| -rw-r--r-- | include/input/Input.h | 1 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 45 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.h | 4 |
3 files changed, 32 insertions, 18 deletions
diff --git a/include/input/Input.h b/include/input/Input.h index 1e810b438a..fe0c775fd3 100644 --- a/include/input/Input.h +++ b/include/input/Input.h @@ -30,7 +30,6 @@ #include <stdint.h> #include <ui/Transform.h> #include <utils/BitSet.h> -#include <utils/RefBase.h> #include <utils/Timers.h> #include <array> #include <limits> diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index a3c129e31a..9125fe49e0 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -2811,6 +2811,30 @@ void InputDispatcher::addDragEventLocked(const MotionEntry& entry) { } } +std::optional<InputTarget> InputDispatcher::createInputTargetLocked( + const sp<android::gui::WindowInfoHandle>& windowHandle, + ftl::Flags<InputTarget::Flags> targetFlags, + std::optional<nsecs_t> firstDownTimeInTarget) const { + std::shared_ptr<InputChannel> inputChannel = getInputChannelLocked(windowHandle->getToken()); + if (inputChannel == nullptr) { + ALOGW("Not creating InputTarget for %s, no input channel", windowHandle->getName().c_str()); + return {}; + } + InputTarget inputTarget; + inputTarget.inputChannel = inputChannel; + inputTarget.flags = targetFlags; + inputTarget.globalScaleFactor = windowHandle->getInfo()->globalScaleFactor; + inputTarget.firstDownTimeInTarget = firstDownTimeInTarget; + const auto& displayInfoIt = mDisplayInfos.find(windowHandle->getInfo()->displayId); + if (displayInfoIt != mDisplayInfos.end()) { + inputTarget.displayTransform = displayInfoIt->second.transform; + } else { + // DisplayInfo not found for this window on display windowInfo->displayId. + // TODO(b/198444055): Make this an error message after 'setInputWindows' API is removed. + } + return inputTarget; +} + void InputDispatcher::addWindowTargetLocked(const sp<WindowInfoHandle>& windowHandle, ftl::Flags<InputTarget::Flags> targetFlags, std::bitset<MAX_POINTER_ID + 1> pointerIds, @@ -2826,25 +2850,12 @@ void InputDispatcher::addWindowTargetLocked(const sp<WindowInfoHandle>& windowHa const WindowInfo* windowInfo = windowHandle->getInfo(); if (it == inputTargets.end()) { - InputTarget inputTarget; - std::shared_ptr<InputChannel> inputChannel = - getInputChannelLocked(windowHandle->getToken()); - if (inputChannel == nullptr) { - ALOGW("Window %s already unregistered input channel", windowHandle->getName().c_str()); + std::optional<InputTarget> target = + createInputTargetLocked(windowHandle, targetFlags, firstDownTimeInTarget); + if (!target) { return; } - inputTarget.inputChannel = inputChannel; - inputTarget.flags = targetFlags; - inputTarget.globalScaleFactor = windowInfo->globalScaleFactor; - inputTarget.firstDownTimeInTarget = firstDownTimeInTarget; - const auto& displayInfoIt = mDisplayInfos.find(windowInfo->displayId); - if (displayInfoIt != mDisplayInfos.end()) { - inputTarget.displayTransform = displayInfoIt->second.transform; - } else { - // DisplayInfo not found for this window on display windowInfo->displayId. - // TODO(b/198444055): Make this an error message after 'setInputWindows' API is removed. - } - inputTargets.push_back(inputTarget); + inputTargets.push_back(*target); it = inputTargets.end() - 1; } diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index 9b12f2f64c..0e9cfeffe4 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -556,6 +556,10 @@ private: std::vector<Monitor> selectResponsiveMonitorsLocked( const std::vector<Monitor>& gestureMonitors) const REQUIRES(mLock); + std::optional<InputTarget> createInputTargetLocked( + const sp<android::gui::WindowInfoHandle>& windowHandle, + ftl::Flags<InputTarget::Flags> targetFlags, + std::optional<nsecs_t> firstDownTimeInTarget) const REQUIRES(mLock); void addWindowTargetLocked(const sp<android::gui::WindowInfoHandle>& windowHandle, ftl::Flags<InputTarget::Flags> targetFlags, std::bitset<MAX_POINTER_ID + 1> pointerIds, |