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

Commit ca205504 authored by Siarhei Vishniakou's avatar Siarhei Vishniakou
Browse files

Cancel wallpaper touch stream when foreground window is gone

When the foreground window is gone, we should also cancel the touch
stream for its wallpaper window. We already cancel touch for the window
itself, and for global monitor.

Without this patch, the wallpaper window simply stops receiving touches,
and never gets CANCEL, either.

The behaviour is slightly strange for the global monitor in this case.
First of all, the global monitor receives CANCEL, which is questionable
(things like pointer location stop working). Also, it only gets cancel
when a *new* event comes in.

That said, it's probably fine, so let's just document this behaviour by
adding a test for it.

Bug: 192981537
Test: atest inputflinger_tests
Change-Id: I8a2ef7cd552acc5cf64b2e13a6df5d5988bd1808
parent 2dcfdc1b
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -524,13 +524,17 @@ public:

    inline int32_t getAction() const { return mAction; }

    inline int32_t getActionMasked() const { return mAction & AMOTION_EVENT_ACTION_MASK; }
    static int32_t getActionMasked(int32_t action) { return action & AMOTION_EVENT_ACTION_MASK; }

    inline int32_t getActionIndex() const {
        return (mAction & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK)
                >> AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
    inline int32_t getActionMasked() const { return getActionMasked(mAction); }

    static int32_t getActionIndex(int32_t action) {
        return (action & AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >>
                AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT;
    }

    inline int32_t getActionIndex() const { return getActionIndex(mAction); }

    inline void setAction(int32_t action) { mAction = action; }

    inline int32_t getFlags() const { return mFlags; }
+2 −2
Original line number Diff line number Diff line
@@ -834,9 +834,9 @@ std::string MotionEvent::actionToString(int32_t action) {
        case AMOTION_EVENT_ACTION_OUTSIDE:
            return "OUTSIDE";
        case AMOTION_EVENT_ACTION_POINTER_DOWN:
            return "POINTER_DOWN";
            return StringPrintf("POINTER_DOWN(%" PRId32 ")", MotionEvent::getActionIndex(action));
        case AMOTION_EVENT_ACTION_POINTER_UP:
            return "POINTER_UP";
            return StringPrintf("POINTER_UP(%" PRId32 ")", MotionEvent::getActionIndex(action));
        case AMOTION_EVENT_ACTION_HOVER_MOVE:
            return "HOVER_MOVE";
        case AMOTION_EVENT_ACTION_SCROLL:
+16 −4
Original line number Diff line number Diff line
@@ -1706,13 +1706,13 @@ void InputDispatcher::logOutboundMotionDetails(const char* prefix, const MotionE
    if (DEBUG_OUTBOUND_EVENT_DETAILS) {
        ALOGD("%seventTime=%" PRId64 ", deviceId=%d, source=0x%x, displayId=%" PRId32
              ", policyFlags=0x%x, "
              "action=0x%x, actionButton=0x%x, flags=0x%x, "
              "action=%s, actionButton=0x%x, flags=0x%x, "
              "metaState=0x%x, buttonState=0x%x,"
              "edgeFlags=0x%x, xPrecision=%f, yPrecision=%f, downTime=%" PRId64,
              prefix, entry.eventTime, entry.deviceId, entry.source, entry.displayId,
              entry.policyFlags, entry.action, entry.actionButton, entry.flags, entry.metaState,
              entry.buttonState, entry.edgeFlags, entry.xPrecision, entry.yPrecision,
              entry.downTime);
              entry.policyFlags, MotionEvent::actionToString(entry.action).c_str(),
              entry.actionButton, entry.flags, entry.metaState, entry.buttonState, entry.edgeFlags,
              entry.xPrecision, entry.yPrecision, entry.downTime);

        for (uint32_t i = 0; i < entry.pointerCount; i++) {
            ALOGD("  Pointer %d: id=%d, toolType=%d, "
@@ -4642,6 +4642,18 @@ void InputDispatcher::setInputWindowsLocked(
                    CancelationOptions options(CancelationOptions::CANCEL_POINTER_EVENTS,
                                               "touched window was removed");
                    synthesizeCancelationEventsForInputChannelLocked(touchedInputChannel, options);
                    // Since we are about to drop the touch, cancel the events for the wallpaper as
                    // well.
                    if (touchedWindow.targetFlags & InputTarget::FLAG_FOREGROUND &&
                        touchedWindow.windowHandle->getInfo()->hasWallpaper) {
                        sp<WindowInfoHandle> wallpaper = state.getWallpaperWindow();
                        if (wallpaper != nullptr) {
                            sp<Connection> wallpaperConnection =
                                    getConnectionLocked(wallpaper->getToken());
                            synthesizeCancelationEventsForConnectionLocked(wallpaperConnection,
                                                                           options);
                        }
                    }
                }
                state.windows.erase(state.windows.begin() + i);
            } else {
+10 −0
Original line number Diff line number Diff line
@@ -134,4 +134,14 @@ bool TouchState::isSlippery() const {
    return haveSlipperyForegroundWindow;
}

sp<WindowInfoHandle> TouchState::getWallpaperWindow() const {
    for (size_t i = 0; i < windows.size(); i++) {
        const TouchedWindow& window = windows[i];
        if (window.windowHandle->getInfo()->type == WindowInfo::Type::WALLPAPER) {
            return window.windowHandle;
        }
    }
    return nullptr;
}

} // namespace android::inputdispatcher
+1 −0
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ struct TouchState {
    void filterNonMonitors();
    sp<android::gui::WindowInfoHandle> getFirstForegroundWindowHandle() const;
    bool isSlippery() const;
    sp<android::gui::WindowInfoHandle> getWallpaperWindow() const;
};

} // namespace inputdispatcher
Loading