Skip to content

Commit

Permalink
Prevent a NPE when checking the location age
Browse files Browse the repository at this point in the history
  • Loading branch information
christianrowlands committed Dec 4, 2024
1 parent 3896c17 commit 9d365cb
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,10 @@ public void onProviderDisabled(@NonNull String provider)
}
}

public Location getLatestLocation()
public synchronized Location getLatestLocation()
{
if (latestLocation == null) return null;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
{
long locationTimeAge = latestLocation.getElapsedRealtimeAgeMillis();
Expand All @@ -160,7 +162,7 @@ public Location getLatestLocation()
*
* @param newLocation The newly provided location.
*/
private void updateLocation(Location newLocation)
private synchronized void updateLocation(Location newLocation)
{
latestLocation = newLocation;

Expand Down

0 comments on commit 9d365cb

Please sign in to comment.