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

Commit 65bbffc1 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add type alias for DeviceId" into main

parents 60c261ad 7e2f8f18
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -501,6 +501,9 @@ struct PointerProperties {
    PointerProperties& operator=(const PointerProperties&) = default;
};

// TODO(b/211379801) : Use a strong type from ftl/mixins.h instead
using DeviceId = int32_t;

/*
 * Input events.
 */
@@ -512,7 +515,7 @@ public:

    inline int32_t getId() const { return mId; }

    inline int32_t getDeviceId() const { return mDeviceId; }
    inline DeviceId getDeviceId() const { return mDeviceId; }

    inline uint32_t getSource() const { return mSource; }

@@ -527,13 +530,13 @@ public:
    static int32_t nextId();

protected:
    void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId,
    void initialize(int32_t id, DeviceId deviceId, uint32_t source, int32_t displayId,
                    std::array<uint8_t, 32> hmac);

    void initialize(const InputEvent& from);

    int32_t mId;
    int32_t mDeviceId;
    DeviceId mDeviceId;
    uint32_t mSource;
    int32_t mDisplayId;
    std::array<uint8_t, 32> mHmac;
@@ -571,7 +574,7 @@ public:
    static const char* getLabel(int32_t keyCode);
    static std::optional<int> getKeyCodeFromLabel(const char* label);

    void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId,
    void initialize(int32_t id, DeviceId deviceId, uint32_t source, int32_t displayId,
                    std::array<uint8_t, 32> hmac, int32_t action, int32_t flags, int32_t keyCode,
                    int32_t scanCode, int32_t metaState, int32_t repeatCount, nsecs_t downTime,
                    nsecs_t eventTime);
@@ -835,7 +838,7 @@ public:

    ssize_t findPointerIndex(int32_t pointerId) const;

    void initialize(int32_t id, int32_t deviceId, uint32_t source, int32_t displayId,
    void initialize(int32_t id, DeviceId deviceId, uint32_t source, int32_t displayId,
                    std::array<uint8_t, 32> hmac, int32_t action, int32_t actionButton,
                    int32_t flags, int32_t edgeFlags, int32_t metaState, int32_t buttonState,
                    MotionClassification classification, const ui::Transform& transform,
@@ -1013,7 +1016,7 @@ struct __attribute__((__packed__)) VerifiedInputEvent {
    };

    Type type;
    int32_t deviceId;
    DeviceId deviceId;
    nsecs_t eventTimeNanos;
    uint32_t source;
    int32_t displayId;
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ InputState::InputState(const IdGenerator& idGenerator) : mIdGenerator(idGenerato

InputState::~InputState() {}

bool InputState::isHovering(int32_t deviceId, uint32_t source, int32_t displayId) const {
bool InputState::isHovering(DeviceId deviceId, uint32_t source, int32_t displayId) const {
    for (const MotionMemento& memento : mMotionMementos) {
        if (memento.deviceId == deviceId && memento.source == source &&
            memento.displayId == displayId && memento.hovering) {
+3 −3
Original line number Diff line number Diff line
@@ -36,7 +36,7 @@ public:

    // Returns true if the specified source is known to have received a hover enter
    // motion event.
    bool isHovering(int32_t deviceId, uint32_t source, int32_t displayId) const;
    bool isHovering(DeviceId deviceId, uint32_t source, int32_t displayId) const;

    // Records tracking information for a key event that has just been published.
    // Returns true if the event should be delivered, false if it is inconsistent
@@ -76,7 +76,7 @@ public:

private:
    struct KeyMemento {
        int32_t deviceId;
        DeviceId deviceId;
        uint32_t source;
        int32_t displayId;
        int32_t keyCode;
@@ -88,7 +88,7 @@ private:
    };

    struct MotionMemento {
        int32_t deviceId;
        DeviceId deviceId;
        uint32_t source;
        int32_t displayId;
        int32_t flags;
+26 −27
Original line number Diff line number Diff line
@@ -40,25 +40,25 @@ std::set<int32_t> TouchState::getActiveDeviceIds() const {
    return out;
}

bool TouchState::hasTouchingPointers(int32_t deviceId) const {
bool TouchState::hasTouchingPointers(DeviceId deviceId) const {
    return std::any_of(windows.begin(), windows.end(), [&](const TouchedWindow& window) {
        return window.hasTouchingPointers(deviceId);
    });
}

void TouchState::removeTouchingPointer(int32_t removedDeviceId, int32_t pointerId) {
void TouchState::removeTouchingPointer(DeviceId deviceId, int32_t pointerId) {
    for (TouchedWindow& touchedWindow : windows) {
        touchedWindow.removeTouchingPointer(removedDeviceId, pointerId);
        touchedWindow.removeTouchingPointer(deviceId, pointerId);
    }
    clearWindowsWithoutPointers();
}

void TouchState::removeTouchingPointerFromWindow(
        int32_t removedDeviceId, int32_t pointerId,
        DeviceId deviceId, int32_t pointerId,
        const sp<android::gui::WindowInfoHandle>& windowHandle) {
    for (TouchedWindow& touchedWindow : windows) {
        if (touchedWindow.windowHandle == windowHandle) {
            touchedWindow.removeTouchingPointer(removedDeviceId, pointerId);
            touchedWindow.removeTouchingPointer(deviceId, pointerId);
            clearWindowsWithoutPointers();
            return;
        }
@@ -79,8 +79,7 @@ void TouchState::clearWindowsWithoutPointers() {
}

void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle,
                                   ftl::Flags<InputTarget::Flags> targetFlags,
                                   int32_t addedDeviceId,
                                   ftl::Flags<InputTarget::Flags> targetFlags, DeviceId deviceId,
                                   std::bitset<MAX_POINTER_ID + 1> touchingPointerIds,
                                   std::optional<nsecs_t> firstDownTimeInTarget) {
    for (TouchedWindow& touchedWindow : windows) {
@@ -94,9 +93,9 @@ void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle,
            // For cases like hover enter/exit or DISPATCH_AS_OUTSIDE a touch window might not have
            // downTime set initially. Need to update existing window when a pointer is down for the
            // window.
            touchedWindow.addTouchingPointers(addedDeviceId, touchingPointerIds);
            touchedWindow.addTouchingPointers(deviceId, touchingPointerIds);
            if (firstDownTimeInTarget) {
                touchedWindow.trySetDownTimeInTarget(addedDeviceId, *firstDownTimeInTarget);
                touchedWindow.trySetDownTimeInTarget(deviceId, *firstDownTimeInTarget);
            }
            return;
        }
@@ -104,25 +103,25 @@ void TouchState::addOrUpdateWindow(const sp<WindowInfoHandle>& windowHandle,
    TouchedWindow touchedWindow;
    touchedWindow.windowHandle = windowHandle;
    touchedWindow.targetFlags = targetFlags;
    touchedWindow.addTouchingPointers(addedDeviceId, touchingPointerIds);
    touchedWindow.addTouchingPointers(deviceId, touchingPointerIds);
    if (firstDownTimeInTarget) {
        touchedWindow.trySetDownTimeInTarget(addedDeviceId, *firstDownTimeInTarget);
        touchedWindow.trySetDownTimeInTarget(deviceId, *firstDownTimeInTarget);
    }
    windows.push_back(touchedWindow);
}

void TouchState::addHoveringPointerToWindow(const sp<WindowInfoHandle>& windowHandle,
                                            int32_t hoveringDeviceId, int32_t hoveringPointerId) {
                                            DeviceId deviceId, int32_t hoveringPointerId) {
    for (TouchedWindow& touchedWindow : windows) {
        if (touchedWindow.windowHandle == windowHandle) {
            touchedWindow.addHoveringPointer(hoveringDeviceId, hoveringPointerId);
            touchedWindow.addHoveringPointer(deviceId, hoveringPointerId);
            return;
        }
    }

    TouchedWindow touchedWindow;
    touchedWindow.windowHandle = windowHandle;
    touchedWindow.addHoveringPointer(hoveringDeviceId, hoveringPointerId);
    touchedWindow.addHoveringPointer(deviceId, hoveringPointerId);
    windows.push_back(touchedWindow);
}

@@ -149,12 +148,12 @@ void TouchState::filterNonAsIsTouchWindows() {
    }
}

void TouchState::cancelPointersForWindowsExcept(int32_t touchedDeviceId,
void TouchState::cancelPointersForWindowsExcept(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) {
            w.removeTouchingPointers(touchedDeviceId, pointerIds);
            w.removeTouchingPointers(deviceId, pointerIds);
        }
    });
    clearWindowsWithoutPointers();
@@ -168,10 +167,10 @@ void TouchState::cancelPointersForWindowsExcept(int32_t touchedDeviceId,
 */
void TouchState::cancelPointersForNonPilferingWindows() {
    // First, find all pointers that are being pilfered, across all windows
    std::map<int32_t /*deviceId*/, std::bitset<MAX_POINTER_ID + 1>> allPilferedPointerIdsByDevice;
    std::map<DeviceId, std::bitset<MAX_POINTER_ID + 1>> allPilferedPointerIdsByDevice;
    for (const TouchedWindow& w : windows) {
        for (const auto& [iterDeviceId, pilferedPointerIds] : w.getPilferingPointers()) {
            allPilferedPointerIdsByDevice[iterDeviceId] |= pilferedPointerIds;
        for (const auto& [deviceId, pilferedPointerIds] : w.getPilferingPointers()) {
            allPilferedPointerIdsByDevice[deviceId] |= pilferedPointerIds;
        }
    };

@@ -183,12 +182,12 @@ void TouchState::cancelPointersForNonPilferingWindows() {
    // (only), the remove pointer 2 from window A and pointer 1 from window B. Usually, the set of
    // pilfered pointers will be disjoint across all windows, but there's no reason to cause that
    // limitation here.
    for (const auto& [iterDeviceId, allPilferedPointerIds] : allPilferedPointerIdsByDevice) {
    for (const auto& [deviceId, allPilferedPointerIds] : allPilferedPointerIdsByDevice) {
        std::for_each(windows.begin(), windows.end(), [&](TouchedWindow& w) {
            std::bitset<MAX_POINTER_ID + 1> pilferedByOtherWindows =
                    w.getPilferingPointers(iterDeviceId) ^ allPilferedPointerIds;
                    w.getPilferingPointers(deviceId) ^ allPilferedPointerIds;
            // Remove all pointers pilfered by other windows
            w.removeTouchingPointers(iterDeviceId, pilferedByOtherWindows);
            w.removeTouchingPointers(deviceId, pilferedByOtherWindows);
        });
    }
    clearWindowsWithoutPointers();
@@ -248,11 +247,11 @@ bool TouchState::hasHoveringPointers() const {
                       [](const TouchedWindow& window) { return window.hasHoveringPointers(); });
}

std::set<sp<WindowInfoHandle>> TouchState::getWindowsWithHoveringPointer(int32_t hoveringDeviceId,
std::set<sp<WindowInfoHandle>> TouchState::getWindowsWithHoveringPointer(DeviceId deviceId,
                                                                         int32_t pointerId) const {
    std::set<sp<WindowInfoHandle>> out;
    for (const TouchedWindow& window : windows) {
        if (window.hasHoveringPointer(hoveringDeviceId, pointerId)) {
        if (window.hasHoveringPointer(deviceId, pointerId)) {
            out.insert(window.windowHandle);
        }
    }
@@ -266,10 +265,10 @@ void TouchState::removeHoveringPointer(int32_t hoveringDeviceId, int32_t hoverin
    clearWindowsWithoutPointers();
}

void TouchState::removeAllPointersForDevice(int32_t removedDeviceId) {
void TouchState::removeAllPointersForDevice(DeviceId deviceId) {
    for (TouchedWindow& window : windows) {
        window.removeAllHoveringPointersForDevice(removedDeviceId);
        window.removeAllTouchingPointersForDevice(removedDeviceId);
        window.removeAllHoveringPointersForDevice(deviceId);
        window.removeAllTouchingPointersForDevice(deviceId);
    }

    clearWindowsWithoutPointers();
+8 −8
Original line number Diff line number Diff line
@@ -41,24 +41,24 @@ struct TouchState {
    std::set<int32_t> getActiveDeviceIds() const;

    bool hasTouchingPointers(int32_t device) const;
    void removeTouchingPointer(int32_t deviceId, int32_t pointerId);
    void removeTouchingPointerFromWindow(int32_t deviceId, int32_t pointerId,
    void removeTouchingPointer(DeviceId deviceId, int32_t pointerId);
    void removeTouchingPointerFromWindow(DeviceId deviceId, int32_t pointerId,
                                         const sp<android::gui::WindowInfoHandle>& windowHandle);
    void addOrUpdateWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
                           ftl::Flags<InputTarget::Flags> targetFlags, int32_t deviceId,
                           ftl::Flags<InputTarget::Flags> targetFlags, DeviceId deviceId,
                           std::bitset<MAX_POINTER_ID + 1> touchingPointerIds,
                           std::optional<nsecs_t> firstDownTimeInTarget = std::nullopt);
    void addHoveringPointerToWindow(const sp<android::gui::WindowInfoHandle>& windowHandle,
                                    int32_t deviceId, int32_t hoveringPointerId);
    void removeHoveringPointer(int32_t deviceId, int32_t hoveringPointerId);
                                    DeviceId deviceId, int32_t hoveringPointerId);
    void removeHoveringPointer(DeviceId deviceId, int32_t hoveringPointerId);
    void clearHoveringPointers();

    void removeAllPointersForDevice(int32_t deviceId);
    void removeAllPointersForDevice(DeviceId deviceId);
    void removeWindowByToken(const sp<IBinder>& token);
    void filterNonAsIsTouchWindows();

    // Cancel pointers for current set of windows except the window with particular binder token.
    void cancelPointersForWindowsExcept(int32_t deviceId,
    void cancelPointersForWindowsExcept(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
@@ -75,7 +75,7 @@ struct TouchState {
    bool hasHoveringPointers() const;

    std::set<sp<android::gui::WindowInfoHandle>> getWindowsWithHoveringPointer(
            int32_t deviceId, int32_t pointerId) const;
            DeviceId deviceId, int32_t pointerId) const;
    std::string dump() const;
};