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

Commit 8296e54a authored by Vishnu Nair's avatar Vishnu Nair Committed by Automerger Merge Worker
Browse files

Merge "FocusResolver: Clean up focus requests and results when a display is...

Merge "FocusResolver: Clean up focus requests and results when a display is removed" into sc-dev am: 831288d4

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/15032232

Change-Id: I677cdb280211830cccd803bae075d628708a0476
parents 3c1ab22b 831288d4
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -216,4 +216,9 @@ std::string FocusResolver::dump() const {
    return dump;
    return dump;
}
}


void FocusResolver::displayRemoved(int32_t displayId) {
    mFocusRequestByDisplay.erase(displayId);
    mLastFocusResultByDisplay.erase(displayId);
}

} // namespace android::inputdispatcher
} // namespace android::inputdispatcher
+3 −0
Original line number Original line Diff line number Diff line
@@ -62,6 +62,9 @@ public:
    std::optional<FocusResolver::FocusChanges> setFocusedWindow(
    std::optional<FocusResolver::FocusChanges> setFocusedWindow(
            const FocusRequest& request, const std::vector<sp<InputWindowHandle>>& windows);
            const FocusRequest& request, const std::vector<sp<InputWindowHandle>>& windows);


    // Display has been removed from the system, clean up old references.
    void displayRemoved(int32_t displayId);

    // exposed for debugging
    // exposed for debugging
    bool hasFocusedWindowTokens() const { return !mFocusedWindowTokenByDisplay.empty(); }
    bool hasFocusedWindowTokens() const { return !mFocusedWindowTokenByDisplay.empty(); }
    std::string dumpFocusedWindows() const;
    std::string dumpFocusedWindows() const;
+36 −17
Original line number Original line Diff line number Diff line
@@ -4613,7 +4613,15 @@ void InputDispatcher::setFocusedApplication(
    }
    }
    { // acquire lock
    { // acquire lock
        std::scoped_lock _l(mLock);
        std::scoped_lock _l(mLock);
        setFocusedApplicationLocked(displayId, inputApplicationHandle);
    } // release lock

    // Wake up poll loop since it may need to make new input dispatching choices.
    mLooper->wake();
}


void InputDispatcher::setFocusedApplicationLocked(
        int32_t displayId, const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) {
    std::shared_ptr<InputApplicationHandle> oldFocusedApplicationHandle =
    std::shared_ptr<InputApplicationHandle> oldFocusedApplicationHandle =
            getValueByKey(mFocusedApplicationHandlesByDisplay, displayId);
            getValueByKey(mFocusedApplicationHandlesByDisplay, displayId);


@@ -4631,10 +4639,6 @@ void InputDispatcher::setFocusedApplication(
    // No matter what the old focused application was, stop waiting on it because it is
    // No matter what the old focused application was, stop waiting on it because it is
    // no longer focused.
    // no longer focused.
    resetNoFocusedWindowTimeoutLocked();
    resetNoFocusedWindowTimeoutLocked();
    } // release lock

    // Wake up poll loop since it may need to make new input dispatching choices.
    mLooper->wake();
}
}


/**
/**
@@ -6208,4 +6212,19 @@ void InputDispatcher::doSetPointerCaptureLockedInterruptible(
    mLock.lock();
    mLock.lock();
}
}


void InputDispatcher::displayRemoved(int32_t displayId) {
    { // acquire lock
        std::scoped_lock _l(mLock);
        // Set an empty list to remove all handles from the specific display.
        setInputWindowsLocked(/* window handles */ {}, displayId);
        setFocusedApplicationLocked(displayId, nullptr);
        // Call focus resolver to clean up stale requests. This must be called after input windows
        // have been removed for the removed display.
        mFocusResolver.displayRemoved(displayId);
    } // release lock

    // Wake up poll loop since it may need to make new input dispatching choices.
    mLooper->wake();
}

} // namespace android::inputdispatcher
} // namespace android::inputdispatcher
+5 −0
Original line number Original line Diff line number Diff line
@@ -139,6 +139,8 @@ public:


    std::array<uint8_t, 32> sign(const VerifiedInputEvent& event) const;
    std::array<uint8_t, 32> sign(const VerifiedInputEvent& event) const;


    void displayRemoved(int32_t displayId) override;

private:
private:
    enum class DropReason {
    enum class DropReason {
        NOT_DROPPED,
        NOT_DROPPED,
@@ -343,6 +345,9 @@ private:
    std::unordered_map<int32_t, TouchState> mTouchStatesByDisplay GUARDED_BY(mLock);
    std::unordered_map<int32_t, TouchState> mTouchStatesByDisplay GUARDED_BY(mLock);
    std::unique_ptr<DragState> mDragState GUARDED_BY(mLock);
    std::unique_ptr<DragState> mDragState GUARDED_BY(mLock);


    void setFocusedApplicationLocked(
            int32_t displayId,
            const std::shared_ptr<InputApplicationHandle>& inputApplicationHandle) REQUIRES(mLock);
    // Focused applications.
    // Focused applications.
    std::unordered_map<int32_t, std::shared_ptr<InputApplicationHandle>>
    std::unordered_map<int32_t, std::shared_ptr<InputApplicationHandle>>
            mFocusedApplicationHandlesByDisplay GUARDED_BY(mLock);
            mFocusedApplicationHandlesByDisplay GUARDED_BY(mLock);
+5 −0
Original line number Original line Diff line number Diff line
@@ -209,6 +209,11 @@ public:
     * Returns true on success.
     * Returns true on success.
     */
     */
    virtual bool flushSensor(int deviceId, InputDeviceSensorType sensorType) = 0;
    virtual bool flushSensor(int deviceId, InputDeviceSensorType sensorType) = 0;

    /**
     * Called when a display has been removed from the system.
     */
    virtual void displayRemoved(int32_t displayId) = 0;
};
};


} // namespace android
} // namespace android
Loading