-
Notifications
You must be signed in to change notification settings - Fork 319
Introduce reset function for the navigator #3701
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
Conversation
24c75a3 to
89e2be7
Compare
| val events = loadReplayHistory() | ||
| mapboxReplayer.clearEvents() | ||
| mapboxReplayer.pushEvents(events) | ||
| mapboxNavigation.resetTripSession() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line is what causes the difference between the videos in the PR description.
The navigator needs to be reset, and then it can start from a new location.
| val activityIntent = Intent(this, HistoryFilesActivity::class.java) | ||
| startActivity(activityIntent) | ||
| finish() | ||
| startActivityForResult(activityIntent, HistoryFilesActivity.REQUEST_CODE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating the example to use startActivityForResult to showcase the resetTripSession function.
When we start an activity for result, the current activity is never destroyed. Making it so, when the onActivityResult comes back it will be able to update the state of MapboxNavigation.
Before we had the resetTripSession function, it required us to call MapboxNavigation.onDestroy first
89e2be7 to
e2a950c
Compare
e2a950c to
22bbaca
Compare
| */ | ||
| fun resetTripSession() { | ||
| tripSession.route = null | ||
| navigator.reset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Digging up some history as we had a similar function in the past.
Introduced a reset function, that would recreate the navigator #2850
That caused a regression in the examples #2769
Fixed the regression with #2905
Notice, the issue was because the reset function was called inside MapboxTripSession.reset()
Worth noting that, our MapboxTripSession private reset function is very different from the Nav Native's resetRideSession.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also tested the repro steps included in the issue from before: #2769 (comment)
And this change is looking good. It's because we don't want to add the Navigator.resetRideSession call to the MapboxTripSession.reset() function
libnavigation-core/src/main/java/com/mapbox/navigation/core/MapboxNavigation.kt
Show resolved
Hide resolved
...avigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigatorImpl.kt
Outdated
Show resolved
Hide resolved
libnavigator/src/main/java/com/mapbox/navigation/navigator/internal/MapboxNativeNavigator.kt
Show resolved
Hide resolved
aee11a2 to
9f5113d
Compare
| mapboxNavigation.onDestroy() | ||
|
|
||
| verify(exactly = 1) { tripSession.route = null } | ||
| verify(exactly = 1) { directionsSession.routes = emptyList() } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
directionsSession is supposed to update tripsSession.route
so our real source of truth is the directionsSession
it's a bit more complicated to wire up tests to have this assumption built in
9f5113d to
cced14f
Compare
| * but the [NavigatorConfig] stays the same. This can be used to transport the | ||
| * navigator to a new location. | ||
| */ | ||
| fun reset() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| fun reset() | |
| fun resetRideSession() |
Let's call it the same as the native API.
| * navigator to a new location. | ||
| */ | ||
| fun resetTripSession() { | ||
| directionsSession.routes = emptyList() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to reset the route as well? I'd expect this method to only reset the Navigator's bias (we can work on the method naming as well) and nothing else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While reviewing this noticed that we were not resetting the directionsSession.routes as part of onDestroy which allows you to do
mapboxNavigation.onDestroy()
mapboxNavigation.getRoutes()We considered adding it here which is called when in onDestroy. If we opt to remove it, we should add it after directionsSession.unregisterAllRoutesObservers() when in onDestroy (we can do it in a separate PR though as it doesn't directly relate to the changes added as part of this PR).
cc @kmadsen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We agreed in comments that native was going to reset the route, and the SDK callers would need to set route again if they wanted to keep it. But that is actually, not true.
void NavigatorImpl::resetRideSession() {
BuildRideSessionImpl();
if (routes_ && ride_session_) {
try {
ride_session_->SetRoutes(routes_);
} catch (const std::exception& ex) {
LOG_ERROR(std::string{"SetRoute error: "} + ex.what());
}
}cc: @mskurydin @SiarheiFedartsou @averkhaturau
I think @LukasPaczos is right, we don't want to reset the route inside this resetTripSession function. So am moving the route reset back to onDestroy
cced14f to
9473970
Compare
9473970 to
02196b7
Compare
LukasPaczos
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| navigatorConfig, | ||
| createTilesConfig() | ||
| ) | ||
| directionsSession.routes = emptyList() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
|
robo tests ran out of memory. wonder if there is a memory leak |
|
Still a pain to deobfuscate stack traces, here's the instructions But the actual crash is coming from the requesting a route from HTTP Syncing with @averkhaturau. We don't believe this is due to this change at this time. The crash is coming from the network call rather than directly from nav-native. I'll run one more test before merging |
|
tl;dr - I'm not finding any reason to believe this pull request is introducing an issue After running some tests locally, not able to identify a leak from requesting routes. But the "Time to request a route" is very slow - I was able to reproduce this on master and it was possibly due to my own network quality. |


Description
Opening this as a draft while working on examples that test out the function.
We are looking to add the ability to teleport the navigator to different locations. For example, simulate a route in new york and then jump to tokyo and simulate a new route - all while keeping the same SDK setup.
A more practical case, would be to simulate a route in your city. And then jump back to the beginning to drive it for real.
bug,feature,new API(s),SEMVER, etc.)Testing
Notice that without the reset function, the navigator will not reliably reset to the new location selected.
Please describe the manual tests that you ran to verify your changes
SNAPSHOTupstream dependencies if needed) through testapp/demo app and run all activities to avoid regressionsChecklist
CHANGELOGincluding this PRapi/current.txtfiles after running$> make core-update-api(Core) /$> make ui-update-api(UI) if there are changes / errors we're 🆗 with (e.g.AddedMethodchanges are marked as errors but don't break SemVer) 🚀 If there are SemVer breaking changes add theSEMVERlabel. See Metalava docs