Skip to content
This repository has been archived by the owner on Apr 23, 2023. It is now read-only.

BinderProxy ClassCastException when running Lost within a bound service #250

Closed
Guardiola31337 opened this issue Dec 19, 2017 · 4 comments
Closed

Comments

@Guardiola31337
Copy link

Description

App crashes at startup.

12-19 19:27:54.659 17440-17440/com.mapbox.mapboxsdk.testapp:lost E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                   Process: com.mapbox.mapboxsdk.testapp:lost, PID: 17440
                                                                                   java.lang.ClassCastException: android.os.BinderProxy cannot be cast to com.mapbox.services.android.telemetry.TelemetryService$TelemetryBinder
                                                                                       at com.mapbox.services.android.telemetry.MapboxTelemetry$3.onServiceConnected(MapboxTelemetry.java:361)
                                                                                       at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1212)
                                                                                       at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1229)
                                                                                       at android.os.Handler.handleCallback(Handler.java:739)
                                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                       at android.os.Looper.loop(Looper.java:135)
                                                                                       at android.app.ActivityThread.main(ActivityThread.java:5312)
                                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
                                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)

Curious thing is that we’re getting the crash twice and then it disappears. This means that everything works until you remove the app from the background (swiping it away from the recent apps list) or you force close the app and relaunch it again, getting two consecutive crashes again.

We’re using a bound service to listen to location updates.
Based on the crash message, it seems that Lost FusedLocationProviderService is messing with our service somehow. As you can see ☝️, the crash is coming from :lost process, which is where you run FusedLocationProviderService.
What I still don’t get/know is why it gets intermingled with our connection (crash is pointing to that specific line). It seems that your service gets created and our connection receives the callback somehow producing that ClassCastException. Any ideas?

Noting here that we’re not getting this crash when using an unbound Service.

Steps to Reproduce

You can reproduce the behavior described above running the test app included in this branch https://github.com/mapbox/mapbox-gl-native/tree/pg-new-events-lib-integration

Lost & Android Version

Lost 3.0.4
Moto X 2nd gen Android 5.0
Nexus 5 Android 6.0 (as soon as the location permissions are granted)

Related issues

#173
#228

cc/ @sarahlensing @msmollin @tallytalwar

@Guardiola31337
Copy link
Author

Adding here relevant log traces:

12-20 10:55:41.422 918-1696/? I/ActivityManager: Start proc com.mapbox.mapboxsdk.testapp:lost for service com.mapbox.mapboxsdk.testapp/com.mapzen.android.lost.internal.FusedLocationProviderService: pid=11163 uid=10008 gids={50008, 9997, 1028, 1015, 3003} abi=armeabi-v7a
// ...
12-20 10:55:41.647 11163-11163/com.mapbox.mapboxsdk.testapp:lost E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                   Process: com.mapbox.mapboxsdk.testapp:lost, PID: 11163
                                                                                   java.lang.ClassCastException: android.os.BinderProxy cannot be cast to com.mapbox.services.android.telemetry.TelemetryService$TelemetryBinder
                                                                                       at com.mapbox.services.android.telemetry.MapboxTelemetry$3.onServiceConnected(MapboxTelemetry.java:361)
                                                                                       at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1212)
                                                                                       at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1229)
                                                                                       at android.os.Handler.handleCallback(Handler.java:739)
                                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                       at android.os.Looper.loop(Looper.java:135)
                                                                                       at android.app.ActivityThread.main(ActivityThread.java:5312)
                                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
                                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
// ...
12-20 10:55:43.176 11163-11163/? I/Process: Sending signal. PID: 11163 SIG: 9
12-20 10:55:43.198 918-1439/? W/InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@1706e5df attribute=null, token = android.os.BinderProxy@1e123a5d
12-20 10:55:43.202 11137-11137/com.mapbox.mapboxsdk.testapp D/LostLocationEngine: Connection suspended
12-20 10:55:43.202 918-933/? I/ActivityManager: Process com.mapbox.mapboxsdk.testapp:lost (pid 11163) has died
12-20 10:55:43.203 918-933/? W/ActivityManager: Scheduling restart of crashed service com.mapbox.mapboxsdk.testapp/com.mapzen.android.lost.internal.FusedLocationProviderService in 1000ms
12-20 10:55:43.808 1352-1352/? I/SBar.MotoNetworkCtrlr: updateDataIcon[0]: mCurrentDataSubId=5 maps to: dataPhoneId:0 ( SubscriptionManager.getPhoneId returned 2147483647=0x7fffffff )
12-20 10:55:44.267 918-939/? I/ActivityManager: Start proc com.mapbox.mapboxsdk.testapp:lost for service com.mapbox.mapboxsdk.testapp/com.mapzen.android.lost.internal.FusedLocationProviderService: pid=11192 uid=10008 gids={50008, 9997, 1028, 1015, 3003} abi=armeabi-v7a
// ...
12-20 10:55:44.466 11192-11192/com.mapbox.mapboxsdk.testapp:lost E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                   Process: com.mapbox.mapboxsdk.testapp:lost, PID: 11192
                                                                                   java.lang.ClassCastException: android.os.BinderProxy cannot be cast to com.mapbox.services.android.telemetry.TelemetryService$TelemetryBinder
                                                                                       at com.mapbox.services.android.telemetry.MapboxTelemetry$3.onServiceConnected(MapboxTelemetry.java:361)
                                                                                       at android.app.LoadedApk$ServiceDispatcher.doConnected(LoadedApk.java:1212)
                                                                                       at android.app.LoadedApk$ServiceDispatcher$RunConnection.run(LoadedApk.java:1229)
                                                                                       at android.os.Handler.handleCallback(Handler.java:739)
                                                                                       at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                       at android.os.Looper.loop(Looper.java:135)
                                                                                       at android.app.ActivityThread.main(ActivityThread.java:5312)
                                                                                       at java.lang.reflect.Method.invoke(Native Method)
                                                                                       at java.lang.reflect.Method.invoke(Method.java:372)
                                                                                       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:901)
                                                                                       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:696)
// ...
12-20 10:55:46.072 11192-11192/com.mapbox.mapboxsdk.testapp:lost I/Process: Sending signal. PID: 11192 SIG: 9
12-20 10:55:46.081 918-1359/? W/InputMethodManagerService: Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@201e9806 attribute=null, token = android.os.BinderProxy@1e123a5d
12-20 10:55:46.085 918-933/? I/ActivityManager: Process com.mapbox.mapboxsdk.testapp:lost (pid 11192) has died
12-20 10:55:46.086 918-933/? W/ActivityManager: Service crashed 2 times, stopping: ServiceRecord{34bd1f59 u0 com.mapbox.mapboxsdk.testapp/com.mapzen.android.lost.internal.FusedLocationProviderService}

This means that everything works

Well, after getting the crashes, I noticed that you don't receive location updates anymore, which makes total sense because ServiceRecord stops the FusedLocationProviderService as you can see in the logs.

@sarahsnow1
Copy link
Contributor

Thanks for the report. I have a few questions to help narrow this down...when is the telemetry service connected in relation to Lost? And from which process is the connection initiated from? Do you expect multiple processes to access the bound telemetry service? You'd see that crash using a binder when multiple processes access the telemetry service.

@Guardiola31337
Copy link
Author

@sarahlensing

when is the telemetry service connected in relation to Lost?

The flow is as follows:

MapboxTelemetry#enable() 👉 MapboxTelemetry#startTelemetry() 👉 MapboxTelemetry#optIn() 👉 MapboxTelemetry#optLocationIn() 👉 MapboxTelemetry#startLocation() which fires the TelemetryService 👉 TelemetryService#onCreate() 👉 TelemetryService#createLocationReceiver() 👉 TelemetryService#registerLocationReceiver() 👉 TelemetryService#connectLocationEngine 👉 TelemetryService#obtainLocationEngine() 👉 TelemetryService#setupLocationEngine() 👉 TelemetryService#activateLocationEngine() which ends up calling LostLocationEngine#activate() 👉 LostLocationEngine#connect() 👉 lostApiClient.connect() which I guess fires FusedLocationProviderService.

And from which process is the connection initiated from?

We're not specifying a concrete process in which TelemetryService should run so default behavior: the process in which the applications runs.

Do you expect multiple processes to access the bound telemetry service?

Nope, not expected. As mentioned before, we don't want to run TelemetryService in a different process (at least for now). We're using a bound service so that be able to communicate with it internally (within the same process is fine at the moment).

You'd see that crash using a binder when multiple processes access the telemetry service.

This is weird because we're not specifying a concrete process in which TelemetryService should run 😖

Let me know if you have any other follow up questions. Thanks @sarahlensing 🙏

@msmollin
Copy link
Contributor

Closing as this repo is no longer maintained.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants