Bugfix: prevent race condition in TrackPointCreator.

This race condition leads to a crash in TrackStatisticsUpdater as the time might appear to move backwards if the created TrackPoints are not stored in order. Might happen if multiple sensors (BLE or GPS) are used in simultaneously.

Every method affected by a race condition is now synchronized.

Problem was introduced in c4b8082efc

Fixes #1151.
This commit is contained in:
Dennis Guse
2022-04-03 12:28:15 +02:00
parent 71288cd9be
commit 18b21a6a3e
5 changed files with 38 additions and 24 deletions
@@ -17,6 +17,8 @@ package de.dennisguse.opentracks.util;
import android.location.Location;
import de.dennisguse.opentracks.data.models.Distance;
/**
* Utility class for decimating tracks at a given level of precision.
*
@@ -40,4 +42,11 @@ public class LocationUtils {
&& Math.abs(location.getLatitude()) <= 90
&& Math.abs(location.getLongitude()) <= 180;
}
public static boolean fulfillsAccuracy(Location location, Distance thresholdHorizontalAccuracy) {
return location.hasAccuracy() &&
Distance.of(location.getAccuracy())
.lessThan(thresholdHorizontalAccuracy);
}
}