forked from upstream-mirrors/OpenTracks
GPX: on import ignore TrackPoints without time.
Previous behavior: abort import. Fixes #2384.
This commit is contained in:
+41
@@ -120,6 +120,47 @@ public class GPXTrackImporterTest {
|
|||||||
), importedTrackPoints);
|
), importedTrackPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@LargeTest
|
||||||
|
@Test
|
||||||
|
public void gpx_missing_time() throws IOException {
|
||||||
|
// given
|
||||||
|
XMLImporter importer = new XMLImporter(new GPXTrackImporter(context, trackImporter));
|
||||||
|
InputStream inputStream = InstrumentationRegistry.getInstrumentation().getContext().getResources().openRawResource(de.dennisguse.opentracks.test.R.raw.gpx11_missing_time);
|
||||||
|
|
||||||
|
// when
|
||||||
|
// 1. import
|
||||||
|
importTrackId = importer.importFile(inputStream).get(0);
|
||||||
|
|
||||||
|
// then
|
||||||
|
// 2. track
|
||||||
|
Track importedTrack = contentProviderUtils.getTrack(importTrackId);
|
||||||
|
assertNotNull(importedTrack);
|
||||||
|
assertEquals("", importedTrack.activityTypeLocalized());
|
||||||
|
assertEquals("", importedTrack.description());
|
||||||
|
assertEquals("20210907_213924.gpx", importedTrack.name());
|
||||||
|
assertEquals(ActivityType.UNKNOWN, importedTrack.activityType());
|
||||||
|
|
||||||
|
// 3. trackstatistics
|
||||||
|
Statistics trackStatistics = importedTrack.statistics();
|
||||||
|
assertEquals(0, trackStatistics.maxSpeed().toMPS(), 0.01);
|
||||||
|
assertEquals(Duration.ofSeconds(0), trackStatistics.movingDuration());
|
||||||
|
|
||||||
|
// 4. trackpoints
|
||||||
|
List<TrackPoint> importedTrackPoints = TestDataUtil.getTrackPoints(contentProviderUtils, importTrackId);
|
||||||
|
assertEquals(1, importedTrackPoints.size());
|
||||||
|
|
||||||
|
TrackPointAssert a = new TrackPointAssert();
|
||||||
|
a.assertEquals(List.of(
|
||||||
|
new TrackPoint(TrackPoint.Type.SEGMENT_START_AUTOMATIC,
|
||||||
|
new Position(
|
||||||
|
Instant.parse("2021-09-07T22:12:00Z"),
|
||||||
|
30.14185982, -40.3863038, null,
|
||||||
|
Altitude.WGS84.of(-5), null,
|
||||||
|
null,
|
||||||
|
null))
|
||||||
|
), importedTrackPoints);
|
||||||
|
}
|
||||||
|
|
||||||
@LargeTest
|
@LargeTest
|
||||||
@Test
|
@Test
|
||||||
public void gpx_speed_no_namespace() throws IOException {
|
public void gpx_speed_no_namespace() throws IOException {
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
|
||||||
|
<gpx version="1.1" creator="Cruiser" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
|
||||||
|
<trk>
|
||||||
|
<name>20210907_213924.gpx</name>
|
||||||
|
<trkseg>
|
||||||
|
<trkpt lat="30.14185982" lon="-40.3863038">
|
||||||
|
<ele>-5</ele>
|
||||||
|
<hdop>4</hdop>
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="30.14184657" lon="-40.38670089">
|
||||||
|
<ele>-5</ele>
|
||||||
|
<time/>
|
||||||
|
<hdop>4</hdop>
|
||||||
|
</trkpt>
|
||||||
|
<trkpt lat="30.14185982" lon="-40.3863038">
|
||||||
|
<ele>-5</ele>
|
||||||
|
<time>2021-09-07T22:12:00Z</time>
|
||||||
|
<hdop>4</hdop>
|
||||||
|
</trkpt>
|
||||||
|
</trkseg>
|
||||||
|
</trk>
|
||||||
|
</gpx>
|
||||||
@@ -18,8 +18,11 @@ package de.dennisguse.opentracks.io.file.importer;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import org.xml.sax.Attributes;
|
import org.xml.sax.Attributes;
|
||||||
import org.xml.sax.Locator;
|
import org.xml.sax.Locator;
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
@@ -178,7 +181,10 @@ public class GPXTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
zoneOffset = null;
|
zoneOffset = null;
|
||||||
}
|
}
|
||||||
case TAG_TRACK_SEGMENT -> onTrackSegmentEnd();
|
case TAG_TRACK_SEGMENT -> onTrackSegmentEnd();
|
||||||
case TAG_TRACK_POINT -> currentSegment.add(createTrackPoint());
|
case TAG_TRACK_POINT -> {
|
||||||
|
TrackPoint trackPoint = createTrackPoint();
|
||||||
|
if (trackPoint != null) currentSegment.add(trackPoint);
|
||||||
|
}
|
||||||
case TAG_NAME -> {
|
case TAG_NAME -> {
|
||||||
if (content != null) {
|
if (content != null) {
|
||||||
name = content.trim();
|
name = content.trim();
|
||||||
@@ -284,8 +290,10 @@ public class GPXTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
currentSegment.clear();
|
currentSegment.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private TrackPoint createTrackPoint() throws ParsingException {
|
private TrackPoint createTrackPoint() throws ParsingException {
|
||||||
|
if (TextUtils.isEmpty(time)) return null;
|
||||||
|
|
||||||
OffsetDateTime parsedTime;
|
OffsetDateTime parsedTime;
|
||||||
try {
|
try {
|
||||||
parsedTime = StringUtils.parseTime(time);
|
parsedTime = StringUtils.parseTime(time);
|
||||||
@@ -468,7 +476,10 @@ public class GPXTrackImporter extends DefaultHandler implements XMLImporter.Trac
|
|||||||
}
|
}
|
||||||
|
|
||||||
TrackPoint trackPoint = createTrackPoint();
|
TrackPoint trackPoint = createTrackPoint();
|
||||||
|
if (trackPoint == null) {
|
||||||
|
Log.w(TAG, "Marker with no TrackPoint");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!trackPoint.position().hasLocation()) {
|
if (!trackPoint.position().hasLocation()) {
|
||||||
Log.w(TAG, "Marker with invalid coordinates ignored: " + trackPoint.position());
|
Log.w(TAG, "Marker with invalid coordinates ignored: " + trackPoint.position());
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user