Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,13 +43,16 @@

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;

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;
Expand All @@ -74,6 +78,8 @@ public class PingFragment extends Fragment {
private Observer<WorkInfo> observer;
private LiveData<WorkInfo> workInfoLiveData;

private MaterialTextView pingTextView;

public PingFragment() {
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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"));
Expand All @@ -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));
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
32 changes: 31 additions & 1 deletion app/src/main/res/layout/fragment_ping.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/ping_metric">
</LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/PingHistory">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.textview.MaterialTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/ping_output"
android:autoSizeMinTextSize="10sp"
android:autoSizeMaxTextSize="100sp"
android:autoSizeStepGranularity="1sp">

</com.google.android.material.textview.MaterialTextView>
</ScrollView>

</LinearLayout>
</androidx.cardview.widget.CardView>

</LinearLayout>

</LinearLayout>

</androidx.coordinatorlayout.widget.CoordinatorLayout>
19 changes: 19 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,23 @@
<item name="android:padding">2dp</item>
<item name="android:textSize">18sp</item>
</style>


<style name="PingHistory">
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:padding">8dp</item>
<item name="android:background">?attr/colorSurface</item>
<item name="android:orientation">vertical</item>
<item name="android:gravity">center_vertical</item>
<item name="android:layout_margin">4dp</item>
<item name="android:backgroundTint">?attr/colorSurface</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">8dp</item>
<item name="android:paddingTop">4dp</item>
<item name="android:paddingBottom">4dp</item>
<item name="android:clipToPadding">false</item>
<item name="android:scrollbars">vertical</item>

</style>
</resources>