diff --git a/app-mincompile/src/main/java/com/mapbox/navigation/examples/mincompile/DropInUIActivity.kt b/app-mincompile/src/main/java/com/mapbox/navigation/examples/mincompile/DropInUIActivity.kt index 73125df4e12..d37f93eb0cf 100644 --- a/app-mincompile/src/main/java/com/mapbox/navigation/examples/mincompile/DropInUIActivity.kt +++ b/app-mincompile/src/main/java/com/mapbox/navigation/examples/mincompile/DropInUIActivity.kt @@ -3,8 +3,6 @@ package com.mapbox.navigation.examples.mincompile import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import com.mapbox.navigation.examples.mincompile.databinding.LayoutActivityDropinBinding -import com.mapbox.navigation.examples.mincompile.databinding.LayoutActivityMainBinding -import com.mapbox.navigation.examples.mincompile.databinding.LayoutActivityNavigationBinding class DropInUIActivity : AppCompatActivity() { private lateinit var binding: LayoutActivityDropinBinding diff --git a/libnavigation-base/src/main/java/com/mapbox/navigation/base/internal/route/RouteCompatibilityCache.kt b/libnavigation-base/src/main/java/com/mapbox/navigation/base/internal/route/RouteCompatibilityCache.kt index c15fd9c68d3..363eae0bbd7 100644 --- a/libnavigation-base/src/main/java/com/mapbox/navigation/base/internal/route/RouteCompatibilityCache.kt +++ b/libnavigation-base/src/main/java/com/mapbox/navigation/base/internal/route/RouteCompatibilityCache.kt @@ -1,11 +1,12 @@ package com.mapbox.navigation.base.internal.route +import android.util.Log import android.util.LruCache import com.mapbox.api.directions.v5.models.DirectionsRoute import com.mapbox.navigation.base.route.NavigationRoute /** - * **Internal** cache object that aims to improve the performance performance of compatibility functions + * **Internal** cache object that aims to improve the performance of compatibility functions * that transform the [DirectionsRoute] route into a [NavigationRoute]. * * It caches up to 3 randomly created [NavigationRoute] instances, diff --git a/libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt b/libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt index ef8e5e3df4b..8d522e1d6ff 100644 --- a/libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt +++ b/libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt @@ -6,6 +6,7 @@ package com.mapbox.navigation.core import android.Manifest.permission.ACCESS_COARSE_LOCATION import android.Manifest.permission.ACCESS_FINE_LOCATION +import android.util.Log import androidx.annotation.RequiresPermission import androidx.annotation.UiThread import androidx.annotation.VisibleForTesting @@ -54,6 +55,7 @@ import com.mapbox.navigation.core.arrival.AutoArrivalController import com.mapbox.navigation.core.directions.LegacyNavigationRouterAdapter import com.mapbox.navigation.core.directions.LegacyRouterAdapter import com.mapbox.navigation.core.directions.session.DirectionsSession +import com.mapbox.navigation.core.directions.session.DirectionsSessionRoutes import com.mapbox.navigation.core.directions.session.RoutesExtra import com.mapbox.navigation.core.directions.session.RoutesObserver import com.mapbox.navigation.core.directions.session.RoutesSetStartedParams @@ -353,6 +355,8 @@ class MapboxNavigation @VisibleForTesting internal constructor( */ private val navigationVersionSwitchObservers = mutableSetOf() + private var directionsSessionRoutesToCache: DirectionsSessionRoutes? = null + /** * [MapboxNavigation.roadObjectsStore] provides methods to get road objects metadata, * add and remove custom road objects. diff --git a/libnavigation-core/src/main/java/com/mapbox/navigation/core/directions/session/MapboxDirectionsSession.kt b/libnavigation-core/src/main/java/com/mapbox/navigation/core/directions/session/MapboxDirectionsSession.kt index e6b1951623f..b81324436d2 100644 --- a/libnavigation-core/src/main/java/com/mapbox/navigation/core/directions/session/MapboxDirectionsSession.kt +++ b/libnavigation-core/src/main/java/com/mapbox/navigation/core/directions/session/MapboxDirectionsSession.kt @@ -46,7 +46,18 @@ internal class MapboxDirectionsSession( ) { return } - RouteCompatibilityCache.setDirectionsSessionResult(routes.acceptedRoutes) + + // A crash was reported due to an LruCache inconsistency. + // The caching implementation is using java.concurrent + // classes for synchronization. This method is getting called + // from a coroutine. Putting this call on it's own thread + // should make the synchronization in the RouteCompatibilityCache + // effective. + Thread { + run { + RouteCompatibilityCache.setDirectionsSessionResult(routes.acceptedRoutes) + } + } val result = routes.toRoutesUpdatedResult().also { routesUpdatedResult = it } onSetNavigationRoutesFinishedObservers.forEach { diff --git a/libnavigation-core/src/test/java/com/mapbox/navigation/core/MapboxNavigationTest.kt b/libnavigation-core/src/test/java/com/mapbox/navigation/core/MapboxNavigationTest.kt index 55118802625..71d9ca832cd 100644 --- a/libnavigation-core/src/test/java/com/mapbox/navigation/core/MapboxNavigationTest.kt +++ b/libnavigation-core/src/test/java/com/mapbox/navigation/core/MapboxNavigationTest.kt @@ -1821,7 +1821,6 @@ internal class MapboxNavigationTest : MapboxNavigationBaseTest() { alternativeWithId("id#2") ) val acceptedRoutes = listOf(inputRoutes[0], inputRoutes[2]) - val ignoredRoutes = listOf(IgnoredRoute(inputRoutes[1], invalidRouteReason)) coEvery { tripSession.setRoutes( inputRoutes, @@ -1848,9 +1847,6 @@ internal class MapboxNavigationTest : MapboxNavigationBaseTest() { coVerifyOrder { tripSession.setRoutes(inputRoutes, setRoutesInfo) - directionsSession.setNavigationRoutesFinished( - DirectionsSessionRoutes(acceptedRoutes, ignoredRoutes, setRoutesInfo) - ) tripSession.setRoutes(acceptedRoutes, setRoutesInfo) }