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

Conversation

kmadsen
Copy link
Contributor

@kmadsen kmadsen commented Aug 30, 2022

Description

Found this issue while testing this #6233

mapboxNavigation is still valid after calling detach. This means all calls to current() will return non-null, and if you unregister an observer it can result detach calls after it has been disabled. It is expected, to have a single onDetached call per every onAttached.

I separated this pull request from 6233 because it would definitely impact anyone using detach.

@kmadsen kmadsen added the bug Defect to be fixed. label Aug 30, 2022
@kmadsen kmadsen requested a review from a team as a code owner August 30, 2022 22:33
@@ -60,6 +60,8 @@ internal class MapboxNavigationOwner {
attached = false
services.forEach { it.onDetached(mapboxNavigation!!) }
MapboxNavigationProvider.destroy()
mapboxNavigation = null
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.

@codecov
Copy link

codecov bot commented Aug 30, 2022

Codecov Report

Merging #6245 (7d8339b) into main (156c544) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main    #6245      +/-   ##
============================================
+ Coverage     68.84%   68.86%   +0.01%     
- Complexity     4336     4338       +2     
============================================
  Files           650      650              
  Lines         26102    26104       +2     
  Branches       3061     3061              
============================================
+ Hits          17971    17976       +5     
+ Misses         6968     6965       -3     
  Partials       1163     1163              
Impacted Files Coverage Δ
...navigation/core/lifecycle/MapboxNavigationOwner.kt 90.00% <100.00%> (+0.52%) ⬆️
...x/navigation/core/lifecycle/MapboxNavigationApp.kt 10.00% <0.00%> (+10.00%) ⬆️

@kmadsen kmadsen enabled auto-merge (squash) August 31, 2022 00:42
Comment on lines 60 to +63
attached = false
services.forEach { it.onDetached(mapboxNavigation!!) }
MapboxNavigationProvider.destroy()
mapboxNavigation = null
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

@kmadsen kmadsen merged commit 057f136 into main Aug 31, 2022
@kmadsen kmadsen deleted the km-fix-mapbox-navigation-app-detach branch August 31, 2022 10:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Defect to be fixed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants