Merge pull request #912 from OpenTracksApp/raceCondition

Bugfix: LocationHandler should ignore locations after stopping.
This commit is contained in:
Dennis Guse
2021-08-15 15:53:30 +02:00
committed by GitHub
@@ -44,6 +44,10 @@ public class LocationHandler implements LocationListener, GpsStatus.GpsStatusLis
gpsStatus.start();
}
private boolean isStarted() {
return locationManager != null;
}
@SuppressWarnings({"MissingPermission"})
//TODO upgrade to AGP7.0.0/API31 started complaining about removeUpdates.
public void onStop() {
@@ -96,6 +100,11 @@ public class LocationHandler implements LocationListener, GpsStatus.GpsStatusLis
*/
@Override
public void onLocationChanged(@NonNull Location location) {
if (!isStarted()) {
Log.w(TAG, "Location is ignored; not started.");
return;
}
TrackPoint trackPoint = new TrackPoint(location, handlerServer.createNow());
boolean isAccurate = trackPoint.fulfillsAccuracy(thresholdHorizontalAccuracy);
boolean isValid = LocationUtils.isValidLocation(location);