Skip to content

Commit

Permalink
Fix an error in logs related to performance statistics (#2310)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiryldz authored Mar 14, 2024
1 parent 1d89156 commit 96f9ed3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sdk/src/main/java/com/mapbox/maps/MapboxMap.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ class MapboxMap :

private val nativeMap: NativeMapImpl
private var isMapValid = true
private var performanceCollectionStatisticsStarted = false

/**
* Whether the [MapboxMap] instance is valid.
Expand Down Expand Up @@ -2079,6 +2080,7 @@ class MapboxMap :
) {
checkNativeMap("startPerformanceStatisticsCollection")
nativeMap.startPerformanceStatisticsCollection(options, callback)
performanceCollectionStatisticsStarted = true
}

/**
Expand All @@ -2092,6 +2094,7 @@ class MapboxMap :
fun stopPerformanceStatisticsCollection() {
checkNativeMap("stopPerformanceStatisticsCollection")
nativeMap.stopPerformanceStatisticsCollection()
performanceCollectionStatisticsStarted = false
}

/**
Expand Down Expand Up @@ -2165,7 +2168,9 @@ class MapboxMap :
@OptIn(MapboxExperimental::class)
@JvmSynthetic
internal fun onDestroy() {
stopPerformanceStatisticsCollection()
if (performanceCollectionStatisticsStarted) {
stopPerformanceStatisticsCollection()
}
cameraAnimationsPlugin = null
gesturesPlugin = null
styleObserver.onDestroy()
Expand Down
13 changes: 13 additions & 0 deletions sdk/src/test/java/com/mapbox/maps/MapboxMapTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,19 @@ class MapboxMapTest {
assertTrue(mapboxMap.gesturesPlugin == null)
}

@Test
fun onDestroyWhenPerformanceStatisticsStarted() {
mapboxMap.startPerformanceStatisticsCollection(mockk(), mockk())
mapboxMap.onDestroy()
verify(exactly = 1) { nativeMap.stopPerformanceStatisticsCollection() }
}

@Test
fun onDestroyWhenPerformanceStatisticsNotStarted() {
mapboxMap.onDestroy()
verify(exactly = 0) { nativeMap.stopPerformanceStatisticsCollection() }
}

@Test
fun loadStyleMapboxUri() {
Shadows.shadowOf(Looper.getMainLooper()).pause()
Expand Down

0 comments on commit 96f9ed3

Please sign in to comment.