diff options
| -rw-r--r-- | include/input/InputTransport.h | 5 | ||||
| -rw-r--r-- | libs/input/Android.bp | 1 | ||||
| -rw-r--r-- | libs/input/InputTransport.cpp | 15 | ||||
| -rw-r--r-- | libs/input/LatencyStatistics.cpp | 2 | ||||
| -rw-r--r-- | services/inputflinger/Android.bp | 1 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/Android.bp | 1 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/Entry.h | 18 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.cpp | 30 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputDispatcher.h | 5 | ||||
| -rw-r--r-- | services/inputflinger/dispatcher/InputState.h | 3 |
10 files changed, 56 insertions, 25 deletions
diff --git a/include/input/InputTransport.h b/include/input/InputTransport.h index 28b8d80074..c056c972d2 100644 --- a/include/input/InputTransport.h +++ b/include/input/InputTransport.h @@ -35,7 +35,6 @@ #include <binder/IBinder.h> #include <input/Input.h> -#include <input/LatencyStatistics.h> #include <utils/BitSet.h> #include <utils/Errors.h> #include <utils/RefBase.h> @@ -289,12 +288,8 @@ public: status_t receiveFinishedSignal(uint32_t* outSeq, bool* outHandled); private: - static constexpr std::chrono::duration TOUCH_STATS_REPORT_PERIOD = 5min; sp<InputChannel> mChannel; - LatencyStatistics mTouchStatistics{TOUCH_STATS_REPORT_PERIOD}; - - void reportTouchEventForStatistics(nsecs_t evdevTime); }; /* diff --git a/libs/input/Android.bp b/libs/input/Android.bp index 7749e66c4d..8efaf3d90b 100644 --- a/libs/input/Android.bp +++ b/libs/input/Android.bp @@ -57,7 +57,6 @@ cc_library { "libutils", "libbinder", "libui", - "libstatslog", ], sanitize: { diff --git a/libs/input/InputTransport.cpp b/libs/input/InputTransport.cpp index 8a2fc2a2d0..366c93cf1f 100644 --- a/libs/input/InputTransport.cpp +++ b/libs/input/InputTransport.cpp @@ -34,7 +34,6 @@ #include <utils/Trace.h> #include <input/InputTransport.h> -#include <statslog.h> using android::base::StringPrintf; @@ -538,9 +537,6 @@ status_t InputPublisher::publishMotionEvent( msg.body.motion.pointers[i].coords.copyFrom(pointerCoords[i]); } - if (source == AINPUT_SOURCE_TOUCHSCREEN) { - reportTouchEventForStatistics(eventTime); - } return mChannel->sendMessage(&msg); } @@ -567,17 +563,6 @@ status_t InputPublisher::receiveFinishedSignal(uint32_t* outSeq, bool* outHandle return OK; } -void InputPublisher::reportTouchEventForStatistics(nsecs_t evdevTime) { - if (mTouchStatistics.shouldReport()) { - android::util::stats_write(android::util::TOUCH_EVENT_REPORTED, mTouchStatistics.getMin(), - mTouchStatistics.getMax(), mTouchStatistics.getMean(), - mTouchStatistics.getStDev(), mTouchStatistics.getCount()); - mTouchStatistics.reset(); - } - nsecs_t latency = nanoseconds_to_microseconds(systemTime(CLOCK_MONOTONIC) - evdevTime); - mTouchStatistics.addValue(latency); -} - // --- InputConsumer --- InputConsumer::InputConsumer(const sp<InputChannel>& channel) : diff --git a/libs/input/LatencyStatistics.cpp b/libs/input/LatencyStatistics.cpp index e343578e00..394da22a62 100644 --- a/libs/input/LatencyStatistics.cpp +++ b/libs/input/LatencyStatistics.cpp @@ -84,7 +84,7 @@ void LatencyStatistics::reset() { bool LatencyStatistics::shouldReport() { std::chrono::duration timeSinceReport = std::chrono::steady_clock::now() - mLastReportTime; - return mCount != 0 && timeSinceReport > mReportPeriod; + return mCount != 0 && timeSinceReport >= mReportPeriod; } } // namespace android diff --git a/services/inputflinger/Android.bp b/services/inputflinger/Android.bp index 11578c393e..f6b5935bcf 100644 --- a/services/inputflinger/Android.bp +++ b/services/inputflinger/Android.bp @@ -44,6 +44,7 @@ cc_library_shared { "libhidlbase", "libinput", "liblog", + "libstatslog", "libutils", "libui", "server_configurable_flags", diff --git a/services/inputflinger/dispatcher/Android.bp b/services/inputflinger/dispatcher/Android.bp index b8c3a808f1..9185e00272 100644 --- a/services/inputflinger/dispatcher/Android.bp +++ b/services/inputflinger/dispatcher/Android.bp @@ -34,6 +34,7 @@ cc_library_static { "libinputreporter", "libinputflinger_base", "liblog", + "libstatslog", "libui", "libutils", ], diff --git a/services/inputflinger/dispatcher/Entry.h b/services/inputflinger/dispatcher/Entry.h index a9e22f19f1..28c2799477 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 @@ struct EventEntry { 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; diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp index e161e8c29c..aa51e23040 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.cpp +++ b/services/inputflinger/dispatcher/InputDispatcher.cpp @@ -50,6 +50,7 @@ static constexpr bool DEBUG_FOCUS = false; #include <errno.h> #include <inttypes.h> #include <limits.h> +#include <statslog.h> #include <stddef.h> #include <time.h> #include <unistd.h> @@ -2276,6 +2277,7 @@ void InputDispatcher::startDispatchCycleLocked(nsecs_t currentTime, motionEntry->downTime, motionEntry->eventTime, motionEntry->pointerCount, motionEntry->pointerProperties, usingCoords); + reportTouchEventForStatistics(*motionEntry); break; } @@ -4481,6 +4483,34 @@ void InputDispatcher::updateDispatchStatistics(nsecs_t currentTime, const EventE // TODO Write some statistics about how long we spend waiting. } +/** + * Report the touch event latency to the statsd server. + * Input events are reported for statistics if: + * - This is a touchscreen event + * - InputFilter is not enabled + * - Event is not injected or synthesized + * + * Statistics should be reported before calling addValue, to prevent a fresh new sample + * from getting aggregated with the "old" data. + */ +void InputDispatcher::reportTouchEventForStatistics(const MotionEntry& motionEntry) + REQUIRES(mLock) { + const bool reportForStatistics = (motionEntry.source == AINPUT_SOURCE_TOUCHSCREEN) && + !(motionEntry.isSynthesized()) && !mInputFilterEnabled; + if (!reportForStatistics) { + return; + } + + if (mTouchStatistics.shouldReport()) { + android::util::stats_write(android::util::TOUCH_EVENT_REPORTED, mTouchStatistics.getMin(), + mTouchStatistics.getMax(), mTouchStatistics.getMean(), + mTouchStatistics.getStDev(), mTouchStatistics.getCount()); + mTouchStatistics.reset(); + } + const float latencyMicros = nanoseconds_to_microseconds(now() - motionEntry.eventTime); + mTouchStatistics.addValue(latencyMicros); +} + void InputDispatcher::traceInboundQueueLengthLocked() { if (ATRACE_ENABLED()) { ATRACE_INT("iq", mInboundQueue.size()); diff --git a/services/inputflinger/dispatcher/InputDispatcher.h b/services/inputflinger/dispatcher/InputDispatcher.h index f2c04028e4..0d9d6b0c15 100644 --- a/services/inputflinger/dispatcher/InputDispatcher.h +++ b/services/inputflinger/dispatcher/InputDispatcher.h @@ -33,6 +33,7 @@ #include <input/InputApplication.h> #include <input/InputTransport.h> #include <input/InputWindow.h> +#include <input/LatencyStatistics.h> #include <limits.h> #include <stddef.h> #include <ui/Region.h> @@ -455,6 +456,10 @@ private: void doOnPointerDownOutsideFocusLockedInterruptible(CommandEntry* commandEntry) REQUIRES(mLock); // Statistics gathering. + static constexpr std::chrono::duration TOUCH_STATS_REPORT_PERIOD = 5min; + LatencyStatistics mTouchStatistics{TOUCH_STATS_REPORT_PERIOD}; + + void reportTouchEventForStatistics(const MotionEntry& entry); void updateDispatchStatistics(nsecs_t currentTime, const EventEntry* entry, int32_t injectionResult, nsecs_t timeSpentWaitingForApplication); void traceInboundQueueLengthLocked() REQUIRES(mLock); diff --git a/services/inputflinger/dispatcher/InputState.h b/services/inputflinger/dispatcher/InputState.h index bccef0fca3..47e9b36219 100644 --- a/services/inputflinger/dispatcher/InputState.h +++ b/services/inputflinger/dispatcher/InputState.h @@ -24,9 +24,6 @@ namespace android::inputdispatcher { -// Sequence number for synthesized or injected events. -constexpr uint32_t SYNTHESIZED_EVENT_SEQUENCE_NUM = 0; - /* Tracks dispatched key and motion event state so that cancellation events can be * synthesized when events are dropped. */ class InputState { |