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
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,7 @@ class MapboxNavigation @VisibleForTesting internal constructor(
navigatorConfig,
)
historyRecorderHandles = createHistoryRecorderHandles(config)

mainJobController.scope.launch {
navigator.recreate(
config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ internal class MapboxTripSession(
override fun start(withTripService: Boolean, withReplayEnabled: Boolean) {
if (state != TripSessionState.STARTED) {
navigator.addNavigatorObserver(navigatorObserver)
navigator.startNavigationSession()
if (withTripService) {
tripService.startService()
}
Expand Down Expand Up @@ -364,6 +365,7 @@ internal class MapboxTripSession(
if (state == TripSessionState.STOPPED) {
return
}
navigator.stopNavigationSession()
navigator.removeNavigatorObserver(navigatorObserver)
tripService.stopService()
tripSessionLocationEngine.stopLocationUpdates()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,12 @@ class MapboxTripSessionTest {
tripSession.start(true)

assertTrue(tripSession.isRunningWithForegroundService())
verify { tripService.startService() }
verify { tripSessionLocationEngine.startLocationUpdates(any(), any()) }

verifyOrder {
navigator.startNavigationSession()
tripService.startService()
tripSessionLocationEngine.startLocationUpdates(any(), any())
}

tripSession.stop()
}
Expand All @@ -234,7 +238,10 @@ class MapboxTripSessionTest {

assertFalse(tripSession.isRunningWithForegroundService())
verify(exactly = 0) { tripService.startService() }
verify { tripSessionLocationEngine.startLocationUpdates(any(), any()) }
verifyOrder {
navigator.startNavigationSession()
tripSessionLocationEngine.startLocationUpdates(any(), any())
}

tripSession.stop()
}
Expand All @@ -249,9 +256,11 @@ class MapboxTripSessionTest {

verifyOrder {
navigator.addNavigatorObserver(any())
navigator.startNavigationSession()
tripService.startService()
tripSessionLocationEngine.startLocationUpdates(any(), any())
tripSessionLocationEngine.startLocationUpdates(any(), any())
navigator.stopNavigationSession()
navigator.removeNavigatorObserver(any())
tripSession.stop()
tripSessionLocationEngine.stopLocationUpdates()
Expand All @@ -267,10 +276,12 @@ class MapboxTripSessionTest {

verifyOrder {
navigator.addNavigatorObserver(any())
navigator.startNavigationSession()
tripService.startService()
tripSessionLocationEngine.startLocationUpdates(false, any())
tripSessionLocationEngine.startLocationUpdates(true, any())
tripSessionLocationEngine.startLocationUpdates(false, any())
navigator.stopNavigationSession()
navigator.removeNavigatorObserver(any())
tripSession.stop()
tripSessionLocationEngine.stopLocationUpdates()
Expand All @@ -286,6 +297,15 @@ class MapboxTripSessionTest {
verify { tripService.stopService() }
}

@Test
fun stopSessionStoppingNativeNavigationSession() {
tripSession.start(true)

tripSession.stop()

verify(exactly = 1) { navigator.stopNavigationSession() }
}

@Test
fun stopSessionCallsLocationEngineRemoveLocationUpdates() {
tripSession.start(true)
Expand Down Expand Up @@ -1444,31 +1464,45 @@ class MapboxTripSessionTest {
}

@Test
fun `routeProgress updates ignored while primary route is being set`() = coroutineRule.runBlockingTest {
val primary = mockNavigationRoute()
val alternative = mockNavigationRoute()
coEvery { navigator.setRoutes(primary, legIndex, listOf(alternative), any()) } coAnswers {
delay(100)
createSetRouteResult()
}
fun `routeProgress updates ignored while primary route is being set`() =
coroutineRule.runBlockingTest {
val primary = mockNavigationRoute()
val alternative = mockNavigationRoute()
coEvery {
navigator.setRoutes(
primary,
legIndex,
listOf(alternative),
any()
)
} coAnswers {
delay(100)
createSetRouteResult()
}

val observer = mockk<RouteProgressObserver>(relaxUnitFun = true)
val observer = mockk<RouteProgressObserver>(relaxUnitFun = true)

val tripSession = buildTripSession()
tripSession.registerRouteProgressObserver(observer)
tripSession.start(withTripService = true)
val tripSession = buildTripSession()
tripSession.registerRouteProgressObserver(observer)
tripSession.start(withTripService = true)

pauseDispatcher {
launch { tripSession.setRoutes(listOf(primary, alternative), setRoutesInfo) }
runCurrent()
advanceTimeBy(delayTimeMillis = 50)
navigatorObserverImplSlot.captured.onStatus(navigationStatusOrigin, navigationStatus)
verify(exactly = 0) { observer.onRouteProgressChanged(any()) }
advanceTimeBy(delayTimeMillis = 100)
navigatorObserverImplSlot.captured.onStatus(navigationStatusOrigin, navigationStatus)
verify(exactly = 1) { observer.onRouteProgressChanged(any()) }
pauseDispatcher {
launch { tripSession.setRoutes(listOf(primary, alternative), setRoutesInfo) }
runCurrent()
advanceTimeBy(delayTimeMillis = 50)
navigatorObserverImplSlot.captured.onStatus(
navigationStatusOrigin,
navigationStatus
)
verify(exactly = 0) { observer.onRouteProgressChanged(any()) }
advanceTimeBy(delayTimeMillis = 100)
navigatorObserverImplSlot.captured.onStatus(
navigationStatusOrigin,
navigationStatus
)
verify(exactly = 1) { observer.onRouteProgressChanged(any()) }
}
}
}

@Test
fun `routeProgress updates not ignored while only alternative route is being set`() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ interface MapboxNativeNavigator {

suspend fun resetRideSession()

fun startNavigationSession()

fun stopNavigationSession()

// Route following

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ object MapboxNativeNavigatorImpl : MapboxNativeNavigator {
historyRecorderComposite: HistoryRecorderHandle?,
tilesConfig: TilesConfig,
accessToken: String,
router: RouterInterface,
router: RouterInterface
) {
val storeNavSessionState = navigator!!.storeNavigationSession()
create(config, historyRecorderComposite, tilesConfig, accessToken, router)
navigator!!.restoreNavigationSession(storeNavSessionState)
nativeNavigatorRecreationObservers.forEach {
it.onNativeNavigatorRecreated()
}
Expand All @@ -127,6 +129,14 @@ object MapboxNativeNavigatorImpl : MapboxNativeNavigator {
}
}

override fun startNavigationSession() {
navigator!!.startNavigationSession()
}

override fun stopNavigationSession() {
navigator!!.stopNavigationSession()
}

/**
* Passes in the current raw location of the user.
*
Expand Down