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.
Bug: 270894765
Test: presubmits
Test: manual fuzz testing (random sleeps added to input flinger listener)
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:a364bd7c0ecc412582eff1160368f3eaa2b4c6f0)
Merged-In: I78b39b10c52f4e4939f1741516d0edbe9898ef3c
Change-Id: I78b39b10c52f4e4939f1741516d0edbe9898ef3c
Change-Id: Ib796d8b459d2157b96acdb334404353ca6b1da61
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 494aa2c..5db7999 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -3257,8 +3257,11 @@
inputFlinger = mInputFlinger, this]() {
ATRACE_NAME("BackgroundExecutor::updateInputFlinger");
if (updateWindowInfo) {
- mWindowInfosListenerInvoker->windowInfosChanged(windowInfos, displayInfos,
- inputWindowCommands.syncInputWindows);
+ mWindowInfosListenerInvoker
+ ->windowInfosChanged(std::move(windowInfos), std::move(displayInfos),
+ /* shouldSync= */ inputWindowCommands.syncInputWindows,
+ /* forceImmediateCall= */
+ !inputWindowCommands.focusRequests.empty());
} else if (inputWindowCommands.syncInputWindows) {
// If the caller requested to sync input windows, but there are no
// changes to input windows, notify immediately.