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

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

Merge changes I30f4c21d,Ie9a5fbd5 into main

* changes:
  InputTracer: Add timestamp to perfetto trace packets
  InputDispatcher: Fix pointer count when canceling a subset of pointers
parents 15028ef2 4fc32e04
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -879,7 +879,7 @@ std::pair<bool /*cancelPointers*/, bool /*cancelNonPointers*/> expandCancellatio
class ScopedSyntheticEventTracer {
public:
    ScopedSyntheticEventTracer(std::unique_ptr<trace::InputTracerInterface>& tracer)
          : mTracer(tracer) {
          : mTracer(tracer), mProcessingTimestamp(now()) {
        if (mTracer) {
            mEventTracker = mTracer->createTrackerForSyntheticEvent();
        }
@@ -887,7 +887,7 @@ public:

    ~ScopedSyntheticEventTracer() {
        if (mTracer) {
            mTracer->eventProcessingComplete(*mEventTracker);
            mTracer->eventProcessingComplete(*mEventTracker, mProcessingTimestamp);
        }
    }

@@ -896,8 +896,9 @@ public:
    }

private:
    std::unique_ptr<trace::InputTracerInterface>& mTracer;
    const std::unique_ptr<trace::InputTracerInterface>& mTracer;
    std::unique_ptr<trace::EventTrackerInterface> mEventTracker;
    const nsecs_t mProcessingTimestamp;
};

} // namespace
@@ -1263,7 +1264,7 @@ void InputDispatcher::dispatchOnceInnerLocked(nsecs_t& nextWakeupTime) {

        if (mTracer) {
            if (auto& traceTracker = getTraceTracker(*mPendingEvent); traceTracker != nullptr) {
                mTracer->eventProcessingComplete(*traceTracker);
                mTracer->eventProcessingComplete(*traceTracker, currentTime);
            }
        }

+30 −44
Original line number Diff line number Diff line
@@ -499,48 +499,36 @@ std::vector<std::unique_ptr<MotionEntry>> InputState::synthesizeCancelationEvent
        nsecs_t currentTime) {
    std::vector<std::unique_ptr<MotionEntry>> events;
    std::vector<uint32_t> canceledPointerIndices;
    std::vector<PointerProperties> pointerProperties(MAX_POINTERS);
    std::vector<PointerCoords> pointerCoords(MAX_POINTERS);

    for (uint32_t pointerIdx = 0; pointerIdx < memento.getPointerCount(); pointerIdx++) {
        uint32_t pointerId = uint32_t(memento.pointerProperties[pointerIdx].id);
        pointerProperties[pointerIdx] = memento.pointerProperties[pointerIdx];
        pointerCoords[pointerIdx] = memento.pointerCoords[pointerIdx];
        if (pointerIds.test(pointerId)) {
            canceledPointerIndices.push_back(pointerIdx);
        }
    }

    if (canceledPointerIndices.size() == memento.getPointerCount()) {
        const int32_t action =
                memento.hovering ? AMOTION_EVENT_ACTION_HOVER_EXIT : AMOTION_EVENT_ACTION_CANCEL;
        int32_t flags = memento.flags;
        if (action == AMOTION_EVENT_ACTION_CANCEL) {
            flags |= AMOTION_EVENT_FLAG_CANCELED;
        // We are cancelling all pointers.
        events.emplace_back(createCancelEntryForMemento(memento, currentTime));
        return events;
    }
        events.push_back(
                std::make_unique<MotionEntry>(mIdGenerator.nextId(), /*injectionState=*/nullptr,
                                              currentTime, memento.deviceId, memento.source,
                                              memento.displayId, memento.policyFlags, action,
                                              /*actionButton=*/0, flags, AMETA_NONE,
                                              /*buttonState=*/0, MotionClassification::NONE,
                                              AMOTION_EVENT_EDGE_FLAG_NONE, memento.xPrecision,
                                              memento.yPrecision, memento.xCursorPosition,
                                              memento.yCursorPosition, memento.downTime,
                                              memento.pointerProperties, memento.pointerCoords));
    } else {

    // If we aren't canceling all pointers, we need to generate ACTION_POINTER_UP with
    // FLAG_CANCELED for each of the canceled pointers. For each event, we must remove the
    // previously canceled pointers from PointerProperties and PointerCoords, and update
        // pointerCount appropriately. For convenience, sort the canceled pointer indices so that we
        // can just slide the remaining pointers to the beginning of the array when a pointer is
        // canceled.
    // pointerCount appropriately. For convenience, sort the canceled pointer indices in
    // descending order so that we can just slide the remaining pointers to the beginning of
    // the array when a pointer is canceled.
    std::sort(canceledPointerIndices.begin(), canceledPointerIndices.end(),
              std::greater<uint32_t>());

        uint32_t pointerCount = memento.getPointerCount();
    std::vector<PointerProperties> pointerProperties = memento.pointerProperties;
    std::vector<PointerCoords> pointerCoords = memento.pointerCoords;
    for (const uint32_t pointerIdx : canceledPointerIndices) {
            const int32_t action = pointerCount == 1 ? AMOTION_EVENT_ACTION_CANCEL
                                                     : AMOTION_EVENT_ACTION_POINTER_UP |
        if (pointerProperties.size() <= 1) {
            LOG(FATAL) << "Unexpected code path for canceling all pointers!";
        }
        const int32_t action = AMOTION_EVENT_ACTION_POINTER_UP |
                (pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
        events.push_back(
                std::make_unique<MotionEntry>(mIdGenerator.nextId(), /*injectionState=*/nullptr,
@@ -558,8 +546,6 @@ std::vector<std::unique_ptr<MotionEntry>> InputState::synthesizeCancelationEvent
        // Cleanup pointer information
        pointerProperties.erase(pointerProperties.begin() + pointerIdx);
        pointerCoords.erase(pointerCoords.begin() + pointerIdx);
            pointerCount--;
        }
    }
    return events;
}
+6 −4
Original line number Diff line number Diff line
@@ -145,7 +145,8 @@ void InputTracer::dispatchToTargetHint(const EventTrackerInterface& cookie,
    eventState->metadata.isSecure |= targetInfo.isSecureWindow;
}

void InputTracer::eventProcessingComplete(const EventTrackerInterface& cookie) {
void InputTracer::eventProcessingComplete(const EventTrackerInterface& cookie,
                                          nsecs_t processingTimestamp) {
    if (isDerivedCookie(cookie)) {
        LOG(FATAL) << "Event processing cannot be set from a derived cookie.";
    }
@@ -154,7 +155,7 @@ void InputTracer::eventProcessingComplete(const EventTrackerInterface& cookie) {
        LOG(FATAL) << "Traced event was already logged. "
                      "eventProcessingComplete() was likely called more than once.";
    }
    eventState->onEventProcessingComplete();
    eventState->onEventProcessingComplete(processingTimestamp);
}

std::unique_ptr<EventTrackerInterface> InputTracer::traceDerivedEvent(
@@ -242,7 +243,8 @@ bool InputTracer::isDerivedCookie(const EventTrackerInterface& cookie) {

// --- InputTracer::EventState ---

void InputTracer::EventState::onEventProcessingComplete() {
void InputTracer::EventState::onEventProcessingComplete(nsecs_t processingTimestamp) {
    metadata.processingTimestamp = processingTimestamp;
    metadata.isImeConnectionActive = tracer.mIsImeConnectionActive;

    // Write all of the events known so far to the trace.
@@ -277,7 +279,7 @@ InputTracer::EventState::~EventState() {
    // We should never end up here in normal operation. However, in tests, it's possible that we
    // stop and destroy InputDispatcher without waiting for it to finish processing events, at
    // which point an event (and thus its EventState) may be destroyed before processing finishes.
    onEventProcessingComplete();
    onEventProcessingComplete(systemTime(CLOCK_MONOTONIC));
}

} // namespace android::inputdispatcher::trace::impl
+3 −2
Original line number Diff line number Diff line
@@ -44,7 +44,8 @@ public:
    std::unique_ptr<EventTrackerInterface> traceInboundEvent(const EventEntry&) override;
    std::unique_ptr<EventTrackerInterface> createTrackerForSyntheticEvent() override;
    void dispatchToTargetHint(const EventTrackerInterface&, const InputTarget&) override;
    void eventProcessingComplete(const EventTrackerInterface&) override;
    void eventProcessingComplete(const EventTrackerInterface&,
                                 nsecs_t processingTimestamp) override;
    std::unique_ptr<EventTrackerInterface> traceDerivedEvent(const EventEntry&,
                                                             const EventTrackerInterface&) override;
    void traceEventDispatch(const DispatchEntry&, const EventTrackerInterface&) override;
@@ -61,7 +62,7 @@ private:
        explicit inline EventState(InputTracer& tracer) : tracer(tracer){};
        ~EventState();

        void onEventProcessingComplete();
        void onEventProcessingComplete(nsecs_t processingTimestamp);

        InputTracer& tracer;
        std::vector<const TracedEvent> events;
+2 −1
Original line number Diff line number Diff line
@@ -81,7 +81,8 @@ public:
     * outside of our control, such as how long apps take to respond, so we don't want to depend on
     * that.
     */
    virtual void eventProcessingComplete(const EventTrackerInterface&) = 0;
    virtual void eventProcessingComplete(const EventTrackerInterface&,
                                         nsecs_t processingTimestamp) = 0;

    /**
     * Trace an input event that is derived from another event. This is used in cases where an event
Loading