Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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,8 +1992,11 @@ class MapboxNavigation @VisibleForTesting internal constructor(
navigatorConfig,
)
historyRecorderHandles = createHistoryRecorderHandles(config)

val navSessionState = navigator.restoreNavigationSession()
Comment thread
RingerJK marked this conversation as resolved.
Outdated
mainJobController.scope.launch {
navigator.recreate(
navSessionState,
config,
historyRecorderHandles.composite,
createTilesConfig(isFallback, tilesVersion),
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 @@ -46,6 +46,7 @@ import com.mapbox.navigation.testing.factories.createDirectionsRoute
import com.mapbox.navigation.testing.factories.createNavigationRoute
import com.mapbox.navigation.testing.factories.createRouteOptions
import com.mapbox.navigator.FallbackVersionsObserver
import com.mapbox.navigator.NavigationSessionState
import com.mapbox.navigator.NavigatorConfig
import com.mapbox.navigator.RouteAlternative
import com.mapbox.navigator.RouteInterface
Expand Down Expand Up @@ -1162,7 +1163,7 @@ internal class MapboxNavigationTest : MapboxNavigationBaseTest() {
}

@Test
fun `verify tile config tilesVersion and isFallback on fallback`() {
fun `verify tile config tilesVersion, isFallback, and restoreNavigationSession invoke on fallback`() {
threadController.cancelAllUICoroutines()

val fallbackObserverSlot = slot<FallbackVersionsObserver>()
Expand All @@ -1174,12 +1175,15 @@ internal class MapboxNavigationTest : MapboxNavigationBaseTest() {
RoutesExtra.ROUTES_UPDATE_REASON_CLEAN_UP
)
every { tripSession.getRouteProgress() } returns mockk()
val mockkNavSessionState = mockk<NavigationSessionState>()
every { navigator.restoreNavigationSession() } returns mockkNavSessionState

mapboxNavigation = MapboxNavigation(navigationOptions, threadController)

val tileConfigSlot = slot<TilesConfig>()
every {
navigator.recreate(
mockkNavSessionState,
any(),
any(),
capture(tileConfigSlot),
Expand All @@ -1196,10 +1200,14 @@ internal class MapboxNavigationTest : MapboxNavigationBaseTest() {

assertEquals(latestTilesVersion, tileConfigSlot.captured.endpointConfig?.version)
assertTrue(tileConfigSlot.captured.endpointConfig?.isFallback!!)
verifyOrder {
navigator.restoreNavigationSession()
navigator.recreate(any(), any(), any(), any(), any(), any())
}
}

@Test
fun `verify tile config tilesVersion and isFallback on return to latest tiles version`() =
fun `verify tile config tilesVersion, isFallback, and restoreNavigationSession invoke on return to latest tiles version`() =
runBlocking {
threadController.cancelAllUICoroutines()

Expand All @@ -1214,12 +1222,15 @@ internal class MapboxNavigationTest : MapboxNavigationBaseTest() {
directionsSession.routes
} returns listOf(mockPrimaryNavigationRoute, mockAlternativeNavigationRoute)
every { tripSession.getRouteProgress()?.currentLegProgress?.legIndex } returns index
val mockkNavSessionState = mockk<NavigationSessionState>()
every { navigator.restoreNavigationSession() } returns mockkNavSessionState

mapboxNavigation = MapboxNavigation(navigationOptions, threadController)

val tileConfigSlot = slot<TilesConfig>()
every {
navigator.recreate(
mockkNavSessionState,
any(),
any(),
capture(tileConfigSlot),
Expand All @@ -1240,6 +1251,10 @@ internal class MapboxNavigationTest : MapboxNavigationBaseTest() {
SetRoutesReason.RESTORE_TO_ONLINE,
)
}
verifyOrder {
navigator.restoreNavigationSession()
navigator.recreate(any(), any(), any(), any(), any(), any())
}
}

@Test
Expand All @@ -1263,6 +1278,7 @@ internal class MapboxNavigationTest : MapboxNavigationBaseTest() {
coEvery { navigator.setRoutes(any(), any(), any(), any()) } answers {
createSetRouteResult()
}
every { navigator.restoreNavigationSession() } returns mockk()

mapboxNavigation = MapboxNavigation(navigationOptions, threadController)

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 @@ -16,6 +16,7 @@ import com.mapbox.navigator.FallbackVersionsObserver
import com.mapbox.navigator.FixLocation
import com.mapbox.navigator.GraphAccessor
import com.mapbox.navigator.HistoryRecorderHandle
import com.mapbox.navigator.NavigationSessionState
import com.mapbox.navigator.NavigationStatus
import com.mapbox.navigator.NavigatorObserver
import com.mapbox.navigator.PredictiveCacheController
Expand Down Expand Up @@ -49,6 +50,7 @@ interface MapboxNativeNavigator {
* Reinitialize the navigator with a device profile
*/
fun recreate(
navigationSessionState: NavigationSessionState,
config: ConfigHandle,
historyRecorderComposite: HistoryRecorderHandle?,
tilesConfig: TilesConfig,
Expand All @@ -58,6 +60,12 @@ interface MapboxNativeNavigator {

suspend fun resetRideSession()

fun startNavigationSession()

fun stopNavigationSession()

fun restoreNavigationSession(): NavigationSessionState
Comment thread
RingerJK marked this conversation as resolved.
Outdated

// Route following

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.mapbox.navigator.FallbackVersionsObserver
import com.mapbox.navigator.FixLocation
import com.mapbox.navigator.GraphAccessor
import com.mapbox.navigator.HistoryRecorderHandle
import com.mapbox.navigator.NavigationSessionState
import com.mapbox.navigator.NavigationStatus
import com.mapbox.navigator.Navigator
import com.mapbox.navigator.NavigatorObserver
Expand Down Expand Up @@ -109,13 +110,15 @@ object MapboxNativeNavigatorImpl : MapboxNativeNavigator {
* Recreate native objects and notify listeners.
*/
override fun recreate(
navigationSessionState: NavigationSessionState,
config: ConfigHandle,
historyRecorderComposite: HistoryRecorderHandle?,
tilesConfig: TilesConfig,
accessToken: String,
router: RouterInterface,
router: RouterInterface
) {
create(config, historyRecorderComposite, tilesConfig, accessToken, router)
navigator!!.restoreNavigationSession(navigationSessionState)
nativeNavigatorRecreationObservers.forEach {
it.onNativeNavigatorRecreated()
}
Expand All @@ -127,6 +130,17 @@ object MapboxNativeNavigatorImpl : MapboxNativeNavigator {
}
}

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

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

override fun restoreNavigationSession(): NavigationSessionState =
Comment thread
RingerJK marked this conversation as resolved.
Outdated
navigator!!.storeNavigationSession()

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