SF: Obey active display's RefreshRateConfigs

When a display becomes active, apply its RefreshRateConfigs' policy,
as it may have changed while the display was inactive.

When booting while folded, DisplayManager first sends DisplayModeSpecs
for each display, and then powers on the outer display. Before this CL,
the outer display would become the new active display, but its
DisplayManagerPolicy would never be applied.

This backport also includes I63d21c2216a3ab864b040bdb2c9e8fba0768b66a
for expanded unit tests.

Bug: 250421145
Test: Force 120 Hz, and reboot while folded.
Test: SetPowerModeInternalTest.activeDisplay{Boot,Single,Dual}
Change-Id: I15e0f5a280e62baf6d4e6ea2748d95342e79ac44
Merged-In: I15e0f5a280e62baf6d4e6ea2748d95342e79ac44
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index a701fe3..1880734 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -6942,9 +6942,12 @@
         return NO_ERROR;
     }
 
-    scheduler::RefreshRateConfigs::Policy currentPolicy =
-            display->refreshRateConfigs().getCurrentPolicy();
+    return applyRefreshRateConfigsPolicy(display);
+}
 
+status_t SurfaceFlinger::applyRefreshRateConfigsPolicy(const sp<DisplayDevice>& display) {
+    const scheduler::RefreshRateConfigs::Policy currentPolicy =
+            display->refreshRateConfigs().getCurrentPolicy();
     ALOGV("Setting desired display mode specs: %s", currentPolicy.toString().c_str());
 
     // TODO(b/140204874): Leave the event in until we do proper testing with all apps that might
@@ -7317,9 +7320,11 @@
     onActiveDisplaySizeChanged(activeDisplay);
     mActiveDisplayTransformHint = activeDisplay->getTransformHint();
 
-    // Update the kernel timer for the current active display, since the policy
-    // for this display might have changed when it was not the active display.
-    toggleKernelIdleTimer();
+    // The policy of the new active/leader display may have changed while it was inactive. In that
+    // case, its preferred mode has not been propagated to HWC (via setDesiredActiveMode). In either
+    // case, the Scheduler's cachedModeChangedParams must be initialized to the newly active mode,
+    // and the kernel idle timer of the newly active display must be toggled.
+    applyRefreshRateConfigsPolicy(activeDisplay);
 }
 
 status_t SurfaceFlinger::addWindowInfosListener(