FP5: Introduce priv-app to control refresh rate switching
Description
Introduce RefreshRateController priv-app to fix discrepancy between preferred refresh rate set in settings and actual refresh rate.
Screenshots
Technical details
On FP5, min_refresh_rate selected through Settings via MinRefreshRatePreferenceController does not get honored after display state change (screen on / off).
On FPOS, which uses QTI/Qualcomm components for SurfaceFlinger, they have specific handling in QtiExtension.
FPOS handles refresh rate switching as follows:
- User sets preferred refresh rate
- User toggles screen state (on / off)
- QTI SurfaceFlinger Extensions restore preferred refresh rate after a 5 second delay
Since modifying SurfaceFlinger to add QTI Extensions is too broad scope, we handle our needs through a priv-app which runs a service at boot.
Through testing, it was noted that in order to force a display state change to the proper refresh rate, we have to:
- Set
min_refresh_ratekey to0f - Set
min_refresh_ratekey to preferred refresh rate
Our RefreshRateController priv-app:
- Listens for
ACTION_LOCKED_BOOT_COMPLETEDevent inRefreshRateBroadcastReceiver - Triggers
RefreshRateMonitoringService, which handles setting and restoringmin_refresh_rate
RefreshRateMonitoringService also implements DisplayManager.DisplayListener class and does following:
- On service creation, register listener for tracking display mode and state changes
- Initializes internal global variables which keep track of display mode, state, min_fps & refresh rate switching progress.
If min_refresh_rate is not present, it will get current refresh rate and set min_refresh_rate to that refresh rate.
This is for handling case when min_refresh_rate key is missing due to any unexpected reasons.
In normal case, when user sets preferred refresh rate through settings, min_refresh_rate is populated and retained across reboots.
Whenever display turns on, our service will reset and set min_refresh_rate key to value user has chosen.
This forces a display mode change and successfully applies preferred refresh rate.
Setting the preferred refresh rate into min_refresh_rate is done after 250ms of resetting min_refresh_rate to allow mode change to fully propagate.
Tests
Set Minimum refresh rate in Settings -> Display to 60hz
- Observe refresh rate through testufo.com and through manual testing by interacting with UI
- Lock and unlock screen and check refresh rate
- Reboot device and check refresh rate
Set Minimum refresh rate in Settings -> Display to 90hz
- Observe refresh rate through testufo.com and through manual testing by interacting with UI
- Lock and unlock screen and check refresh rate
- Reboot device and check refresh rate
Issues
https://gitlab.e.foundation/e/backlog/-/issues/7590