Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions libnavigation-core/api/current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,6 @@ package com.mapbox.navigation.core.sensors {

package com.mapbox.navigation.core.telemetry {

public final class TelemetryLocationAndProgressDispatcherKt {
}

public final class TelemetryUtilsKt {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import com.mapbox.api.directions.v5.models.DirectionsRoute
import com.mapbox.api.directions.v5.models.RouteOptions
import com.mapbox.base.common.logger.Logger
import com.mapbox.base.common.logger.model.Message
import com.mapbox.base.common.logger.model.Tag
import com.mapbox.common.module.provider.MapboxModuleProvider
import com.mapbox.common.module.provider.ModuleProviderArgument
import com.mapbox.navigation.base.internal.VoiceUnit
Expand Down Expand Up @@ -192,7 +191,7 @@ class MapboxNavigation(
navigationSession.registerNavigationSessionStateObserver(navigationAccountsSession)
ifNonNull(accessToken) { token ->
logger.d(
Tag(MapboxNavigationTelemetry.TAG),
MapboxNavigationTelemetry.TAG,
Message("MapboxMetricsReporter.init from MapboxNavigation main")
)
MapboxMetricsReporter.init(
Expand All @@ -202,13 +201,10 @@ class MapboxNavigation(
)
MapboxMetricsReporter.toggleLogging(navigationOptions.isDebugLoggingEnabled)
MapboxNavigationTelemetry.initialize(
navigationOptions.applicationContext,
this,
MapboxMetricsReporter,
navigationOptions.locationEngine.javaClass.name,
ThreadController.getMainScopeAndRootJob(),
navigationOptions,
obtainUserAgent(navigationOptions.isFromNavigationUi)
MapboxMetricsReporter,
logger
)
}

Expand Down Expand Up @@ -331,8 +327,8 @@ class MapboxNavigation(
*/
fun onDestroy() {
logger.d(
Tag(MapboxNavigationTelemetry.TAG),
Message("onDestroy")
MapboxNavigationTelemetry.TAG,
Message("MapboxNavigation onDestroy")
)
MapboxNavigationTelemetry.unregisterListeners(this@MapboxNavigation)
directionsSession.shutdown()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.mapbox.navigation.core.telemetry

import android.location.Location

internal class EventLocations(
private val preEventLocations: List<Location>,
private val postEventLocations: MutableList<Location>,
private val onBufferFull: (List<Location>, List<Location>) -> Unit
) {
fun onBufferFull() {
onBufferFull(preEventLocations, postEventLocations)
}

fun addPostEventLocation(location: Location) {
postEventLocations.add(location)
}

fun postEventLocationsSize() = postEventLocations.size
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.mapbox.navigation.core.telemetry

import android.location.Location
import com.mapbox.navigation.core.trip.session.LocationObserver

internal interface LocationsCollector : LocationObserver {
val lastLocation: Location?

fun flushBuffers()
fun collectLocations(onBufferFull: (List<Location>, List<Location>) -> Unit)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.mapbox.navigation.core.telemetry

import android.location.Location
import com.mapbox.base.common.logger.Logger
import com.mapbox.base.common.logger.model.Message
import com.mapbox.navigation.core.telemetry.MapboxNavigationTelemetry.TAG

internal class LocationsCollectorImpl(
private val logger: Logger?
) : LocationsCollector {

companion object {
private const val LOCATION_BUFFER_MAX_SIZE = 20
}

private val locationsBuffer = mutableListOf<Location>()
private val eventsLocationsBuffer = mutableListOf<EventLocations>()

override val lastLocation: Location?
get() = locationsBuffer.lastOrNull()

private fun accumulatePostEventLocation(location: Location) {
val iterator = eventsLocationsBuffer.iterator()
while (iterator.hasNext()) {
iterator.next().let {
it.addPostEventLocation(location)
if (it.postEventLocationsSize() >= LOCATION_BUFFER_MAX_SIZE) {
it.onBufferFull()
iterator.remove()
}
}
}
}

private fun accumulateLocation(location: Location) {
locationsBuffer.run {
if (size >= LOCATION_BUFFER_MAX_SIZE) {
removeAt(0)
}
add(location)
}
}

override fun collectLocations(
onBufferFull: (List<Location>, List<Location>) -> Unit
) {
eventsLocationsBuffer.add(
EventLocations(
locationsBuffer.getCopy(),
mutableListOf(),
onBufferFull
)
)
}

override fun flushBuffers() {
logger?.d(TAG, Message("flush buffer. Pending events = ${eventsLocationsBuffer.size}"))
eventsLocationsBuffer.forEach { it.onBufferFull() }
eventsLocationsBuffer.clear()
}

override fun onRawLocationChanged(rawLocation: Location) {
accumulateLocation(rawLocation)
accumulatePostEventLocation(rawLocation)
}

override fun onEnhancedLocationChanged(enhancedLocation: Location, keyPoints: List<Location>) {
// Do nothing
}

@Synchronized
private fun <T> MutableList<T>.getCopy(): List<T> {
return mutableListOf<T>().also {
it.addAll(this)
}
}
}
Loading