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

Commit 60448cf0 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: I9f2f1821e4bf22c3177ca4bb9fd3370976e8e2d6
parent 365ec0bd
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),
@@ -3164,8 +3163,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());
@@ -5271,8 +5270,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.
@@ -5307,7 +5307,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) {
@@ -5751,13 +5751,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>
@@ -7362,4 +7357,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
@@ -290,6 +290,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;
@@ -334,6 +336,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:
@@ -342,6 +346,7 @@ private:
                mWindowHandlesByDisplay;
        std::unordered_map<ui::LogicalDisplayId /*displayId*/, android::gui::DisplayInfo>
                mDisplayInfos;
        float mMaximumObscuringOpacityForTouch{1.0f};
    };

    DispatcherWindowInfo mWindowInfos GUARDED_BY(mLock);
@@ -443,7 +448,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,
@@ -646,8 +650,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);