Skip to content

Commit

Permalink
Merge pull request #45 from omnt/fix/logging_notification
Browse files Browse the repository at this point in the history
Draft: Fix Notification for LoggingService and Show Cell Parameter in Seperate Notification
  • Loading branch information
PeterHasse authored Jan 8, 2025
2 parents 16aa781 + 276ebca commit e68be6a
Show file tree
Hide file tree
Showing 13 changed files with 483 additions and 117 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@
android:foregroundServiceType="location" />
<service android:name="de.fraunhofer.fokus.OpenMobileNetworkToolkit.Ping.PingService" />


<service
android:name="de.fraunhofer.fokus.OpenMobileNetworkToolkit.NotificationService"
android:foregroundServiceType="location" />
<service
android:name="androidx.work.impl.foreground.SystemForegroundService"
android:foregroundServiceType="specialUse">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ public Point getPoint(Point point){

public StringBuilder getStringBuilder(){
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append(" Type: ").append(this.getCellType());
if(this.getPci() != -1) stringBuilder.append(" PCI: ").append(this.getPci());
stringBuilder.append(" Type: ").append(this.getCellType()).append("\n");
if(this.getPci() != -1) stringBuilder.append(" PCI: ").append(this.getPci()).append("\n");
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.R && this.getAlphaLong() != null && !this.getAlphaLong().equals("N/A") && !this.getAlphaLong().isEmpty()){
stringBuilder.append(" Alpha Long: ").append(this.getAlphaLong());
stringBuilder.append(" Alpha Long: ").append(this.getAlphaLong()).append("\n");
}
return stringBuilder;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,22 @@ public Point getPoint(Point point){
@Override
public StringBuilder getStringBuilder(){
StringBuilder stringBuilder = super.getStringBuilder();
stringBuilder.append(" RSRQ: ").append(this.getRsrq());
stringBuilder.append(" RSRP: ").append(this.getRsrp());
stringBuilder.append(" RSSI: ").append(this.getRssi());
stringBuilder.append(" RSSNR: ").append(this.getRssnr());
stringBuilder.append(" CQI: ").append(this.getCqi());
stringBuilder.append(" Bandwidth: ").append(this.getBandwidth());
stringBuilder.append(" EARFCN: ").append(this.getEarfcn());
stringBuilder.append(" TimingAdvance: ").append(this.getTimingAdvance());
String max = Integer.MAX_VALUE + "";
if(!this.getRsrqString().equals(max)) stringBuilder.append(" RSRQ: ").append(this.getRsrq()).append(" dB").append("\n");

if(!this.getRsrpString().equals(max)) stringBuilder.append(" RSRP: ").append(this.getRsrp()).append(" dBm").append("\n");

if(!this.getRssiString().equals(max)) stringBuilder.append(" RSSI: ").append(this.getRssi()).append(" dBm").append("\n");

if(!this.getRssnrString().equals(max)) stringBuilder.append(" RSSNR: ").append(this.getRssnr()).append(" dB").append("\n");

if(!this.getCqiString().equals(max)) stringBuilder.append(" CQI: ").append(this.getCqi()).append("\n");

if(!this.getBandwidthString().equals(max)) stringBuilder.append(" Bandwidth: ").append(this.getBandwidth()).append(" kHz").append("\n");

if(!this.getEarfcnString().equals(max)) stringBuilder.append(" EARFCN: ").append(this.getEarfcn()).append("\n");

if(!this.getTimingAdvanceString().equals(max)) stringBuilder.append(" TimingAdvance: ").append(this.getTimingAdvance()).append(" ns").append("\n");

return stringBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,18 @@ public List<Integer> getCqis() {
return cqis;
}

public int getFirstCqi() {
try {
return cqis.get(0);
} catch (IndexOutOfBoundsException e) {
return 0;
}
}

public String getFirstCqiString(){
return Integer.toString(this.getFirstCqi());
}

public void setCqis(List<Integer> cqis) {
this.cqis = cqis;
}
Expand Down Expand Up @@ -279,11 +291,20 @@ public Point getPoint(Point point){

@Override
public StringBuilder getStringBuilder(){
StringBuilder sb = super.getStringBuilder();
sb.append(" SSRSQ: ").append(this.getSsrsrq());
sb.append(" SSRSRP: ").append(this.getSsrsrp());
sb.append(" SSSINR: ").append(this.getSssinr());
return sb;
}
StringBuilder stringBuilder = super.getStringBuilder();
String max = Integer.MAX_VALUE + "";
if(!this.getSsrsrqString().equals(max)) stringBuilder.append(" SSRSRQ: ").append(this.getSsrsrqString()).append(" dB").append("\n");

if(!this.getSsrsrpString().equals(max)) stringBuilder.append(" SSRSRP: ").append(this.getSsrsrpString()).append(" dBm").append("\n");

if(!this.getSssinrString().equals(max)) stringBuilder.append(" SSRSRP: ").append(this.getSssinrString()).append(" dBm").append("\n");

if(!this.getFirstCqiString().equals(max)) stringBuilder.append(" CQI: ").append(this.getFirstCqiString()).append("\n");

if(!this.getNrarfcnString().equals(max)) stringBuilder.append(" NRARFCN: ").append(this.getNrarfcnString()).append("\n");

if(!this.getTimingAdvanceString().equals(max)) stringBuilder.append(" TimingAdvance: ").append(this.getTimingAdvance()).append(" ns").append("\n");

return stringBuilder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class GlobalVars {
public static final String SSRSRP = "SSRSRP";
public static final String SSRSRQ = "SSRSRQ";
public static final String SSSINR = "SSSINR";
public static final String INFLUX_WRITE_STATUS = "influxdb_write_status";
private static GlobalVars instance;
ImageView log_status;
private DataProvider dp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,23 +69,22 @@ public void open_write_api() {
.exponentialBase(4)
.build());
writeApi.listenEvents(BackpressureEvent.class, value -> {
Log.d(TAG, "Backpressure: Reason: " + value.getReason());
value.logEvent();
Log.d(TAG, "open_write_api: Could not write to InfluxDBv2 due to backpressure");
});
writeApi.listenEvents(WriteSuccessEvent.class, value -> {
//Log.d(TAG, "open_write_api: Write to InfluxDBv2 was successful");
if ( spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_influx", false)) {
gv.getLog_status().setColorFilter(Color.argb(255, 0, 255, 0));
}
});
writeApi.listenEvents(WriteErrorEvent.class, value -> {
value.logEvent();
Log.d(TAG, "open_write_api: Could not write to InfluxDBv2 due to error");
if ( spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_influx", false)) {
gv.getLog_status().setColorFilter(Color.argb(255, 255, 0, 0));
}
});

writeApi.listenEvents(WriteRetriableErrorEvent.class, value -> {
value.logEvent();
Log.d(TAG, "open_write_api: Could not write to InfluxDBv2 due to retriable error");
if ( spg.getSharedPreference(SPType.logging_sp).getBoolean("enable_influx", false)) {
gv.getLog_status().setColorFilter(Color.argb(255, 255, 0, 0));
}
Expand All @@ -109,27 +108,20 @@ public void disconnect() {
writeApi.close();
writeApi = null;
} catch (com.influxdb.exceptions.InfluxException e) {
Log.d(TAG, "disconnect: Error while closing write API");
Log.d(TAG,e.toString());
}
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");
Log.e(TAG, "disconnect: Error while closing write API");
Log.d(TAG,e.toString());
}
} else {
Log.d(TAG, "disconnect() was called on not existing instance of the influx client");
}
Log.d(TAG, "disconnect: InfluxDB connection closed");
}

/**
* Add a point to the message queue
*/
public boolean writePoint(Point point) {
if (influxDBClient != null && influxDBClient.ping()) {
if (influxDBClient != null && ping()) {
try {
writeApi.writePoint(point);
} catch (com.influxdb.exceptions.InfluxException e) {
Expand All @@ -153,7 +145,7 @@ public boolean writePoint(Point point) {
public boolean writeRecords(List<String> points) throws IOException {
new Thread(() -> {
try {
if (influxDBClient != null && influxDBClient.ping()) {
if (influxDBClient != null && ping()) {
try {
writeApi.writeRecords(WritePrecision.MS, points);
} catch (com.influxdb.exceptions.InfluxException e) {
Expand All @@ -180,18 +172,19 @@ public boolean writeRecords(List<String> points) throws IOException {
public boolean writePoints(List<Point> points) throws IOException {
new Thread(() -> {
try {
if (influxDBClient != null && influxDBClient.ping()) {
if (influxDBClient != null && ping()) {
try {
writeApi.writePoints(points);
} catch (com.influxdb.exceptions.InfluxException e) {
Log.d(TAG, "writePoint: Error while writing points to influx DB");
Log.e(TAG, "writePoint: Error while writing points to influx DB");
Log.d(TAG,e.toString());
}
} else {
Log.d(TAG, "writePoints: InfluxDB not reachable: " + url);
Log.e(TAG, "writePoints: InfluxDB not reachable: " + url);
}
}
catch (Exception e) {
Log.e(TAG, "writePoints: Error while writing points to influx DB");
Log.d(TAG,e.toString());
}
}).start();
Expand Down Expand Up @@ -230,11 +223,12 @@ public boolean onboard() {
public boolean flush() {
new Thread(() -> {
try {
if (influxDBClient.ping()) {
if (ping()) {
writeApi.flush();
}
} catch (Exception e) {
Log.d(TAG,e.toString());
Log.e(TAG, "flush: Error while flushing write API");
Log.d(TAG, "flush: \n"+e.toString());
}
}).start();
return true;
Expand All @@ -243,6 +237,9 @@ public boolean flush() {
public WriteApi getWriteApi() {
return writeApi;
}
public String getUrl() {
return this.url;
}

public boolean ping() {
return influxDBClient.ping();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package de.fraunhofer.fokus.OpenMobileNetworkToolkit.InfluxDB2x;

import androidx.annotation.NonNull;

public enum InfluxdbWriteApiStatus {
Backpressure,
WriteSuccess,
WriteErrorEvent,
WriteRetriableErrorEvent,
Unknown;
@NonNull
public String toString() {
switch(this) {
case Backpressure: return "Backpressure";
case WriteSuccess: return "WriteSuccess";
case WriteErrorEvent: return "WriteErrorEvent";
case WriteRetriableErrorEvent: return "WriteRetriableErrorEvent";
case Unknown:;
default: return "Unknown";
}
}
public static InfluxdbWriteApiStatus fromString(String str) {
str = str.toLowerCase();
switch(str) {
case "backpressure": return Backpressure;
case "writesuccess": return WriteSuccess;
case "writeerrorevent": return WriteErrorEvent;
case "writeeetriableerrorevent": return WriteRetriableErrorEvent;
case "unknown": return Unknown;
default: return Unknown;
}
}

public boolean isEquals(InfluxdbWriteApiStatus status) {
return this==status;
}
}
Loading

0 comments on commit e68be6a

Please sign in to comment.