Loading services/inputflinger/dispatcher/Entry.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -192,6 +192,18 @@ void KeyEntry::recycle() { interceptKeyWakeupTime = 0; } // --- TouchModeEntry --- TouchModeEntry::TouchModeEntry(int32_t id, nsecs_t eventTime, bool inTouchMode) : EventEntry(id, Type::TOUCH_MODE_CHANGED, eventTime, POLICY_FLAG_PASS_TO_USER), inTouchMode(inTouchMode) {} TouchModeEntry::~TouchModeEntry() {} std::string TouchModeEntry::getDescription() const { return StringPrintf("TouchModeEvent(inTouchMode=%s)", inTouchMode ? "true" : "false"); } // --- MotionEntry --- MotionEntry::MotionEntry(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source, Loading services/inputflinger/dispatcher/Entry.h +11 −1 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ struct EventEntry { SENSOR, POINTER_CAPTURE_CHANGED, DRAG, TOUCH_MODE_CHANGED, }; int32_t id; Loading Loading @@ -185,7 +186,7 @@ struct MotionEntry : EventEntry { float xOffset, float yOffset); std::string getDescription() const override; virtual ~MotionEntry(); ~MotionEntry() override; }; struct SensorEntry : EventEntry { Loading @@ -207,6 +208,15 @@ struct SensorEntry : EventEntry { ~SensorEntry() override; }; struct TouchModeEntry : EventEntry { bool inTouchMode; TouchModeEntry(int32_t id, nsecs_t eventTime, bool inTouchMode); std::string getDescription() const override; ~TouchModeEntry() override; }; // Tracks the progress of dispatching a particular event to a particular connection. struct DispatchEntry { const uint32_t seq; // unique sequence number, never 0 Loading services/inputflinger/dispatcher/InputDispatcher.cpp +66 −0 Original line number Diff line number Diff line Loading @@ -825,6 +825,14 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) { break; } case EventEntry::Type::TOUCH_MODE_CHANGED: { const auto typedEntry = std::static_pointer_cast<TouchModeEntry>(mPendingEvent); dispatchTouchModeChangeLocked(currentTime, typedEntry); done = true; dropReason = DropReason::NOT_DROPPED; // touch mode events are never dropped break; } case EventEntry::Type::POINTER_CAPTURE_CHANGED: { const auto typedEntry = std::static_pointer_cast<PointerCaptureChangedEntry>(mPendingEvent); Loading Loading @@ -1005,6 +1013,7 @@ bool InputDispatcher::enqueueInboundEventLocked(std::unique_ptr<EventEntry> newE LOG_ALWAYS_FATAL("Focus events should be inserted using enqueueFocusEventLocked"); break; } case EventEntry::Type::TOUCH_MODE_CHANGED: case EventEntry::Type::CONFIGURATION_CHANGED: case EventEntry::Type::DEVICE_RESET: case EventEntry::Type::SENSOR: Loading Loading @@ -1139,6 +1148,7 @@ void InputDispatcher::dropInboundEventLocked(const EventEntry& entry, DropReason break; } case EventEntry::Type::FOCUS: case EventEntry::Type::TOUCH_MODE_CHANGED: case EventEntry::Type::CONFIGURATION_CHANGED: case EventEntry::Type::DEVICE_RESET: { LOG_ALWAYS_FATAL("Should not drop %s events", NamedEnum::string(entry.type).c_str()); Loading Loading @@ -1397,6 +1407,43 @@ void InputDispatcher::dispatchPointerCaptureChangedLocked( dropReason = DropReason::NOT_DROPPED; } void InputDispatcher::dispatchTouchModeChangeLocked(nsecs_t currentTime, const std::shared_ptr<TouchModeEntry>& entry) { const std::vector<sp<WindowInfoHandle>>& windowHandles = getWindowHandlesLocked(mFocusedDisplayId); if (windowHandles.empty()) { return; } const std::vector<InputTarget> inputTargets = getInputTargetsFromWindowHandlesLocked(windowHandles); if (inputTargets.empty()) { return; } entry->dispatchInProgress = true; dispatchEventLocked(currentTime, entry, inputTargets); } std::vector<InputTarget> InputDispatcher::getInputTargetsFromWindowHandlesLocked( const std::vector<sp<WindowInfoHandle>>& windowHandles) const { std::vector<InputTarget> inputTargets; for (const sp<WindowInfoHandle>& handle : windowHandles) { // TODO(b/193718270): Due to performance concerns, consider notifying visible windows only. const sp<IBinder>& token = handle->getToken(); if (token == nullptr) { continue; } std::shared_ptr<InputChannel> channel = getInputChannelLocked(token); if (channel == nullptr) { continue; // Window has gone away } InputTarget target; target.inputChannel = channel; target.flags = InputTarget::FLAG_DISPATCH_AS_IS; inputTargets.push_back(target); } return inputTargets; } bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, std::shared_ptr<KeyEntry> entry, DropReason* dropReason, nsecs_t* nextWakeupTime) { // Preprocessing. Loading Loading @@ -1759,6 +1806,7 @@ int32_t InputDispatcher::getTargetDisplayId(const EventEntry& entry) { } case EventEntry::Type::POINTER_CAPTURE_CHANGED: case EventEntry::Type::FOCUS: case EventEntry::Type::TOUCH_MODE_CHANGED: case EventEntry::Type::CONFIGURATION_CHANGED: case EventEntry::Type::DEVICE_RESET: case EventEntry::Type::SENSOR: Loading Loading @@ -2745,6 +2793,10 @@ void InputDispatcher::pokeUserActivityLocked(const EventEntry& eventEntry) { eventType = USER_ACTIVITY_EVENT_BUTTON; break; } case EventEntry::Type::TOUCH_MODE_CHANGED: { break; } case EventEntry::Type::FOCUS: case EventEntry::Type::CONFIGURATION_CHANGED: case EventEntry::Type::DEVICE_RESET: Loading Loading @@ -2973,6 +3025,7 @@ void InputDispatcher::enqueueDispatchEntryLocked(const sp<Connection>& connectio break; } case EventEntry::Type::FOCUS: case EventEntry::Type::TOUCH_MODE_CHANGED: case EventEntry::Type::POINTER_CAPTURE_CHANGED: case EventEntry::Type::DRAG: { break; Loading Loading @@ -3191,6 +3244,16 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime, break; } case EventEntry::Type::TOUCH_MODE_CHANGED: { const TouchModeEntry& touchModeEntry = static_cast<const TouchModeEntry&>(eventEntry); status = connection->inputPublisher .publishTouchModeEvent(dispatchEntry->seq, touchModeEntry.id, touchModeEntry.inTouchMode); break; } case EventEntry::Type::POINTER_CAPTURE_CHANGED: { const auto& captureEntry = static_cast<const PointerCaptureChangedEntry&>(eventEntry); Loading Loading @@ -3525,6 +3588,7 @@ void InputDispatcher::synthesizeCancelationEventsForConnectionLocked( break; } case EventEntry::Type::FOCUS: case EventEntry::Type::TOUCH_MODE_CHANGED: case EventEntry::Type::POINTER_CAPTURE_CHANGED: case EventEntry::Type::DRAG: { LOG_ALWAYS_FATAL("Canceling %s events is not supported", Loading Loading @@ -3588,6 +3652,7 @@ void InputDispatcher::synthesizePointerDownEventsForConnectionLocked( case EventEntry::Type::KEY: case EventEntry::Type::FOCUS: case EventEntry::Type::TOUCH_MODE_CHANGED: case EventEntry::Type::CONFIGURATION_CHANGED: case EventEntry::Type::DEVICE_RESET: case EventEntry::Type::POINTER_CAPTURE_CHANGED: Loading Loading @@ -4787,6 +4852,7 @@ void InputDispatcher::setInputFilterEnabled(bool enabled) { void InputDispatcher::setInTouchMode(bool inTouchMode) { std::scoped_lock lock(mLock); mInTouchMode = inTouchMode; // TODO(b/193718270): Fire TouchModeEvent here. } void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) { Loading services/inputflinger/dispatcher/InputDispatcher.h +9 −0 Original line number Diff line number Diff line Loading @@ -361,6 +361,12 @@ private: bool hasResponsiveConnectionLocked(android::gui::WindowInfoHandle& windowHandle) const REQUIRES(mLock); // Gets all the input targets (with their respective input channels) from the window handles // passed as argument. std::vector<InputTarget> getInputTargetsFromWindowHandlesLocked( const std::vector<sp<android::gui::WindowInfoHandle>>& windowHandles) const REQUIRES(mLock); /* * Validate and update InputWindowHandles for a given display. */ Loading Loading @@ -423,6 +429,9 @@ private: void dispatchPointerCaptureChangedLocked( nsecs_t currentTime, const std::shared_ptr<PointerCaptureChangedEntry>& entry, DropReason& dropReason) REQUIRES(mLock); void dispatchTouchModeChangeLocked(nsecs_t currentTime, const std::shared_ptr<TouchModeEntry>& entry) REQUIRES(mLock); void dispatchEventLocked(nsecs_t currentTime, std::shared_ptr<EventEntry> entry, const std::vector<InputTarget>& inputTargets) REQUIRES(mLock); void dispatchSensorLocked(nsecs_t currentTime, const std::shared_ptr<SensorEntry>& entry, Loading services/inputflinger/dispatcher/include/InputDispatcherInterface.h +1 −0 Original line number Diff line number Diff line Loading @@ -202,6 +202,7 @@ public: * InputDispatcher is the source of truth of Pointer Capture. */ virtual void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) = 0; /* Flush input device motion sensor. * * Returns true on success. Loading Loading
services/inputflinger/dispatcher/Entry.cpp +12 −0 Original line number Diff line number Diff line Loading @@ -192,6 +192,18 @@ void KeyEntry::recycle() { interceptKeyWakeupTime = 0; } // --- TouchModeEntry --- TouchModeEntry::TouchModeEntry(int32_t id, nsecs_t eventTime, bool inTouchMode) : EventEntry(id, Type::TOUCH_MODE_CHANGED, eventTime, POLICY_FLAG_PASS_TO_USER), inTouchMode(inTouchMode) {} TouchModeEntry::~TouchModeEntry() {} std::string TouchModeEntry::getDescription() const { return StringPrintf("TouchModeEvent(inTouchMode=%s)", inTouchMode ? "true" : "false"); } // --- MotionEntry --- MotionEntry::MotionEntry(int32_t id, nsecs_t eventTime, int32_t deviceId, uint32_t source, Loading
services/inputflinger/dispatcher/Entry.h +11 −1 Original line number Diff line number Diff line Loading @@ -39,6 +39,7 @@ struct EventEntry { SENSOR, POINTER_CAPTURE_CHANGED, DRAG, TOUCH_MODE_CHANGED, }; int32_t id; Loading Loading @@ -185,7 +186,7 @@ struct MotionEntry : EventEntry { float xOffset, float yOffset); std::string getDescription() const override; virtual ~MotionEntry(); ~MotionEntry() override; }; struct SensorEntry : EventEntry { Loading @@ -207,6 +208,15 @@ struct SensorEntry : EventEntry { ~SensorEntry() override; }; struct TouchModeEntry : EventEntry { bool inTouchMode; TouchModeEntry(int32_t id, nsecs_t eventTime, bool inTouchMode); std::string getDescription() const override; ~TouchModeEntry() override; }; // Tracks the progress of dispatching a particular event to a particular connection. struct DispatchEntry { const uint32_t seq; // unique sequence number, never 0 Loading
services/inputflinger/dispatcher/InputDispatcher.cpp +66 −0 Original line number Diff line number Diff line Loading @@ -825,6 +825,14 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t* nextWakeupTime) { break; } case EventEntry::Type::TOUCH_MODE_CHANGED: { const auto typedEntry = std::static_pointer_cast<TouchModeEntry>(mPendingEvent); dispatchTouchModeChangeLocked(currentTime, typedEntry); done = true; dropReason = DropReason::NOT_DROPPED; // touch mode events are never dropped break; } case EventEntry::Type::POINTER_CAPTURE_CHANGED: { const auto typedEntry = std::static_pointer_cast<PointerCaptureChangedEntry>(mPendingEvent); Loading Loading @@ -1005,6 +1013,7 @@ bool InputDispatcher::enqueueInboundEventLocked(std::unique_ptr<EventEntry> newE LOG_ALWAYS_FATAL("Focus events should be inserted using enqueueFocusEventLocked"); break; } case EventEntry::Type::TOUCH_MODE_CHANGED: case EventEntry::Type::CONFIGURATION_CHANGED: case EventEntry::Type::DEVICE_RESET: case EventEntry::Type::SENSOR: Loading Loading @@ -1139,6 +1148,7 @@ void InputDispatcher::dropInboundEventLocked(const EventEntry& entry, DropReason break; } case EventEntry::Type::FOCUS: case EventEntry::Type::TOUCH_MODE_CHANGED: case EventEntry::Type::CONFIGURATION_CHANGED: case EventEntry::Type::DEVICE_RESET: { LOG_ALWAYS_FATAL("Should not drop %s events", NamedEnum::string(entry.type).c_str()); Loading Loading @@ -1397,6 +1407,43 @@ void InputDispatcher::dispatchPointerCaptureChangedLocked( dropReason = DropReason::NOT_DROPPED; } void InputDispatcher::dispatchTouchModeChangeLocked(nsecs_t currentTime, const std::shared_ptr<TouchModeEntry>& entry) { const std::vector<sp<WindowInfoHandle>>& windowHandles = getWindowHandlesLocked(mFocusedDisplayId); if (windowHandles.empty()) { return; } const std::vector<InputTarget> inputTargets = getInputTargetsFromWindowHandlesLocked(windowHandles); if (inputTargets.empty()) { return; } entry->dispatchInProgress = true; dispatchEventLocked(currentTime, entry, inputTargets); } std::vector<InputTarget> InputDispatcher::getInputTargetsFromWindowHandlesLocked( const std::vector<sp<WindowInfoHandle>>& windowHandles) const { std::vector<InputTarget> inputTargets; for (const sp<WindowInfoHandle>& handle : windowHandles) { // TODO(b/193718270): Due to performance concerns, consider notifying visible windows only. const sp<IBinder>& token = handle->getToken(); if (token == nullptr) { continue; } std::shared_ptr<InputChannel> channel = getInputChannelLocked(token); if (channel == nullptr) { continue; // Window has gone away } InputTarget target; target.inputChannel = channel; target.flags = InputTarget::FLAG_DISPATCH_AS_IS; inputTargets.push_back(target); } return inputTargets; } bool InputDispatcher::dispatchKeyLocked(nsecs_t currentTime, std::shared_ptr<KeyEntry> entry, DropReason* dropReason, nsecs_t* nextWakeupTime) { // Preprocessing. Loading Loading @@ -1759,6 +1806,7 @@ int32_t InputDispatcher::getTargetDisplayId(const EventEntry& entry) { } case EventEntry::Type::POINTER_CAPTURE_CHANGED: case EventEntry::Type::FOCUS: case EventEntry::Type::TOUCH_MODE_CHANGED: case EventEntry::Type::CONFIGURATION_CHANGED: case EventEntry::Type::DEVICE_RESET: case EventEntry::Type::SENSOR: Loading Loading @@ -2745,6 +2793,10 @@ void InputDispatcher::pokeUserActivityLocked(const EventEntry& eventEntry) { eventType = USER_ACTIVITY_EVENT_BUTTON; break; } case EventEntry::Type::TOUCH_MODE_CHANGED: { break; } case EventEntry::Type::FOCUS: case EventEntry::Type::CONFIGURATION_CHANGED: case EventEntry::Type::DEVICE_RESET: Loading Loading @@ -2973,6 +3025,7 @@ void InputDispatcher::enqueueDispatchEntryLocked(const sp<Connection>& connectio break; } case EventEntry::Type::FOCUS: case EventEntry::Type::TOUCH_MODE_CHANGED: case EventEntry::Type::POINTER_CAPTURE_CHANGED: case EventEntry::Type::DRAG: { break; Loading Loading @@ -3191,6 +3244,16 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime, break; } case EventEntry::Type::TOUCH_MODE_CHANGED: { const TouchModeEntry& touchModeEntry = static_cast<const TouchModeEntry&>(eventEntry); status = connection->inputPublisher .publishTouchModeEvent(dispatchEntry->seq, touchModeEntry.id, touchModeEntry.inTouchMode); break; } case EventEntry::Type::POINTER_CAPTURE_CHANGED: { const auto& captureEntry = static_cast<const PointerCaptureChangedEntry&>(eventEntry); Loading Loading @@ -3525,6 +3588,7 @@ void InputDispatcher::synthesizeCancelationEventsForConnectionLocked( break; } case EventEntry::Type::FOCUS: case EventEntry::Type::TOUCH_MODE_CHANGED: case EventEntry::Type::POINTER_CAPTURE_CHANGED: case EventEntry::Type::DRAG: { LOG_ALWAYS_FATAL("Canceling %s events is not supported", Loading Loading @@ -3588,6 +3652,7 @@ void InputDispatcher::synthesizePointerDownEventsForConnectionLocked( case EventEntry::Type::KEY: case EventEntry::Type::FOCUS: case EventEntry::Type::TOUCH_MODE_CHANGED: case EventEntry::Type::CONFIGURATION_CHANGED: case EventEntry::Type::DEVICE_RESET: case EventEntry::Type::POINTER_CAPTURE_CHANGED: Loading Loading @@ -4787,6 +4852,7 @@ void InputDispatcher::setInputFilterEnabled(bool enabled) { void InputDispatcher::setInTouchMode(bool inTouchMode) { std::scoped_lock lock(mLock); mInTouchMode = inTouchMode; // TODO(b/193718270): Fire TouchModeEvent here. } void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) { Loading
services/inputflinger/dispatcher/InputDispatcher.h +9 −0 Original line number Diff line number Diff line Loading @@ -361,6 +361,12 @@ private: bool hasResponsiveConnectionLocked(android::gui::WindowInfoHandle& windowHandle) const REQUIRES(mLock); // Gets all the input targets (with their respective input channels) from the window handles // passed as argument. std::vector<InputTarget> getInputTargetsFromWindowHandlesLocked( const std::vector<sp<android::gui::WindowInfoHandle>>& windowHandles) const REQUIRES(mLock); /* * Validate and update InputWindowHandles for a given display. */ Loading Loading @@ -423,6 +429,9 @@ private: void dispatchPointerCaptureChangedLocked( nsecs_t currentTime, const std::shared_ptr<PointerCaptureChangedEntry>& entry, DropReason& dropReason) REQUIRES(mLock); void dispatchTouchModeChangeLocked(nsecs_t currentTime, const std::shared_ptr<TouchModeEntry>& entry) REQUIRES(mLock); void dispatchEventLocked(nsecs_t currentTime, std::shared_ptr<EventEntry> entry, const std::vector<InputTarget>& inputTargets) REQUIRES(mLock); void dispatchSensorLocked(nsecs_t currentTime, const std::shared_ptr<SensorEntry>& entry, Loading
services/inputflinger/dispatcher/include/InputDispatcherInterface.h +1 −0 Original line number Diff line number Diff line Loading @@ -202,6 +202,7 @@ public: * InputDispatcher is the source of truth of Pointer Capture. */ virtual void requestPointerCapture(const sp<IBinder>& windowToken, bool enabled) = 0; /* Flush input device motion sensor. * * Returns true on success. Loading