bkonyi / FlutterGeofencing

Rough work for Flutter geofencing plugin
BSD 3-Clause "New" or "Revised" License
338 stars 220 forks source link

android: don't crash when callback not registered #36

Closed accek closed 3 years ago

accek commented 4 years ago

It happens sometimes that when an app is uninstalled and reinstalled, or app data is cleared, that the geofencing framework calls our service and the callback is not registered yet, causing a crash.

bkonyi commented 4 years ago

I can't seem to remember if 0 is actually a valid raw callback handle or not, but I don't think we try and restrict it since there's no reason the hashing algorithm used to create the handle can't output 0. Can you share where the crash is happening exactly? This code should already bail out if a callback handle isn't valid.

accek commented 4 years ago

Well, maybe I'm misinterpreting the stack trace or the code. Here it is:

Fatal Exception: java.lang.RuntimeException
Unable to create service io.flutter.plugins.geofencing.GeofencingService: java.lang.IllegalStateException: FlutterCallbackInformati…formation(callbackHandle) must not be null
Fatal Exception: java.lang.RuntimeException: Unable to create service io.flutter.plugins.geofencing.GeofencingService: java.lang.IllegalStateException: FlutterCallbackInformati…formation(callbackHandle) must not be null
       at android.app.ActivityThread.handleCreateService(ActivityThread.java:3965)
       at android.app.ActivityThread.access$1500(ActivityThread.java:219)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1875)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7356)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by java.lang.IllegalStateException
FlutterCallbackInformati…formation(callbackHandle) must not be null
Caused by java.lang.IllegalStateException: FlutterCallbackInformati…formation(callbackHandle) must not be null
       at io.flutter.plugins.geofencing.GeofencingService.startGeofencingService(GeofencingService.kt:65)
       at io.flutter.plugins.geofencing.GeofencingService.onCreate(GeofencingService.kt:114)
       at android.app.ActivityThread.handleCreateService(ActivityThread.java:3953)
       at android.app.ActivityThread.access$1500(ActivityThread.java:219)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1875)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:214)
       at android.app.ActivityThread.main(ActivityThread.java:7356)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
JFreakDK commented 4 years ago

I did not see your fix before I created one myself. I reported it here: #60 and tried to catch the exception #62 instead of your approach.

What is the status here @bkonyi ? Can we include one of the fixes?

bkonyi commented 3 years ago

This appears to have already been fixed on master. Sorry for the delay on this!