Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 43a1d490 authored by Arpit Singh's avatar Arpit Singh Committed by Android (Google) Code Review
Browse files

Merge changes I34ed5f0f,I9538646f into main

* changes:
  [23/n Dispatcher refactor] Add const ref to window and connection
  Move utility functions related to isFromSource to Input.h
parents 4e451db0 5b4aeb3d
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -316,6 +316,19 @@ struct PointerProperties;

bool isStylusEvent(uint32_t source, const std::vector<PointerProperties>& properties);

bool isStylusHoverEvent(uint32_t source, const std::vector<PointerProperties>& properties,
                        int32_t action);

bool isFromMouse(uint32_t source, ToolType tooltype);

bool isFromTouchpad(uint32_t source, ToolType tooltype);

bool isFromDrawingTablet(uint32_t source, ToolType tooltype);

bool isHoverAction(int32_t action);

bool isMouseOrTouchpad(uint32_t sources);

/*
 * Flags that flow alongside events in the input dispatch system to help with certain
 * policy decisions such as waking from device sleep.
+30 −0
Original line number Diff line number Diff line
@@ -284,6 +284,36 @@ bool isStylusEvent(uint32_t source, const std::vector<PointerProperties>& proper
    return false;
}

bool isStylusHoverEvent(uint32_t source, const std::vector<PointerProperties>& properties,
                        int32_t action) {
    return isStylusEvent(source, properties) && isHoverAction(action);
}

bool isFromMouse(uint32_t source, ToolType toolType) {
    return isFromSource(source, AINPUT_SOURCE_MOUSE) && toolType == ToolType::MOUSE;
}

bool isFromTouchpad(uint32_t source, ToolType toolType) {
    return isFromSource(source, AINPUT_SOURCE_MOUSE) && toolType == ToolType::FINGER;
}

bool isFromDrawingTablet(uint32_t source, ToolType toolType) {
    return isFromSource(source, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS) &&
            isStylusToolType(toolType);
}

bool isHoverAction(int32_t action) {
    return action == AMOTION_EVENT_ACTION_HOVER_ENTER ||
            action == AMOTION_EVENT_ACTION_HOVER_MOVE || action == AMOTION_EVENT_ACTION_HOVER_EXIT;
}

bool isMouseOrTouchpad(uint32_t sources) {
    // Check if this is a mouse or touchpad, but not a drawing tablet.
    return isFromSource(sources, AINPUT_SOURCE_MOUSE_RELATIVE) ||
            (isFromSource(sources, AINPUT_SOURCE_MOUSE) &&
             !isFromSource(sources, AINPUT_SOURCE_STYLUS));
}

VerifiedKeyEvent verifiedKeyEventFromKeyEvent(const KeyEvent& event) {
    return {{VerifiedInputEvent::Type::KEY, event.getDeviceId(), event.getEventTime(),
             event.getSource(), event.getDisplayId()},
+5 −35
Original line number Diff line number Diff line
@@ -36,37 +36,6 @@ namespace android {

namespace {

bool isFromMouse(const NotifyMotionArgs& args) {
    return isFromSource(args.source, AINPUT_SOURCE_MOUSE) &&
            args.pointerProperties[0].toolType == ToolType::MOUSE;
}

bool isFromTouchpad(const NotifyMotionArgs& args) {
    return isFromSource(args.source, AINPUT_SOURCE_MOUSE) &&
            args.pointerProperties[0].toolType == ToolType::FINGER;
}

bool isFromDrawingTablet(const NotifyMotionArgs& args) {
    return isFromSource(args.source, AINPUT_SOURCE_MOUSE | AINPUT_SOURCE_STYLUS) &&
            isStylusToolType(args.pointerProperties[0].toolType);
}

bool isHoverAction(int32_t action) {
    return action == AMOTION_EVENT_ACTION_HOVER_ENTER ||
            action == AMOTION_EVENT_ACTION_HOVER_MOVE || action == AMOTION_EVENT_ACTION_HOVER_EXIT;
}

bool isStylusHoverEvent(const NotifyMotionArgs& args) {
    return isStylusEvent(args.source, args.pointerProperties) && isHoverAction(args.action);
}

bool isMouseOrTouchpad(uint32_t sources) {
    // Check if this is a mouse or touchpad, but not a drawing tablet.
    return isFromSource(sources, AINPUT_SOURCE_MOUSE_RELATIVE) ||
            (isFromSource(sources, AINPUT_SOURCE_MOUSE) &&
             !isFromSource(sources, AINPUT_SOURCE_STYLUS));
}

inline void notifyPointerDisplayChange(std::optional<std::tuple<ui::LogicalDisplayId, vec2>> change,
                                       PointerChoreographerPolicyInterface& policy) {
    if (!change) {
@@ -239,15 +208,16 @@ NotifyMotionArgs PointerChoreographer::processMotion(const NotifyMotionArgs& arg
    PointerDisplayChange pointerDisplayChange;
    { // acquire lock
        std::scoped_lock _l(getLock());
        if (isFromMouse(args)) {
        if (isFromMouse(args.source, args.pointerProperties[0].toolType)) {
            newArgs = processMouseEventLocked(args);
            pointerDisplayChange = calculatePointerDisplayChangeToNotify();
        } else if (isFromTouchpad(args)) {
        } else if (isFromTouchpad(args.source, args.pointerProperties[0].toolType)) {
            newArgs = processTouchpadEventLocked(args);
            pointerDisplayChange = calculatePointerDisplayChangeToNotify();
        } else if (isFromDrawingTablet(args)) {
        } else if (isFromDrawingTablet(args.source, args.pointerProperties[0].toolType)) {
            processDrawingTabletEventLocked(args);
        } else if (mStylusPointerIconEnabled && isStylusHoverEvent(args)) {
        } else if (mStylusPointerIconEnabled &&
                   isStylusHoverEvent(args.source, args.pointerProperties, args.action)) {
            processStylusHoverEventLocked(args);
        } else if (isFromSource(args.source, AINPUT_SOURCE_TOUCHSCREEN)) {
            processTouchscreenAndStylusEventLocked(args);
+88 −122

File changed.

Preview size limit exceeded, changes collapsed.

+36 −49
Original line number Diff line number Diff line
@@ -380,21 +380,20 @@ private:
            const ftl::Flags<InputTarget::Flags> targetFlags;
        };

        static void addPointerWindowTarget(const sp<android::gui::WindowInfoHandle>& windowHandle,
        DispatcherTouchState(const DispatcherWindowInfo& windowInfos,
                             const ConnectionManager& connections);

        void addPointerWindowTarget(const sp<android::gui::WindowInfoHandle>& windowHandle,
                                    InputTarget::DispatchMode dispatchMode,
                                    ftl::Flags<InputTarget::Flags> targetFlags,
                                    std::bitset<MAX_POINTER_ID + 1> pointerIds,
                                    std::optional<nsecs_t> firstDownTimeInTarget,
                                    std::optional<ui::LogicalDisplayId> pointerDisplayId,
                                           const ConnectionManager& connections,
                                           const DispatcherWindowInfo& windowInfos,
                                    std::function<void()> dump,
                                    std::vector<InputTarget>& inputTargets);

        base::Result<std::vector<InputTarget>, android::os::InputEventInjectionResult>
        findTouchedWindowTargets(nsecs_t currentTime, const MotionEntry& entry,
                                 const ConnectionManager& connections,
                                 const DispatcherWindowInfo& windowInfos,
                                 const sp<android::gui::WindowInfoHandle> dragWindow,
                                 std::function<void(const MotionEntry&)> addDragEvent,
                                 std::function<void()> dump);
@@ -421,8 +420,7 @@ private:

        // Updates the touchState for display from WindowInfo,
        // returns list of CancellationArgs for every cancelled touch
        std::list<CancellationArgs> updateFromWindowInfo(ui::LogicalDisplayId displayId,
                                                         const DispatcherWindowInfo& windowInfos);
        std::list<CancellationArgs> updateFromWindowInfo(ui::LogicalDisplayId displayId);

        void removeAllPointersForDevice(DeviceId deviceId);

@@ -431,9 +429,7 @@ private:
        std::optional<
                std::tuple<sp<gui::WindowInfoHandle>, DeviceId, std::vector<PointerProperties>,
                           std::list<CancellationArgs>, std::list<PointerDownArgs>>>
        transferTouchGesture(const sp<IBinder>& fromToken, const sp<IBinder>& toToken,
                             const DispatcherWindowInfo& windowInfos,
                             const ConnectionManager& connections);
        transferTouchGesture(const sp<IBinder>& fromToken, const sp<IBinder>& toToken);

        base::Result<std::list<CancellationArgs>, status_t> pilferPointers(
                const sp<IBinder>& token, const Connection& requestingConnection);
@@ -474,40 +470,31 @@ private:
                const sp<gui::WindowInfoHandle> toWindowHandle, TouchState& state,
                DeviceId deviceId, const std::vector<PointerProperties>& pointers,
                ftl::Flags<InputTarget::Flags> oldTargetFlags,
                ftl::Flags<InputTarget::Flags> newTargetFlags,
                const DispatcherWindowInfo& windowInfos, const ConnectionManager& connections);
                ftl::Flags<InputTarget::Flags> newTargetFlags);

        void saveTouchStateForMotionEntry(const MotionEntry& entry, TouchState&& touchState,
                                          const DispatcherWindowInfo& windowInfos);
        void saveTouchStateForMotionEntry(const MotionEntry& entry, TouchState&& touchState);

        void eraseTouchStateForMotionEntry(const MotionEntry& entry,
                                           const DispatcherWindowInfo& windowInfos);
        void eraseTouchStateForMotionEntry(const MotionEntry& entry);

        const TouchState* getTouchStateForMotionEntry(
                const android::inputdispatcher::MotionEntry& entry,
                const DispatcherWindowInfo& windowInfos) const;
                const android::inputdispatcher::MotionEntry& entry) const;

        bool canWindowReceiveMotion(const sp<gui::WindowInfoHandle>& window,
                                    const MotionEntry& motionEntry,
                                    const ConnectionManager& connections,
                                    const DispatcherWindowInfo& windowInfos) const;
                                    const MotionEntry& motionEntry) const;

        // Return true if stylus is currently down anywhere on the specified display,
        // and false otherwise.
        bool isStylusActiveInDisplay(ui::LogicalDisplayId displayId) const;

        static std::list<CancellationArgs> eraseRemovedWindowsFromWindowInfo(
                TouchState& state, ui::LogicalDisplayId displayId,
                const DispatcherWindowInfo& windowInfos);
        std::list<CancellationArgs> eraseRemovedWindowsFromWindowInfo(
                TouchState& state, ui::LogicalDisplayId displayId);

        static std::list<CancellationArgs> updateHoveringStateFromWindowInfo(
                TouchState& state, ui::LogicalDisplayId displayId,
                const DispatcherWindowInfo& windowInfos);
        std::list<CancellationArgs> updateHoveringStateFromWindowInfo(
                TouchState& state, ui::LogicalDisplayId displayId);

        static std::vector<InputTarget> findOutsideTargets(
                ui::LogicalDisplayId displayId, const sp<gui::WindowInfoHandle>& touchedWindow,
                int32_t pointerId, const ConnectionManager& connections,
                const DispatcherWindowInfo& windowInfos, std::function<void()> dump);
        std::vector<InputTarget> findOutsideTargets(ui::LogicalDisplayId displayId,
                                                    const sp<gui::WindowInfoHandle>& touchedWindow,
                                                    int32_t pointerId, std::function<void()> dump);

        /**
         * Slip the wallpaper touch if necessary.
@@ -522,18 +509,18 @@ private:
         * @param targets the current targets to add the walpaper ones to
         * @param eventTime the new downTime for the wallpaper target
         */
        static void slipWallpaperTouch(ftl::Flags<InputTarget::Flags> targetFlags,
        void slipWallpaperTouch(ftl::Flags<InputTarget::Flags> targetFlags,
                                const sp<android::gui::WindowInfoHandle>& oldWindowHandle,
                                const sp<android::gui::WindowInfoHandle>& newWindowHandle,
                                TouchState& state, const MotionEntry& entry,
                                       std::vector<InputTarget>& targets,
                                       const ConnectionManager& connections,
                                       const DispatcherWindowInfo& windowInfos,
                                       std::function<void()> dump);
                                std::vector<InputTarget>& targets, std::function<void()> dump);

        static ftl::Flags<InputTarget::Flags> getTargetFlags(
        ftl::Flags<InputTarget::Flags> getTargetFlags(
                const sp<android::gui::WindowInfoHandle>& targetWindow, vec2 targetPosition,
                bool isSplit, const DispatcherWindowInfo& windowInfos);
                bool isSplit);

        const DispatcherWindowInfo& mWindowInfos;
        const ConnectionManager& mConnectionManager;
    };

    DispatcherTouchState mTouchStates GUARDED_BY(mLock);
Loading