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

Commit a29a2d14 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "revert-31063667-ZXNTVOTPQF" into main

* changes:
  Revert "[8/n InputDispatcher refactor] move input connections to a subclass"
  Revert "[9/n Dispatcher refactor] Move computeTouchOcclusionInfo..."
  Revert "[10/n Dispatcher refactor] Move obscuring related method..."
  Revert "[11/n Dispatcher refactor] Move isTouchTrusted to WindowInfo"
parents 0c9866a6 75223155
Loading
Loading
Loading
Loading
+209 −252

File changed.

Preview size limit exceeded, changes collapsed.

+105 −127
Original line number Diff line number Diff line
@@ -224,133 +224,6 @@ private:
    /** Stores the latest user-activity poke event times per user activity types. */
    std::array<nsecs_t, USER_ACTIVITY_EVENT_LAST + 1> mLastUserActivityTimes GUARDED_BY(mLock);

    template <typename T>
    struct StrongPointerHash {
        std::size_t operator()(const sp<T>& b) const { return std::hash<T*>{}(b.get()); }
    };

    class ConnectionManager {
    public:
        ConnectionManager(sp<Looper> lopper);
        ~ConnectionManager();

        std::shared_ptr<Connection> getConnection(const sp<IBinder>& inputConnectionToken) const;
        std::string getConnectionName(const sp<IBinder>& connectionToken) const;

        // Find a monitor pid by the provided token.
        std::optional<gui::Pid> findMonitorPidByToken(const sp<IBinder>& token) const;
        void forEachGlobalMonitorConnection(
                std::function<void(const std::shared_ptr<Connection>&)> f) const;
        void forEachGlobalMonitorConnection(
                ui::LogicalDisplayId displayId,
                std::function<void(const std::shared_ptr<Connection>&)> f) const;

        void createGlobalInputMonitor(ui::LogicalDisplayId displayId,
                                      std::unique_ptr<InputChannel>&& inputChannel,
                                      const IdGenerator& idGenerator, gui::Pid pid);

        status_t removeInputChannel(const std::shared_ptr<Connection>& connection);
        void removeConnection(const std::shared_ptr<Connection>& connection);

        void createConnection(std::unique_ptr<InputChannel>&& inputChannel,
                              const IdGenerator& idGenerator);

        std::string dump(nsecs_t currentTime) const;

    private:
        sp<Looper> mLooper;

        // All registered connections mapped by input channel token.
        std::unordered_map<sp<IBinder>, std::shared_ptr<Connection>, StrongPointerHash<IBinder>>
                mConnectionsByToken;

        // Input channels that will receive a copy of all input events sent to the provided display.
        std::unordered_map<ui::LogicalDisplayId, std::vector<Monitor>> mGlobalMonitorsByDisplay;

        void removeMonitorChannel(const sp<IBinder>& connectionToken);
    };

    ConnectionManager mConnectionManager GUARDED_BY(mLock);

    class DispatcherWindowInfo {
    public:
        struct TouchOcclusionInfo {
            bool hasBlockingOcclusion;
            float obscuringOpacity;
            std::string obscuringPackage;
            gui::Uid obscuringUid = gui::Uid::INVALID;
            std::vector<std::string> debugInfo;
        };

        void setWindowHandlesForDisplay(
                ui::LogicalDisplayId displayId,
                std::vector<sp<android::gui::WindowInfoHandle>>&& windowHandles);

        void setDisplayInfos(const std::vector<android::gui::DisplayInfo>& displayInfos);

        void removeDisplay(ui::LogicalDisplayId displayId);

        void setMaximumObscuringOpacityForTouch(float opacity);

        // Get a reference to window handles by display, return an empty vector if not found.
        const std::vector<sp<android::gui::WindowInfoHandle>>& getWindowHandlesForDisplay(
                ui::LogicalDisplayId displayId) const;

        void forEachWindowHandle(
                std::function<void(const sp<android::gui::WindowInfoHandle>&)> f) const;

        void forEachDisplayId(std::function<void(ui::LogicalDisplayId)> f) const;

        // Get the transform for display, returns Identity-transform if display is missing.
        ui::Transform getDisplayTransform(ui::LogicalDisplayId displayId) const;

        // Get the raw transform to use for motion events going to the given window.
        ui::Transform getRawTransform(const android::gui::WindowInfo&) const;

        // Lookup for WindowInfoHandle from token and optionally a display-id. In cases where
        // display-id is not provided lookup is done for all displays.
        sp<android::gui::WindowInfoHandle> findWindowHandle(
                const sp<IBinder>& windowHandleToken,
                std::optional<ui::LogicalDisplayId> displayId = {}) const;

        bool isWindowPresent(const sp<android::gui::WindowInfoHandle>& windowHandle) const;

        // Returns the touched window at the given location, excluding the ignoreWindow if provided.
        sp<android::gui::WindowInfoHandle> findTouchedWindowAt(
                ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false,
                const sp<android::gui::WindowInfoHandle> ignoreWindow = nullptr) const;

        std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAt(
                ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId,
                const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay)
                const;

        TouchOcclusionInfo computeTouchOcclusionInfo(
                const sp<android::gui::WindowInfoHandle>& windowHandle, float x, float y) const;

        bool isWindowObscured(const sp<android::gui::WindowInfoHandle>& windowHandle) const;

        bool isWindowObscuredAtPoint(const sp<android::gui::WindowInfoHandle>& windowHandle,
                                     float x, float y) const;

        sp<android::gui::WindowInfoHandle> findWallpaperWindowBelow(
                const sp<android::gui::WindowInfoHandle>& windowHandle) const;

        bool isTouchTrusted(const TouchOcclusionInfo& occlusionInfo) const;

        std::string dumpDisplayAndWindowInfo() const;

    private:
        std::unordered_map<ui::LogicalDisplayId /*displayId*/,
                           std::vector<sp<android::gui::WindowInfoHandle>>>
                mWindowHandlesByDisplay;
        std::unordered_map<ui::LogicalDisplayId /*displayId*/, android::gui::DisplayInfo>
                mDisplayInfos;
        float mMaximumObscuringOpacityForTouch{1.0f};
    };

    DispatcherWindowInfo mWindowInfos GUARDED_BY(mLock);

    // With each iteration, InputDispatcher nominally processes one queued event,
    // a timeout, or a response from an input consumer.
    // This method should only be called on the input dispatcher's own thread.
@@ -387,8 +260,31 @@ private:
            const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay,
            ui::LogicalDisplayId displayId);

    std::shared_ptr<Connection> getConnectionLocked(const sp<IBinder>& inputConnectionToken) const
            REQUIRES(mLock);

    std::string getConnectionNameLocked(const sp<IBinder>& connectionToken) const REQUIRES(mLock);

    void removeConnectionLocked(const std::shared_ptr<Connection>& connection) REQUIRES(mLock);

    status_t pilferPointersLocked(const sp<IBinder>& token) REQUIRES(mLock);

    template <typename T>
    struct StrongPointerHash {
        std::size_t operator()(const sp<T>& b) const { return std::hash<T*>{}(b.get()); }
    };

    // All registered connections mapped by input channel token.
    std::unordered_map<sp<IBinder>, std::shared_ptr<Connection>, StrongPointerHash<IBinder>>
            mConnectionsByToken GUARDED_BY(mLock);

    // Find a monitor pid by the provided token.
    std::optional<gui::Pid> findMonitorPidByTokenLocked(const sp<IBinder>& token) REQUIRES(mLock);

    // Input channels that will receive a copy of all input events sent to the provided display.
    std::unordered_map<ui::LogicalDisplayId, std::vector<Monitor>> mGlobalMonitorsByDisplay
            GUARDED_BY(mLock);

    const HmacKeyManager mHmacKeyManager;
    const std::array<uint8_t, 32> getSignature(const MotionEntry& motionEntry,
                                               const DispatchEntry& dispatchEntry) const;
@@ -448,6 +344,7 @@ private:
    bool mDispatchEnabled GUARDED_BY(mLock);
    bool mDispatchFrozen GUARDED_BY(mLock);
    bool mInputFilterEnabled GUARDED_BY(mLock);
    float mMaximumObscuringOpacityForTouch GUARDED_BY(mLock);

    // This map is not really needed, but it helps a lot with debugging (dumpsys input).
    // In the java layer, touch mode states are spread across multiple DisplayContent objects,
@@ -465,6 +362,61 @@ private:
    };
    sp<gui::WindowInfosListener> mWindowInfoListener;

    class DispatcherWindowInfo {
    public:
        void setWindowHandlesForDisplay(
                ui::LogicalDisplayId displayId,
                std::vector<sp<android::gui::WindowInfoHandle>>&& windowHandles);

        void setDisplayInfos(const std::vector<android::gui::DisplayInfo>& displayInfos);

        void removeDisplay(ui::LogicalDisplayId displayId);

        // Get a reference to window handles by display, return an empty vector if not found.
        const std::vector<sp<android::gui::WindowInfoHandle>>& getWindowHandlesForDisplay(
                ui::LogicalDisplayId displayId) const;

        void forEachWindowHandle(
                std::function<void(const sp<android::gui::WindowInfoHandle>&)> f) const;

        void forEachDisplayId(std::function<void(ui::LogicalDisplayId)> f) const;

        // Get the transform for display, returns Identity-transform if display is missing.
        ui::Transform getDisplayTransform(ui::LogicalDisplayId displayId) const;

        // Get the raw transform to use for motion events going to the given window.
        ui::Transform getRawTransform(const android::gui::WindowInfo&) const;

        // Lookup for WindowInfoHandle from token and optionally a display-id. In cases where
        // display-id is not provided lookup is done for all displays.
        sp<android::gui::WindowInfoHandle> findWindowHandle(
                const sp<IBinder>& windowHandleToken,
                std::optional<ui::LogicalDisplayId> displayId = {}) const;

        bool isWindowPresent(const sp<android::gui::WindowInfoHandle>& windowHandle) const;

        // Returns the touched window at the given location, excluding the ignoreWindow if provided.
        sp<android::gui::WindowInfoHandle> findTouchedWindowAt(
                ui::LogicalDisplayId displayId, float x, float y, bool isStylus = false,
                const sp<android::gui::WindowInfoHandle> ignoreWindow = nullptr) const;

        std::vector<sp<android::gui::WindowInfoHandle>> findTouchedSpyWindowsAt(
                ui::LogicalDisplayId displayId, float x, float y, bool isStylus, DeviceId deviceId,
                const std::unordered_map<ui::LogicalDisplayId, TouchState>& touchStatesByDisplay)
                const;

        std::string dumpDisplayAndWindowInfo() const;

    private:
        std::unordered_map<ui::LogicalDisplayId /*displayId*/,
                           std::vector<sp<android::gui::WindowInfoHandle>>>
                mWindowHandlesByDisplay;
        std::unordered_map<ui::LogicalDisplayId /*displayId*/, android::gui::DisplayInfo>
                mDisplayInfos;
    };

    DispatcherWindowInfo mWindowInfos GUARDED_BY(mLock);

    void setInputWindowsLocked(
            const std::vector<sp<android::gui::WindowInfoHandle>>& inputWindowHandles,
            ui::LogicalDisplayId displayId) REQUIRES(mLock);
@@ -630,6 +582,8 @@ private:
                                  nsecs_t& nextWakeupTime) REQUIRES(mLock);
    base::Result<std::vector<InputTarget>, android::os::InputEventInjectionResult>
    findTouchedWindowTargetsLocked(nsecs_t currentTime, const MotionEntry& entry) REQUIRES(mLock);
    std::vector<Monitor> selectResponsiveMonitorsLocked(
            const std::vector<Monitor>& gestureMonitors) const REQUIRES(mLock);

    void addWindowTargetLocked(const sp<android::gui::WindowInfoHandle>& windowHandle,
                               InputTarget::DispatchMode dispatchMode,
@@ -650,6 +604,24 @@ private:
    void addDragEventLocked(const MotionEntry& entry) REQUIRES(mLock);
    void finishDragAndDrop(ui::LogicalDisplayId displayId, float x, float y) REQUIRES(mLock);

    struct TouchOcclusionInfo {
        bool hasBlockingOcclusion;
        float obscuringOpacity;
        std::string obscuringPackage;
        gui::Uid obscuringUid = gui::Uid::INVALID;
        std::vector<std::string> debugInfo;
    };

    TouchOcclusionInfo computeTouchOcclusionInfoLocked(
            const sp<android::gui::WindowInfoHandle>& windowHandle, float x, float y) const
            REQUIRES(mLock);
    bool isTouchTrustedLocked(const TouchOcclusionInfo& occlusionInfo) const REQUIRES(mLock);
    bool isWindowObscuredAtPointLocked(const sp<android::gui::WindowInfoHandle>& windowHandle,
                                       float x, float y) const REQUIRES(mLock);
    bool isWindowObscuredLocked(const sp<android::gui::WindowInfoHandle>& windowHandle) const
            REQUIRES(mLock);
    std::string dumpWindowForTouchOcclusion(const android::gui::WindowInfo* info,
                                            bool isTouchWindow) const;
    std::string getApplicationWindowLabel(const InputApplicationHandle* applicationHandle,
                                          const sp<android::gui::WindowInfoHandle>& windowHandle);

@@ -717,9 +689,12 @@ private:

    // Dump state.
    void dumpDispatchStateLocked(std::string& dump) const REQUIRES(mLock);
    void dumpMonitors(std::string& dump, const std::vector<Monitor>& monitors) const;
    void logDispatchStateLocked() const REQUIRES(mLock);
    std::string dumpPointerCaptureStateLocked() const REQUIRES(mLock);

    // Registration.
    void removeMonitorChannelLocked(const sp<IBinder>& connectionToken) REQUIRES(mLock);
    status_t removeInputChannelLocked(const std::shared_ptr<Connection>& connection, bool notify)
            REQUIRES(mLock);

@@ -802,6 +777,9 @@ private:
                                const std::unique_ptr<trace::EventTrackerInterface>& traceTracker)
            REQUIRES(mLock);

    sp<android::gui::WindowInfoHandle> findWallpaperWindowBelow(
            const sp<android::gui::WindowInfoHandle>& windowHandle) const REQUIRES(mLock);

    /** Stores the value of the input flag for per device input latency metrics. */
    const bool mPerDeviceInputLatencyMetricsFlag =
            com::android::input::flags::enable_per_device_input_latency_metrics();