Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Play Services FusedLocatioAPI getLastLocation crashes with SecurityException

A few days ago Crashlytics startet reporting weird crashes within my Google Play Services Location API Implementation. After the Google Play Services API is connected I try to get the last known location with FusedLocationApi.getLastLocation(...) but this call ends in a Security Exception telling me I don't have the right permission to do that (see stack trace below)

I do have the runtime permissions and this code is working on most devices for a few months. This error occurs mainly on the OnePlus One and I could repoduce it on a HTC One M8 with Android 6.

I think the problem is related to the latest google play services update but I could not validate this. This error occurs only if the devices location services are disabled (which actually automatically removes the location permission from google play services) so I think the newest play services on these devices have a bug that throws the security exception cause the google play services do not have the permission to access location data although my app does.

Is anyone experiencing a similar problem and maybe had found a better solution then try{}catch the whole thing or any update from google about the issue?

UPDATE:


I could test this again on HTC One M8 with Android 6.0 and the SecurityException is also thrown with enabled location services and grantet permissions to the app and the play services. Switching between BALANCED_POWER AND HIGH_ACCURACY has no effect except chaning the exception message to

Client must have ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission to perform any location operations.

File access Permission has no issues and my fallback implementation which useses the Android LocationManager throws no SecurityException but the location is only determined when location services set to gps only.

Interessting fact: Google Play Services crash every few seconds when using Google Maps and no location can be found. Only navigation, which enables gps can find the location.

In summary The HTC One M8 (Android 6.0 Software Nr. 6.12.401.4) with Google Play Services 9.2.56 (438-124593566) has a general problem with Location services which are not gps only. The Google Play Services FusedLocationApi has an issue with the permission system cause the permissions are given but it throws a SecurityException. Using old LocationManager implementation has no security issues but can only determine the location if device settings are set to gps only.


The Stacktrace:

Fatal Exception: java.lang.SecurityException: Client must have ACCESS_FINE_LOCATION permission to request PRIORITY_HIGH_ACCURACY locations.
   at android.os.Parcel.readException(Parcel.java:1620)
   at android.os.Parcel.readException(Parcel.java:1573)
   at com.google.android.gms.location.internal.zzi$zza$zza.zza(Unknown Source)
   at com.google.android.gms.location.internal.zzk.getLastLocation(Unknown Source)
   at com.google.android.gms.location.internal.zzl.getLastLocation(Unknown Source)
   at com.google.android.gms.location.internal.zzd$1.zza(Unknown Source)
   at com.google.android.gms.location.internal.zzd$1.zza(Unknown Source)
   at com.google.android.gms.internal.zznt$zza.zzre(Unknown Source)
   at com.google.android.gms.internal.zzoc.connect(Unknown Source)
   at com.google.android.gms.internal.zzoc.zzd(Unknown Source)
   at com.google.android.gms.internal.zzoh.zzd(Unknown Source)
   at com.google.android.gms.internal.zzof.zzd(Unknown Source)
   at com.google.android.gms.location.internal.zzd.getLastLocation(Unknown Source)
   at com.my.package.location.PlayServicesLocationFinder.onConnected(PlayServicesLocationFinder.java:74)
   at com.google.android.gms.common.internal.zzl.zztI(Unknown Source)
   at com.google.android.gms.internal.zzof.zzc(Unknown Source)
   at com.google.android.gms.internal.zzod.zzsb(Unknown Source)
   at com.google.android.gms.internal.zzod.begin(Unknown Source)
   at com.google.android.gms.internal.zzoh.zzc(Unknown Source)
   at com.google.android.gms.internal.zznw.onConnected(Unknown Source)
   at com.google.android.gms.common.internal.zzk$1.onConnected(Unknown Source)
   at com.google.android.gms.common.internal.zzd$zzj.zzl(Unknown Source)
   at com.google.android.gms.common.internal.zzd$zza.zztp(Unknown Source)
   at com.google.android.gms.common.internal.zzd$zza.zztp(Unknown Source)
   at com.google.android.gms.common.internal.zzd$zze.zztr(Unknown Source)
   at com.google.android.gms.common.internal.zzd$zzd.handleMessage(Unknown Source)
   at android.os.Handler.dispatchMessage(Handler.java:102)
   at android.os.Looper.loop(Looper.java:148)
   at android.app.ActivityThread.main(ActivityThread.java:5461)
   at java.lang.reflect.Method.invoke(Method.java)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
like image 447
marilion91 Avatar asked Jun 28 '16 14:06

marilion91


1 Answers

should be fixed now, in Play Services 9.6 https://developers.google.com/maps/documentation/android-api/releases#september_21_2016

September 21, 2016
Resolved Issues

  • Client must have ACCESS_FINE_LOCATION permission to request PRIORITY_HIGH_ACCURACY locations. (Issue 10166)
like image 147
nGL Avatar answered Sep 30 '22 14:09

nGL