Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MapboxNavigation#detach issue #6245

Merged
merged 1 commit into from
Aug 31, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Mapbox welcomes participation and contributions from everyone.
- Fixed incorrect values in `AlternativeRouteInfo#duration` and `RouteProgress#durationRemaining`: now they rely on `route.leg.annotations.duration` if available, otherwise, `LegStep#duration` is used for calculations. [#6237](https://github.com/mapbox/mapbox-navigation-android/pull/6237)
- Added `guideMapUri` to the `RestStop`. [#6237](https://github.com/mapbox/mapbox-navigation-android/pull/6237)
- [TileStore Android Service] Fixed a crash when the service process is killed by the Android system. [#6237](https://github.com/mapbox/mapbox-navigation-android/pull/6237)
- Fixed `MapboxNavigationApp#detach` will not fully detach. This causes `MapboxNavigation` to continue to be accessible, and causes `MapboxNavigationObserver.onDetached` to be called multiple times.

## Mapbox Navigation SDK 2.8.0-beta.1 - 25 August, 2022
### Changelog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ internal class MapboxNavigationOwner {
attached = false
services.forEach { it.onDetached(mapboxNavigation!!) }
MapboxNavigationProvider.destroy()
mapboxNavigation = null
Comment on lines 60 to +63
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is repeated in carAppLifecycleObserver.onStop, looks like it should be moved to a separate function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are still some slight differences like logs and the condition for if (attached)

think i prefer to let them continue to be separate, cover the issues with tests

logI("disabled ${services.size} observers", LOG_CATEGORY)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding this log because it is useful to figure out how many services are attached when you call disable.

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,23 @@ class MapboxNavigationAppDelegateTest {
verify(exactly = 1) { observer.onAttached(any()) }
}

@Test
fun `verify disable will detach and current becomes null`() {
mapboxNavigationApp.setup { navigationOptions }

val testLifecycleOwner = CarAppLifecycleOwnerTest.TestLifecycleOwner()
mapboxNavigationApp.attach(testLifecycleOwner)
testLifecycleOwner.lifecycleRegistry.currentState = Lifecycle.State.RESUMED

val observer = mockk<MapboxNavigationObserver>(relaxUnitFun = true)
mapboxNavigationApp.registerObserver(observer)
mapboxNavigationApp.disable()
mapboxNavigationApp.unregisterObserver(observer)

assertNull(MapboxNavigationApp.current())
verify(exactly = 1) { observer.onDetached(any()) }
}

@Test
fun `verify current is null when all lifecycle owners are destroyed`() {
mapboxNavigationApp.setup { navigationOptions }
Expand Down