@@ -96,7 +96,7 @@ import com.mapbox.navigation.core.routerefresh.RouteRefreshController
9696import com.mapbox.navigation.core.routerefresh.RouteRefreshControllerProvider
9797import com.mapbox.navigation.core.sensor.SensorData
9898import com.mapbox.navigation.core.sensor.UpdateExternalSensorDataCallback
99- import com.mapbox.navigation.core.telemetry.MapboxNavigationTelemetry
99+ import com.mapbox.navigation.core.telemetry.TelemetryWrapper
100100import com.mapbox.navigation.core.telemetry.events.FeedbackEvent
101101import com.mapbox.navigation.core.telemetry.events.FeedbackHelper
102102import com.mapbox.navigation.core.telemetry.events.FeedbackMetadata
@@ -126,8 +126,6 @@ import com.mapbox.navigation.core.trip.session.eh.EHorizonObserver
126126import com.mapbox.navigation.core.trip.session.eh.GraphAccessor
127127import com.mapbox.navigation.core.trip.session.eh.RoadObjectMatcher
128128import com.mapbox.navigation.core.trip.session.eh.RoadObjectsStore
129- import com.mapbox.navigation.metrics.MapboxMetricsReporter
130- import com.mapbox.navigation.metrics.internal.TelemetryUtilsDelegate
131129import com.mapbox.navigation.navigator.internal.MapboxNativeNavigator
132130import com.mapbox.navigation.navigator.internal.NavigatorLoader
133131import com.mapbox.navigation.navigator.internal.router.RouterInterfaceAdapter
@@ -255,11 +253,15 @@ private const val MAPBOX_NOTIFICATION_ACTION_CHANNEL = "notificationActionButton
255253class MapboxNavigation @VisibleForTesting internal constructor(
256254 val navigationOptions : NavigationOptions ,
257255 private val threadController : ThreadController ,
256+ private val telemetryWrapper : TelemetryWrapper = TelemetryWrapper (),
258257) {
259258
260- constructor (navigationOptions: NavigationOptions ) : this (navigationOptions, ThreadController ())
259+ constructor (navigationOptions: NavigationOptions ) : this (
260+ navigationOptions,
261+ ThreadController (),
262+ TelemetryWrapper (),
263+ )
261264
262- private val accessToken: String? = navigationOptions.accessToken
263265 private val mainJobController = threadController.getMainScopeAndRootJob()
264266 private val directionsSession: DirectionsSession
265267 private var navigator: MapboxNativeNavigator
@@ -473,7 +475,7 @@ class MapboxNavigation @VisibleForTesting internal constructor(
473475 val result = MapboxModuleProvider .createModule<Router >(MapboxModuleType .NavigationRouter ) {
474476 paramsProvider(
475477 ModuleParams .NavigationRouter (
476- accessToken
478+ navigationOptions. accessToken
477479 ? : throw RuntimeException (MAPBOX_NAVIGATION_TOKEN_EXCEPTION_ROUTER ),
478480 nativeRouter,
479481 threadController,
@@ -568,25 +570,11 @@ class MapboxNavigation @VisibleForTesting internal constructor(
568570 arrivalProgressObserver
569571 )
570572
571- ifNonNull(accessToken) { token ->
572- runInTelemetryContext { telemetry ->
573- logD(
574- " MapboxMetricsReporter.init from MapboxNavigation main" ,
575- telemetry.LOG_CATEGORY
576- )
577- MapboxMetricsReporter .init (
578- navigationOptions.applicationContext,
579- token,
580- obtainUserAgent()
581- )
582- MapboxMetricsReporter .toggleLogging(navigationOptions.isDebugLoggingEnabled)
583- telemetry.initialize(
584- this ,
585- navigationOptions,
586- MapboxMetricsReporter ,
587- )
588- }
589- }
573+ telemetryWrapper.initialize(
574+ mapboxNavigation = this ,
575+ navigationOptions = navigationOptions,
576+ userAgent = obtainUserAgent(),
577+ )
590578
591579 val routeOptionsProvider = RouteOptionsUpdater ()
592580
@@ -1298,9 +1286,7 @@ class MapboxNavigation @VisibleForTesting internal constructor(
12981286 @OptIn(ExperimentalPreviewMapboxNavigationAPI ::class )
12991287 routeRefreshController.destroy()
13001288 routesPreviewController.unregisterAllRoutesPreviewObservers()
1301- runInTelemetryContext { telemetry ->
1302- telemetry.destroy(this @MapboxNavigation)
1303- }
1289+ telemetryWrapper.destroy()
13041290 threadController.cancelAllNonUICoroutines()
13051291 threadController.cancelAllUICoroutines()
13061292 ifNonNull(reachabilityObserverId) {
@@ -1756,17 +1742,15 @@ class MapboxNavigation @VisibleForTesting internal constructor(
17561742 feedbackMetadata : FeedbackMetadata ? ,
17571743 userFeedbackCallback : UserFeedbackCallback ? ,
17581744 ) {
1759- runInTelemetryContext { telemetry ->
1760- telemetry.postUserFeedback(
1761- feedbackType,
1762- description,
1763- feedbackSource,
1764- screenshot,
1765- feedbackSubType,
1766- feedbackMetadata,
1767- userFeedbackCallback,
1768- )
1769- }
1745+ telemetryWrapper.postUserFeedback(
1746+ feedbackType,
1747+ description,
1748+ feedbackSource,
1749+ screenshot,
1750+ feedbackSubType,
1751+ feedbackMetadata,
1752+ userFeedbackCallback,
1753+ )
17701754 }
17711755
17721756 @ExperimentalPreviewMapboxNavigationAPI
@@ -1775,13 +1759,11 @@ class MapboxNavigation @VisibleForTesting internal constructor(
17751759 @CustomEvent.Type customEventType : String ,
17761760 customEventVersion : String ,
17771761 ) {
1778- runInTelemetryContext { telemetry ->
1779- telemetry.postCustomEvent(
1780- payload = payload,
1781- customEventType = customEventType,
1782- customEventVersion = customEventVersion
1783- )
1784- }
1762+ telemetryWrapper.postCustomEvent(
1763+ payload = payload,
1764+ customEventType = customEventType,
1765+ customEventVersion = customEventVersion
1766+ )
17851767 }
17861768
17871769 /* *
@@ -1794,9 +1776,7 @@ class MapboxNavigation @VisibleForTesting internal constructor(
17941776 */
17951777 @ExperimentalPreviewMapboxNavigationAPI
17961778 fun provideFeedbackMetadataWrapper (): FeedbackMetadataWrapper =
1797- runInTelemetryContext { telemetry ->
1798- telemetry.provideFeedbackMetadataWrapper()
1799- } ? : throw java.lang.IllegalStateException (
1779+ telemetryWrapper.provideFeedbackMetadataWrapper() ? : throw java.lang.IllegalStateException (
18001780 " To get FeedbackMetadataWrapper Telemetry must be enabled"
18011781 )
18021782
@@ -2170,14 +2150,6 @@ class MapboxNavigation @VisibleForTesting internal constructor(
21702150 }
21712151 }
21722152
2173- private inline fun <T > runInTelemetryContext (func : (MapboxNavigationTelemetry ) -> T ): T ? {
2174- return if (TelemetryUtilsDelegate .getEventsCollectionState()) {
2175- func(MapboxNavigationTelemetry )
2176- } else {
2177- null
2178- }
2179- }
2180-
21812153 private fun obtainUserAgent (): String {
21822154 return " $MAPBOX_NAVIGATION_USER_AGENT_BASE /${BuildConfig .MAPBOX_NAVIGATION_VERSION_NAME } "
21832155 }
0 commit comments