smart-location-lib
smart-location-lib copied to clipboard
SecurityException: "fused" location provider requires ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.
Found this SecurityException in my Crashlytics reports after integrating your sdk. Let me know How I can handle this issue.
Fatal Exception: java.lang.SecurityException: "fused" location provider requires ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission.
at android.os.Parcel.createException(Parcel.java:1950)
at android.os.Parcel.readException(Parcel.java:1918)
at android.os.Parcel.readException(Parcel.java:1868)
at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:755)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:1007)
at android.location.LocationManager.requestLocationUpdates(LocationManager.java:626)
at io.nlopez.smartlocation.location.providers.LocationManagerProvider.start(LocationManagerProvider.java:65)
at io.nlopez.smartlocation.location.providers.LocationGooglePlayServicesWithFallbackProvider.fallbackToLocationManager(LocationGooglePlayServicesWithFallbackProvider.java:88)
at io.nlopez.smartlocation.location.providers.LocationGooglePlayServicesWithFallbackProvider.onConnectionSuspended(LocationGooglePlayServicesWithFallbackProvider.java:75)
at io.nlopez.smartlocation.location.providers.LocationGooglePlayServicesProvider.onConnectionSuspended(LocationGooglePlayServicesProvider.java:235)
at com.google.android.gms.common.internal.GmsClientEventManager.onUnintentionalDisconnection(com.google.android.gms:play-services-base@@17.1.0:47)
at com.google.android.gms.common.api.internal.zaaw.zab(com.google.android.gms:play-services-base@@17.1.0:321)
at com.google.android.gms.common.api.internal.zaaf.onConnectionSuspended(com.google.android.gms:play-services-base@@17.1.0:42)
at com.google.android.gms.common.api.internal.zabe.onConnectionSuspended(com.google.android.gms:play-services-base@@17.1.0:106)
at com.google.android.gms.common.api.internal.zap.onConnectionSuspended(com.google.android.gms:play-services-base@@17.1.0:9)
at com.google.android.gms.common.internal.zaf.onConnectionSuspended(com.google.android.gms:play-services-base@@17.1.0:4)
at com.google.android.gms.common.internal.BaseGmsClient$zzb.handleMessage(:40)
at android.os.Handler.dispatchMessage(Handler.java:106)
at com.google.android.gms.internal.common.zze.dispatchMessage(:8)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
I had the same issue when the location permission got removed while smartlocation was running.
Obviously this check should wrap the if(singleUpdate)
one
https://github.com/mrmans0n/smart-location-lib/blob/8939ae96140e1a469f40a2dde1489002faca10ad/library/src/main/java/io/nlopez/smartlocation/location/providers/LocationManagerProvider.java#L52
In the meantime, one can silently catch the exception by registering a custom exception handler after crashlytics init Application#onCreate()
/**
* To be registered after Crashlytics init
* Catch for https://github.com/mrmans0n/smart-location-lib/issues/277
*/
private void handleSmartLocationExceptionSilently() {
final Thread.UncaughtExceptionHandler defaultExceptionHandler = getDefaultUncaughtExceptionHandler();
setDefaultUncaughtExceptionHandler((t, e) -> {
if (e != null && e.getStackTrace() != null
&& e.getStackTrace().length > 6
&& e.getStackTrace()[6].toString().contains("io.nlopez.smartlocation")
&& e.getMessage() != null
&& e.getMessage().contains("location provider requires")) {
return;
}
if (defaultExceptionHandler != null) {
defaultExceptionHandler.uncaughtException(t, e);
}
});
}