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

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

Merge changes I6e3b959d,I222df277 into main

* changes:
  Remove unknown connection token from Anr tracker
  [8/n InputDispatcher refactor] move input connections to a subclass
parents f8a4189b ac988061
Loading
Loading
Loading
Loading
+200 −164

File changed.

Preview size limit exceeded, changes collapsed.

+42 −23
Original line number Diff line number Diff line
@@ -260,13 +260,6 @@ 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>
@@ -274,17 +267,6 @@ private:
        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;
@@ -417,6 +399,48 @@ private:

    DispatcherWindowInfo mWindowInfos GUARDED_BY(mLock);

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

        std::shared_ptr<Connection> getConnection(const sp<IBinder>& inputConnectionToken) 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,
                                      std::function<int(int)> callback);

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

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

        std::string dump(nsecs_t currentTime) const;

    private:
        const 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);

    void setInputWindowsLocked(
            const std::vector<sp<android::gui::WindowInfoHandle>>& inputWindowHandles,
            ui::LogicalDisplayId displayId) REQUIRES(mLock);
@@ -582,8 +606,6 @@ 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,
@@ -689,12 +711,9 @@ 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);