Reputation: 31
About two weeks ago, several areas of our app stopped working randomly, specifically those that relied on up to date location. This is happening on multiple devices, both real devices and emulators. Before this, it was working every time. Fortunately for us all the stuff that stopped working was behind a flag and we were able to disable it in production.
Our location wrapper code had barely been touched for two years, and was working fine for ~ a month after its only recent change (which was trivial). In other words, it's been working without issue for two years. Snippets below.
Now, after registering to receive location updates, we are no longer getting a result in our callback most of the time. Here's the callback and other relevant snippets:
private val locationCallback = object : LocationCallback() {
override fun onLocationResult(locationResult: LocationResult?) {
Timber.tag("DERP").d("LocationProviderImpl.onLocationResult: got location; loc=${locationResult?.lastLocation}; thread=${Thread.currentThread().name}")
locationResult ?: return
subject.onNext(locationResult.lastLocation)
}
}
override fun getUpdatedLocation(request: LocationRequest): Observable<Location> {
try {
client.requestLocationUpdates(request, locationCallback, Looper.getMainLooper())
} catch (e: SecurityException) {
Timber.tag(LOGTAG).d(e, "security exception getting last location")
}
return subject
}
fun getDefaultLocationRequest(): LocationRequest = LocationRequest()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setNumUpdates(1)
.setFastestInterval(TimeUnit.MILLISECONDS.toMillis(500))
Here's the libs/versions we're using:
implementation 'com.google.android.gms:play-services-auth:19.0.0'
implementation 'com.google.android.gms:play-services-base:17.5.0'
implementation 'com.google.android.gms:play-services-location:17.1.0'
implementation "com.google.android.gms:play-services-gcm:17.0.0"
A few other things of note:
lastLocation
works every time, but is often stale.lastLocation
first does not seem to make the callback work any more reliably, as it seems to indicate in the docs.Is there some type of quota or restrictions that we previously weren't hitting but are now? Anything else that could be causing this?
Upvotes: 3
Views: 718
Reputation: 3258
Hi there I have recently struggled with exactly the same issue. It first came on one device and then on the other. As in your case, I hadnt done any modifications to the location service, it just started happening that I either got no callback at all or only 1 or 2 at startup. while I can only speculate as to what the underlying cause of the crash is I think the bug is not in your app but in google play services.
In my case restarting the app didnt help but restarting the device did. I noticed that there was a recent update to google play services before the first bug happened and I suspect that might have had something to do with it.
If you are able to reprocude this issue it might be worthwhile to log:
GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(mContext);
or experiment with:
GoogleApiAvailability.getInstance().makeGooglePlayServicesAvailable(activity)
GoogleApiAvailability.getInstance().checkApiAvailability(googleApi)
I know this isnt a real answer but maybe it helps to get closer to the root cause
Upvotes: 0
Reputation: 1
Try downgrade version
implementation 'com.google.android.gms:play-services-location:17.0.0'
I had the same, I think that this is a bug in 17.1.0 version
Upvotes: 0