This repository has been archived by the owner on Apr 23, 2023. It is now read-only.
Simplify service shutdown to prevent crash on screen rotation #180
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
Simplifies service shutdown process to prevent race condition that leads to a crash when the device is rotated.
Proposed Changes
Removes
FusedLocationProviderServiceImpl#shutdown()
. This method was previously invoked when the system calledFusedLocationProviderService#onDestroy()
and did two things:LocationEngine#setRequest(null)
.LostClientManager#shutdown()
.The problem is that
FusedLocationProviderService#onDestroy()
would be invoked asynchronously by the system after rotating the device. By the timeonDestroy()
fires the client application may have already re-connected the location client and/or made a new request for location updates.If
onDestroy()
fires sometime between connecting the client and requesting updates it would lead to a crash similar those reported in #170.Fortunately it seems neither of the operations in
FusedLocationProviderServiceImpl#shutdown()
are needed since both are already completed by the timeonDestroy()
is invoked by the system:checkAllListenersPendingIntentsAndCallbacks()
is called which callsLocationEngine#setRequest(null)
if all listeners have been removed (a prerequisite to stopping the service).LostApiClientImpl#disconnect()
the fused location service is only shutdown if there are no remaining clients so clearing the clients again when the service is destroyed is unnecessary.Other Changes and Cleanup
shutdown()
fromClientManager
interface.LostClientManager#clearClients()
visible for testing only.@Override
annotations toClientManager
interface methods implemented inLostClientManager
.MultipleLocationListenerSingleClientActivity
to speed up feedback loop.Fixes #170