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

Commit 293a1543 authored by Arpit Singh's avatar Arpit Singh
Browse files

[11/n Dispatcher refactor] Move isTouchTrusted to WindowInfo

This CL moves isTouchTrusted to WindowInfo subclass along with
setMaximumObscuringOpacityForTouch.

Bug: 367661487
Bug: 245989146
Test: atest inputflinger_tests
Flag: EXEMPT refactor
Change-Id: I7b0b560483e9f758b08a3e2ebfff548c173e906b
parent edcc7307
Loading
Loading
Loading
Loading
+14 −12
Original line number Diff line number Diff line
@@ -954,7 +954,6 @@ InputDispatcher::InputDispatcher(InputDispatcherPolicyInterface& policy,
        mDispatchEnabled(false),
        mDispatchFrozen(false),
        mInputFilterEnabled(false),
        mMaximumObscuringOpacityForTouch(1.0f),
        mFocusedDisplayId(ui::LogicalDisplayId::DEFAULT),
        mWindowTokenWithPointerCapture(nullptr),
        mAwaitedApplicationDisplayId(ui::LogicalDisplayId::INVALID),
@@ -3161,8 +3160,8 @@ InputDispatcher::DispatcherWindowInfo::computeTouchOcclusionInfo(
    return info;
}

bool InputDispatcher::isTouchTrustedLocked(
        const DispatcherWindowInfo::TouchOcclusionInfo& occlusionInfo) const {
bool InputDispatcher::DispatcherWindowInfo::isTouchTrusted(
        const TouchOcclusionInfo& occlusionInfo) const {
    if (occlusionInfo.hasBlockingOcclusion) {
        ALOGW("Untrusted touch due to occlusion by %s/%s", occlusionInfo.obscuringPackage.c_str(),
              occlusionInfo.obscuringUid.toString().c_str());
@@ -5268,8 +5267,9 @@ std::string InputDispatcher::DispatcherWindowInfo::dumpDisplayAndWindowInfo() co
    return dump;
}

bool InputDispatcher::canWindowReceiveMotionLocked(const sp<WindowInfoHandle>& window,
                                                   const MotionEntry& motionEntry) const {
bool InputDispatcher::canWindowReceiveMotionLocked(
        const sp<android::gui::WindowInfoHandle>& window,
        const android::inputdispatcher::MotionEntry& motionEntry) const {
    const WindowInfo& info = *window->getInfo();

    // Skip spy window targets that are not valid for targeted injection.
@@ -5304,7 +5304,7 @@ bool InputDispatcher::canWindowReceiveMotionLocked(const sp<WindowInfoHandle>& w
    const auto [x, y] = resolveTouchedPosition(motionEntry);
    DispatcherWindowInfo::TouchOcclusionInfo occlusionInfo =
            mWindowInfos.computeTouchOcclusionInfo(window, x, y);
    if (!isTouchTrustedLocked(occlusionInfo)) {
    if (!mWindowInfos.isTouchTrusted(occlusionInfo)) {
        if (DEBUG_TOUCH_OCCLUSION) {
            ALOGD("Stack of obscuring windows during untrusted touch (%.1f, %.1f):", x, y);
            for (const auto& log : occlusionInfo.debugInfo) {
@@ -5748,13 +5748,8 @@ bool InputDispatcher::recentWindowsAreOwnedByLocked(gui::Pid pid, gui::Uid uid)
}

void InputDispatcher::setMaximumObscuringOpacityForTouch(float opacity) {
    if (opacity < 0 || opacity > 1) {
        LOG_ALWAYS_FATAL("Maximum obscuring opacity for touch should be >= 0 and <= 1");
        return;
    }

    std::scoped_lock lock(mLock);
    mMaximumObscuringOpacityForTouch = opacity;
    mWindowInfos.setMaximumObscuringOpacityForTouch(opacity);
}

std::tuple<const TouchState*, const TouchedWindow*, ui::LogicalDisplayId>
@@ -7354,4 +7349,11 @@ std::string InputDispatcher::ConnectionManager::dump(nsecs_t currentTime) const
    return dump;
}

void InputDispatcher::DispatcherWindowInfo::setMaximumObscuringOpacityForTouch(float opacity) {
    if (opacity < 0 || opacity > 1) {
        LOG_ALWAYS_FATAL("Maximum obscuring opacity for touch should be >= 0 and <= 1");
    }
    mMaximumObscuringOpacityForTouch = opacity;
}

} // namespace android::inputdispatcher
+5 −3
Original line number Diff line number Diff line
@@ -289,6 +289,8 @@ private:

        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;
@@ -333,6 +335,8 @@ private:
        sp<android::gui::WindowInfoHandle> findWallpaperWindowBelow(
                const sp<android::gui::WindowInfoHandle>& windowHandle) const;

        bool isTouchTrusted(const TouchOcclusionInfo& occlusionInfo) const;

        std::string dumpDisplayAndWindowInfo() const;

    private:
@@ -341,6 +345,7 @@ private:
                mWindowHandlesByDisplay;
        std::unordered_map<ui::LogicalDisplayId /*displayId*/, android::gui::DisplayInfo>
                mDisplayInfos;
        float mMaximumObscuringOpacityForTouch{1.0f};
    };

    DispatcherWindowInfo mWindowInfos GUARDED_BY(mLock);
@@ -442,7 +447,6 @@ 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,
@@ -645,8 +649,6 @@ private:
    void addDragEventLocked(const MotionEntry& entry) REQUIRES(mLock);
    void finishDragAndDrop(ui::LogicalDisplayId displayId, float x, float y) REQUIRES(mLock);

    bool isTouchTrustedLocked(const DispatcherWindowInfo::TouchOcclusionInfo& occlusionInfo) const
            REQUIRES(mLock);
    std::string getApplicationWindowLabel(const InputApplicationHandle* applicationHandle,
                                          const sp<android::gui::WindowInfoHandle>& windowHandle);