From 0b414b6672b5a10d39573e0ab57b8995f7b4b174 Mon Sep 17 00:00:00 2001 From: hajoha Date: Mon, 21 Jul 2025 13:50:18 +0200 Subject: [PATCH] show history of ping --- .../Ping/PingFragment.java | 32 +++++++++++++++---- .../Ping/Worker/PingWorker.java | 7 ++++ app/src/main/res/layout/fragment_ping.xml | 32 ++++++++++++++++++- app/src/main/res/values/styles.xml | 19 +++++++++++ 4 files changed, 83 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/PingFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/PingFragment.java index 04e918ad..81e69ded 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/PingFragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/PingFragment.java @@ -8,6 +8,7 @@ package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping; +import static android.view.View.GONE; import static android.view.View.INVISIBLE; import android.annotation.SuppressLint; @@ -42,6 +43,8 @@ import com.google.android.material.button.MaterialButtonToggleGroup; import com.google.android.material.textfield.TextInputEditText; +import com.google.android.material.textview.MaterialTextView; +import com.google.gson.Gson; import java.io.FileOutputStream; import java.util.UUID; @@ -49,6 +52,7 @@ import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Metric.METRIC_TYPE; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Metric.MetricCalculator; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Metric.MetricView; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.PingInformations.RTTLine; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.Worker.PingWorker; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SPType; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Preferences.SharedPreferencesGrouper; @@ -74,6 +78,8 @@ public class PingFragment extends Fragment { private Observer observer; private LiveData workInfoLiveData; + private MaterialTextView pingTextView; + public PingFragment() { } @@ -132,11 +138,20 @@ private void checkLastUUID(String uuidStr) { if (workInfo == null) return; Data progress = workInfo.getProgress(); Log.d(TAG, "registerObserver: workInfo-State: " + workInfo.getState()); - double rtt = progress.getDouble(PingWorker.RTT, -1.0); - if(rtt != -1.0) { - rttMetric.update(rtt); + String rtt = progress.getString(PingWorker.RTT); + if(rtt != null) { + RTTLine rttLine = new Gson().fromJson(rtt, RTTLine.class); + rttMetric.update(rttLine.getRtt()); + StringBuilder sb = new StringBuilder(); + sb.append("Host: ").append(rttLine.getHost()).append(" "); + sb.append("Seq: ").append(rttLine.getIcmpSeq()).append(" "); + sb.append("TTL: ").append(rttLine.getTtl()).append(" "); + sb.append("RTT: ").append(rttLine.getRtt()).append(" ms"); + pingTextView.setText(sb.toString()+"\n"+pingTextView.getText()); + } + double packetLoss = progress.getDouble(PingWorker.PACKET_LOSS, -1.0); if(packetLoss != -1.0) { @@ -213,7 +228,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, workManager = WorkManager.getInstance(ct); verticalLL = v.findViewById(R.id.ping_vertical_ll); horizontalLL1 = verticalLL.findViewById(R.id.ping_horizontal1_ll); - + pingTextView = v.findViewById(R.id.ping_output); toggleGroup = verticalLL.findViewById(R.id.ping_toggle_group); input = verticalLL.findViewById(R.id.ping_input); input.setText(spg.getSharedPreference(SPType.ping_sp).getString("ping_input", "-w 5 8.8.8.8")); @@ -240,6 +255,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, if (isRunning) { v.findViewById(R.id.ping_start).setBackgroundColor(ct.getResources().getColor(R.color.purple_500, null)); v.findViewById(R.id.ping_stop).setBackgroundColor(Color.TRANSPARENT); + pingTextView.setText(""); } else { v.findViewById(R.id.ping_start).setBackgroundColor(Color.TRANSPARENT); v.findViewById(R.id.ping_stop).setBackgroundColor(ct.getResources().getColor(R.color.purple_500, null)); @@ -289,8 +305,12 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, metricsLL.setLayoutParams(foo1); metricsLL.addView(rttMetric); metricsLL.addView(packetLossMetric); - packetLossMetric.setVisibility(INVISIBLE); - horizontalLL1.addView(metricsLL); + packetLossMetric.setVisibility(GONE); + LinearLayout foobar= v.findViewById(R.id.ping_metric); + foobar.addView(metricsLL); + + +// horizontalLL1.addView(metricsLL); return v; } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/Worker/PingWorker.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/Worker/PingWorker.java index 4e21b6d3..3150c698 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/Worker/PingWorker.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/Worker/PingWorker.java @@ -147,13 +147,20 @@ public Result doWork() { Log.w(TAG, "doWork: Line or PingInformation is null, skipping line"); continue; } + switch (pingInformation.getLineType()){ case RTT: rtt = ((RTTLine)pingInformation).getRtt(); + progressOutput.putDouble(RTT, rtt); + progressOutput.putString(RTT, new Gson().toJson((RTTLine)pingInformation)); + setProgressAsync(progressOutput.build()); setForegroundAsync(createForegroundInfo(((RTTLine) pingInformation).getHost()+": " + rtt + " ms")); + + + Log.d(TAG, "doWork: RTT: " + rtt); break; case UNREACHABLE: diff --git a/app/src/main/res/layout/fragment_ping.xml b/app/src/main/res/layout/fragment_ping.xml index ccc4af19..62fefabf 100644 --- a/app/src/main/res/layout/fragment_ping.xml +++ b/app/src/main/res/layout/fragment_ping.xml @@ -109,11 +109,41 @@ android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" - android:orientation="horizontal" + android:orientation="vertical" android:baselineAligned="false"> + + + + + + + + + + + + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 19dd8d58..6f801720 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -71,4 +71,23 @@ 2dp 18sp + + + \ No newline at end of file