Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit da21f422 authored by Leon Scroggins III's avatar Leon Scroggins III
Browse files

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
parent 6f5ed5b8
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -127,6 +127,11 @@ void Scheduler::unregisterDisplay(PhysicalDisplayId displayId) {
    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();
}

+0 −3
Original line number Diff line number Diff line
@@ -301,9 +301,6 @@ TEST_F(SchedulerTest, chooseDisplayModesSingleDisplay) {
    choice = modeChoices.get(kDisplayId1);
    ASSERT_TRUE(choice);
    EXPECT_EQ(choice->get(), DisplayModeChoice({120_Hz, kDisplay1Mode120}, globalSignals));

    mScheduler->unregisterDisplay(kDisplayId1);
    EXPECT_FALSE(mScheduler->hasRefreshRateSelectors());
}

TEST_F(SchedulerTest, chooseDisplayModesMultipleDisplays) {
+0 −2
Original line number Diff line number Diff line
@@ -79,8 +79,6 @@ public:
        return mRefreshRateSelectors;
    }

    bool hasRefreshRateSelectors() const { return !refreshRateSelectors().empty(); }

    void registerDisplay(PhysicalDisplayId displayId, RefreshRateSelectorPtr selectorPtr) {
        ftl::FakeGuard guard(kMainThreadContext);
        Scheduler::registerDisplay(displayId, std::move(selectorPtr));