Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #18642 #18676

Merged
merged 1 commit into from
Dec 6, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
import net.osmand.gpx.GPXUtilities.TrkSegment;
import net.osmand.gpx.GPXUtilities.WptPt;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.simulation.SimulationProvider;
import net.osmand.plus.Version;
import net.osmand.plus.notifications.OsmandNotification.NotificationType;
import net.osmand.plus.plugins.PluginsHelper;
import net.osmand.plus.plugins.development.OsmandDevelopmentPlugin;
import net.osmand.plus.routing.ColoringType;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.simulation.SimulationProvider;
import net.osmand.plus.track.helpers.GpxDataItem;
import net.osmand.plus.track.helpers.GpxDbHelper;
import net.osmand.plus.track.helpers.SelectedGpxFile;
Expand Down Expand Up @@ -87,6 +87,7 @@ public class SavingTrackHelper extends SQLiteOpenHelper {
private static final String POINT_COL_BACKGROUND = "background";

private static final NumberFormat DECIMAL_FORMAT = new DecimalFormat("#.#", new DecimalFormatSymbols(Locale.US));
private static final long LOCATION_TIME_INTERVAL_MS = 28L * 1000L * 60L * 60L * 24L; // 4 weeks


private final OsmandApplication app;
Expand Down Expand Up @@ -502,16 +503,24 @@ public void startNewSegment() {
}

public void updateLocation(@Nullable Location location, @Nullable Float heading) {
// use because there is a bug on some devices with location.getTime() see #18642
long time = System.currentTimeMillis();
if (location != null) {
long locationTime = location.getTime();
if (Math.abs(time - locationTime) < LOCATION_TIME_INTERVAL_MS) {
time = locationTime;
}
}
if (app.getRoutingHelper().isFollowingMode()) {
lastRoutingApplicationMode = settings.getApplicationMode();
} else if (settings.getApplicationMode() == settings.DEFAULT_APPLICATION_MODE.get()) {
lastRoutingApplicationMode = null;
}
boolean record = shouldRecordLocation(location);
boolean record = shouldRecordLocation(location, time);
if (record) {
heading = getAdjustedHeading(heading);

WptPt wptPt = new WptPt(location.getLatitude(), location.getLongitude(), location.getTime(),
WptPt wptPt = new WptPt(location.getLatitude(), location.getLongitude(), time,
location.getAltitude(), location.getSpeed(), location.getAccuracy(), heading);

String pluginsInfo = getPluginsInfo(location);
Expand All @@ -525,11 +534,10 @@ boolean record = shouldRecordLocation(location);
}
}

private boolean shouldRecordLocation(@Nullable Location location) {
private boolean shouldRecordLocation(@Nullable Location location, long locationTime) {
boolean record = false;
if (location != null && SimulationProvider.isNotSimulatedLocation(location)
&& PluginsHelper.isActive(OsmandMonitoringPlugin.class)) {
long locationTime = location.getTime();
if (isRecordingAutomatically() && locationTime - lastTimeUpdated > settings.SAVE_TRACK_INTERVAL.get()) {
record = true;
} else if (settings.SAVE_GLOBAL_TRACK_TO_GPX.get()
Expand Down