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

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

Merge "Dispatcher: refactor getWindowHandleLocked and StrongPointerHash" into sc-dev

parents 3654df01 6a9a8312
Loading
Loading
Loading
Loading
+12 −11
Original line number Diff line number Diff line
@@ -2967,7 +2967,7 @@ void InputDispatcher::updateInteractionTokensLocked(const EventEntry& entry,
        return; // Not a key or a motion
    }

    std::unordered_set<sp<IBinder>, IBinderHash> newConnectionTokens;
    std::unordered_set<sp<IBinder>, StrongPointerHash<IBinder>> newConnectionTokens;
    std::vector<sp<Connection>> newConnections;
    for (const InputTarget& target : targets) {
        if ((target.flags & InputTarget::FLAG_DISPATCH_AS_OUTSIDE) ==
@@ -4284,12 +4284,8 @@ sp<InputWindowHandle> InputDispatcher::getWindowHandleLocked(const sp<IBinder>&
    return nullptr;
}

sp<InputWindowHandle> InputDispatcher::getFocusedWindowHandleLocked(int displayId) const {
    sp<IBinder> focusedToken = mFocusResolver.getFocusedWindowToken(displayId);
    return getWindowHandleLocked(focusedToken, displayId);
}

bool InputDispatcher::hasWindowHandleLocked(const sp<InputWindowHandle>& windowHandle) const {
sp<InputWindowHandle> InputDispatcher::getWindowHandleLocked(
        const sp<InputWindowHandle>& windowHandle) const {
    for (auto& it : mWindowHandlesByDisplay) {
        const std::vector<sp<InputWindowHandle>>& windowHandles = it.second;
        for (const sp<InputWindowHandle>& handle : windowHandles) {
@@ -4301,11 +4297,16 @@ bool InputDispatcher::hasWindowHandleLocked(const sp<InputWindowHandle>& windowH
                          windowHandle->getName().c_str(), it.first,
                          windowHandle->getInfo()->displayId);
                }
                return true;
                return handle;
            }
        }
    }
    return false;
    return nullptr;
}

sp<InputWindowHandle> InputDispatcher::getFocusedWindowHandleLocked(int displayId) const {
    sp<IBinder> focusedToken = mFocusResolver.getFocusedWindowToken(displayId);
    return getWindowHandleLocked(focusedToken, displayId);
}

bool InputDispatcher::hasResponsiveConnectionLocked(InputWindowHandle& windowHandle) const {
@@ -4461,7 +4462,7 @@ void InputDispatcher::setInputWindowsLocked(
        TouchState& state = stateIt->second;
        for (size_t i = 0; i < state.windows.size();) {
            TouchedWindow& touchedWindow = state.windows[i];
            if (!hasWindowHandleLocked(touchedWindow.windowHandle)) {
            if (getWindowHandleLocked(touchedWindow.windowHandle) == nullptr) {
                if (DEBUG_FOCUS) {
                    ALOGD("Touched window was removed: %s in display %" PRId32,
                          touchedWindow.windowHandle->getName().c_str(), displayId);
@@ -4493,7 +4494,7 @@ void InputDispatcher::setInputWindowsLocked(
    // Otherwise, they might stick around until the window handle is destroyed
    // which might not happen until the next GC.
    for (const sp<InputWindowHandle>& oldWindowHandle : oldWindowHandles) {
        if (!hasWindowHandleLocked(oldWindowHandle)) {
        if (getWindowHandleLocked(oldWindowHandle) == nullptr) {
            if (DEBUG_FOCUS) {
                ALOGD("Window went away: %s", oldWindowHandle->getName().c_str());
            }
+8 −7
Original line number Diff line number Diff line
@@ -221,12 +221,11 @@ private:

    void removeConnectionLocked(const sp<Connection>& connection) REQUIRES(mLock);

    struct IBinderHash {
        std::size_t operator()(const sp<IBinder>& b) const {
            return std::hash<IBinder*>{}(b.get());
        }
    template <typename T>
    struct StrongPointerHash {
        std::size_t operator()(const sp<T>& b) const { return std::hash<T*>{}(b.get()); }
    };
    std::unordered_map<sp<IBinder>, std::shared_ptr<InputChannel>, IBinderHash>
    std::unordered_map<sp<IBinder>, std::shared_ptr<InputChannel>, StrongPointerHash<IBinder>>
            mInputChannelsByToken GUARDED_BY(mLock);

    // Finds the display ID of the gesture monitor identified by the provided token.
@@ -327,10 +326,11 @@ private:
    // to loop through all displays.
    sp<InputWindowHandle> getWindowHandleLocked(const sp<IBinder>& windowHandleToken,
                                                int displayId) const REQUIRES(mLock);
    sp<InputWindowHandle> getWindowHandleLocked(const sp<InputWindowHandle>& windowHandle) const
            REQUIRES(mLock);
    std::shared_ptr<InputChannel> getInputChannelLocked(const sp<IBinder>& windowToken) const
            REQUIRES(mLock);
    sp<InputWindowHandle> getFocusedWindowHandleLocked(int displayId) const REQUIRES(mLock);
    bool hasWindowHandleLocked(const sp<InputWindowHandle>& windowHandle) const REQUIRES(mLock);
    bool hasResponsiveConnectionLocked(InputWindowHandle& windowHandle) const REQUIRES(mLock);

    /*
@@ -371,7 +371,8 @@ private:
    std::string mLastAnrState GUARDED_BY(mLock);

    // The connection tokens of the channels that the user last interacted, for debugging
    std::unordered_set<sp<IBinder>, IBinderHash> mInteractionConnectionTokens GUARDED_BY(mLock);
    std::unordered_set<sp<IBinder>, StrongPointerHash<IBinder>> mInteractionConnectionTokens
            GUARDED_BY(mLock);
    void updateInteractionTokensLocked(const EventEntry& entry,
                                       const std::vector<InputTarget>& targets) REQUIRES(mLock);