Metrics Collector: Prevent queuing interactions from ignored devices

We don't collect metrics for injected events. Since the interactions
queue is processed from the InputReader thread, if many interactions
are notified by InputDispatcher when the Reader thread is not active
(e.g. for interactions from injected events), it's possible for the
interactions queue to grow indefinitely.

To mitigate this:
- Do not queue interactions from ignored devices, such as those
  from injected events that use VIRTUAL_KEYBOARD_ID. This prevents
  the queue from growing in the first place due to injected events,
  which do not come from the Reader thread.
- Ensure the interactions queue is bounded so that it cannot grow
  indefinitely.

Bug: 287676652
Test: manual
Test: atest inputflinger_tests
Change-Id: I1ce27b1817704dd83307fab1917465dcb85ac31e
diff --git a/services/inputflinger/InputDeviceMetricsCollector.cpp b/services/inputflinger/InputDeviceMetricsCollector.cpp
index 89e37db..2799327 100644
--- a/services/inputflinger/InputDeviceMetricsCollector.cpp
+++ b/services/inputflinger/InputDeviceMetricsCollector.cpp
@@ -39,6 +39,8 @@
  */
 const bool DEBUG = __android_log_is_loggable(ANDROID_LOG_DEBUG, LOG_TAG, ANDROID_LOG_INFO);
 
+constexpr size_t INTERACTIONS_QUEUE_CAPACITY = 500;
+
 int32_t linuxBusToInputDeviceBusEnum(int32_t linuxBus) {
     // When adding cases to this switch, also add them to the copy of this method in
     // TouchpadInputMapper.cpp.
@@ -201,7 +203,10 @@
 InputDeviceMetricsCollector::InputDeviceMetricsCollector(InputListenerInterface& listener,
                                                          InputDeviceMetricsLogger& logger,
                                                          nanoseconds usageSessionTimeout)
-      : mNextListener(listener), mLogger(logger), mUsageSessionTimeout(usageSessionTimeout) {}
+      : mNextListener(listener),
+        mLogger(logger),
+        mUsageSessionTimeout(usageSessionTimeout),
+        mInteractionsQueue(INTERACTIONS_QUEUE_CAPACITY) {}
 
 void InputDeviceMetricsCollector::notifyInputDevicesChanged(
         const NotifyInputDevicesChangedArgs& args) {
@@ -262,6 +267,9 @@
 
 void InputDeviceMetricsCollector::notifyDeviceInteraction(int32_t deviceId, nsecs_t timestamp,
                                                           const std::set<Uid>& uids) {
+    if (isIgnoredInputDeviceId(deviceId)) {
+        return;
+    }
     mInteractionsQueue.push(DeviceId{deviceId}, timestamp, uids);
 }