Skip to content

Commit ef32eb9

Browse files
pengdevgithub-actions[bot]
authored andcommitted
[MAPSAND-2265] Fix MapSurface.setMaximumFps not working on secondary displays (#10405)
### Summary Fixes https://mapbox.atlassian.net/browse/MAPSAND-2265 - Fix `MapSurface.setMaximumFps` returning wrong FPS on secondary displays (e.g. Android Auto) - Use `Context.getDisplay()` on API 30+ instead of `WindowManager.defaultDisplay` - Change is confined to a single method in `MapSurface.kt` ### Problem `MapSurface.surfaceCreated()` reads the screen refresh rate via `WindowManager.defaultDisplay.refreshRate`, which always returns the **primary display's** refresh rate. When `MapSurface` runs on a secondary display (e.g. Android Auto at 60Hz) with a 120Hz primary display, `setMaximumFps(30)` produces ~60fps instead of 30fps. The `FpsManager` receives 120Hz as the screen rate, yielding a ratio of 30/120=0.25 instead of the correct 30/60=0.5. ### Solution On API 30+ (`Build.VERSION_CODES.R`), use `Context.getDisplay()` to obtain the display the surface is actually attached to, consistent with how `MapView.onStart()` already uses `View.getDisplay()`. Fall back to the deprecated `WindowManager.defaultDisplay` on older APIs. ### Key Changes - **`MapSurface.kt` `surfaceCreated()`**: `WindowManager.defaultDisplay.refreshRate` → `Context.getDisplay().refreshRate` (API 30+) ### Note on reproduction I was not able to reproduce the exact issue described in the ticket. My test setup: phone with 120Hz display + Android Auto emulator supporting 60fps. Both `context.display.refreshRate` and `(context.getSystemService(Context.WINDOW_SERVICE) as WindowManager?)?.defaultDisplay?.refreshRate` returned 60, and the Android Auto refresh rate can be correctly set to 30fps both before and after the change. It might require a specific device/head unit combination to reproduce the discrepancy. ### Validation - [x] Manual test: `setMaximumFps(30)` on a 60Hz secondary display produces ~30fps as expected cc @mapbox/maps-android GitOrigin-RevId: ab04871940ea3b605a7c0e6894a1975fb6f448ba
1 parent a179e9d commit ef32eb9

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ Mapbox welcomes participation and contributions from everyone.
1111

1212
## Bug fixes 🐞
1313
* Fix NPE crash in `PointAnnotationClusterActivity` example when the remote GeoJSON endpoint returns a non-successful HTTP response.
14+
* Fix `MapSurface.setMaximumFps` not working correctly on secondary displays (e.g. Android Auto). Use `Context.getDisplay()` on API 30+ to get the actual display refresh rate instead of always using the primary display's rate.
15+
1416
# 11.19.0 February 24, 2026
1517
## Dependencies
1618
* Update gl-native to [v11.19.0](https://github.com/mapbox/mapbox-maps-android/releases/tag/v11.19.0), common to [v24.19.0](https://github.com/mapbox/mapbox-maps-android/releases/tag/v11.19.0).
1719

18-
1920
# 11.19.0-rc.1 February 12, 2026
2021

2122
## Features ✨ and improvements 🏁

maps-sdk/src/main/java/com/mapbox/maps/MapSurface.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.mapbox.maps
22

33
import android.content.Context
44
import android.graphics.Bitmap
5+
import android.os.Build
56
import android.view.MotionEvent
67
import android.view.Surface
78
import android.view.WindowManager
@@ -95,9 +96,13 @@ class MapSurface : MapPluginProviderDelegate, MapControllable {
9596
fallback = MapView.DEFAULT_FPS,
9697
logTag = TAG,
9798
operation = {
98-
@Suppress("DEPRECATION")
99-
(context.getSystemService(Context.WINDOW_SERVICE) as WindowManager?)
100-
?.defaultDisplay?.refreshRate?.toInt() ?: MapView.DEFAULT_FPS
99+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
100+
context.display.refreshRate.toInt()
101+
} else {
102+
@Suppress("DEPRECATION")
103+
(context.getSystemService(Context.WINDOW_SERVICE) as WindowManager?)
104+
?.defaultDisplay?.refreshRate?.toInt() ?: MapView.DEFAULT_FPS
105+
}
101106
}
102107
) { screenRefreshRate ->
103108
mapController.setScreenRefreshRate(screenRefreshRate)

0 commit comments

Comments
 (0)