SF: throttle WindowInfosListener calls

This change updates WindowInfosListenerInvoker to delay and drop
messages when there are unacked messages. When WindowInfosListener calls
are acknowledged before the next windowInfosChanged call, there is no
behavior change. If windowInfosChanged is called and there are unacked
messages, then the update is delayed and sent once the messages are
acked via WindowInfosReportedListener. If windowInfosChanged is called
and there is already a delayed update, then the previous delayed update
is overwritten and only the latest update is sent.

WindowInfosListeners are still called immediately when there are focus
requests. This means the number of unacked messages may be greater than
one.

This reverts commit 1234a337651a79d492b6c453eb7f4cf30ec341cf.

Bug: 270894765
Test: presubmits
Test: manual fuzz testing (random sleeps added to input flinger listener)
Change-Id: If43b7ab91e05df863e9e6ac51b0bbd36cabe85d7
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 8394ffb..31bf7ef 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -3715,17 +3715,33 @@
         return;
     }
 
+    std::unordered_set<Layer*> visibleLayers;
+    mDrawingState.traverse([&visibleLayers](Layer* layer) {
+        if (layer->isVisibleForInput()) {
+            visibleLayers.insert(layer);
+        }
+    });
+    bool visibleLayersChanged = false;
+    if (visibleLayers != mVisibleLayers) {
+        visibleLayersChanged = true;
+        mVisibleLayers = std::move(visibleLayers);
+    }
+
     BackgroundExecutor::getInstance().sendCallbacks({[updateWindowInfo,
                                                       windowInfos = std::move(windowInfos),
                                                       displayInfos = std::move(displayInfos),
                                                       inputWindowCommands =
                                                               std::move(mInputWindowCommands),
-                                                      inputFlinger = mInputFlinger, this]() {
+                                                      inputFlinger = mInputFlinger, this,
+                                                      visibleLayersChanged]() {
         ATRACE_NAME("BackgroundExecutor::updateInputFlinger");
         if (updateWindowInfo) {
             mWindowInfosListenerInvoker
-                    ->windowInfosChanged(windowInfos, displayInfos,
-                                         inputWindowCommands.windowInfosReportedListeners);
+                    ->windowInfosChanged(std::move(windowInfos), std::move(displayInfos),
+                                         std::move(
+                                                 inputWindowCommands.windowInfosReportedListeners),
+                                         /* forceImmediateCall= */ visibleLayersChanged ||
+                                                 !inputWindowCommands.focusRequests.empty());
         } else {
             // If there are listeners but no changes to input windows, call the listeners
             // immediately.