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

Commit 04a66429 authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

InputTracer: Adjust sensitivity based on IME connection

Based on the trace rules, we can adjust the trace level depending on
when there was an active IME connection when the event processing was
complete.

Bug: 210460522
Test: manual with perfetto
Change-Id: I90587c3004fa05517cf44c4c0b6b5c5c40fc00d1
parent c7edaaa0
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -7144,4 +7144,11 @@ bool InputDispatcher::isPointerInWindow(const sp<android::IBinder>& token, int32
    return false;
}

void InputDispatcher::setInputMethodConnectionIsActive(bool isActive) {
    std::scoped_lock _l(mLock);
    if (mTracer) {
        mTracer->setInputMethodConnectionIsActive(isActive);
    }
}

} // namespace android::inputdispatcher
+2 −0
Original line number Diff line number Diff line
@@ -158,6 +158,8 @@ public:
    bool isPointerInWindow(const sp<IBinder>& token, int32_t displayId, DeviceId deviceId,
                           int32_t pointerId) override;

    void setInputMethodConnectionIsActive(bool isActive) override;

private:
    enum class DropReason {
        NOT_DROPPED,
+5 −0
Original line number Diff line number Diff line
@@ -236,6 +236,11 @@ public:
     */
    virtual bool isPointerInWindow(const sp<IBinder>& token, int32_t displayId, DeviceId deviceId,
                                   int32_t pointerId) = 0;

    /*
     * Notify the dispatcher that the state of the input method connection changed.
     */
    virtual void setInputMethodConnectionIsActive(bool isActive) = 0;
};

} // namespace android
+22 −7
Original line number Diff line number Diff line
@@ -141,7 +141,6 @@ void InputTracer::dispatchToTargetHint(const EventTrackerInterface& cookie,

    eventState->targets.emplace(targetInfo.uid);
    eventState->isSecure |= targetInfo.isSecureWindow;
    // TODO(b/210460522): Set events as sensitive when the IME connection is active.
}

void InputTracer::eventProcessingComplete(const EventTrackerInterface& cookie) {
@@ -177,8 +176,11 @@ std::unique_ptr<EventTrackerInterface> InputTracer::traceDerivedEvent(
        // is dispatched, such as in the case of key fallback events. To account for these cases,
        // derived events can be traced after the processing is complete for the original event.
        const auto& event = eventState->events.back();
        const TracedEventMetadata metadata{.isSecure = eventState->isSecure,
                                           .targets = eventState->targets};
        const TracedEventMetadata metadata{
                .isSecure = eventState->isSecure,
                .targets = eventState->targets,
                .isImeConnectionActive = eventState->isImeConnectionActive,
        };
        writeEventToBackend(event, std::move(metadata), *mBackend);
    }
    return std::make_unique<EventTrackerImpl>(std::move(eventState), /*isDerived=*/true);
@@ -226,8 +228,11 @@ void InputTracer::traceEventDispatch(const DispatchEntry& dispatchEntry,
                                                /*hmac=*/{},
                                                resolvedKeyRepeatCount};
    if (eventState->isEventProcessingComplete) {
        const TracedEventMetadata metadata{.isSecure = eventState->isSecure,
                                           .targets = eventState->targets};
        const TracedEventMetadata metadata{
                .isSecure = eventState->isSecure,
                .targets = eventState->targets,
                .isImeConnectionActive = eventState->isImeConnectionActive,
        };
        mBackend->traceWindowDispatch(std::move(windowDispatchArgs), std::move(metadata));
    } else {
        eventState->pendingDispatchArgs.emplace_back(std::move(windowDispatchArgs));
@@ -246,9 +251,15 @@ bool InputTracer::isDerivedCookie(const EventTrackerInterface& cookie) {
// --- InputTracer::EventState ---

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

    // Write all of the events known so far to the trace.
    for (const auto& event : events) {
        const TracedEventMetadata metadata{.isSecure = isSecure, .targets = targets};
        const TracedEventMetadata metadata{
                .isSecure = isSecure,
                .targets = targets,
                .isImeConnectionActive = isImeConnectionActive,
        };
        writeEventToBackend(event, std::move(metadata), *tracer.mBackend);
    }
    // Write all pending dispatch args to the trace.
@@ -263,7 +274,11 @@ void InputTracer::EventState::onEventProcessingComplete() {
                       << ": Failed to find a previously traced event that matches the dispatched "
                          "event";
        }
        const TracedEventMetadata metadata{.isSecure = isSecure, .targets = targets};
        const TracedEventMetadata metadata{
                .isSecure = isSecure,
                .targets = targets,
                .isImeConnectionActive = isImeConnectionActive,
        };
        tracer.mBackend->traceWindowDispatch(windowDispatchArgs, std::move(metadata));
    }
    pendingDispatchArgs.clear();
+5 −0
Original line number Diff line number Diff line
@@ -48,9 +48,13 @@ public:
    std::unique_ptr<EventTrackerInterface> traceDerivedEvent(const EventEntry&,
                                                             const EventTrackerInterface&) override;
    void traceEventDispatch(const DispatchEntry&, const EventTrackerInterface&) override;
    void setInputMethodConnectionIsActive(bool isActive) override {
        mIsImeConnectionActive = isActive;
    }

private:
    std::unique_ptr<InputTracingBackendInterface> mBackend;
    bool mIsImeConnectionActive{false};

    // The state of a tracked event, shared across all events derived from the original event.
    struct EventState {
@@ -68,6 +72,7 @@ private:
        bool isSecure{false};
        // The list of all possible UIDs that this event could be targeting.
        std::set<gui::Uid> targets;
        bool isImeConnectionActive{false};
    };

    // Get the event state associated with a tracking cookie.
Loading