Skip to content

Commit 8248c1f

Browse files
authored
NAVAND-1025: fix the crash in MapboxVoiceInstructionsPlayer (#6760)
1 parent 0077240 commit 8248c1f

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Mapbox welcomes participation and contributions from everyone.
2424
}
2525
```
2626
- Added guarantees that route progress with `RouteProgress#currentState == OFF_ROUTE` arrives earlier than `NavigationRerouteController#reroute` is called. [#6764](https://github.com/mapbox/mapbox-navigation-android/pull/6764)
27+
- Fixed a rare `java.lang.NullPointerException: Attempt to read from field 'SpeechAnnouncement PlayCallback.announcement' on a null object reference` crash in `PlayCallback.getAnnouncement`. [#6760](https://github.com/mapbox/mapbox-navigation-android/pull/6760)
2728

2829
## Mapbox Navigation SDK 2.10.0-rc.1 - 16 December, 2022
2930
### Changelog

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ class MapboxVoiceInstructionsPlayer @JvmOverloads constructor(
9292
abandonFocus()
9393
}
9494

95-
val currentAnnouncement = currentPlayCallback.announcement
96-
val currentClientCallback = currentPlayCallback.consumer
97-
currentClientCallback.accept(currentAnnouncement)
95+
if (currentPlayCallback != null) {
96+
val currentAnnouncement = currentPlayCallback.announcement
97+
val currentClientCallback = currentPlayCallback.consumer
98+
currentClientCallback.accept(currentAnnouncement)
99+
}
98100
play()
99101
}
100102

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,32 @@ class MapboxVoiceInstructionsPlayerTest {
633633
}
634634
}
635635

636+
@Test
637+
fun `play is done after clear`() {
638+
val anyLanguage = Locale.US.language
639+
val mockedAnnouncement: SpeechAnnouncement = mockk(relaxed = true)
640+
val mapboxVoiceInstructionsPlayer =
641+
MapboxVoiceInstructionsPlayer(
642+
aMockedContext,
643+
anyLanguage,
644+
mockedPlayerOptions
645+
)
646+
val mockedPlay: SpeechAnnouncement = mockedAnnouncement
647+
val voiceInstructionsPlayerConsumer =
648+
mockk<MapboxNavigationConsumer<SpeechAnnouncement>>(relaxed = true)
649+
650+
val requestSlotCallback = slot<AudioFocusRequestCallback>()
651+
every {
652+
mockedAudioFocusDelegate.requestFocus(any(), capture(requestSlotCallback))
653+
} just Runs
654+
mapboxVoiceInstructionsPlayer.play(mockedPlay, voiceInstructionsPlayerConsumer)
655+
mapboxVoiceInstructionsPlayer.clear()
656+
657+
requestSlotCallback.captured.invoke(false)
658+
659+
verify(exactly = 0) { voiceInstructionsPlayerConsumer.accept(any()) }
660+
}
661+
636662
private fun given(
637663
audioFocusResult: Boolean,
638664
filePlayerCallbackAnswer: (VoiceInstructionsPlayerCallback) -> Unit,

0 commit comments

Comments
 (0)