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

Commit 7d420470 authored by arthurhung's avatar arthurhung Committed by Automerger Merge Worker
Browse files

Allow touch if some pointers are MT_TOOL_PALM am: 65600040 am: 182306f5

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1455628

Change-Id: Ifd38af7346c6e6f572cb4c59f8baf95e7b8bf4a0
parents 47c26f5b 182306f5
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -86,6 +86,13 @@ constexpr int32_t VERIFIED_KEY_EVENT_FLAGS = AKEY_EVENT_FLAG_CANCELED;
constexpr int32_t VERIFIED_MOTION_EVENT_FLAGS =
        AMOTION_EVENT_FLAG_WINDOW_IS_OBSCURED | AMOTION_EVENT_FLAG_WINDOW_IS_PARTIALLY_OBSCURED;

/**
 * This flag indicates that the point up event has been canceled.
 * Typically this is used for palm event when the user has accidental touches.
 * TODO: Adjust flag to public api
 */
constexpr int32_t AMOTION_EVENT_FLAG_CANCELED = 0x20;

enum {
    /* Used when a motion event is not associated with any display.
     * Typically used for non-pointer events. */
+17 −4
Original line number Diff line number Diff line
@@ -236,6 +236,20 @@ void MultiTouchInputMapper::process(const RawEvent* rawEvent) {
    mMultiTouchMotionAccumulator.process(rawEvent);
}

std::optional<int32_t> MultiTouchInputMapper::getActiveBitId(
        const MultiTouchMotionAccumulator::Slot& inSlot) {
    if (mHavePointerIds) {
        int32_t trackingId = inSlot.getTrackingId();
        for (BitSet32 idBits(mPointerIdBits); !idBits.isEmpty();) {
            int32_t n = idBits.clearFirstMarkedBit();
            if (mPointerTrackingIdMap[n] == trackingId) {
                return std::make_optional(n);
            }
        }
    }
    return std::nullopt;
}

void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) {
    size_t inCount = mMultiTouchMotionAccumulator.getSlotCount();
    size_t outCount = 0;
@@ -250,10 +264,9 @@ void MultiTouchInputMapper::syncTouch(nsecs_t when, RawState* outState) {
        }

        if (inSlot->getToolType() == AMOTION_EVENT_TOOL_TYPE_PALM) {
            if (!mCurrentMotionAborted) {
                ALOGI("Canceling touch gesture from device %s because the palm event was detected",
                      getDeviceName().c_str());
                cancelTouch(when);
            std::optional<int32_t> id = getActiveBitId(*inSlot);
            if (id) {
                outState->rawPointerData.canceledIdBits.markBit(id.value());
            }
            continue;
        }
+2 −0
Original line number Diff line number Diff line
@@ -103,6 +103,8 @@ protected:
    bool hasStylus() const override;

private:
    // If the slot is in use, return the bit id. Return std::nullopt otherwise.
    std::optional<int32_t> getActiveBitId(const MultiTouchMotionAccumulator::Slot& inSlot);
    MultiTouchMotionAccumulator mMultiTouchMotionAccumulator;

    // Specifies the pointer id bits that are in use, and their associated tracking id.
+16 −6
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ void RawPointerData::copyFrom(const RawPointerData& other) {
    pointerCount = other.pointerCount;
    hoveringIdBits = other.hoveringIdBits;
    touchingIdBits = other.touchingIdBits;
    canceledIdBits = other.canceledIdBits;

    for (uint32_t i = 0; i < pointerCount; i++) {
        pointers[i] = other.pointers[i];
@@ -140,6 +141,7 @@ void CookedPointerData::clear() {
    pointerCount = 0;
    hoveringIdBits.clear();
    touchingIdBits.clear();
    canceledIdBits.clear();
}

void CookedPointerData::copyFrom(const CookedPointerData& other) {
@@ -1444,10 +1446,11 @@ void TouchInputMapper::sync(nsecs_t when) {

#if DEBUG_RAW_EVENTS
    ALOGD("syncTouch: pointerCount %d -> %d, touching ids 0x%08x -> 0x%08x, "
          "hovering ids 0x%08x -> 0x%08x",
          "hovering ids 0x%08x -> 0x%08x, canceled ids 0x%08x",
          last->rawPointerData.pointerCount, next->rawPointerData.pointerCount,
          last->rawPointerData.touchingIdBits.value, next->rawPointerData.touchingIdBits.value,
          last->rawPointerData.hoveringIdBits.value, next->rawPointerData.hoveringIdBits.value);
          last->rawPointerData.hoveringIdBits.value, next->rawPointerData.hoveringIdBits.value,
          next->rawPointerData.canceledIdBits.value);
#endif

    processRawTouches(false /*timeout*/);
@@ -1892,14 +1895,15 @@ void TouchInputMapper::dispatchTouches(nsecs_t when, uint32_t policyFlags) {
        // Dispatch pointer up events.
        while (!upIdBits.isEmpty()) {
            uint32_t upId = upIdBits.clearFirstMarkedBit();

            dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_UP, 0, 0,
                           metaState, buttonState, 0,
            bool isCanceled = mCurrentCookedState.cookedPointerData.canceledIdBits.hasBit(upId);
            dispatchMotion(when, policyFlags, mSource, AMOTION_EVENT_ACTION_POINTER_UP, 0,
                           isCanceled ? AMOTION_EVENT_FLAG_CANCELED : 0, metaState, buttonState, 0,
                           mLastCookedState.cookedPointerData.pointerProperties,
                           mLastCookedState.cookedPointerData.pointerCoords,
                           mLastCookedState.cookedPointerData.idToIndex, dispatchedIdBits, upId,
                           mOrientedXPrecision, mOrientedYPrecision, mDownTime);
            dispatchedIdBits.clearBit(upId);
            mCurrentCookedState.cookedPointerData.canceledIdBits.clearBit(upId);
        }

        // Dispatch move events if any of the remaining pointers moved from their old locations.
@@ -2025,6 +2029,8 @@ void TouchInputMapper::cookPointerData() {
            mCurrentRawState.rawPointerData.hoveringIdBits;
    mCurrentCookedState.cookedPointerData.touchingIdBits =
            mCurrentRawState.rawPointerData.touchingIdBits;
    mCurrentCookedState.cookedPointerData.canceledIdBits =
            mCurrentRawState.rawPointerData.canceledIdBits;

    if (mCurrentCookedState.cookedPointerData.pointerCount == 0) {
        mCurrentCookedState.buttonState = 0;
@@ -3563,7 +3569,11 @@ void TouchInputMapper::dispatchMotion(nsecs_t when, uint32_t policyFlags, uint32
        if (action == AMOTION_EVENT_ACTION_POINTER_DOWN) {
            action = AMOTION_EVENT_ACTION_DOWN;
        } else if (action == AMOTION_EVENT_ACTION_POINTER_UP) {
            if ((flags & AMOTION_EVENT_FLAG_CANCELED) != 0) {
                action = AMOTION_EVENT_ACTION_CANCEL;
            } else {
                action = AMOTION_EVENT_ACTION_UP;
            }
        } else {
            // Can't happen.
            ALOG_ASSERT(false);
+3 −2
Original line number Diff line number Diff line
@@ -71,7 +71,7 @@ struct RawPointerData {

    uint32_t pointerCount;
    Pointer pointers[MAX_POINTERS];
    BitSet32 hoveringIdBits, touchingIdBits;
    BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits;
    uint32_t idToIndex[MAX_POINTER_ID + 1];

    RawPointerData();
@@ -90,6 +90,7 @@ struct RawPointerData {
    inline void clearIdBits() {
        hoveringIdBits.clear();
        touchingIdBits.clear();
        canceledIdBits.clear();
    }

    inline const Pointer& pointerForId(uint32_t id) const { return pointers[idToIndex[id]]; }
@@ -102,7 +103,7 @@ struct CookedPointerData {
    uint32_t pointerCount;
    PointerProperties pointerProperties[MAX_POINTERS];
    PointerCoords pointerCoords[MAX_POINTERS];
    BitSet32 hoveringIdBits, touchingIdBits;
    BitSet32 hoveringIdBits, touchingIdBits, canceledIdBits;
    uint32_t idToIndex[MAX_POINTER_ID + 1];

    CookedPointerData();
Loading