From 0cf2b172c1e7d9a4646fd3b55fde86c3c6fe6193 Mon Sep 17 00:00:00 2001 From: hajoha Date: Fri, 15 Aug 2025 13:30:36 +0200 Subject: [PATCH 1/6] fix stream not saved bug --- .../Iperf3/Fragments/Iperf3Fragment.java | 8 ++++---- app/src/main/res/layout/fragment_iperf3_input.xml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Fragments/Iperf3Fragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Fragments/Iperf3Fragment.java index 8ff211b7..0866d307 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Fragments/Iperf3Fragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Fragments/Iperf3Fragment.java @@ -74,7 +74,7 @@ public class Iperf3Fragment extends Fragment { private TextInputEditText duration; private TextInputEditText interval; private TextInputEditText bytes; - private TextInputEditText streams; + private TextInputEditText parallel; private TextInputEditText cport; @@ -151,7 +151,7 @@ private void setupTextWatchers() { duration.addTextChangedListener(createTextWatcher(s -> iperf3Input.getParameter().setTime(Integer.parseInt("0"+s)), Iperf3Parameter.TIME)); interval.addTextChangedListener(createTextWatcher(s -> iperf3Input.getParameter().setInterval(Double.parseDouble("0"+s)), Iperf3Parameter.INTERVAL)); bytes.addTextChangedListener(createTextWatcher(s -> iperf3Input.getParameter().setBytes(s), Iperf3Parameter.BYTES)); - streams.addTextChangedListener(createTextWatcher(s -> iperf3Input.getParameter().setParallel(Integer.parseInt("0"+s)), Iperf3Parameter.PARALLEL)); + parallel.addTextChangedListener(createTextWatcher(s -> iperf3Input.getParameter().setParallel(Integer.parseInt("0"+s)), Iperf3Parameter.PARALLEL)); cport.addTextChangedListener(createTextWatcher(s -> iperf3Input.getParameter().setCport(Integer.parseInt("0"+s) ), Iperf3Parameter.CPORT)); } @@ -256,7 +256,7 @@ private void setTextsFromSharedPreferences(){ setTextFromSharedPreferences(duration, Iperf3Parameter.TIME); setTextFromSharedPreferences(interval, Iperf3Parameter.INTERVAL); setTextFromSharedPreferences(bytes, Iperf3Parameter.BYTES); - setTextFromSharedPreferences(streams, Iperf3Parameter.STREAMS); + setTextFromSharedPreferences(parallel, Iperf3Parameter.PARALLEL); setTextFromSharedPreferences(cport, Iperf3Parameter.CPORT); } @@ -347,7 +347,7 @@ public void onClick(View view) { duration = view.findViewById(R.id.iperf3_duration); interval = view.findViewById(R.id.iperf3_interval); bytes = view.findViewById(R.id.iperf3_bytes); - streams = view.findViewById(R.id.iperf3_streams); + parallel = view.findViewById(R.id.iperf3_parallel); cport = view.findViewById(R.id.iperf3_cport); diff --git a/app/src/main/res/layout/fragment_iperf3_input.xml b/app/src/main/res/layout/fragment_iperf3_input.xml index 0e7f743a..6bdf0dbf 100644 --- a/app/src/main/res/layout/fragment_iperf3_input.xml +++ b/app/src/main/res/layout/fragment_iperf3_input.xml @@ -101,7 +101,7 @@ From 3f635b276368b23c67bbdfda500ba95348b88f29 Mon Sep 17 00:00:00 2001 From: hajoha Date: Tue, 25 Nov 2025 09:54:47 +0100 Subject: [PATCH 2/6] remove unused rootPath constant from Iperf3Parameter --- .../OpenMobileNetworkToolkit/Parameter/Iperf3Parameter.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/Iperf3Parameter.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/Iperf3Parameter.java index 913965ea..badca39e 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/Iperf3Parameter.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/Iperf3Parameter.java @@ -24,7 +24,6 @@ import java.util.ArrayList; public class Iperf3Parameter extends Parameter { - public static final String rootPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath(); public static final String rawDirPath = rootPath+"/omnt/iperf3/raw/"; public static final String lineProtocolDirPath = rootPath+"/omnt/iperf3/lineprotocol/"; public static final String HOST = "host"; From 770d9aa63fc09b095ecc747f460e1fc5fd9f33e2 Mon Sep 17 00:00:00 2001 From: hajoha Date: Sun, 12 Oct 2025 21:18:31 +0200 Subject: [PATCH 3/6] fix addTag bug --- .../Ping/Worker/PingToLineProtocolWorker.java | 5 +++++ app/src/main/res/raw/config.json | 2 +- docs/config.json | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/Worker/PingToLineProtocolWorker.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/Worker/PingToLineProtocolWorker.java index 51d45ade..33e5597d 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/Worker/PingToLineProtocolWorker.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/Worker/PingToLineProtocolWorker.java @@ -136,6 +136,11 @@ public Result doWork() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { point.addTags(GlobalVars.getInstance().get_dp().getTagsMap()); } + if(!pingInput.getSequenceUUID().isEmpty()) point.addTag("sequenceUUID", pingInput.getSequenceUUID()); + if(!pingInput.getTestUUID().isEmpty()) point.addTag("testUUID", pingInput.getTestUUID()); + if(!pingInput.getMeasurementUUID().isEmpty())point.addTag("measurementUUID", pingInput.getMeasurementUUID()); + if(!pingInput.getCampaignUUID().isEmpty()) point.addTag("campaignUUID", pingInput.getCampaignUUID()); + pingStream.write((point.toLineProtocol() + "\n").getBytes()); } catch (IOException e) { diff --git a/app/src/main/res/raw/config.json b/app/src/main/res/raw/config.json index f00711d3..a3118585 100644 --- a/app/src/main/res/raw/config.json +++ b/app/src/main/res/raw/config.json @@ -513,7 +513,7 @@ "metadata": { "version": "0.7", "code": 7, - "gitHash": "9d3ed7b" + "gitHash": "52f0533" } } ] \ No newline at end of file diff --git a/docs/config.json b/docs/config.json index f00711d3..a3118585 100644 --- a/docs/config.json +++ b/docs/config.json @@ -513,7 +513,7 @@ "metadata": { "version": "0.7", "code": 7, - "gitHash": "9d3ed7b" + "gitHash": "52f0533" } } ] \ No newline at end of file From 7ef436f282cf688aae69a7778381d2c70e244158 Mon Sep 17 00:00:00 2001 From: hajoha Date: Fri, 12 Sep 2025 08:45:35 +0200 Subject: [PATCH 4/6] fix mqtt multiple client bug --- app/src/main/AndroidManifest.xml | 1 + .../MQTT/MQTTService.java | 214 ++++++++++++++---- .../MQTTSettingsFragment.java | 1 + .../SettingPreferences/SettingsFragment.java | 12 + app/src/main/res/raw/config.json | 2 +- app/src/main/res/values/strings.xml | 2 +- docs/config.json | 2 +- docs/preferences.md | 2 +- 8 files changed, 187 insertions(+), 49 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 884d74b2..cd98672f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -23,6 +23,7 @@ + diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MQTT/MQTTService.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MQTT/MQTTService.java index d4270189..5cf18801 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MQTT/MQTTService.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MQTT/MQTTService.java @@ -9,6 +9,7 @@ package de.fraunhofer.fokus.OpenMobileNetworkToolkit.MQTT; import android.app.Notification; +import android.app.NotificationChannel; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.Service; @@ -20,6 +21,7 @@ import android.os.Handler; import android.os.IBinder; import android.util.Log; +import android.widget.Toast; import androidx.annotation.Nullable; import androidx.core.app.NotificationCompat; @@ -29,19 +31,27 @@ import androidx.work.multiprocess.RemoteWorkManager; +import com.hivemq.client.mqtt.MqttClientState; import com.hivemq.client.mqtt.datatypes.MqttQos; +import com.hivemq.client.mqtt.lifecycle.MqttClientConnectedContext; +import com.hivemq.client.mqtt.lifecycle.MqttClientDisconnectedContext; import com.hivemq.client.mqtt.mqtt5.Mqtt5AsyncClient; import com.hivemq.client.mqtt.mqtt5.Mqtt5Client; import com.hivemq.client.mqtt.mqtt5.message.connect.connack.Mqtt5ConnAck; import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5PayloadFormatIndicator; +import org.jetbrains.annotations.NotNull; + import java.net.InetSocketAddress; +import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.ArrayList; +import java.util.EnumSet; import java.util.HashMap; import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.CustomEventListener; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.MQTT.Handler.Iperf3Handler; @@ -77,31 +87,104 @@ private void setupSharedPreferences(){ mqttSP = spg.getSharedPreference(SPType.MQTT); mqttSP.registerOnSharedPreferenceChangeListener((sharedPreferences, key) -> { if(key == null) return; - if (key.equals("mqtt_host")) { - Log.d(TAG, "MQTT Host update: " + sharedPreferences.getString("mqtt_host", "")); - client.disconnect(); - createClient(); - createNotification(); + isEnabled = sharedPreferences.getBoolean("enable_mqtt", false); + switch (key){ + case "mqtt_host": + if(!isEnabled) return; + Log.d(TAG, "mqtt_host: " + sharedPreferences.getString("mqtt_host", "")); + disconnectClient(); + createClient(); + createNotification(); + break; + case "enable_mqtt": + Log.d(TAG, "enable_mqtt: " + isEnabled); + if(!isEnabled && client != null){ + this.onDestroy(); + } + break; } + }); } - - public void createClient(){ - String addressString = mqttSP.getString("mqtt_host", "localhost:1883"); - String host = null; - int port = -1; + private boolean isValidUrl(String addressString) { try { - host = addressString.split(":")[0]; - port = Integer.parseInt(addressString.split(":")[1]); + new java.net.URL(addressString); + return true; } catch (Exception e) { - Log.e(TAG, "createClient: Invalid address string: " + addressString); + return false; + } + } + + private boolean isProtocolIpPort(String addressString) { + // Example: mqtt://192.168.1.1:1883 + String regex = "^[\\d.]+:\\d+$"; + return addressString.matches(regex); + } + + + public String mQTTClientStateToString(MqttClientState state) { + switch (state) { + case CONNECTED: + return "Connected"; + case CONNECTING: + return "Connecting"; + case DISCONNECTED: + return "Disconnected"; + case DISCONNECTED_RECONNECT: + return "Disconnected_Reconnecting"; + case CONNECTING_RECONNECT: + return "Connecting_Reconnecting"; + default: + return "Unknown"; + } + } + + + public void createClient() { + String addressString = mqttSP.getString("mqtt_host", ""); + Log.d(TAG, "createClient: creating client..."); + if (addressString.isBlank()) { + Log.e(TAG, "createClient: MQTT Host is empty"); + spg.getSharedPreference(SPType.MQTT).edit().putBoolean("enable_mqtt", false).apply(); + client = null; return; } - if(host == null || port == -1){ - Log.e(TAG, "createClient: Invalid address string: " + addressString); + + if (!isValidUrl(addressString) && !isProtocolIpPort(addressString)) { + Log.e(TAG, "createClient: MQTT Host is not a valid URL or IP:Port"); + Toast.makeText(context, "MQTT Host is not a valid URL or IP:Port", Toast.LENGTH_SHORT).show(); + spg.getSharedPreference(SPType.MQTT).edit().putBoolean("enable_mqtt", false).apply(); + client = null; + return; + } + + String host; + int port; + + try { + if (isProtocolIpPort(addressString)) { + // Case: raw host:port + String[] hostPort = addressString.split(":"); + host = hostPort[0]; + port = Integer.parseInt(hostPort[1]); + } else { + // Case: URL with scheme + URI uri = new URI(addressString); + host = uri.getHost(); + port = uri.getPort() == -1 ? 1883 : uri.getPort(); // default MQTT port + } + } catch (Exception e) { + Log.e(TAG, "createClient: Invalid MQTT address", e); + spg.getSharedPreference(SPType.MQTT).edit().putBoolean("enable_mqtt", false).apply(); + client = null; return; } - InetSocketAddress address = new InetSocketAddress(host, port); + + InetSocketAddress address = InetSocketAddress.createUnresolved(host, port); + if(client != null){ + disconnectClient(); + client = null; + } client = Mqtt5Client.builder() .identifier(deviceName) .serverAddress(address) @@ -109,30 +192,35 @@ public void createClient(){ .initialDelay(5, TimeUnit.SECONDS) .maxDelay(30, TimeUnit.SECONDS) .applyAutomaticReconnect() - .addConnectedListener(context -> { - Log.i(TAG, "createClient: Connected to MQTT server"); - createNotification(); + .addConnectedListener(ctx -> { + Log.i(TAG, "addConnectedListener: Connected to MQTT server"); + createNotification(null, ctx); publishToTopic(String.format("device/%s/status", deviceName), "1", false); + Log.d(TAG, "addConnectedListener: "+mQTTClientStateToString(client.getState())); }) - .addDisconnectedListener(context -> { - Log.i(TAG, "createClient: Disconnected from MQTT server"); - createNotification(); + .addDisconnectedListener(ctx -> { + Log.i(TAG, "addDisconnectedListener: Disconnected from MQTT server"); + createNotification(ctx, null); + }) .willPublish() - .topic(String.format("device/%s/status", deviceName)) - .qos(MqttQos.EXACTLY_ONCE) - .payload("0".getBytes()) - .retain(true) - .payloadFormatIndicator(Mqtt5PayloadFormatIndicator.UTF_8) - .contentType("text/plain") - .noMessageExpiry() - .applyWillPublish() + .topic(String.format("device/%s/status", deviceName)) + .qos(MqttQos.EXACTLY_ONCE) + .payload("0".getBytes()) + .retain(true) + .payloadFormatIndicator(Mqtt5PayloadFormatIndicator.UTF_8) + .contentType("text/plain") + .noMessageExpiry() + .applyWillPublish() .buildAsync(); - - Log.i(TAG, "createClient: Client created with address: " + addressString); + Log.i(TAG, "createClient: Client created with address: " + host + ":" + port); } - private void createNotification(){ + private void createNotification() { + createNotification(null, null); + } + private void createNotification(MqttClientDisconnectedContext mqttClientDisconnectedContext, + MqttClientConnectedContext mqttClientConnectedContext) { StringBuilder s = new StringBuilder(); String address = spg.getSharedPreference(SPType.MQTT).getString("mqtt_host", "None"); if(address.equals("None")){ @@ -140,6 +228,11 @@ private void createNotification(){ } else { s.append("Host: ").append(address).append("\n"); s.append("State: ").append(client.getState().toString()).append("\n"); + if(mqttClientDisconnectedContext != null){ + if(mqttClientDisconnectedContext.getCause() != null){ + s.append("Cause: ").append(mqttClientDisconnectedContext.getCause().getMessage()).append("\n"); + } + } } builder.setStyle(new NotificationCompat.BigTextStyle() .bigText(s)); @@ -149,9 +242,21 @@ private void createNotification(){ @Override public void onCreate() { super.onCreate(); + Log.d(TAG, "onCreate: Creating MQTTService"); nm = getSystemService(NotificationManager.class); Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_IMMUTABLE); + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + NotificationChannel channel = new NotificationChannel( + "OMNT_notification_channel", + "OMNT MQTT Service", + NotificationManager.IMPORTANCE_MAX + ); + nm.createNotificationChannel(channel); + } + setupSharedPreferences(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { // create notification builder = new NotificationCompat.Builder(this, "OMNT_notification_channel") @@ -184,19 +289,33 @@ public void publishToTopic(String topic, String message, boolean retain){ .retain(retain) .send(); } - + private boolean isConnected(){ + if(client == null){ + Log.e(TAG, "isConnected: Client is null"); + return false; + } + return client.getState().isConnected(); + } public void disconnectClient(){ - CompletableFuture disconnect = client.disconnect(); - disconnect.whenComplete((aVoid, throwable) -> { - if(throwable != null){ - Log.e(TAG, "disconnectClient: Error disconnecting from MQTT server: " + throwable.getMessage()); - } else { - Log.i(TAG, "disconnectClient: Disconnected from MQTT server"); - } - }); + Log.d(TAG, "disconnectClient: starting to disconnect client...."); + if(isConnected()){ + + CompletableFuture disconnect = client.disconnect(); + disconnect.whenComplete((aVoid, throwable) -> { + if(throwable != null){ + Log.e(TAG, "disconnectClient: Error disconnecting from MQTT server: " + throwable.getMessage()); + } else { + Log.i(TAG, "disconnectClient: Disconnected from MQTT server"); + } + + }); + } + client = null; + nm.cancel(3); } public void connectClient(){ + Log.d(TAG, "connectClient: Connecting to MQTT server..."); CompletableFuture connAck = client.connectWith() .keepAlive(1) @@ -435,16 +554,21 @@ private void subscribeToAllTopics(){ subsribetoTopic(String.format("device/%s/#", deviceName)); } + public void onDestroy(){ + disconnectClient(); + client = null; + Log.d(TAG, "onDestroy: Destroying MQTTService"); + super.onDestroy(); + + } @Override public int onStartCommand(Intent intent, int flags, int startId) { - Log.d(TAG, "onStartCommand: Start MQTT service"); + Log.d(TAG, "onStartCommand: Start MQTTservice"); context = getApplicationContext(); - mqttSP = SharedPreferencesGrouper.getInstance(context).getSharedPreference(SPType.MQTT); deviceName = SharedPreferencesGrouper.getInstance(context).getSharedPreference(SPType.MAIN).getString("device_name", "null").strip(); startForeground(3, builder.build()); - setupSharedPreferences(); createClient(); if(client == null){ Log.e(TAG, "onStartCommand: Client is null"); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/MQTTSettingsFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/MQTTSettingsFragment.java index d9258029..86f468d5 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/MQTTSettingsFragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/MQTTSettingsFragment.java @@ -43,6 +43,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, @Null if (key.equals("enable_mqtt")) { boolean logger = sharedPreferences.getBoolean("enable_mqtt", false); Log.d(TAG, "Logger update: " + logger); + _switch.setChecked(logger); } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/SettingsFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/SettingsFragment.java index d3785f8a..0e49edc8 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/SettingsFragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SettingPreferences/SettingsFragment.java @@ -12,6 +12,7 @@ import android.os.Build; import android.os.Bundle; import android.telephony.SubscriptionInfo; +import android.util.Log; import android.widget.Toast; import androidx.activity.OnBackPressedCallback; @@ -33,6 +34,8 @@ public class SettingsFragment extends PreferenceFragmentCompat { + private static final String TAG = "SettingsFragment"; + @Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { SharedPreferencesGrouper spg = SharedPreferencesGrouper.getInstance(requireContext()); @@ -64,6 +67,15 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { } } + for (String key : pfm.getSharedPreferences().getAll().keySet()) { + Preference pref = pfm.findPreference(key); + if (pref != null) { + pref.setOnPreferenceChangeListener((preference, newValue) -> { + Log.d(TAG, "Preference changed: " + preference.getKey() + " -> " + newValue); + return true; + }); + } + } Preference button = pfm.findPreference("reset_modem"); if (button != null) { if (GlobalVars.getInstance().isCarrier_permissions()) { diff --git a/app/src/main/res/raw/config.json b/app/src/main/res/raw/config.json index f00711d3..a3118585 100644 --- a/app/src/main/res/raw/config.json +++ b/app/src/main/res/raw/config.json @@ -513,7 +513,7 @@ "metadata": { "version": "0.7", "code": 7, - "gitHash": "9d3ed7b" + "gitHash": "52f0533" } } ] \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index fb6f3ffc..51d8c75b 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -121,7 +121,7 @@ MQTT Client Password MQTT-Broker Address, including Port MQTT-Broker Address - tcp://192.168.213.89:1883 + 192.168.213.89:1883 MQTT Service diff --git a/docs/config.json b/docs/config.json index f00711d3..a3118585 100644 --- a/docs/config.json +++ b/docs/config.json @@ -513,7 +513,7 @@ "metadata": { "version": "0.7", "code": 7, - "gitHash": "9d3ed7b" + "gitHash": "52f0533" } } ] \ No newline at end of file diff --git a/docs/preferences.md b/docs/preferences.md index 0600fe49..2b83a785 100644 --- a/docs/preferences.md +++ b/docs/preferences.md @@ -92,7 +92,7 @@ _Section to set Credentials for MQTT._ | Key | Title | Summary | Default Value | | --- | ----- | ------- | ------------- | -| **mqtt_host** | MQTT-Broker Address | MQTT Broker Address | `tcp://192.168.213.89:1883` | +| **mqtt_host** | MQTT-Broker Address | MQTT Broker Address | `192.168.213.89:1883` | | **mqtt_client_username** | MQTT Client Username | MQTT Username | `USERNAME` | | **mqtt_client_password** | MQTT Client Password | MQTT Client Password. | `PASSWORD` | From 8cb68080878db9aa7e5f3a2b8e5f922fabbbe79f Mon Sep 17 00:00:00 2001 From: hajoha Date: Tue, 25 Nov 2025 10:17:14 +0100 Subject: [PATCH 5/6] update Iperf3Parameter and Parameter classes for improved path handling and cleanup --- .../Parameter/Iperf3Parameter.java | 432 ++---------------- .../Parameter/Parameter.java | 75 +-- .../Parameter/PingParameter.java | 40 +- app/src/main/res/raw/config.json | 2 +- docs/config.json | 2 +- 5 files changed, 81 insertions(+), 470 deletions(-) diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/Iperf3Parameter.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/Iperf3Parameter.java index 913965ea..28f74131 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/Iperf3Parameter.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/Iperf3Parameter.java @@ -8,9 +8,7 @@ package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Parameter; -import android.os.Environment; import android.os.Parcel; -import android.os.Parcelable; import android.util.Log; import androidx.annotation.NonNull; @@ -24,9 +22,7 @@ import java.util.ArrayList; public class Iperf3Parameter extends Parameter { - public static final String rootPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath(); - public static final String rawDirPath = rootPath+"/omnt/iperf3/raw/"; - public static final String lineProtocolDirPath = rootPath+"/omnt/iperf3/lineprotocol/"; + public static final String HOST = "host"; public static final String PORT = "port"; public static final String BITRATE = "bitrate"; @@ -67,7 +63,6 @@ public class Iperf3Parameter extends Parameter { public static final String RSAPRIVATEKEYPATH = "rsaPrivateKeyPath"; public static final String IDLETIMEOUT = "idleTimeout"; public static final String SERVERBITRATELIMIT = "serverBitrateLimit"; - public static final String SERVER = "server"; public static final String CLIENT = "client"; public static final String DAEMON = "daemon"; @@ -95,332 +90,35 @@ public class Iperf3Parameter extends Parameter { private static final String TAG = "Iperf3Parameter"; - - protected Iperf3Parameter(Parcel in) { - super(in); - host = in.readString(); - iPerf3UUID = in.readString(); - port = in.readInt(); - interval = in.readDouble(); - bitrate = in.readString(); - length = in.readInt(); - pidfile = in.readString(); - file = in.readString(); - affinity = in.readString(); - bind = in.readString(); - bindDev = in.readString(); - byte tmpVerbose = in.readByte(); - verbose = tmpVerbose == 0 ? null : tmpVerbose == 1; - byte tmpJson = in.readByte(); - json = tmpJson == 0 ? null : tmpJson == 1; - byte tmpJsonStream = in.readByte(); - jsonStream = tmpJsonStream == 0 ? null : tmpJsonStream == 1; - byte tmpForceflush = in.readByte(); - forceflush = tmpForceflush == 0 ? null : tmpForceflush == 1; - timestamps = in.readString(); - if (in.readByte() == 0) { - rcvTimeout = null; - } else { - rcvTimeout = in.readInt(); - } - if (in.readByte() == 0) { - sndTimeout = null; - } else { - sndTimeout = in.readInt(); - } - if (in.readByte() == 0) { - debug = null; - } else { - debug = in.readInt(); - } - byte tmpVersion = in.readByte(); - version = tmpVersion == 0 ? null : tmpVersion == 1; - byte tmpHelp = in.readByte(); - help = tmpHelp == 0 ? null : tmpHelp == 1; - byte tmpDaemon = in.readByte(); - daemon = tmpDaemon == 0 ? null : tmpDaemon == 1; - byte tmpOneOff = in.readByte(); - oneOff = tmpOneOff == 0 ? null : tmpOneOff == 1; - serverBitrateLimit = in.readString(); - if (in.readByte() == 0) { - idleTimeout = null; - } else { - idleTimeout = in.readInt(); - } - rsaPrivateKeyPath = in.readString(); - authorizedUsersPath = in.readString(); - if (in.readByte() == 0) { - timeSkewThreshold = null; - } else { - timeSkewThreshold = in.readInt(); - } - byte tmpUsePkcs1Padding = in.readByte(); - usePkcs1Padding = tmpUsePkcs1Padding == 0 ? null : tmpUsePkcs1Padding == 1; - byte tmpSctp = in.readByte(); - sctp = tmpSctp == 0 ? null : tmpSctp == 1; - xbind = in.readString(); - if (in.readByte() == 0) { - nstreams = null; - } else { - nstreams = in.readInt(); - } - if (in.readByte() == 0) { - connectTimeout = null; - } else { - connectTimeout = in.readInt(); - } - pacingTimer = in.readString(); - fqRate = in.readString(); - if (in.readByte() == 0) { - time = null; - } else { - time = in.readInt(); - } - bytes = in.readString(); - blockcount = in.readString(); - if (in.readByte() == 0) { - cport = null; - } else { - cport = in.readInt(); - } - if (in.readByte() == 0) { - parallel = null; - } else { - parallel = in.readInt(); - } - byte tmpReverse = in.readByte(); - reverse = tmpReverse == 0 ? null : tmpReverse == 1; - byte tmpBidir = in.readByte(); - bidir = tmpBidir == 0 ? null : tmpBidir == 1; - window = in.readString(); - congestion = in.readString(); - if (in.readByte() == 0) { - setMss = null; - } else { - setMss = in.readInt(); - } - byte tmpNoDelay = in.readByte(); - noDelay = tmpNoDelay == 0 ? null : tmpNoDelay == 1; - byte tmpVersion4 = in.readByte(); - version4 = tmpVersion4 == 0 ? null : tmpVersion4 == 1; - byte tmpVersion6 = in.readByte(); - version6 = tmpVersion6 == 0 ? null : tmpVersion6 == 1; - if (in.readByte() == 0) { - tos = null; - } else { - tos = in.readInt(); - } - dscp = in.readString(); - if (in.readByte() == 0) { - flowlabel = null; - } else { - flowlabel = in.readInt(); - } - byte tmpZerocopy = in.readByte(); - zerocopy = tmpZerocopy == 0 ? null : tmpZerocopy == 1; - if (in.readByte() == 0) { - omit = null; - } else { - omit = in.readInt(); - } - title = in.readString(); - extraData = in.readString(); - byte tmpGetServerOutput = in.readByte(); - getServerOutput = tmpGetServerOutput == 0 ? null : tmpGetServerOutput == 1; - byte tmpUdpCounters64bit = in.readByte(); - udpCounters64bit = tmpUdpCounters64bit == 0 ? null : tmpUdpCounters64bit == 1; - byte tmpRepeatingPayload = in.readByte(); - repeatingPayload = tmpRepeatingPayload == 0 ? null : tmpRepeatingPayload == 1; - byte tmpDontFragment = in.readByte(); - dontFragment = tmpDontFragment == 0 ? null : tmpDontFragment == 1; - username = in.readString(); - rsaPublicKeyPath = in.readString(); - } - - public static final Creator CREATOR = new Creator() { - @Override - public Iperf3Parameter createFromParcel(Parcel in) { - return new Iperf3Parameter(in); - } - - @Override - public Iperf3Parameter[] newArray(int size) { - return new Iperf3Parameter[size]; - } - }; - - public Iperf3Parameter(String ip, - int port, - String bitrate, - int duration, - double interval, - String bytes, - int streams, - int cport, - String testUUID, - Iperf3Mode mode, - Iperf3Protocol protocol, - Iperf3Direction direction - ) { - - super(rawDirPath+testUUID+".txt", lineProtocolDirPath+testUUID+".txt"); - this.testUUID = testUUID; - this.host = ip; - this.port = port; - this.bitrate = bitrate; - this.time = duration; - this.interval = interval; - this.bytes = bytes; - this.nstreams = streams; - this.cport = cport; - this.mode = mode; - this.direction = direction; - this.protocol = protocol; - - } - - public Iperf3Parameter(String iPerf3UUID){ - super(rawDirPath+iPerf3UUID+".txt", lineProtocolDirPath+iPerf3UUID+".txt"); - } - public Iperf3Parameter(String ip, - String iPerf3UUID, - Iperf3Protocol protocol, - int port, - double interval, - String bitrate, - int length, - Iperf3Mode mode, - Iperf3Direction direction, - String pidfile, - String file, - String affinity, - String bind, - String bindDev, - Boolean verbose, - Boolean json, - Boolean jsonStream, - String logfile, - Boolean forceflush, - String timestamps, - Integer rcvTimeout, - Integer sndTimeout, - Integer debug, - Boolean version, - Boolean help, - Boolean daemon, - Boolean oneOff, - String serverBitrateLimit, - Integer idleTimeout, - String rsaPrivateKeyPath, - String authorizedUsersPath, - Integer timeSkewThreshold, - Boolean usePkcs1Padding, - Boolean sctp, - String xbind, - Integer nstreams, - Integer connectTimeout, - String pacingTimer, - String fqRate, - Integer time, - String bytes, - String blockcount, - Integer cport, - Integer parallel, - Boolean reverse, - Boolean bidir, - String window, - String congestion, - Integer setMss, - Boolean noDelay, - Boolean version4, - Boolean version6, - Integer tos, - String dscp, - Integer flowlabel, - Boolean zerocopy, - Integer omit, - String title, - String extraData, - Boolean getServerOutput, - Boolean udpCounters64bit, - Boolean repeatingPayload, - Boolean dontFragment, - String username, - String rsaPublicKeyPath) { - super(rawDirPath+iPerf3UUID+".txt", lineProtocolDirPath+iPerf3UUID+".txt"); - this.host = ip; - this.iPerf3UUID = iPerf3UUID; - this.protocol = protocol; - this.port = port; - this.interval = interval; - this.bitrate = bitrate; - this.length = length; - this.mode = mode; - this.direction = direction; - this.pidfile = pidfile; - this.file = file; - this.affinity = affinity; - this.bind = bind; - this.bindDev = bindDev; - this.verbose = verbose; - this.json = json; - this.jsonStream = jsonStream; - this.forceflush = forceflush; - this.timestamps = timestamps; - this.rcvTimeout = rcvTimeout; - this.sndTimeout = sndTimeout; - this.debug = debug; - this.version = version; - this.help = help; - this.daemon = daemon; - this.oneOff = oneOff; - this.serverBitrateLimit = serverBitrateLimit; - this.idleTimeout = idleTimeout; - this.rsaPrivateKeyPath = rsaPrivateKeyPath; - this.authorizedUsersPath = authorizedUsersPath; - this.timeSkewThreshold = timeSkewThreshold; - this.usePkcs1Padding = usePkcs1Padding; - this.sctp = sctp; - this.xbind = xbind; - this.nstreams = nstreams; - this.connectTimeout = connectTimeout; - this.pacingTimer = pacingTimer; - this.fqRate = fqRate; - this.time = time; - this.bytes = bytes; - this.blockcount = blockcount; - this.cport = cport; - this.parallel = parallel; - this.reverse = reverse; - this.bidir = bidir; - this.window = window; - this.congestion = congestion; - this.setMss = setMss; - this.noDelay = noDelay; - this.version4 = version4; - this.version6 = version6; - this.tos = tos; - this.dscp = dscp; - this.flowlabel = flowlabel; - this.zerocopy = zerocopy; - this.omit = omit; - this.title = title; - this.extraData = extraData; - this.getServerOutput = getServerOutput; - this.udpCounters64bit = udpCounters64bit; - this.repeatingPayload = repeatingPayload; - this.dontFragment = dontFragment; - this.username = username; - this.rsaPublicKeyPath = rsaPublicKeyPath; + public void updatePaths(){ + super.setRawLogFilePath(super.getRawDirPath()+"/"+testUUID+".json"); + super.setLineProtocolFilePath(super.getLineProtocolDirPath()+"/"+testUUID+".lp"); + } + public Iperf3Parameter(String testUUID){ + this(new JSONObject(), testUUID); } - public void updatePaths(){ - super.setLogfile(rawDirPath+testUUID+".txt"); - super.setLineProtocolFile(lineProtocolDirPath+testUUID+".txt"); + public void setDirectionFlags() { + switch (this.direction) { + case UP: + this.reverse = false; + this.bidir = false; + break; + case DOWN: + this.reverse = true; + this.bidir = false; + break; + case BIDIR: + this.bidir = true; + this.reverse = false; + break; + } } + public Iperf3Parameter(JSONObject jsonObject, String testUUID) { - super(rawDirPath+testUUID+".txt", lineProtocolDirPath+testUUID+".txt"); + super(ParameterType.IPERF3, + testUUID); this.testUUID = testUUID; this.jsonStream = true; @@ -470,6 +168,8 @@ public Iperf3Parameter(JSONObject jsonObject, String testUUID) { String direction = jsonObject.getString(DIRECTION); Log.d(TAG, "Iperf3Parameter: direction: "+direction); this.direction = Iperf3Direction.valueOf(direction.toUpperCase().trim()); + setDirectionFlags(); + } catch (JSONException e) { this.direction = Iperf3Direction.UP; Log.d(TAG, "direction not set."); @@ -756,85 +456,13 @@ public Iperf3Parameter(JSONObject jsonObject, String testUUID) { Log.d(TAG, "title not set."); } try { - Files.createDirectories(Paths.get(rawDirPath)); - Files.createDirectories(Paths.get(lineProtocolDirPath)); + Files.createDirectories(Paths.get(super.getRawDirPath())); + Files.createDirectories(Paths.get(super.getLineProtocolDirPath())); } catch (IOException e) { Log.d(TAG, "Could not create directories."); } } - @Override - public int describeContents() { - return 0; - } - - @Override - public void writeToParcel(@NonNull Parcel dest, int flags) { - dest.writeString(host); - dest.writeString(iPerf3UUID); - dest.writeInt(port); - dest.writeDouble(interval); - dest.writeString(bitrate); - dest.writeInt(length); - dest.writeString(mode.name()); - dest.writeString(direction.name()); - dest.writeString(pidfile); - dest.writeString(file); - dest.writeString(affinity); - dest.writeString(bind); - dest.writeString(bindDev); - dest.writeBoolean(verbose); - dest.writeBoolean(json); - dest.writeBoolean(jsonStream); - dest.writeBoolean(forceflush); - dest.writeString(timestamps); - dest.writeInt(rcvTimeout); - dest.writeInt(sndTimeout); - dest.writeInt(debug); - dest.writeBoolean(version); - dest.writeBoolean(help); - dest.writeBoolean(daemon); - dest.writeBoolean(oneOff); - dest.writeString(serverBitrateLimit); - dest.writeInt(idleTimeout); - dest.writeString(rsaPrivateKeyPath); - dest.writeString(authorizedUsersPath); - dest.writeInt(timeSkewThreshold); - dest.writeBoolean(usePkcs1Padding); - dest.writeBoolean(sctp); - dest.writeString(xbind); - dest.writeInt(nstreams); - dest.writeInt(connectTimeout); - dest.writeString(pacingTimer); - dest.writeString(fqRate); - dest.writeInt(time); - dest.writeString(bytes); - dest.writeString(blockcount); - dest.writeInt(cport); - dest.writeInt(parallel); - dest.writeBoolean(reverse); - dest.writeBoolean(bidir); - dest.writeString(window); - dest.writeString(congestion); - dest.writeInt(setMss); - dest.writeBoolean(noDelay); - dest.writeBoolean(version4); - dest.writeBoolean(version6); - dest.writeInt(tos); - dest.writeString(dscp); - dest.writeInt(flowlabel); - dest.writeBoolean(zerocopy); - dest.writeInt(omit); - dest.writeString(title); - dest.writeString(extraData); - dest.writeBoolean(getServerOutput); - dest.writeBoolean(udpCounters64bit); - dest.writeBoolean(repeatingPayload); - dest.writeBoolean(dontFragment); - dest.writeString(username); - dest.writeString(rsaPublicKeyPath); - } - public String getHost() { return host; } @@ -1811,7 +1439,7 @@ public String[] getInputAsCommand() { command.add("--json-stream"); command.add("--forceflush"); command.add("--logfile"); - command.add(super.getLogfile()); + command.add(super.getRawLogFilePath()); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/Parameter.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/Parameter.java index ccf116eb..a259bbfe 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/Parameter.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/Parameter.java @@ -12,53 +12,64 @@ import android.os.Parcel; import android.os.Parcelable; -public class Parameter implements Parcelable { - public static final String rootPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath(); - private String lineProtocolFile; - private String logfile; +public class Parameter { + private ParameterType parameterType; + public static final String rootPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath()+"/omnt"; + private String rawDirPath; + private String lineProtocolDirPath; + private String lineProtocolFilePath; + private String rawLogFilePath; protected Parameter(Parcel in) { - lineProtocolFile = in.readString(); - logfile = in.readString(); + lineProtocolFilePath = in.readString(); + rawLogFilePath = in.readString(); } - public Parameter(String logfile, String lineProtocolFile) { - this.logfile = logfile; - this.lineProtocolFile = lineProtocolFile; + public Parameter(ParameterType type, + String testUUID) { + this.parameterType = type; + this.rawDirPath = rootPath + "/" + this.parameterType.toString().toLowerCase() + "/raw"; + this.lineProtocolDirPath = rootPath + "/" + this.parameterType.toString().toLowerCase() + "/lineprotocol"; + this.rawLogFilePath = this.rawDirPath + "/" + testUUID + ".log"; + this.lineProtocolFilePath = this.lineProtocolDirPath + "/" + testUUID + ".lp"; } - public static final Creator CREATOR = new Creator() { - @Override - public Parameter createFromParcel(Parcel in) { - return new Parameter(in); - } + public ParameterType getParameterType() { + return parameterType; + } + + public String getRootPath() { + return rootPath; + } - @Override - public Parameter[] newArray(int size) { - return new Parameter[size]; - } - }; + public String getRawDirPath() { + return rawDirPath; + } - public String getLineProtocolFile() { - return lineProtocolFile; + public void setRawDirPath(String rawDirPath) { + this.rawDirPath = rawDirPath; } - public String getLogfile() { - return logfile; + public String getLineProtocolDirPath() { + return lineProtocolDirPath; } - public int describeContents() { - return 0; + public void setLineProtocolDirPath(String lineProtocolDirPath) { + this.lineProtocolDirPath = lineProtocolDirPath; } - public void writeToParcel(android.os.Parcel dest, int flags) { - dest.writeString(lineProtocolFile); - dest.writeString(logfile); + public String getLineProtocolFilePath() { + return lineProtocolFilePath; } - public void setLineProtocolFile(String lineProtocolFile) { - this.lineProtocolFile = lineProtocolFile; + + public void setLineProtocolFilePath(String lineProtocolFilePath) { + this.lineProtocolFilePath = lineProtocolFilePath; + } + + public String getRawLogFilePath() { + return rawLogFilePath; } - public void setLogfile(String logfile) { - this.logfile = logfile; + public void setRawLogFilePath(String rawLogFilePath) { + this.rawLogFilePath = rawLogFilePath; } } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/PingParameter.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/PingParameter.java index 586be41e..0d25d67a 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/PingParameter.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/PingParameter.java @@ -23,11 +23,8 @@ import java.util.ArrayList; public class PingParameter extends Parameter { - public static final String rawDirPath = rootPath+"/omnt/ping/raw/"; - public static final String lineProtocolDirPath = rootPath+"/omnt/ping/lineprotocol/"; private static final String TAG = "PingParameter"; - public static final String PING = "ping"; public static final String DESTINATION = "destination"; public static final String COUNT = "count"; @@ -101,15 +98,16 @@ public String[] getInputAsCommand() { private void setupDirs(){ try { - Files.createDirectories(Paths.get(rawDirPath)); - Files.createDirectories(Paths.get(lineProtocolDirPath)); + Files.createDirectories(Paths.get(super.getRawDirPath())); + Files.createDirectories(Paths.get(super.getLineProtocolFilePath())); } catch (IOException e) { Log.d(TAG, "Could not create directories."); } } public PingParameter(String stringParameter, String testUUID) { - super(rawDirPath + testUUID + ".txt", lineProtocolDirPath + testUUID + ".txt"); + super(ParameterType.PING, + testUUID); this.testUUID = testUUID; String[] parts = stringParameter.split(" "); for (int i = 0; i < parts.length; i++) { @@ -136,7 +134,8 @@ public PingParameter(String stringParameter, String testUUID) { } public PingParameter(JSONObject parameter, String testUUID) { - super(rawDirPath + testUUID + ".txt", lineProtocolDirPath + testUUID + ".txt"); + super(ParameterType.PING, + testUUID); this.testUUID = testUUID; try { destination = parameter.getString(DESTINATION); @@ -188,32 +187,5 @@ protected PingParameter(Parcel in) { network = in.readParcelable(Network.class.getClassLoader()); } - public static final Creator CREATOR = new Creator() { - @Override - public PingParameter createFromParcel(Parcel in) { - return new PingParameter(in); - } - - @Override - public PingParameter[] newArray(int size) { - return new PingParameter[size]; - } - }; - - @Override - public int describeContents() { - return super.describeContents(); - } - - @Override - public void writeToParcel(@NonNull Parcel dest, int flags) { - super.writeToParcel(dest, flags); - dest.writeString(destination); - dest.writeInt(count); - dest.writeDouble(timeoutMillis); - dest.writeInt(packetSize); - dest.writeDouble(intervalMillis); - dest.writeParcelable(network, flags); - } } diff --git a/app/src/main/res/raw/config.json b/app/src/main/res/raw/config.json index f00711d3..9524a1f6 100644 --- a/app/src/main/res/raw/config.json +++ b/app/src/main/res/raw/config.json @@ -513,7 +513,7 @@ "metadata": { "version": "0.7", "code": 7, - "gitHash": "9d3ed7b" + "gitHash": "391e3bd" } } ] \ No newline at end of file diff --git a/docs/config.json b/docs/config.json index f00711d3..9524a1f6 100644 --- a/docs/config.json +++ b/docs/config.json @@ -513,7 +513,7 @@ "metadata": { "version": "0.7", "code": 7, - "gitHash": "9d3ed7b" + "gitHash": "391e3bd" } } ] \ No newline at end of file From 75a193aa8aa6c3c007715edbd5f6bf958f6f6893 Mon Sep 17 00:00:00 2001 From: hajoha Date: Tue, 25 Nov 2025 11:44:17 +0100 Subject: [PATCH 6/6] refactor: update file path methods and clean up unused code --- .../InfluxDB2x/Worker/InfluxDB2xUploadWorker.java | 6 +++--- .../OpenMobileNetworkToolkit/Inputs/Inputs.java | 1 - .../Iperf3/Fragments/Iperf3Fragment.java | 4 ++-- .../Iperf3/Worker/Iperf3ExecutorWorker.java | 4 ++-- .../Iperf3/Worker/Iperf3MonitorWorker.java | 2 +- .../Iperf3/Worker/Iperf3ToLineProtocolWorker.java | 6 +++--- .../Iperf3/Worker/Iperf3UploadWorker.java | 6 +++--- .../MQTT/Handler/Iperf3Handler.java | 2 +- .../MQTT/Handler/PingHandler.java | 2 +- .../Parameter/ParameterType.java | 14 ++++++++++++++ .../Ping/Worker/PingToLineProtocolWorker.java | 10 +++++----- .../Ping/Worker/PingWorker.java | 6 +++--- app/src/main/res/raw/config.json | 2 +- docs/config.json | 2 +- 14 files changed, 40 insertions(+), 27 deletions(-) create mode 100644 app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/ParameterType.java diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/Worker/InfluxDB2xUploadWorker.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/Worker/InfluxDB2xUploadWorker.java index 55115321..0782ff88 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/Worker/InfluxDB2xUploadWorker.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/Worker/InfluxDB2xUploadWorker.java @@ -65,17 +65,17 @@ public Result doWork() { } BufferedReader br; try { - br = new BufferedReader(new FileReader(input.getParameter().getLineProtocolFile())); + br = new BufferedReader(new FileReader(input.getParameter().getLineProtocolFilePath())); } catch (FileNotFoundException | NullPointerException e) { Log.d(TAG,e.toString()); return Result.failure(output); } List points = br.lines().collect(Collectors.toList()); try { - Log.d(TAG, String.format("doWork: uploading %s", input.getParameter().getLineProtocolFile())); + Log.d(TAG, String.format("doWork: uploading %s", input.getParameter().getLineProtocolFilePath())); influx.writeRecords(points); } catch (IOException e) { - Log.d(TAG, String.format("doWork: upload of %s failed!", input.getParameter().getLineProtocolFile())); + Log.d(TAG, String.format("doWork: upload of %s failed!", input.getParameter().getLineProtocolFilePath())); return Result.failure(output); } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Inputs/Inputs.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Inputs/Inputs.java index 12203af5..bda00df5 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Inputs/Inputs.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Inputs/Inputs.java @@ -115,7 +115,6 @@ public void writeToParcel(@NonNull Parcel dest, int flags) { dest.writeString(sequenceUUID); dest.writeString(measurementUUID); dest.writeString(testUUID); - dest.writeParcelable(parameter, flags); } public Data.Builder getInputAsDataBuilder(int i, String packageName) { diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Fragments/Iperf3Fragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Fragments/Iperf3Fragment.java index 9c1b8d64..69ee3980 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Fragments/Iperf3Fragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Fragments/Iperf3Fragment.java @@ -311,8 +311,8 @@ public void onClick(View view) { iperf3Input.getParameter().updatePaths(); iperf3Input.setTimestamp(new Timestamp(System.currentTimeMillis())); - File logFile = new File(iperf3Input.getParameter().getLogfile()); - File rawPath = new File(Iperf3Parameter.rawDirPath); + File logFile = new File(iperf3Input.getParameter().getRawLogFilePath()); + File rawPath = new File(iperf3Input.getParameter().getRawDirPath()); if(!rawPath.exists()) { rawPath.mkdirs(); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3ExecutorWorker.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3ExecutorWorker.java index f1af4024..79d99623 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3ExecutorWorker.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3ExecutorWorker.java @@ -77,8 +77,8 @@ public Iperf3ExecutorWorker(@NonNull Context context, @NonNull WorkerParameters public ListenableFuture startRemoteWork() { return CallbackToFutureAdapter.getFuture(completer -> { Log.d(TAG, "startRemoteWork: tags: "+this.getTags()); - File logFile = new File(iperf3Input.getParameter().getLogfile()); - File rawPath = new File(Iperf3Parameter.rawDirPath); + File logFile = new File(iperf3Input.getParameter().getRawLogFilePath()); + File rawPath = new File(iperf3Input.getParameter().getRawDirPath()); if(!rawPath.exists()) { rawPath.mkdirs(); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3MonitorWorker.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3MonitorWorker.java index 7a0210a0..cf72312e 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3MonitorWorker.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3MonitorWorker.java @@ -111,7 +111,7 @@ public Iperf3MonitorWorker(@NonNull Context context, @NonNull WorkerParameters w notificationLayout.setViewVisibility(R.id.notification_direction, GONE); setForegroundAsync(createForegroundInfo(notificationLayout)); - this.pathToFile = iperf3Input.getParameter().getLogfile(); + this.pathToFile = iperf3Input.getParameter().getRawLogFilePath(); Log.d(TAG, "Iperf3MonitorWorker: pathToFile: "+this.pathToFile); this.file = new File(this.pathToFile); } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3ToLineProtocolWorker.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3ToLineProtocolWorker.java index 4ab5490e..8346e2eb 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3ToLineProtocolWorker.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3ToLineProtocolWorker.java @@ -186,11 +186,11 @@ public Result doWork() { } } - File path = new File(Iperf3Parameter.lineProtocolDirPath); + File path = new File(iperf3Input.getParameter().getRawDirPath()); if(!path.exists()){ path.mkdirs(); } - File iperf3File = new File(iperf3Input.getParameter().getLineProtocolFile()); + File iperf3File = new File(iperf3Input.getParameter().getLineProtocolDirPath()); if (!iperf3File.exists()) { try { iperf3File.createNewFile(); @@ -201,7 +201,7 @@ public Result doWork() { FileOutputStream iperf3Stream = null; try { - iperf3Stream = new FileOutputStream(iperf3Input.getParameter().getLineProtocolFile(), true); + iperf3Stream = new FileOutputStream(iperf3Input.getParameter().getLineProtocolDirPath(), true); } catch (FileNotFoundException e) { Toast.makeText(getApplicationContext(), "logfile not created", Toast.LENGTH_SHORT).show(); Log.d(TAG,e.toString()); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3UploadWorker.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3UploadWorker.java index 54e9cbcf..aae60667 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3UploadWorker.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Worker/Iperf3UploadWorker.java @@ -65,17 +65,17 @@ public Result doWork() { } BufferedReader br; try { - br = new BufferedReader(new FileReader(iperf3Input.getParameter().getLineProtocolFile())); + br = new BufferedReader(new FileReader(iperf3Input.getParameter().getLineProtocolFilePath())); } catch (FileNotFoundException | NullPointerException e) { Log.d(TAG,e.toString()); return Result.failure(output); } List points = br.lines().collect(Collectors.toList()); try { - Log.d(TAG, String.format("doWork: uploading %s", iperf3Input.getParameter().getLineProtocolFile())); + Log.d(TAG, String.format("doWork: uploading %s", iperf3Input.getParameter().getLineProtocolFilePath())); influx.writeRecords(points); } catch (IOException e) { - Log.d(TAG, String.format("doWork: upload of %s failed!", iperf3Input.getParameter().getLineProtocolFile())); + Log.d(TAG, String.format("doWork: upload of %s failed!", iperf3Input.getParameter().getLineProtocolFilePath())); return Result.failure(output); } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MQTT/Handler/Iperf3Handler.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MQTT/Handler/Iperf3Handler.java index c1af87f9..fd817f10 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MQTT/Handler/Iperf3Handler.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MQTT/Handler/Iperf3Handler.java @@ -63,7 +63,7 @@ public void parsePayload(String payload) throws JSONException { Iperf3RunResult iperf3RunResult = new Iperf3RunResult(iperf3Input.getTestUUID(), -100, false, iperf3Input, new java.sql.Timestamp(System.currentTimeMillis())); iperf3RunResultDao.insert(iperf3RunResult); - File logFile = new File(iperf3Input.getParameter().getLogfile()); + File logFile = new File(iperf3Input.getParameter().getRawLogFilePath()); if(logFile.exists()) { logFile.delete(); } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MQTT/Handler/PingHandler.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MQTT/Handler/PingHandler.java index bb65c70d..15c20f52 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MQTT/Handler/PingHandler.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MQTT/Handler/PingHandler.java @@ -48,7 +48,7 @@ public void parsePayload(String payload) throws JSONException { PingParameter pingParameter = new PingParameter(params, testUUID); if(pingParameter == null) continue; PingInput pingInput = new PingInput(pingParameter, testUUID, sequenceUUID, measurementUUUID,campaignUUID); - File logFile = new File(pingInput.getParameter().getLogfile()); + File logFile = new File(pingInput.getParameter().getLineProtocolFilePath()); if(logFile.exists()) { logFile.delete(); } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/ParameterType.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/ParameterType.java new file mode 100644 index 00000000..99146213 --- /dev/null +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Parameter/ParameterType.java @@ -0,0 +1,14 @@ +/* + * SPDX-FileCopyrightText: 2025 Peter Hasse + * SPDX-FileCopyrightText: 2025 Johann Hackler + * SPDX-FileCopyrightText: 2025 Fraunhofer FOKUS + * + * SPDX-License-Identifier: BSD-3-Clause-Clear + */ + +package de.fraunhofer.fokus.OpenMobileNetworkToolkit.Parameter; + +public enum ParameterType { + PING, + IPERF3 +} diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/Worker/PingToLineProtocolWorker.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/Worker/PingToLineProtocolWorker.java index 33e5597d..ec1ab588 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/Worker/PingToLineProtocolWorker.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Ping/Worker/PingToLineProtocolWorker.java @@ -54,10 +54,10 @@ public PingToLineProtocolWorker(@NonNull Context context, @NonNull WorkerParamet pingInput = gson.fromJson(iperf3InputString, PingInput.class); spg = SharedPreferencesGrouper.getInstance(getApplicationContext()); - File lineProtocolDirPath = new File(PingParameter.lineProtocolDirPath); + File lineProtocolDirPath = new File(pingInput.getParameter().getLineProtocolDirPath()); if(!lineProtocolDirPath.exists()){ if(!lineProtocolDirPath.mkdirs()){ - Log.e(TAG, "Error creating lineProtocolDirPath directory: " + PingParameter.lineProtocolDirPath); + Log.e(TAG, "Error creating lineProtocolDirPath directory: " + pingInput.getParameter().getLineProtocolDirPath()); } } } @@ -81,7 +81,7 @@ private LINEType getLineType(String line){ @Override public Result doWork() { Data.Builder output = new Data.Builder().putBoolean("pingUpload", false); - File myObj = new File(pingInput.getPingParameter().getLogfile()); + File myObj = new File(pingInput.getPingParameter().getLineProtocolFilePath()); Scanner scanner = null; try { scanner = new Scanner(myObj); @@ -112,7 +112,7 @@ public Result doWork() { pingInformations.add(pi); } scanner.close(); - File lineprotocolfile = new File(pingInput.getPingParameter().getLineProtocolFile()); + File lineprotocolfile = new File(pingInput.getPingParameter().getLineProtocolFilePath()); if(lineprotocolfile.exists()){ lineprotocolfile.delete(); try { @@ -124,7 +124,7 @@ public Result doWork() { } FileOutputStream pingStream = null; try { - pingStream = new FileOutputStream(pingInput.getPingParameter().getLineProtocolFile(), true); + pingStream = new FileOutputStream(pingInput.getPingParameter().getLineProtocolFilePath(), true); } catch (FileNotFoundException e) { Log.d(TAG, "doWork: " + e.toString()); Log.e(TAG, "doWork: Could not create FileOutputStream"); 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 e167f977..cbb286d1 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 @@ -85,10 +85,10 @@ public PingWorker(@NonNull Context context, @NonNull WorkerParameters workerPara notificationManager = (NotificationManager) ct.getSystemService(Context.NOTIFICATION_SERVICE); notificationBuilder = new NotificationCompat.Builder(ct, channelId); - File rawPath = new File(PingParameter.rawDirPath); + File rawPath = new File(pingInput.getParameter().getRawDirPath()); if(!rawPath.exists()){ if(!rawPath.mkdirs()){ - Log.e(TAG, "Error creating rawDirPath directory: " + PingParameter.rawDirPath); + Log.e(TAG, "Error creating rawDirPath directory: " + pingInput.getParameter().getRawDirPath()); } } @@ -154,7 +154,7 @@ public Result doWork() { ProcessBuilder processBuilder = new ProcessBuilder(command); Process process = processBuilder.start(); BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); - FileOutputStream pingStream = new FileOutputStream(pingInput.getPingParameter().getLogfile(), true); + FileOutputStream pingStream = new FileOutputStream(pingInput.getPingParameter().getRawLogFilePath(), true); PingParser pingParser = new PingParser(); String line; diff --git a/app/src/main/res/raw/config.json b/app/src/main/res/raw/config.json index 9524a1f6..17639304 100644 --- a/app/src/main/res/raw/config.json +++ b/app/src/main/res/raw/config.json @@ -513,7 +513,7 @@ "metadata": { "version": "0.7", "code": 7, - "gitHash": "391e3bd" + "gitHash": "377044e" } } ] \ No newline at end of file diff --git a/docs/config.json b/docs/config.json index 9524a1f6..17639304 100644 --- a/docs/config.json +++ b/docs/config.json @@ -513,7 +513,7 @@ "metadata": { "version": "0.7", "code": 7, - "gitHash": "391e3bd" + "gitHash": "377044e" } } ] \ No newline at end of file