diff --git a/CHANGELOG.md b/CHANGELOG.md index 25498834dfc..eda2ba4bd54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,11 +6,16 @@ Mapbox welcomes participation and contributions from everyone. #### Features #### Bug fixes and improvements - Marked `ReplayProgressObserver`, `MapboxReplayer`, `ReplayLocationEngine`, `RerouteController#RoutesCallback`, `NavigationRerouteController#RoutesCallback`, `LocationObserver`, `NavigationSessionStateObserver`, `OffRouteObserver`, `RouteProgressObserver`, `TripSessionStateObserver`, `VoiceInstructionsObserver` methods with `@UiThread` annotation. [#6266](https://github.com/mapbox/mapbox-navigation-android/pull/6266) +- Fix crash due to multiple DataStores active. [#6392](https://github.com/mapbox/mapbox-navigation-android/pull/6392) ## Mapbox Navigation SDK 2.9.0-alpha.3 - 23 September, 2022 ### Changelog [Changes between v2.9.0-alpha.2 and v2.9.0-alpha.3](https://github.com/mapbox/mapbox-navigation-android/compare/v2.9.0-alpha.2...v2.9.0-alpha.3) +#### Known issues + +:bangbang: `MapboxAudioGuidance` crashes when attached to new instances of `MapboxNavigation`. This will crash `ui-androidauto` and `ui-dropin`. There is no known work around and it will be fixed in 2.9.0-alpha.4. [#6392](https://github.com/mapbox/mapbox-navigation-android/pull/6392) + #### Features - Moved `MapboxAudioGuidance` and `MapboxAudioGuidanceState` into public api. [#6336](https://github.com/mapbox/mapbox-navigation-android/pull/6336) - Introduced `ViewOptionsCustomization.showCameraDebugInfo` to allow end users to enable camera debug info. [#6356](https://github.com/mapbox/mapbox-navigation-android/pull/6356) diff --git a/libnavui-util/src/main/java/com/mapbox/navigation/ui/utils/internal/datastore/NavigationDataStoreOwner.kt b/libnavui-util/src/main/java/com/mapbox/navigation/ui/utils/internal/datastore/NavigationDataStoreOwner.kt index e9a50beb3e9..cc42673a65e 100644 --- a/libnavui-util/src/main/java/com/mapbox/navigation/ui/utils/internal/datastore/NavigationDataStoreOwner.kt +++ b/libnavui-util/src/main/java/com/mapbox/navigation/ui/utils/internal/datastore/NavigationDataStoreOwner.kt @@ -11,10 +11,9 @@ import kotlinx.coroutines.flow.map /** * Implementation for preferences that exist beyond app and car sessions. */ -class NavigationDataStoreOwner(context: Context, storeName: String) { +class NavigationDataStoreOwner(context: Context) { - private val Context.dataStore by preferencesDataStore(storeName) - private var dataStore: DataStore = context.dataStore + private val dataStore: DataStore = context.dataStore fun read(key: NavigationDataStoreKey): Flow { return dataStore.data.map { preferences -> @@ -27,4 +26,9 @@ class NavigationDataStoreOwner(context: Context, storeName: String) { preferences[key.preferenceKey] = value ?: key.defaultValue } } + + private companion object { + private const val NAVIGATION_DATA_STORE_NAME = "mapbox_navigation_preferences" + private val Context.dataStore by preferencesDataStore(name = NAVIGATION_DATA_STORE_NAME) + } } diff --git a/libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidance.kt b/libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidance.kt index 517593ceaea..ff75a7914b2 100644 --- a/libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidance.kt +++ b/libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidance.kt @@ -54,7 +54,7 @@ internal constructor( */ override fun onAttached(mapboxNavigation: MapboxNavigation) { val context = mapboxNavigation.navigationOptions.applicationContext - dataStoreOwner = audioGuidanceServices.dataStoreOwner(context, DEFAULT_DATA_STORE_NAME) + dataStoreOwner = audioGuidanceServices.dataStoreOwner(context) configOwner = audioGuidanceServices.configOwner(context) mapboxVoiceInstructions.registerObservers(mapboxNavigation) job = scope.launch { @@ -198,7 +198,6 @@ internal constructor( companion object { private val STORE_AUDIO_GUIDANCE_MUTED = booleanDataStoreKey("audio_guidance_muted", false) - private const val DEFAULT_DATA_STORE_NAME = "mapbox_navigation_preferences" /** * Construct an instance without registering to [MapboxNavigationApp]. diff --git a/libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/internal/impl/MapboxAudioGuidanceServices.kt b/libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/internal/impl/MapboxAudioGuidanceServices.kt index 764820d3776..696a6c2c1bd 100644 --- a/libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/internal/impl/MapboxAudioGuidanceServices.kt +++ b/libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/internal/impl/MapboxAudioGuidanceServices.kt @@ -46,6 +46,5 @@ class MapboxAudioGuidanceServices { fun configOwner(context: Context): NavigationConfigOwner = NavigationConfigOwner(context) - fun dataStoreOwner(context: Context, storeName: String) = - NavigationDataStoreOwner(context, storeName) + fun dataStoreOwner(context: Context) = NavigationDataStoreOwner(context) } diff --git a/libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/TestMapboxAudioGuidanceServices.kt b/libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/TestMapboxAudioGuidanceServices.kt index ab17cedc8b8..ede31eef73a 100644 --- a/libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/TestMapboxAudioGuidanceServices.kt +++ b/libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/TestMapboxAudioGuidanceServices.kt @@ -63,7 +63,7 @@ class TestMapboxAudioGuidanceServices( every { mapboxVoiceInstructions() } returns mapboxVoiceInstructions every { mapboxAudioGuidanceVoice(any(), any()) } returns mapboxAudioGuidanceVoice every { configOwner(any()) } returns carAppConfigOwner - every { dataStoreOwner(any(), any()) } returns dataStoreOwner + every { dataStoreOwner(any()) } returns dataStoreOwner } fun emitVoiceInstruction(state: MapboxVoiceInstructions.State) { diff --git a/libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidanceTest.kt b/libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidanceTest.kt index dcad7f2483b..7754e4cfe2f 100644 --- a/libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidanceTest.kt +++ b/libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidanceTest.kt @@ -204,7 +204,7 @@ class MapboxAudioGuidanceTest { mapboxAudioGuidanceServices.mapboxVoiceInstructions() } verifySequence { - mapboxAudioGuidanceServices.dataStoreOwner(any(), any()) + mapboxAudioGuidanceServices.dataStoreOwner(any()) mapboxAudioGuidanceServices.configOwner(any()) mapboxAudioGuidanceServices.mapboxAudioGuidanceVoice(any(), "en") mapboxAudioGuidanceServices.mapboxAudioGuidanceVoice(any(), voiceLanguage)