Use a single trackListener method in LatencyTracker
This simplifies the code for the caller (InputDispatcher) and reduces the API surface of LatencyTracker.
Bug: 270049345
Change-Id: Ia25e95a24b5e89abcfce8060893ec3cce0c7892e
Flag: EXEMPT refactor
Test: atest inputflinger_tests
diff --git a/services/inputflinger/dispatcher/LatencyTracker.cpp b/services/inputflinger/dispatcher/LatencyTracker.cpp
index 0852026..0921e37 100644
--- a/services/inputflinger/dispatcher/LatencyTracker.cpp
+++ b/services/inputflinger/dispatcher/LatencyTracker.cpp
@@ -20,6 +20,7 @@
#include <inttypes.h>
+#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android/os/IInputConstants.h>
@@ -32,6 +33,8 @@
namespace android::inputdispatcher {
+namespace {
+
/**
* Events that are older than this time will be considered mature, at which point we will stop
* waiting for the apps to provide further information about them.
@@ -62,27 +65,25 @@
}
}
+} // namespace
+
LatencyTracker::LatencyTracker(InputEventTimelineProcessor& processor)
: mTimelineProcessor(&processor) {}
-void LatencyTracker::trackNotifyMotion(const NotifyMotionArgs& args) {
- std::set<InputDeviceUsageSource> sources = getUsageSourcesForMotionArgs(args);
- trackListener(args.id, args.eventTime, args.readTime, args.deviceId, sources, args.action,
- InputEventType::MOTION);
-}
+void LatencyTracker::trackListener(const NotifyArgs& args) {
+ if (const NotifyKeyArgs* keyArgs = std::get_if<NotifyKeyArgs>(&args)) {
+ std::set<InputDeviceUsageSource> sources =
+ getUsageSourcesForKeyArgs(*keyArgs, mInputDevices);
+ trackListener(keyArgs->id, keyArgs->eventTime, keyArgs->readTime, keyArgs->deviceId,
+ sources, keyArgs->action, InputEventType::KEY);
-void LatencyTracker::trackNotifyKey(const NotifyKeyArgs& args) {
- int32_t keyboardType = AINPUT_KEYBOARD_TYPE_NONE;
- for (auto& inputDevice : mInputDevices) {
- if (args.deviceId == inputDevice.getId()) {
- keyboardType = inputDevice.getKeyboardType();
- break;
- }
+ } else if (const NotifyMotionArgs* motionArgs = std::get_if<NotifyMotionArgs>(&args)) {
+ std::set<InputDeviceUsageSource> sources = getUsageSourcesForMotionArgs(*motionArgs);
+ trackListener(motionArgs->id, motionArgs->eventTime, motionArgs->readTime,
+ motionArgs->deviceId, sources, motionArgs->action, InputEventType::MOTION);
+ } else {
+ LOG(FATAL) << "Unexpected NotifyArgs type: " << args.index();
}
- std::set<InputDeviceUsageSource> sources =
- std::set{getUsageSourceForKeyArgs(keyboardType, args)};
- trackListener(args.id, args.eventTime, args.readTime, args.deviceId, sources, args.action,
- InputEventType::KEY);
}
void LatencyTracker::trackListener(int32_t inputEventId, nsecs_t eventTime, nsecs_t readTime,