From 3e63bfe64c058b1686c8967fd904cfc1ac62bd07 Mon Sep 17 00:00:00 2001 From: Dennis Guse Date: Wed, 18 Dec 2024 19:13:07 +0100 Subject: [PATCH] Dashboard API: check if parameters are present before forwarding them. Part of #2030. --- .../publicapi/CreateMarkerActivity.java | 7 ++++-- .../publicapi/ShowMarkerActivity.java | 22 ++++--------------- 2 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/main/java/de/dennisguse/opentracks/publicapi/CreateMarkerActivity.java b/src/main/java/de/dennisguse/opentracks/publicapi/CreateMarkerActivity.java index 501f7630ca..a0328daff2 100644 --- a/src/main/java/de/dennisguse/opentracks/publicapi/CreateMarkerActivity.java +++ b/src/main/java/de/dennisguse/opentracks/publicapi/CreateMarkerActivity.java @@ -23,8 +23,11 @@ public class CreateMarkerActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Track.Id trackId = new Track.Id(getIntent().getLongExtra(EXTRA_TRACK_ID, 0L)); - Location location = getIntent().getParcelableExtra(EXTRA_LOCATION); + Track.Id trackId = new Track.Id(getIntent().getLongExtra(EXTRA_TRACK_ID, -1L)); + Location location = getIntent().getParcelableExtra(EXTRA_LOCATION, Location.class); + if (!getIntent().hasExtra(EXTRA_TRACK_ID) || location == null) { + throw new IllegalStateException("Parameter 'track_id' and/or 'location' missing or invalid."); + } TrackRecordingServiceConnection.execute(this, (service, self) -> { Intent intent = IntentUtils diff --git a/src/main/java/de/dennisguse/opentracks/publicapi/ShowMarkerActivity.java b/src/main/java/de/dennisguse/opentracks/publicapi/ShowMarkerActivity.java index 07b47ef3ec..9f01a5835d 100644 --- a/src/main/java/de/dennisguse/opentracks/publicapi/ShowMarkerActivity.java +++ b/src/main/java/de/dennisguse/opentracks/publicapi/ShowMarkerActivity.java @@ -1,30 +1,15 @@ package de.dennisguse.opentracks.publicapi; import android.content.Intent; -import android.database.Cursor; import android.os.Bundle; -import android.util.Log; -import android.view.View; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; -import androidx.fragment.app.Fragment; -import androidx.fragment.app.FragmentManager; -import androidx.fragment.app.FragmentStatePagerAdapter; -import androidx.viewpager.widget.ViewPager; -import java.util.ArrayList; import java.util.List; -import de.dennisguse.opentracks.AbstractActivity; -import de.dennisguse.opentracks.R; -import de.dennisguse.opentracks.data.ContentProviderUtils; import de.dennisguse.opentracks.data.models.Marker; import de.dennisguse.opentracks.databinding.MarkerDetailActivityBinding; -import de.dennisguse.opentracks.ui.markers.DeleteMarkerDialogFragment.DeleteMarkerCaller; import de.dennisguse.opentracks.ui.markers.MarkerDetailActivity; -import de.dennisguse.opentracks.ui.markers.MarkerDetailFragment; import de.dennisguse.opentracks.util.IntentUtils; /** @@ -44,10 +29,11 @@ public class ShowMarkerActivity extends AppCompatActivity { protected void onCreate(Bundle bundle) { super.onCreate(bundle); - Marker.Id markerId = new Marker.Id(getIntent().getLongExtra(EXTRA_MARKER_ID, 0)); - if (markerId.id() == 0) { - throw new IllegalStateException("No valid markerId provided"); + if (!getIntent().hasExtra(EXTRA_MARKER_ID)) { + throw new IllegalStateException("Parameter 'markerId' missing"); } + + Marker.Id markerId = new Marker.Id(getIntent().getLongExtra(EXTRA_MARKER_ID, -1)); Intent intent = IntentUtils.newIntent(this, MarkerDetailActivity.class) .putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, markerId); startActivity(intent);