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

Commit 20c75502 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

InputDispatcher: Add and implement InputConfig::DO_NOT_PILFER

Bug: 216789894
Test: Presubmit
Flag: EXEMPT refactor
Change-Id: Ic8986a1b943bd5f112b20a49431151936cbc0abf
parent 8c078119
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -180,6 +180,8 @@ struct WindowInfo : public Parcelable {
                static_cast<uint32_t>(os::InputConfig::SENSITIVE_FOR_PRIVACY),
        DISPLAY_TOPOLOGY_AWARE =
                static_cast<uint32_t>(os::InputConfig::DISPLAY_TOPOLOGY_AWARE),
        DO_NOT_PILFER =
                static_cast<uint32_t>(os::InputConfig::DO_NOT_PILFER),
        // clang-format on
    };

+9 −0
Original line number Diff line number Diff line
@@ -173,4 +173,13 @@ enum InputConfig {
     * remain unchanged and coordinate space will extend beyond the logical display space.
     */
     DISPLAY_TOPOLOGY_AWARE       = 1 << 19,

    /**
     * InputConfig used to indicate that any pointer streams targeting this window should not be
     * canceled as part of a pilferPointers request.
     *
     * This is only meant to be used by system components that need to be perpetually be aware of
     * all input streams, such as the PointerLocationView used for debugging.
     */
     DO_NOT_PILFER                = 1 << 20,
}
+21 −7
Original line number Diff line number Diff line
@@ -5514,6 +5514,13 @@ void InputDispatcher::setInputWindowsLocked(
                                            WindowInfo::InputConfig::TRUSTED_OVERLAY),
                            "%s has feature INTERCEPTS_STYLUS, but is not a trusted overlay.",
                            window->getName().c_str());

        // Ensure all do-not-pilfer requests come from trusted overlays
        LOG_ALWAYS_FATAL_IF(info.inputConfig.test(WindowInfo::InputConfig::DO_NOT_PILFER) &&
                                    !info.inputConfig.test(
                                            WindowInfo::InputConfig::TRUSTED_OVERLAY),
                            "%s has feature DO_NOT_PILFER, but is not a trusted overlay.",
                            window->getName().c_str());
    }

    // Copy old handles for release if they are no longer present.
@@ -6380,14 +6387,21 @@ InputDispatcher::DispatcherTouchState::pilferPointers(const sp<IBinder>& token,
        std::bitset<MAX_POINTER_ID + 1> pointerIds = getPointerIds(pointers);
        std::string canceledWindows;
        for (const TouchedWindow& w : state.windows) {
            if (w.windowHandle->getToken() != token) {
            if (w.windowHandle->getToken() == token) {
                // Skip cancelling from pilfering window.
                continue;
            }
            if (w.windowHandle->getInfo()->inputConfig.test(
                        WindowInfo::InputConfig::DO_NOT_PILFER)) {
                // Skip cancelling from window with DO_NOT_PILFER flag.
                continue;
            }
            cancellations.emplace_back(w.windowHandle,
                                           CancelationOptions::Mode::CANCEL_POINTER_EVENTS,
                                           deviceId, displayId, pointerIds);
                                       CancelationOptions::Mode::CANCEL_POINTER_EVENTS, deviceId,
                                       displayId, pointerIds);
            canceledWindows += canceledWindows.empty() ? "[" : ", ";
            canceledWindows += w.windowHandle->getName();
        }
        }
        canceledWindows += canceledWindows.empty() ? "[]" : "]";
        LOG(INFO) << "Channel " << requestingConnection.getInputChannelName()
                  << " is stealing input gesture for device " << deviceId << " from "
@@ -6397,7 +6411,7 @@ InputDispatcher::DispatcherTouchState::pilferPointers(const sp<IBinder>& token,
        // This only blocks relevant pointers to be sent to other windows
        window.addPilferingPointers(deviceId, pointerIds);

        state.cancelPointersForWindowsExcept(deviceId, pointerIds, token);
        state.cancelPointersForPilferingRequest(deviceId, pointerIds, token);
    }
    return cancellations;
}
+10 −4
Original line number Diff line number Diff line
@@ -138,11 +138,13 @@ void TouchState::removeWindowByToken(const sp<IBinder>& token) {
    }
}

void TouchState::cancelPointersForWindowsExcept(DeviceId deviceId,
void TouchState::cancelPointersForPilferingRequest(DeviceId deviceId,
                                                   std::bitset<MAX_POINTER_ID + 1> pointerIds,
                                                   const sp<IBinder>& token) {
    std::for_each(windows.begin(), windows.end(), [&](TouchedWindow& w) {
        if (w.windowHandle->getToken() != token) {
        if (w.windowHandle->getToken() != token &&
            !w.windowHandle->getInfo()->inputConfig.test(
                    gui::WindowInfo::InputConfig::DO_NOT_PILFER)) {
            w.removeTouchingPointers(deviceId, pointerIds);
        }
    });
@@ -174,6 +176,10 @@ void TouchState::cancelPointersForNonPilferingWindows() {
    // limitation here.
    for (const auto& [deviceId, allPilferedPointerIds] : allPilferedPointerIdsByDevice) {
        std::for_each(windows.begin(), windows.end(), [&](TouchedWindow& w) {
            if (w.windowHandle->getInfo()->inputConfig.test(
                        gui::WindowInfo::InputConfig::DO_NOT_PILFER)) {
                return;
            }
            std::bitset<MAX_POINTER_ID + 1> pilferedByOtherWindows =
                    w.getPilferingPointers(deviceId) ^ allPilferedPointerIds;
            // Remove all pointers pilfered by other windows
+4 −4
Original line number Diff line number Diff line
@@ -57,8 +57,8 @@ struct TouchState {
    void removeAllPointersForDevice(DeviceId deviceId);
    void removeWindowByToken(const sp<IBinder>& token);

    // Cancel pointers for current set of windows except the window with particular binder token.
    void cancelPointersForWindowsExcept(DeviceId deviceId,
    // Cancel pointers for current set of windows for a pilfering request.
    void cancelPointersForPilferingRequest(DeviceId deviceId,
                                           std::bitset<MAX_POINTER_ID + 1> pointerIds,
                                           const sp<IBinder>& token);
    // Cancel pointers for current set of non-pilfering windows i.e. windows with isPilferingWindow
Loading