Fix some cases when refresh rate switching didn't work/timed out (#901)

## Description
An attempt to fix #769

1. Always fetch the `DisplayManager` when switching refresh rates
2. Use the Activity context instead of Application context

### Related issues
Fixes #769

### Testing
I still haven't reproduced #769 myself, but this change works fine on my
shield + LG C2

## Screenshots
N/A

## AI or LLM usage
None
This commit is contained in:
Ray 2026-02-16 09:04:28 -05:00 committed by GitHub
parent 0276c5f49b
commit dc3c6dc739
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 19 deletions

View file

@ -28,21 +28,6 @@ class RefreshRateService
constructor(
@param:ApplicationContext private val context: Context,
) {
private val displayManager = context.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
private val display get() = displayManager.getDisplay(Display.DEFAULT_DISPLAY)
val supportedDisplayModes get() = display.supportedModes.orEmpty()
private val displayModes: List<DisplayMode> by lazy {
display.supportedModes
.orEmpty()
.map { DisplayMode(it) }
.sortedWith(
compareByDescending<DisplayMode>({ it.physicalWidth * it.physicalHeight })
.thenBy { it.refreshRateRounded },
)
}
/**
* Find the best display mode for the given stream and signal to change to it
*/
@ -55,6 +40,18 @@ class RefreshRateService
Timber.v("Not switching either refresh rate nor resolution")
return@withContext
}
val displayManager =
MainActivity.instance.getSystemService(Context.DISPLAY_SERVICE) as DisplayManager
val display = displayManager.getDisplay(Display.DEFAULT_DISPLAY)
val displayModes =
display.supportedModes
.orEmpty()
.map { DisplayMode(it) }
.sortedWith(
compareByDescending<DisplayMode>({ it.physicalWidth * it.physicalHeight })
.thenBy { it.refreshRateRounded },
)
val currentDisplayMode = display.mode
require(stream.type == MediaStreamType.VIDEO) { "Stream is not video" }
val width = stream.width