Android Play Services FusedLocatioAPI getLastLocation crashes with SecurityException
M

1

7

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)
Metzger answered 28/6, 2016 at 14:20 Comment(9)
#32636204Erosive
I asked for the permission an I can guarantee that I have the permission to ask for FINE and CORSE_LOCATIONMetzger
Is it possible that user denied the permission and you handled it wrong?Eelpout
@TimCastelijns this was my first thought, some strange oneplus cynagen mod hack thad disabled the permission on a weird way but I double checked I had the permission and all was as expected only thing I noticed was the missing permission on the google play services which could only be enabled by enabling the location services of the device. same code on my galaxy s6 has no crash and it gives notification that location services are disabledMetzger
I happen to have a oneplus one. I have not experiences this kind of issue before. Do you know whether or not the one you had tested is modded or not?Eelpout
@TimCastelijns I tested a HTC One M8 with stock rom, no modifications as far as I know. Google Play Services Version 9.2.56 (438-....) unfortunately my co-worker had to go early and it was his device.Metzger
I have a stock OnePlus and I confirm the exception of play services and some dependent app. About the permission hack, the goal was to fix the battery drain issue and it worked well before.Paraplegia
Same problem here. But it happened also with other devices (OnePlus, LGE, Xiaomi, Nexus 5X). The common point seems to be GPS 9.2.56 and Android 6.0.xDunite
This has been reported here: gmaps-api-isses issues 10166Mudslinger
J
4

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)
Joni answered 4/10, 2016 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.