Skip to content

Commit 8fe7cc6

Browse files
authored
Remove unnecessary checks for mapbox tracing, improved documentation. (#3015)
1 parent 630e9ce commit 8fe7cc6

File tree

2 files changed

+7
-56
lines changed

2 files changed

+7
-56
lines changed

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

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package com.mapbox.maps
22

3-
import android.content.pm.ApplicationInfo
4-
import androidx.annotation.VisibleForTesting
5-
import com.mapbox.common.MapboxSDKCommon
6-
73
/**
84
* Allows to control several levels of tracing that could be useful to understand the performance of Mapbox Maps.
95
* For more details about Android tracing refer to relevant section of DEVELOPING.md file.
@@ -13,29 +9,14 @@ object MapboxTracing {
139
internal const val MAPBOX_TRACE_ID = "mbx"
1410

1511
internal var platformTracingEnabled = false
16-
@VisibleForTesting(otherwise = VisibleForTesting.PRIVATE)
17-
internal var tracerAvailable: Boolean? = null
18-
19-
private fun checkTracerEnabled() {
20-
if (tracerAvailable == null) {
21-
tracerAvailable =
22-
MapboxSDKCommon.getContext().applicationInfo.flags != 0 and ApplicationInfo.FLAG_DEBUGGABLE
23-
}
24-
if (tracerAvailable == false) {
25-
throw RuntimeException(
26-
"Mapbox Tracing could not be used as build is not debuggable!" +
27-
" You could enable it by setting android:debuggable=\"true\" in AndroidManifest <application> block."
28-
)
29-
}
30-
}
3112

3213
/**
3314
* Enable all the traces: native rendering engine traces and Android Maps SDK traces.
3415
*
35-
* @throws [RuntimeException] if build is not debuggable.
16+
* Enabling Mapbox tracing is only recommended for local performance measurements, to capture accurate results.
17+
* This tracing is designed to be usable in release builds to enable local profiling.
3618
*/
3719
fun enableAll() {
38-
checkTracerEnabled()
3920
platformTracingEnabled = true
4021
Tracing.setTracingBackendType(TracingBackendType.PLATFORM)
4122
}
@@ -46,7 +27,6 @@ object MapboxTracing {
4627
* @throws [RuntimeException] if build is not debuggable.
4728
*/
4829
fun enablePlatform() {
49-
checkTracerEnabled()
5030
platformTracingEnabled = true
5131
}
5232

@@ -56,7 +36,6 @@ object MapboxTracing {
5636
* @throws [RuntimeException] if build is not debuggable.
5737
*/
5838
fun enableCore() {
59-
checkTracerEnabled()
6039
Tracing.setTracingBackendType(TracingBackendType.PLATFORM)
6140
}
6241

@@ -66,7 +45,6 @@ object MapboxTracing {
6645
* @throws [RuntimeException] if build is not debuggable.
6746
*/
6847
fun disableAll() {
69-
checkTracerEnabled()
7048
platformTracingEnabled = false
7149
Tracing.setTracingBackendType(TracingBackendType.NOOP)
7250
}

maps-sdk/src/test/java/com/mapbox/maps/MapboxTracingTest.kt

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -23,61 +23,34 @@ class MapboxTracingTest {
2323
@After
2424
fun cleanUp() {
2525
unmockkStatic("com.mapbox.maps.Tracing")
26+
MapboxTracing.disableAll()
2627
}
2728

2829
@Test
29-
fun enableAllTracerAvailable() {
30-
MapboxTracing.tracerAvailable = true
30+
fun enableAll() {
3131
MapboxTracing.enableAll()
3232
verifyOnce { Tracing.setTracingBackendType(TracingBackendType.PLATFORM) }
3333
assert(MapboxTracing.platformTracingEnabled)
3434
}
3535

36-
@Test(expected = RuntimeException::class)
37-
fun enableAllTracerNotAvailable() {
38-
MapboxTracing.tracerAvailable = false
39-
MapboxTracing.enableAll()
40-
}
41-
4236
@Test
43-
fun enablePlatformTracerAvailable() {
44-
MapboxTracing.tracerAvailable = true
37+
fun enablePlatform() {
4538
MapboxTracing.enablePlatform()
4639
verifyNo { Tracing.setTracingBackendType(any()) }
4740
assert(MapboxTracing.platformTracingEnabled)
4841
}
4942

50-
@Test(expected = RuntimeException::class)
51-
fun enablePlatformTracerNotAvailable() {
52-
MapboxTracing.tracerAvailable = false
53-
MapboxTracing.enablePlatform()
54-
}
55-
5643
@Test
57-
fun enableCoreTracerAvailable() {
58-
MapboxTracing.tracerAvailable = true
44+
fun enableCore() {
5945
MapboxTracing.enableCore()
6046
verifyOnce { Tracing.setTracingBackendType(TracingBackendType.PLATFORM) }
6147
assert(!MapboxTracing.platformTracingEnabled)
6248
}
6349

64-
@Test(expected = RuntimeException::class)
65-
fun enableCoreTracerNotAvailable() {
66-
MapboxTracing.tracerAvailable = false
67-
MapboxTracing.enableCore()
68-
}
69-
7050
@Test
71-
fun disableAllTracerAvailable() {
72-
MapboxTracing.tracerAvailable = true
51+
fun disableAll() {
7352
MapboxTracing.disableAll()
7453
verifyOnce { Tracing.setTracingBackendType(TracingBackendType.NOOP) }
7554
assert(!MapboxTracing.platformTracingEnabled)
7655
}
77-
78-
@Test(expected = RuntimeException::class)
79-
fun disableAllTracerNotAvailable() {
80-
MapboxTracing.tracerAvailable = false
81-
MapboxTracing.disableAll()
82-
}
8356
}

0 commit comments

Comments
 (0)