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

Commit e9e86076 authored by Jeff Brown's avatar Jeff Brown Committed by Android (Google) Code Review
Browse files

Merge "Improve input event consistency invariants."

parents cf93ed0d 8134681b
Loading
Loading
Loading
Loading
+13 −14
Original line number Diff line number Diff line
@@ -239,7 +239,7 @@ public final class InputEventConsistencyVerifier {
                    break;
            }
        } finally {
            finishEvent(false);
            finishEvent();
        }
    }

@@ -302,7 +302,7 @@ public final class InputEventConsistencyVerifier {
                problem("Source was not SOURCE_CLASS_TRACKBALL.");
            }
        } finally {
            finishEvent(false);
            finishEvent();
        }
    }

@@ -328,7 +328,9 @@ public final class InputEventConsistencyVerifier {
            mTouchEventStreamUnhandled = false;
            mTouchEventStreamPointers = 0;
        }
        final boolean wasTainted = mTouchEventStreamIsTainted;
        if (mTouchEventStreamIsTainted) {
            event.setTainted(true);
        }

        try {
            ensureMetaStateIsNormalized(event.getMetaState());
@@ -441,7 +443,7 @@ public final class InputEventConsistencyVerifier {
                problem("Source was not SOURCE_CLASS_POINTER.");
            }
        } finally {
            finishEvent(wasTainted);
            finishEvent();
        }
    }

@@ -499,7 +501,7 @@ public final class InputEventConsistencyVerifier {
                }
            }
        } finally {
            finishEvent(false);
            finishEvent();
        }
    }

@@ -591,9 +593,9 @@ public final class InputEventConsistencyVerifier {
        return true;
    }

    private void finishEvent(boolean tainted) {
    private void finishEvent() {
        if (mViolationMessage != null && mViolationMessage.length() != 0) {
            if (!tainted) {
            if (!mCurrentEvent.isTainted()) {
                // Write a log message only if the event was not already tainted.
                mViolationMessage.append("\n  in ").append(mCaller);
                mViolationMessage.append("\n  ");
@@ -614,16 +616,13 @@ public final class InputEventConsistencyVerifier {
                }

                Log.d(mLogTag, mViolationMessage.toString());
                tainted = true;
            }
            mViolationMessage.setLength(0);
        }

        if (tainted) {
                // Taint the event so that we do not generate additional violations from it
                // further downstream.
                mCurrentEvent.setTainted(true);
            }
            mViolationMessage.setLength(0);
        }

        if (RECENT_EVENTS_TO_LOG != 0) {
            if (mRecentEvents == null) {
+1 −1
Original line number Diff line number Diff line
@@ -2885,7 +2885,7 @@ public final class MotionEvent extends InputEvent implements Parcelable {
                    toolTypeToString(getToolType(i)));
        }

        msg.append(", buttonState=").append(KeyEvent.metaStateToString(getButtonState()));
        msg.append(", buttonState=").append(MotionEvent.buttonStateToString(getButtonState()));
        msg.append(", metaState=").append(KeyEvent.metaStateToString(getMetaState()));
        msg.append(", flags=0x").append(Integer.toHexString(getFlags()));
        msg.append(", edgeFlags=0x").append(Integer.toHexString(getEdgeFlags()));
+2 −1
Original line number Diff line number Diff line
@@ -443,7 +443,8 @@ status_t InputPublisher::appendMotionSample(

    if (! mPinned || ! mMotionEventSampleDataTail) {
        LOGE("channel '%s' publisher ~ Cannot append motion sample because there is no current "
                "AMOTION_EVENT_ACTION_MOVE event.", mChannel->getName().string());
                "AMOTION_EVENT_ACTION_MOVE or AMOTION_EVENT_ACTION_HOVER_MOVE event.",
                mChannel->getName().string());
        return INVALID_OPERATION;
    }

+292 −164

File changed.

Preview size limit exceeded, changes collapsed.

+20 −4
Original line number Diff line number Diff line
@@ -522,6 +522,10 @@ private:
        // True if dispatch has started.
        bool inProgress;

        // Set to the resolved action and flags when the event is enqueued.
        int32_t resolvedAction;
        int32_t resolvedFlags;

        // For motion events:
        //   Pointer to the first motion sample to dispatch in this cycle.
        //   Usually NULL to indicate that the list of motion samples begins at
@@ -709,14 +713,19 @@ private:
        // Returns true if there is no state to be canceled.
        bool isNeutral() const;

        // Records tracking information for an event that has just been published.
        void trackEvent(const EventEntry* entry, int32_t action);
        // Returns true if the specified source is known to have received a hover enter
        // motion event.
        bool isHovering(int32_t deviceId, uint32_t source) const;

        // Records tracking information for a key event that has just been published.
        void trackKey(const KeyEntry* entry, int32_t action);
        // Returns true if the event should be delivered, false if it is inconsistent
        // and should be skipped.
        bool trackKey(const KeyEntry* entry, int32_t action, int32_t flags);

        // Records tracking information for a motion event that has just been published.
        void trackMotion(const MotionEntry* entry, int32_t action);
        // Returns true if the event should be delivered, false if it is inconsistent
        // and should be skipped.
        bool trackMotion(const MotionEntry* entry, int32_t action, int32_t flags);

        // Synthesizes cancelation events for the current state and resets the tracked state.
        void synthesizeCancelationEvents(nsecs_t currentTime, Allocator* allocator,
@@ -756,6 +765,7 @@ private:
        struct MotionMemento {
            int32_t deviceId;
            uint32_t source;
            int32_t flags;
            float xPrecision;
            float yPrecision;
            nsecs_t downTime;
@@ -771,6 +781,12 @@ private:
        Vector<MotionMemento> mMotionMementos;
        KeyedVector<int32_t, int32_t> mFallbackKeys;

        ssize_t findKeyMemento(const KeyEntry* entry) const;
        ssize_t findMotionMemento(const MotionEntry* entry, bool hovering) const;

        void addKeyMemento(const KeyEntry* entry, int32_t flags);
        void addMotionMemento(const MotionEntry* entry, int32_t flags, bool hovering);

        static bool shouldCancelKey(const KeyMemento& memento,
                const CancelationOptions& options);
        static bool shouldCancelMotion(const MotionMemento& memento,
Loading