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:
- The callback is intermittently getting results (maybe 1 in 15 attempts)
- No rhyme or reason as to why, tried many different hacks to get it to fire with no luck.
lastLocation
works every time, but is often stale.- calling
lastLocation
first does not seem to make the callback work any more reliably, as it seems to indicate in the docs. - this location provider (wrapper around the fused client) was used in several areas of the app, but only recently did we start using it a lot more in our latest feature.
Is there some type of quota or restrictions that we previously weren't hitting but are now? Anything else that could be causing this?