Scheduler: Prevent removing the last display
unregisterDisplay calls promoteLeaderDisplay, which assumes that there
is at least one RefreshRateSelector remaining. Other Scheduler code also
assumes that there will be at least one display, which is necessary for
there to be a leader.
In SchedulerTest, remove the final call to unregisterDisplay, so we
don't put Scheduler in a bad state. Remove hasRefreshRateSelectors(),
since this condition must be true.
Bug: 241285191
Test: libsurfaceflinger_unittest
Change-Id: I827f20acd6a105d9f99e1ca9a7bfc59e633ab33f
diff --git a/services/surfaceflinger/Scheduler/Scheduler.cpp b/services/surfaceflinger/Scheduler/Scheduler.cpp
index 1e97f35..b8b3f51 100644
--- a/services/surfaceflinger/Scheduler/Scheduler.cpp
+++ b/services/surfaceflinger/Scheduler/Scheduler.cpp
@@ -127,6 +127,11 @@
std::scoped_lock lock(mDisplayLock);
mRefreshRateSelectors.erase(displayId);
+ // Do not allow removing the final display. Code in the scheduler expects
+ // there to be at least one display. (This may be relaxed in the future with
+ // headless virtual display.)
+ LOG_ALWAYS_FATAL_IF(mRefreshRateSelectors.empty(), "Cannot unregister all displays!");
+
promoteLeaderDisplay();
}