Do not report latency for injected events
When reporting the latency of touch events, ensure that injected events
are excluded. These events can have arbitrary timestamps, and would not
result in meaningful data. Also do not report events for statistics if
inputfilter is enabled.
Move the statistics reporting from InputTransport to InputDispatcher.
This ensures that there's only 1 instance of the mStatistics object.
This also provides easy access to the inputfilterenabled state.
Bug: 13894199
Test: Change the reporting period to 0 (to report every event immediately)
Inject events in various ways and ensure they don't go to statsd
$ m statsd_testdrive && ./out/host/linux-x86/bin/statsd_testdrive 34
$ adb shell input tap 100 100
$ adb shell monkey 1000
Next, relaunch the statsd_testdrive script and touch the screen
Observe that events are reported.
Change-Id: Ief8040599a347e084e75584ed3164c60a6dbc4ad
diff --git a/services/inputflinger/dispatcher/Entry.h b/services/inputflinger/dispatcher/Entry.h
index a9e22f1..28c2799 100644
--- a/services/inputflinger/dispatcher/Entry.h
+++ b/services/inputflinger/dispatcher/Entry.h
@@ -29,6 +29,9 @@
namespace android::inputdispatcher {
+// Sequence number for synthesized or injected events.
+constexpr uint32_t SYNTHESIZED_EVENT_SEQUENCE_NUM = 0;
+
struct EventEntry {
enum { TYPE_CONFIGURATION_CHANGED, TYPE_DEVICE_RESET, TYPE_KEY, TYPE_MOTION };
@@ -41,8 +44,23 @@
bool dispatchInProgress; // initially false, set to true while dispatching
+ /**
+ * Injected keys are events from an external (probably untrusted) application
+ * and are not related to real hardware state. They come in via
+ * InputDispatcher::injectInputEvent, which sets policy flag POLICY_FLAG_INJECTED.
+ */
inline bool isInjected() const { return injectionState != nullptr; }
+ /**
+ * Synthesized events are either injected events, or events that come
+ * from real hardware, but aren't directly attributable to a specific hardware event.
+ * Key repeat is a synthesized event, because it is related to an actual hardware state
+ * (a key is currently pressed), but the repeat itself is generated by the framework.
+ */
+ inline bool isSynthesized() const {
+ return isInjected() || sequenceNum == SYNTHESIZED_EVENT_SEQUENCE_NUM;
+ }
+
void release();
virtual void appendDescription(std::string& msg) const = 0;