Skip to content

Commit 34ebc8a

Browse files
authored
Fix data store crash (#6392)
* Fix data store crash * fix * add known issue
1 parent db7bb16 commit 34ebc8a

6 files changed

Lines changed: 16 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ Mapbox welcomes participation and contributions from everyone.
66
#### Features
77
#### Bug fixes and improvements
88
- 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)
9+
- Fix crash due to multiple DataStores active. [#6392](https://github.com/mapbox/mapbox-navigation-android/pull/6392)
910

1011
## Mapbox Navigation SDK 2.9.0-alpha.3 - 23 September, 2022
1112
### Changelog
1213
[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)
1314

15+
#### Known issues
16+
17+
: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)
18+
1419
#### Features
1520
- Moved `MapboxAudioGuidance` and `MapboxAudioGuidanceState` into public api. [#6336](https://github.com/mapbox/mapbox-navigation-android/pull/6336)
1621
- Introduced `ViewOptionsCustomization.showCameraDebugInfo` to allow end users to enable camera debug info. [#6356](https://github.com/mapbox/mapbox-navigation-android/pull/6356)

libnavui-util/src/main/java/com/mapbox/navigation/ui/utils/internal/datastore/NavigationDataStoreOwner.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,9 @@ import kotlinx.coroutines.flow.map
1111
/**
1212
* Implementation for preferences that exist beyond app and car sessions.
1313
*/
14-
class NavigationDataStoreOwner(context: Context, storeName: String) {
14+
class NavigationDataStoreOwner(context: Context) {
1515

16-
private val Context.dataStore by preferencesDataStore(storeName)
17-
private var dataStore: DataStore<Preferences> = context.dataStore
16+
private val dataStore: DataStore<Preferences> = context.dataStore
1817

1918
fun <T> read(key: NavigationDataStoreKey<T>): Flow<T> {
2019
return dataStore.data.map { preferences ->
@@ -27,4 +26,9 @@ class NavigationDataStoreOwner(context: Context, storeName: String) {
2726
preferences[key.preferenceKey] = value ?: key.defaultValue
2827
}
2928
}
29+
30+
private companion object {
31+
private const val NAVIGATION_DATA_STORE_NAME = "mapbox_navigation_preferences"
32+
private val Context.dataStore by preferencesDataStore(name = NAVIGATION_DATA_STORE_NAME)
33+
}
3034
}

libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidance.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ internal constructor(
5454
*/
5555
override fun onAttached(mapboxNavigation: MapboxNavigation) {
5656
val context = mapboxNavigation.navigationOptions.applicationContext
57-
dataStoreOwner = audioGuidanceServices.dataStoreOwner(context, DEFAULT_DATA_STORE_NAME)
57+
dataStoreOwner = audioGuidanceServices.dataStoreOwner(context)
5858
configOwner = audioGuidanceServices.configOwner(context)
5959
mapboxVoiceInstructions.registerObservers(mapboxNavigation)
6060
job = scope.launch {
@@ -198,7 +198,6 @@ internal constructor(
198198
companion object {
199199
private val STORE_AUDIO_GUIDANCE_MUTED =
200200
booleanDataStoreKey("audio_guidance_muted", false)
201-
private const val DEFAULT_DATA_STORE_NAME = "mapbox_navigation_preferences"
202201

203202
/**
204203
* Construct an instance without registering to [MapboxNavigationApp].

libnavui-voice/src/main/java/com/mapbox/navigation/ui/voice/internal/impl/MapboxAudioGuidanceServices.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,5 @@ class MapboxAudioGuidanceServices {
4646

4747
fun configOwner(context: Context): NavigationConfigOwner = NavigationConfigOwner(context)
4848

49-
fun dataStoreOwner(context: Context, storeName: String) =
50-
NavigationDataStoreOwner(context, storeName)
49+
fun dataStoreOwner(context: Context) = NavigationDataStoreOwner(context)
5150
}

libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/TestMapboxAudioGuidanceServices.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class TestMapboxAudioGuidanceServices(
6363
every { mapboxVoiceInstructions() } returns mapboxVoiceInstructions
6464
every { mapboxAudioGuidanceVoice(any(), any()) } returns mapboxAudioGuidanceVoice
6565
every { configOwner(any()) } returns carAppConfigOwner
66-
every { dataStoreOwner(any(), any()) } returns dataStoreOwner
66+
every { dataStoreOwner(any()) } returns dataStoreOwner
6767
}
6868

6969
fun emitVoiceInstruction(state: MapboxVoiceInstructions.State) {

libnavui-voice/src/test/java/com/mapbox/navigation/ui/voice/api/MapboxAudioGuidanceTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class MapboxAudioGuidanceTest {
204204
mapboxAudioGuidanceServices.mapboxVoiceInstructions()
205205
}
206206
verifySequence {
207-
mapboxAudioGuidanceServices.dataStoreOwner(any(), any())
207+
mapboxAudioGuidanceServices.dataStoreOwner(any())
208208
mapboxAudioGuidanceServices.configOwner(any())
209209
mapboxAudioGuidanceServices.mapboxAudioGuidanceVoice(any(), "en")
210210
mapboxAudioGuidanceServices.mapboxAudioGuidanceVoice(any(), voiceLanguage)

0 commit comments

Comments
 (0)