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
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index 065c5c8..d857723 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -7144,4 +7144,11 @@
return false;
}
+void InputDispatcher::setInputMethodConnectionIsActive(bool isActive) {
+ std::scoped_lock _l(mLock);
+ if (mTracer) {
+ mTracer->setInputMethodConnectionIsActive(isActive);
+ }
+}
+
} // namespace android::inputdispatcher
diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h
index 13571b3..f884685 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.h
+++ b/services/inputflinger/dispatcher/InputDispatcher.h
@@ -158,6 +158,8 @@
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,
diff --git a/services/inputflinger/dispatcher/include/InputDispatcherInterface.h b/services/inputflinger/dispatcher/include/InputDispatcherInterface.h
index 7c440e8..6b9262c 100644
--- a/services/inputflinger/dispatcher/include/InputDispatcherInterface.h
+++ b/services/inputflinger/dispatcher/include/InputDispatcherInterface.h
@@ -236,6 +236,11 @@
*/
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
diff --git a/services/inputflinger/dispatcher/trace/InputTracer.cpp b/services/inputflinger/dispatcher/trace/InputTracer.cpp
index 019283f..32fa740 100644
--- a/services/inputflinger/dispatcher/trace/InputTracer.cpp
+++ b/services/inputflinger/dispatcher/trace/InputTracer.cpp
@@ -141,7 +141,6 @@
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 @@
// 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 @@
/*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 @@
// --- 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 @@
<< ": 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();
diff --git a/services/inputflinger/dispatcher/trace/InputTracer.h b/services/inputflinger/dispatcher/trace/InputTracer.h
index 717bc1f..dfaf7c3 100644
--- a/services/inputflinger/dispatcher/trace/InputTracer.h
+++ b/services/inputflinger/dispatcher/trace/InputTracer.h
@@ -48,9 +48,13 @@
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 @@
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.
diff --git a/services/inputflinger/dispatcher/trace/InputTracerInterface.h b/services/inputflinger/dispatcher/trace/InputTracerInterface.h
index 609d10c..af6eefb 100644
--- a/services/inputflinger/dispatcher/trace/InputTracerInterface.h
+++ b/services/inputflinger/dispatcher/trace/InputTracerInterface.h
@@ -103,6 +103,11 @@
* provided.
*/
virtual void traceEventDispatch(const DispatchEntry&, const EventTrackerInterface&) = 0;
+
+ /**
+ * Notify that the state of the input method connection changed.
+ */
+ virtual void setInputMethodConnectionIsActive(bool isActive) = 0;
};
} // namespace android::inputdispatcher::trace
diff --git a/services/inputflinger/dispatcher/trace/InputTracingBackendInterface.h b/services/inputflinger/dispatcher/trace/InputTracingBackendInterface.h
index bc037b3..2b45e3a 100644
--- a/services/inputflinger/dispatcher/trace/InputTracingBackendInterface.h
+++ b/services/inputflinger/dispatcher/trace/InputTracingBackendInterface.h
@@ -97,6 +97,8 @@
bool isSecure;
// The list of possible UIDs that this event could be targeting.
std::set<gui::Uid> targets;
+ // True if the there was an active input method connection while this event was processed.
+ bool isImeConnectionActive;
};
/** Additional information about an input event being dispatched to a window. */
diff --git a/services/inputflinger/dispatcher/trace/InputTracingPerfettoBackend.cpp b/services/inputflinger/dispatcher/trace/InputTracingPerfettoBackend.cpp
index b413def..9c39743 100644
--- a/services/inputflinger/dispatcher/trace/InputTracingPerfettoBackend.cpp
+++ b/services/inputflinger/dispatcher/trace/InputTracingPerfettoBackend.cpp
@@ -118,6 +118,12 @@
return false;
}
+ // Match the event if it was processed while there was an active InputMethod connection.
+ if (rule.matchImeConnectionActive.has_value() &&
+ *rule.matchImeConnectionActive != metadata.isImeConnectionActive) {
+ return false;
+ }
+
// Match the event if all of its target packages are explicitly allowed in the "match all" list.
if (!rule.matchAllPackages.empty() &&
!std::all_of(metadata.targets.begin(), metadata.targets.end(), [&](const auto& uid) {