Custom router over API

Started by TrulloF, April 13, 2026, 08:49:49

0 Members and 3 Guests are viewing this topic.

TrulloF

[Bug] InvalidObjectException crash when tapping navigation tile with external routing providers - ACTION_COMPUTE_TRACK_PROVIDER service not yet bound

Hi Menion,

I'm developing a third-party routing addon with the help of Claude Code that registers as an ACTION_COMPUTE_TRACK_PROVIDER service. Routing and rerouting work correctly, but Locus crashes whenever the navigation tile is tapped during active navigation (or when the navigation menu is opened, e.g. from the point menu, without having gone through Navigation → Routing first).

Crash:

java.io.InvalidObjectException: Service does not return valid 'trackTypes'

Root cause:
The navigation tile/menu ViewModel enumerates all registered ACTION_COMPUTE_TRACK_PROVIDER services and calls getTrackTypes() on each one synchronously, before onServiceConnected() has fired for services that haven't been bound in the current session. Internally, the API proxy guards every call with an isConnected flag that is only set inside onServiceConnected(). If the service wasn't previously bound, isConnected is still false at call time → InvalidObjectException.

100% reproducible steps:

Install any app (e.g. BRouter) that exports a service with action="locus.api.android.ACTION_COMPUTE_TRACK_PROVIDER".
Start a navigation session without going through Navigation → Routing (so the service was never bound in this session).
Tap the navigation tile during active navigation.
Crash.
Suggested fix (Locus side):

Wrap the getTrackTypes() call in a try/catch and treat the service as temporarily unavailable rather than crashing:

try {
    int[] types = service.getTrackTypes();
    // use types
} catch (InvalidObjectException | RemoteException e) {
    Log.w(TAG, "Routing service not yet connected, skipping: " + e.getMessage());
}

Alternatively, collect track types asynchronously inside onServiceConnected() and update the UI once binding completes, rather than calling eagerly before the connection is established.

Thanks for looking into this!
  •  

Menion

Hi @TrulloF
Nice to see someone playing with the API! To be honest, this API functionality is not used by any addon, so it is, as you see, not well tested.

Anyway, in this case > issue found and should be fixed in the next (Friday probably) version.

- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download
  •  

TrulloF

Thanks for looking into it. BRouter, if installed as separate app is also affected by this bug. It crashes Locus, if you try to plan a route or try to navigate from the point menu. Because BRouter is now integrated into Locus Map, probably nobody noticed.

Quote from: Menion on April 15, 2026, 14:47:19Hi @TrulloF
Nice to see someone playing with the API! To be honest, this API functionality is not used by any addon, so it is, as you see, not well tested.

Anyway, in this case > issue found and should be fixed in the next (Friday probably) version.


  •  
    The following users thanked this post: Menion

TrulloF

Problem is fixed with the latest build. Great work. Now I can route with my TomTom-addon in Locus and use traffic information to avoid traffic jams. That was the only thing missing for me. Thanks to Claude Code... 😊
By the way, if you enabled Google location services in GPS & Sensor settings, but have only MicroG installed, GPS position will be found but the GPS icon stays yellow and position doesn't follow during routing, even though the signal is strong. Only disabling this option fixed it for me.
  •  

Menion

Hmm, nice!

And MicroG problem ... I can't test it. Probably some problem in the Google Services location implementation.
- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download
  •  

TrulloF

The problem with external routers crashing is only half gone. I have to open the settings of the addon, before trying any routing activities. If not the app crashes while initializing/enumerating the present routing services. I'll send a better description and a log, if I find the time. I can live with the current situation. It's just an additional step before I can start routing. So take your time.
  •  

Menion

Hmm are you willing to privately share your add-on so I may test it more precisely? There is probably an API key inside, so I will of course, delete the add-on once it is fixed. At least a log for now, thanks!
- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download
  •  

TrulloF

Sent you a PM. Thank you for looking into it.
  •  

TrulloF

Can we expect a fix for the third party routing addons soon? Even with the latest build I need to tap the settings button of the external navigation service once or else the app either restarts or crashes right away. Did I miss something with my implementation?
  •  

Menion

Hello TrulloF,
ah sorry, I've missed your PM and now the request is no longer valid. Once more please, thanks.
- Official help (ideas, questions, problems): help.locusmap.eu
- Advanced topics, sharing of knowledges: you're here!
- LM 4 Beta download, LM 4 Release download
  •  

TrulloF

Thank you for your reply. I sent another invite. BR
  •  

TrulloF

#11
Hi Menion,

I can confirm it is still reproducible on 4.34.1.2 (versionCode 1214). I think I now understand exactly why it happens and what the fix should be.

---
Crash (condensed logcat, 4.34.1.2):

FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity
  ComponentInfo{.../RoutePlannerActivity}:
  An exception happened in constructor of class xt.d1
Caused by: java.io.InvalidObjectException: Service does not return valid 'trackTypes'
    at vr.q.m(...)
    at gx.b.k(...)
    at xt.d1.<init>(163)
    at RoutePlannerActivity.K0(...)
    at RoutePlannerActivity.onCreate(...)

---
Root cause

Android's Context.bindService() is asynchronous - the binder is only available after onServiceConnected() fires. If RoutePlannerActivity opens before that callback has fired (i.e. in any fresh Locus session where the user hasn't visited routing settings yet), Locus asks the external service for its trackTypes while it is not yet connected.
Instead of treating "not yet connected" as a transient state and returning an empty list, Locus throws InvalidObjectException - which propagates uncaught out of the ViewModel constructor and crashes the Activity.

This is a race condition inherent to the Android binding lifecycle: there is no way for an external addon to guarantee it is pre-connected before the user opens the route planner.

---
Suggested fix

When an external ACTION_COMPUTE_TRACK_PROVIDER service is registered but its onServiceConnected() has not fired yet, getTrackTypes() should return an empty array rather than throw. An empty array is a valid transient state - the UI can show a spinner or refresh once the connection is established. Throwing an uncaught exception from a ViewModel constructor is never recoverable.

The error message "Service does not return valid 'trackTypes'" already exists as a user-facing toast for when something goes wrong during active use - that path is fine. The issue is specifically the throw propagating up into RoutePlannerActivity.onCreate() before the service has even had a chance to connect.

---
Workaround for users until fixed: in Locus Routing Settings, tap the configure icon next to the external router once per session. This triggers bindService() explicitly and the crash won't occur for the rest of the session.

Thank you!
  •