From d6ec35a2fa0e871b922375ced88814158f9edd15 Mon Sep 17 00:00:00 2001 From: Peter Hasse Date: Thu, 18 Apr 2024 14:15:15 +0200 Subject: [PATCH 1/8] fix crash when no subscription present --- .../fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java index c65d2710..4f7695fa 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java @@ -91,7 +91,7 @@ protected void onCreate(Bundle savedInstanceState) { tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); gv.setTm(tm); dp = new DataProvider(this); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && !dp.getSubscriptions().isEmpty()) { // make sure the subscription in the app settings exists in the current subscription list. // if it is not in the subscription list change it to the first one of the current list boolean valid_subscription = false; From 035504539685b254e745a20c89282a04526948b5 Mon Sep 17 00:00:00 2001 From: Peter Hasse Date: Thu, 18 Apr 2024 14:15:57 +0200 Subject: [PATCH 2/8] fix racecondition on startup --- .../fokus/OpenMobileNetworkToolkit/LoggingService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java index ed0ee20a..367284de 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java @@ -226,7 +226,7 @@ public int onStartCommand(Intent intent, int flags, int startId) { if (feature_telephony) { //tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tm = GlobalVars.getInstance().getTm(); - cp = tm.hasCarrierPrivileges(); + cp = gv.isCarrier_permissions(); } wm = WorkManager.getInstance(context); if(intent != null) { From 1b1dc90e65009013b2a5e1b79daa81380a17612d Mon Sep 17 00:00:00 2001 From: Peter Hasse Date: Thu, 18 Apr 2024 14:30:55 +0200 Subject: [PATCH 3/8] ask android to keep the screen on while omnt is in front --- app/src/main/res/layout/activity_main.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index b374c0eb..f17f1fd3 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -10,10 +10,11 @@ + android:keepScreenOn="true" + tools:context=".MainActivity"> Date: Thu, 18 Apr 2024 17:16:13 +0200 Subject: [PATCH 4/8] handle missing CI. This needs more thoughts in the future --- .../DataProvider/DataProvider.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java index 4b17bfa6..d1804b0c 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java @@ -325,7 +325,9 @@ public void onCellInfoChanged(@NonNull List list) { cim.setSsrsrq(ssNR.getSsRsrq()); cim.setSssinr(ssNR.getSsSinr()); cim.setAsuLevel(ssNR.getAsuLevel()); - cim.setTimingAdvance(ssNR.getTimingAdvanceMicros()); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { + cim.setTimingAdvance(ssNR.getTimingAdvanceMicros()); + } } if (ci instanceof CellInfoLte) { CellInfoLte ciLTE = (CellInfoLte) ci; @@ -408,8 +410,11 @@ public List getCellInformationPoint() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { point.addField("Bands", ci_.getBands()); } - point.addField("CI", ci_.getCi()); - point.addTag("CI", String.valueOf(ci_.getCi())); + long ci = ci_.getCi(); + if (ci != CellInfo.UNAVAILABLE) { + point.addField("CI", ci_.getCi()); + point.addTag("CI", String.valueOf(ci_.getCi())); + } point.addField("NRARFCN", ci_.getARFCN()); point.addField("MNC", ci_.getMnc()); point.addField("MCC", ci_.getMcc()); @@ -430,8 +435,11 @@ public List getCellInformationPoint() { point.addField("Bands", ci_.getBands()); } point.addField("Bandwidth", ci_.getBandwidth()); - point.addField("CI", ci_.getCi()); - point.addTag("CI", String.valueOf(ci_.getCi())); + long ci = ci_.getCi(); + if (ci != CellInfo.UNAVAILABLE) { + point.addField("CI", ci_.getCi()); + point.addTag("CI", String.valueOf(ci_.getCi())); + } point.addField("ARFCN", ci_.getARFCN()); point.addField("MNC", ci_.getMnc()); point.addField("MCC", ci_.getMcc()); @@ -452,8 +460,11 @@ public List getCellInformationPoint() { } if (Objects.equals(ci_.getCellType(), "GSM")) { point.addField("CellType", "GSM"); - point.addField("CI", ci_.getCi()); - point.addTag("CI", String.valueOf(ci_.getCi())); + long ci = ci_.getCi(); + if (ci != CellInfo.UNAVAILABLE) { + point.addField("CI", ci_.getCi()); + point.addTag("CI", String.valueOf(ci_.getCi())); + } point.addField("ARFCN", ci_.getARFCN()); point.addField("MNC", ci_.getMnc()); point.addField("MCC", ci_.getMcc()); From a8521b5cc1abff086ac3a644d8edbbe6f0d54751 Mon Sep 17 00:00:00 2001 From: Peter Hasse Date: Thu, 18 Apr 2024 17:16:39 +0200 Subject: [PATCH 5/8] add missing CP check --- .../fokus/OpenMobileNetworkToolkit/SpecialCodesFragment.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SpecialCodesFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SpecialCodesFragment.java index cfbb2fa4..923a7989 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SpecialCodesFragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/SpecialCodesFragment.java @@ -63,6 +63,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle saved samsung_ims.setEnabled(false); huawei_projects.setEnabled(false); custom_special_code.setEnabled(false); + xiaomi.setEnabled(false); TextView tv = v.findViewById(R.id.special_code_warning); tv.setText( "Carrier Permissions needed to dial special codes, try to dial code in system dialer"); From 12ecc91b47726d89cf9ed98d2b8085aecbfae85b Mon Sep 17 00:00:00 2001 From: Peter Hasse Date: Thu, 18 Apr 2024 17:54:15 +0200 Subject: [PATCH 6/8] added setting to disable neighbourcells on homescreen --- .../OpenMobileNetworkToolkit/HomeFragment.java | 5 +++++ app/src/main/res/values/strings.xml | 5 ++++- app/src/main/res/xml/preference.xml | 17 +++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/HomeFragment.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/HomeFragment.java index 33668226..1a2bfed1 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/HomeFragment.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/HomeFragment.java @@ -37,6 +37,7 @@ import androidx.cardview.widget.CardView; import androidx.core.app.ActivityCompat; import androidx.fragment.app.Fragment; +import androidx.preference.PreferenceManager; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import java.security.MessageDigest; @@ -427,6 +428,10 @@ private CardView get_cell_card_view(){ List cil = dp.getCellInformation(); int cell = 1; for (CellInformation ci : cil) { + if ( !PreferenceManager.getDefaultSharedPreferences(context).getBoolean("show_neighbour_cells", false) && ! ci.isRegistered()) { + continue; + } + TableRow title = rowBuilder("Cell " + cell, ""); if (cell > 1) { title.setPadding(0,20,0,0); diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0a361f97..2c529140 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -159,7 +159,10 @@ Exit\n --cport xiaomi - Applied on SIM / network change> + Applied on SIM / network change + Show neighbour cells\n + Home screen settings + App settings> diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml index ab3264b9..02af0e97 100644 --- a/app/src/main/res/xml/preference.xml +++ b/app/src/main/res/xml/preference.xml @@ -10,6 +10,23 @@ + + + + + + + Date: Fri, 19 Apr 2024 14:10:41 +0200 Subject: [PATCH 7/8] fix bug where logging could not be restarted, fix logo in menubar not centered, add logging indicator to toolbar --- OpenMNT_logo_no_title.svg | 127 ++++++++++++++++++ .../OpenMobileNetworkToolkit/GlobalVars.java | 10 ++ .../InfluxDB2x/InfluxdbConnection.java | 27 +++- .../LoggingService.java | 7 + .../MainActivity.java | 2 + .../res/drawable/openmnt_logo_no_title.xml | 63 +++++++++ app/src/main/res/layout/activity_main.xml | 16 ++- 7 files changed, 250 insertions(+), 2 deletions(-) create mode 100644 OpenMNT_logo_no_title.svg create mode 100644 app/src/main/res/drawable/openmnt_logo_no_title.xml diff --git a/OpenMNT_logo_no_title.svg b/OpenMNT_logo_no_title.svg new file mode 100644 index 00000000..58e5713b --- /dev/null +++ b/OpenMNT_logo_no_title.svg @@ -0,0 +1,127 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + OMNT + + + + diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/GlobalVars.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/GlobalVars.java index a719a345..bf8ddb95 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/GlobalVars.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/GlobalVars.java @@ -12,6 +12,7 @@ import android.telephony.CarrierConfigManager; import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; +import android.widget.ImageView; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.DataProvider; @@ -45,6 +46,15 @@ public class GlobalVars { private boolean feature_work_profile; private boolean permission_phone_state; + public ImageView getLog_status() { + return log_status; + } + + public void setLog_status(ImageView log_status) { + this.log_status = log_status; + } + + ImageView log_status; private GlobalVars(){} public static synchronized GlobalVars getInstance(){ diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnection.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnection.java index 188289ea..7b8ff1f5 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnection.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnection.java @@ -8,9 +8,9 @@ package de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x; - import android.content.Context; import android.content.SharedPreferences; +import android.graphics.Color; import android.util.Log; import androidx.preference.PreferenceManager; @@ -22,11 +22,15 @@ import com.influxdb.client.domain.OnboardingRequest; import com.influxdb.client.domain.WritePrecision; import com.influxdb.client.write.Point; +import com.influxdb.client.write.events.BackpressureEvent; +import com.influxdb.client.write.events.WriteRetriableErrorEvent; +import com.influxdb.client.write.events.WriteSuccessEvent; import java.io.IOException; import java.net.InetAddress; import java.util.List; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars; import io.reactivex.rxjava3.core.BackpressureOverflowStrategy; @@ -40,6 +44,7 @@ public class InfluxdbConnection { private final Context context; private InfluxDBClient influxDBClient; private WriteApi writeApi; + private GlobalVars gv; public InfluxdbConnection(String URL, String token, String org, String bucket, Context context) { @@ -48,8 +53,11 @@ public InfluxdbConnection(String URL, String token, String org, String bucket, this.url = URL; this.bucket = bucket; this.context = context; + this.gv = GlobalVars.getInstance(); sp = PreferenceManager.getDefaultSharedPreferences(context); influxDBClient = InfluxDBClientFactory.create(url, this.token, org, bucket); + influxDBClient.enableGzip(); // maybe we want a setting for this? + } public void open_write_api() { @@ -65,6 +73,22 @@ public void open_write_api() { .retryInterval(500) .exponentialBase(4) .build()); + writeApi.listenEvents(BackpressureEvent.class, value -> { + Log.d(TAG, "Backpressure: Reason: " + value.getReason()); + value.logEvent(); + }); + writeApi.listenEvents(WriteSuccessEvent.class, value -> { + //Log.d(TAG, "WriteSuccess: Line: " + value.getLineProtocol()); + if ( sp.getBoolean("enable_influx", false)) { + gv.getLog_status().setColorFilter(Color.argb(255, 0, 255, 0)); + } + }); + writeApi.listenEvents(WriteRetriableErrorEvent.class, value -> { + value.logEvent(); + if ( sp.getBoolean("enable_influx", false)) { + gv.getLog_status().setColorFilter(Color.argb(255, 255, 0, 0)); + } + }); } catch (com.influxdb.exceptions.InfluxException e) { Log.d(TAG, "connect: Can't connect to InfluxDB"); e.printStackTrace(); @@ -80,6 +104,7 @@ public void disconnect() { try { Log.d(TAG, "disconnect: Closing Influx write API"); writeApi.close(); + writeApi = null; } catch (com.influxdb.exceptions.InfluxException e) { Log.d(TAG, "disconnect: Error while closing write API"); e.printStackTrace(); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java index 367284de..fd0a541b 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java @@ -87,6 +87,8 @@ public class LoggingService extends Service { private Handler pingLogging; private String pingInput; private WorkManager wm; + + GlobalVars gv; private ArrayList pingWRs; // Handle local on-device logging to logfile private final Runnable localFileUpdate = new Runnable() { @@ -165,6 +167,7 @@ public void run() { private final Runnable localInfluxUpdate = new Runnable() { @Override public void run() { + gv.getLog_status().setColorFilter(Color.argb(255, 255, 0, 0)); long ts = System.currentTimeMillis(); // write network information if (sp.getBoolean("influx_network_data", false)) { @@ -209,6 +212,7 @@ public void run() { public void onCreate() { super.onCreate(); Log.d(TAG, "onCreate: Logging service created"); + gv = GlobalVars.getInstance(); } @Override @@ -508,6 +512,7 @@ private void setupRemoteInfluxDB() { stopRemoteInfluxDB(); return; } + ic.setup(); Objects.requireNonNull(ic).open_write_api(); remoteInfluxHandler = new Handler(Objects.requireNonNull(Looper.myLooper())); remoteInfluxHandler.post(RemoteInfluxUpdate); @@ -525,6 +530,8 @@ private void stopRemoteInfluxDB() { if (ic != null) { ic.disconnect(); } + gv.getLog_status().setColorFilter(Color.argb(255, 192, 192, 192)); + } private long unixTimestampWithMicrosToMillis(double timestampWithMicros) { long seconds = (long) timestampWithMicros; diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java index 4f7695fa..cfd384f5 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/MainActivity.java @@ -126,6 +126,8 @@ protected void onCreate(Bundle savedInstanceState) { toolbar.setTitle(""); setSupportActionBar(toolbar); + gv.setLog_status(findViewById(R.id.log_status_icon)); + NavHostFragment navHostFragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.fragmentContainerView); navController = Objects.requireNonNull(navHostFragment).getNavController(); diff --git a/app/src/main/res/drawable/openmnt_logo_no_title.xml b/app/src/main/res/drawable/openmnt_logo_no_title.xml new file mode 100644 index 00000000..0654d8cb --- /dev/null +++ b/app/src/main/res/drawable/openmnt_logo_no_title.xml @@ -0,0 +1,63 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f17f1fd3..1d8a00d4 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -21,11 +21,24 @@ android:layout_height="match_parent" android:orientation="vertical"> + + app:navigationIcon="@drawable/openmnt_logo_no_title"> + + + + + + \ No newline at end of file From 8a8234c94e243bfba0f04e359c27a7205fff95a1 Mon Sep 17 00:00:00 2001 From: Peter Hasse Date: Thu, 25 Apr 2024 14:14:50 +0200 Subject: [PATCH 8/8] remove unused parameter --- .../DataProvider/DataProvider.java | 5 +- .../InfluxDB2x/InfluxdbConnection.java | 83 ++++++++++--------- .../InfluxDB2x/InfluxdbConnections.java | 6 +- .../Iperf3/Iperf3ToLineProtocolWorker.java | 20 +++-- .../Iperf3/Iperf3UploadWorker.java | 5 +- .../LoggingService.java | 19 +++-- 6 files changed, 74 insertions(+), 64 deletions(-) diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java index d1804b0c..f91eb915 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/DataProvider/DataProvider.java @@ -412,8 +412,7 @@ public List getCellInformationPoint() { } long ci = ci_.getCi(); if (ci != CellInfo.UNAVAILABLE) { - point.addField("CI", ci_.getCi()); - point.addTag("CI", String.valueOf(ci_.getCi())); + point.addTag("CI", String.valueOf(ci)); } point.addField("NRARFCN", ci_.getARFCN()); point.addField("MNC", ci_.getMnc()); @@ -437,7 +436,6 @@ public List getCellInformationPoint() { point.addField("Bandwidth", ci_.getBandwidth()); long ci = ci_.getCi(); if (ci != CellInfo.UNAVAILABLE) { - point.addField("CI", ci_.getCi()); point.addTag("CI", String.valueOf(ci_.getCi())); } point.addField("ARFCN", ci_.getARFCN()); @@ -462,7 +460,6 @@ public List getCellInformationPoint() { point.addField("CellType", "GSM"); long ci = ci_.getCi(); if (ci != CellInfo.UNAVAILABLE) { - point.addField("CI", ci_.getCi()); point.addTag("CI", String.valueOf(ci_.getCi())); } point.addField("ARFCN", ci_.getARFCN()); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnection.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnection.java index 7b8ff1f5..1eea3e33 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnection.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnection.java @@ -27,7 +27,6 @@ import com.influxdb.client.write.events.WriteSuccessEvent; import java.io.IOException; -import java.net.InetAddress; import java.util.List; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars; @@ -55,15 +54,17 @@ public InfluxdbConnection(String URL, String token, String org, String bucket, this.context = context; this.gv = GlobalVars.getInstance(); sp = PreferenceManager.getDefaultSharedPreferences(context); - influxDBClient = InfluxDBClientFactory.create(url, this.token, org, bucket); + influxDBClient = InfluxDBClientFactory.create(this.url, this.token, this.org, this.bucket); influxDBClient.enableGzip(); // maybe we want a setting for this? - } + /** + * Open the write API on the InfluxConnection + */ public void open_write_api() { - if(writeApi != null) return; + if (writeApi != null) return; try { - influxDBClient = InfluxDBClientFactory.create(url, this.token, org, bucket); + //influxDBClient = InfluxDBClientFactory.create(url, this.token, org, bucket); writeApi = influxDBClient.makeWriteApi(WriteOptions.builder() .batchSize(1000) .flushInterval(1000) @@ -78,7 +79,6 @@ public void open_write_api() { value.logEvent(); }); writeApi.listenEvents(WriteSuccessEvent.class, value -> { - //Log.d(TAG, "WriteSuccess: Line: " + value.getLineProtocol()); if ( sp.getBoolean("enable_influx", false)) { gv.getLog_status().setColorFilter(Color.argb(255, 0, 255, 0)); } @@ -95,7 +95,9 @@ public void open_write_api() { } } - + /** + * Disconnect and destroy the client + */ public void disconnect() { // make sure we a instance of the client. This can happen on an app resume if (influxDBClient != null) { @@ -112,6 +114,7 @@ public void disconnect() { try { Log.d(TAG, "disconnect: Closing influx connection"); influxDBClient.close(); + influxDBClient = null; } catch (com.influxdb.exceptions.InfluxException e) { Log.d(TAG, "disconnect: Error while closing influx connection"); e.printStackTrace(); @@ -121,12 +124,10 @@ public void disconnect() { } } - // Add a point to the message queue + /** + * Add a point to the message queue + */ public boolean writePoint(Point point) throws IOException { - //InetAddress[] addresses = InetAddress.getAllByName("www.google.com"); - // only add the point if the database is reachable - //InetAddress.getByName(url.split(":")[0]).isReachable(1); - //if (influxDBClient != null && influxDBClient.ping()) { if (influxDBClient != null && influxDBClient.ping()) { try { writeApi.writePoint(point); @@ -142,27 +143,26 @@ public boolean writePoint(Point point) throws IOException { } } + /** + * Write string records to the queue + * @param points String list of records + * @return not yet usefull + * @throws IOException + */ public boolean writeRecords(List points) throws IOException { - // only add the point if the database is reachable - //InetAddress.getByName(url.split(":")[0]).isReachable(1); - //if (influxDBClient != null && influxDBClient.ping()) { - new Thread(new Runnable() { @Override public void run() { try { - if (influxDBClient != null && InetAddress.getByName(url.split(":")[1].replace("//","")).isReachable(1000)) { + if (influxDBClient != null && influxDBClient.ping()) { try { writeApi.writeRecords(WritePrecision.MS, points); } catch (com.influxdb.exceptions.InfluxException e) { - Log.d(TAG, "writePoint: Error while writing points to influx DB"); + Log.d(TAG, "writeRecords: Error while writing points to influx DB"); e.printStackTrace(); - //return false; } - //return true; } else { - Log.d(TAG, "writePoints: InfluxDB not reachable: " + url.split(":")[1].replace("//","")); - //return false; + Log.d(TAG, "writeRecords: InfluxDB not reachable: " + url); } } catch (Exception ex) { @@ -173,29 +173,26 @@ public void run() { return true; } + /** + * + * @param points + * @return + * @throws IOException + */ public boolean writePoints(List points) throws IOException { - // only add the point if the database is reachable - //InetAddress.getByName(url.split(":")[0]).isReachable(1); - //if (influxDBClient != null && influxDBClient.ping()) { - new Thread(new Runnable() { @Override public void run() { try { - if (influxDBClient != null && InetAddress.getByName(url.split(":")[1].replace("//","")).isReachable(1000)) { + if (influxDBClient != null && influxDBClient.ping()) { try { - for (Point point : points) { - writeApi.writePoint(point); - } + writeApi.writePoints(points); } catch (com.influxdb.exceptions.InfluxException e) { Log.d(TAG, "writePoint: Error while writing points to influx DB"); e.printStackTrace(); - //return false; } - //return true; } else { - Log.d(TAG, "writePoints: InfluxDB not reachable: " + url.split(":")[1].replace("//","")); - //return false; + Log.d(TAG, "writePoints: InfluxDB not reachable: " + url); } } catch (Exception ex) { @@ -206,8 +203,11 @@ public void run() { return true; } - // Setup a local database and store credentials - public boolean setup() { + /** + * Onboard a influxDB and store credentials + * @return + */ + public boolean onboard() { try { if (influxDBClient.isOnboardingAllowed()) { OnboardingRequest or = new OnboardingRequest(); @@ -228,17 +228,20 @@ public boolean setup() { } } - // If we can reach the influxDB call flush on the write API + /** + * If we can reach the influxDB call flush on the write API + * @return + */ + // todo handle unreachable DB public boolean flush() { new Thread(new Runnable() { @Override public void run() { try { - if (InetAddress.getByName(url.split(":")[1].replace("//","")).isReachable(50)) { + if (influxDBClient.ping()) { writeApi.flush(); } - } - catch (Exception ex) { + } catch (Exception ex) { ex.printStackTrace(); } } diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnections.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnections.java index 1db8f4c8..cbdf7d64 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnections.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/InfluxDB2x/InfluxdbConnections.java @@ -38,15 +38,17 @@ public static InfluxdbConnection getRicInstance(Context context) { if (Looper.getMainLooper().isCurrentThread()) { Toast.makeText(context, "Influx Parameter not correctly set!", Toast.LENGTH_LONG).show();// On UI thread. } - return null; } - ric = new InfluxdbConnection(url, token, org, bucket, context); } return ric; } + public static void removeRicInstance() { + ric = null; + } + //todo Remote setting are currently hardcoded and should be generated public static InfluxdbConnection getLicInstance(Context context) { if (lic == null) { diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3ToLineProtocolWorker.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3ToLineProtocolWorker.java index febced4a..2226a10a 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3ToLineProtocolWorker.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3ToLineProtocolWorker.java @@ -13,22 +13,18 @@ import android.os.Build; import android.util.Log; import android.widget.Toast; + import androidx.annotation.NonNull; import androidx.preference.PreferenceManager; import androidx.work.Data; import androidx.work.Worker; import androidx.work.WorkerParameters; + import com.google.common.base.Splitter; import com.google.gson.Gson; import com.influxdb.client.domain.WritePrecision; import com.influxdb.client.write.Point; -import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.DeviceInformation; -import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars; -import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnection; -import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnections; -import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval; -import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Root; -import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Stream; + import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -39,6 +35,14 @@ import java.util.LinkedList; import java.util.Map; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider.DeviceInformation; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.GlobalVars; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnection; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnections; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Interval; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Root; +import de.fraunhofer.fokus.OpenMobileNetworkToolkit.Iperf3.JSON.Stream; + public class Iperf3ToLineProtocolWorker extends Worker { private static final String TAG = "Iperf3UploadWorker"; InfluxdbConnection influx; @@ -178,7 +182,7 @@ public Result doWork() { point.addTag("connectingToPort", String.valueOf(iperf3AsJson.start.connectingTo.port)); point.addTag("bandwith", bandwidth); point.addTag("duration", duration); - point.addTag("bytes", bytes); + point.addTag("bytesToTransmit", bytes); point.addTag("streams", String.valueOf(interval.streams.size())); point.addTag("streamIdx", String.valueOf(interval.streams.indexOf(stream))); point.addTag("intervalIdx", String.valueOf(intervalIdx)); diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3UploadWorker.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3UploadWorker.java index 404dccb4..16dbba99 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3UploadWorker.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/Iperf3/Iperf3UploadWorker.java @@ -10,8 +10,8 @@ import android.content.Context; import android.content.SharedPreferences; - import android.util.Log; + import androidx.annotation.NonNull; import androidx.preference.PreferenceManager; import androidx.work.Data; @@ -22,12 +22,11 @@ import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; - import java.util.List; +import java.util.stream.Collectors; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnection; import de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x.InfluxdbConnections; -import java.util.stream.Collectors; public class Iperf3UploadWorker extends Worker { private static final String TAG = "Iperf3UploadWorker"; diff --git a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java index fd0a541b..fadf9f47 100644 --- a/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java +++ b/app/src/main/java/de/fraunhofer/fokus/OpenMobileNetworkToolkit/LoggingService.java @@ -228,7 +228,6 @@ public int onStartCommand(Intent intent, int flags, int startId) { interval = Integer.parseInt(sp.getString("logging_interval", "1000")); feature_telephony = pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY); if (feature_telephony) { - //tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tm = GlobalVars.getInstance().getTm(); cp = gv.isCarrier_permissions(); } @@ -508,18 +507,17 @@ private void stopLocalInfluxDB() { private void setupRemoteInfluxDB() { Log.d(TAG, "setupRemoteInfluxDB"); ic = InfluxdbConnections.getRicInstance(getApplicationContext()); - if(ic == null){ - stopRemoteInfluxDB(); - return; - } - ic.setup(); Objects.requireNonNull(ic).open_write_api(); remoteInfluxHandler = new Handler(Objects.requireNonNull(Looper.myLooper())); remoteInfluxHandler.post(RemoteInfluxUpdate); } + /** + * stop remote influx logging in clear up all internal instances of involved objects + */ private void stopRemoteInfluxDB() { Log.d(TAG, "stopRemoteInfluxDB"); + // cleanup the handler is existing if (remoteInfluxHandler != null) { try { remoteInfluxHandler.removeCallbacks(RemoteInfluxUpdate); @@ -527,12 +525,18 @@ private void stopRemoteInfluxDB() { Log.d(TAG, "trying to stop remote influx service while it was not running"); } } + + // close disconnect influx connection if existing if (ic != null) { ic.disconnect(); + ic = null; } - gv.getLog_status().setColorFilter(Color.argb(255, 192, 192, 192)); + // remove reference in connection manager + InfluxdbConnections.removeRicInstance(); + gv.getLog_status().setColorFilter(Color.argb(255, 192, 192, 192)); } + private long unixTimestampWithMicrosToMillis(double timestampWithMicros) { long seconds = (long) timestampWithMicros; long microseconds = (long) ((timestampWithMicros - seconds) * 1e6); @@ -573,6 +577,7 @@ private void setupPing(){ pingLogging = new Handler(Objects.requireNonNull(Looper.myLooper())); pingLogging.post(pingUpdate); } + private final Runnable pingUpdate = new Runnable() { @Override public void run() {