Skip to content

Commit

Permalink
refactor some warnings in logging service
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterHasse committed Jul 25, 2024
1 parent d34aaa1 commit 93b9388
Show file tree
Hide file tree
Showing 5 changed files with 396 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@

package de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider;

import static android.net.wifi.ScanResult.WIFI_STANDARD_11AC;
import static android.net.wifi.ScanResult.WIFI_STANDARD_11AD;
import static android.net.wifi.ScanResult.WIFI_STANDARD_11AX;
import static android.net.wifi.ScanResult.WIFI_STANDARD_11BE;
import static android.net.wifi.ScanResult.WIFI_STANDARD_11N;
import static android.net.wifi.ScanResult.WIFI_STANDARD_LEGACY;
import static android.net.wifi.ScanResult.WIFI_STANDARD_UNKNOWN;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
Expand All @@ -31,7 +23,9 @@
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.net.TrafficStats;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.BatteryManager;
import android.os.Build;
import android.os.Looper;
Expand Down Expand Up @@ -105,9 +99,9 @@ public class DataProvider extends TelephonyCallback implements LocationListener,
private NetworkInformation ni;// = new NetworkInformation();
private List<NetworkInterfaceInformation> nii = new ArrayList<>();
private ArrayList<SignalStrengthInformation> ssi = new ArrayList<>();
private WifiInfo wi = null;
private WifiInformation wi = null;
private LocationManager lm;
private BuildInformation buildInformation = new BuildInformation();
private final BuildInformation buildInformation = new BuildInformation();
// Time stamp, should be updated on each update of internal data caches
private long ts = System.currentTimeMillis();

Expand Down Expand Up @@ -280,8 +274,8 @@ public void refreshNetworkInterfaceInformation() {
niil.add(nii);
}
}
} catch (SocketException ex) {
ex.printStackTrace();
} catch (SocketException e) {
Log.d(TAG,e.toString());
}
nii = niil;
}
Expand Down Expand Up @@ -315,8 +309,9 @@ public List<Point> getNetworkInterfaceInformationPoints() {
}
}
}
} catch (SocketException ex) {
ex.printStackTrace();
} catch (SocketException e) {
Log.d(TAG,e.toString());

}
return points;
}
Expand Down Expand Up @@ -937,36 +932,20 @@ private void updateTimestamp() {
ts = System.currentTimeMillis();
}

/**
* Return a influx point representation of the wifi information
*
* @return Influx Point
*/
public Point getWifiInformationPoint() {
Point point = new Point("WifiInformation");
point.time(System.currentTimeMillis(), WritePrecision.MS);
WifiInfo wi_ = wi;
point.addField("SSID", wi_.getSSID());
point.addField("BSSID", wi_.getBSSID());
point.addField("RSSI", wi_.getRssi());
point.addField("Frequency", wi_.getFrequency());
point.addField("Link Speed", wi_.getLinkSpeed());
point.addField("TXLink Speed", wi_.getTxLinkSpeedMbps());
point.addField("Max Supported RX Speed", wi_.getMaxSupportedRxLinkSpeedMbps());
point.addField("RX Link Speed", wi_.getRxLinkSpeedMbps());
point.addField("Max Supported TX Speed", wi_.getMaxSupportedTxLinkSpeedMbps());
point.addField("TX Link Speed", wi_.getTxLinkSpeedMbps());
point.addField("Standard", getWifiStandardString(wi_.getWifiStandard()));
return point;
}

/**
* Return wifi info if available
*
* @return Wifi info or null
*/
public WifiInfo getWifiInfo() {
@SuppressLint("MissingPermission")
public WifiInformation getWifiInformation() {
if (wi != null) {
WifiManager wifiManager = (WifiManager) ct.getSystemService(Context.WIFI_SERVICE);
for (ScanResult r : wifiManager.getScanResults()) {
if (Objects.equals(r.BSSID, wi.getBssid())) {
wi.setChannel_width(r.channelWidth);
}
}
return wi;
} else {
return null;
Expand Down Expand Up @@ -1002,7 +981,12 @@ public void onBlockedStatusChanged(@NonNull Network network, boolean blocked) {
public void onCapabilitiesChanged(@NonNull Network network, @NonNull
NetworkCapabilities networkCapabilities) {
super.onCapabilitiesChanged(network, networkCapabilities);
wi = (WifiInfo) networkCapabilities.getTransportInfo();
WifiInfo wifiInfo = (WifiInfo) networkCapabilities.getTransportInfo();
if (wifiInfo != null) {
wi = new WifiInformation(wifiInfo);
} else {
wi = null;
}
}

@Override
Expand Down Expand Up @@ -1030,26 +1014,6 @@ public void onUnavailable() {
}
}

public String getWifiStandardString(int standard) {
switch (standard) {
case WIFI_STANDARD_UNKNOWN:
return "Unknown";
case WIFI_STANDARD_LEGACY:
return "Legacy";
case WIFI_STANDARD_11N:
return "11n";
case WIFI_STANDARD_11AC:
return "11AC";
case WIFI_STANDARD_11AX:
return "11AX";
case WIFI_STANDARD_11AD:
return "11AD";
case WIFI_STANDARD_11BE:
return "11BD";
default:
return "Unknown";
}
}

/**
* Filter values before adding them as we don't need to log not available information
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
/*
* SPDX-FileCopyrightText: 2024 Peter Hasse <[email protected]>
* SPDX-FileCopyrightText: 2024 Johann Hackler <[email protected]>
* SPDX-FileCopyrightText: 2024 Fraunhofer FOKUS
*
* SPDX-License-Identifier: apache2
*/

package de.fraunhofer.fokus.OpenMobileNetworkToolkit.DataProvider;

import static android.net.wifi.ScanResult.CHANNEL_WIDTH_160MHZ;
import static android.net.wifi.ScanResult.CHANNEL_WIDTH_20MHZ;
import static android.net.wifi.ScanResult.CHANNEL_WIDTH_320MHZ;
import static android.net.wifi.ScanResult.CHANNEL_WIDTH_40MHZ;
import static android.net.wifi.ScanResult.CHANNEL_WIDTH_80MHZ;
import static android.net.wifi.ScanResult.CHANNEL_WIDTH_80MHZ_PLUS_MHZ;
import static android.net.wifi.ScanResult.WIFI_STANDARD_11AC;
import static android.net.wifi.ScanResult.WIFI_STANDARD_11AD;
import static android.net.wifi.ScanResult.WIFI_STANDARD_11AX;
import static android.net.wifi.ScanResult.WIFI_STANDARD_11BE;
import static android.net.wifi.ScanResult.WIFI_STANDARD_11N;
import static android.net.wifi.ScanResult.WIFI_STANDARD_LEGACY;
import static android.net.wifi.ScanResult.WIFI_STANDARD_UNKNOWN;

import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;

import com.influxdb.client.domain.WritePrecision;
import com.influxdb.client.write.Point;

public class WifiInformation {
private String ssid;
private String bssid;
private int rssi;
private int frequency;
private int link_speed;
private int tx_link_speed;
private int max_tx_link_speed;
private int rx_link_speed;
private int max_rx_link_speed;
private int standard;
private int channel_bandwidth;

public WifiInformation(String ssid, String bssid, int rssi, int frequency, int link_speed, int tx_link_speed, int max_tx_link_speed, int rx_link_speed, int max_rx_link_speed, int standard, int channel_bandwidth) {
this.ssid = ssid;
this.bssid = bssid;
this.rssi = rssi;
this.frequency = frequency;
this.link_speed = link_speed;
this.tx_link_speed = tx_link_speed;
this.max_tx_link_speed = max_tx_link_speed;
this.rx_link_speed = rx_link_speed;
this.max_rx_link_speed = max_rx_link_speed;
this.standard = standard;
this.channel_bandwidth = channel_bandwidth;
}

public WifiInformation(ScanResult scanResult) {
ssid = scanResult.SSID;
bssid = scanResult.BSSID;
rssi = Integer.parseInt(scanResult.SSID);
frequency = scanResult.frequency;
channel_bandwidth = scanResult.channelWidth;
}

public WifiInformation(WifiInfo wifiInfo) {
ssid = wifiInfo.getSSID().replace("\"", "");
bssid = wifiInfo.getBSSID();
rssi = wifiInfo.getRssi();
frequency = wifiInfo.getFrequency();
link_speed = wifiInfo.getLinkSpeed();
max_tx_link_speed = wifiInfo.getMaxSupportedTxLinkSpeedMbps();
tx_link_speed = wifiInfo.getTxLinkSpeedMbps();
max_rx_link_speed = wifiInfo.getMaxSupportedRxLinkSpeedMbps();
rx_link_speed = wifiInfo.getTxLinkSpeedMbps();
standard = wifiInfo.getWifiStandard();
}



public String getWifiStandardString(int standard) {
switch (standard) {
case WIFI_STANDARD_UNKNOWN:
return "Unknown";
case WIFI_STANDARD_LEGACY:
return "Legacy";
case WIFI_STANDARD_11N:
return "11n";
case WIFI_STANDARD_11AC:
return "11ac";
case WIFI_STANDARD_11AX:
return "11ax";
case WIFI_STANDARD_11AD:
return "11ad";
case WIFI_STANDARD_11BE:
return "11bd";
default:
return "Unknown";
}
}

public String getStandardString() {
return getWifiStandardString(standard);
}

public String getChannelBandwidthStringFromInt(int channel_bandwidth) {
switch (channel_bandwidth) {
case CHANNEL_WIDTH_20MHZ:
return "20MHz";
case CHANNEL_WIDTH_40MHZ:
return "40MHz";
case CHANNEL_WIDTH_80MHZ:
return "80MHz";
case CHANNEL_WIDTH_160MHZ:
return "160Mhz";
case CHANNEL_WIDTH_80MHZ_PLUS_MHZ:
return "80MHz + 80MHz";
case CHANNEL_WIDTH_320MHZ:
return "320MHz";
default:
return "N/A";
}
}

public String getChannelBandwithString(){
return getChannelBandwidthStringFromInt(channel_bandwidth);
}

public String getSsid() {
return ssid;
}

public void setSsid(String ssid) {
this.ssid = ssid;
}

public String getBssid() {
return bssid;
}

public void setBssid(String bssid) {
this.bssid = bssid;
}

public int getRssi() {
return rssi;
}

public void setRssi(int rssi) {
this.rssi = rssi;
}

public int getFrequency() {
return frequency;
}

public void setFrequency(int frequency) {
this.frequency = frequency;
}

public int getLink_speed() {
return link_speed;
}

public void setLink_speed(int link_speed) {
this.link_speed = link_speed;
}

public int getTx_link_speed() {
return tx_link_speed;
}

public void setTx_link_speed(int tx_link_speed) {
this.tx_link_speed = tx_link_speed;
}

public int getMax_tx_link_speed() {
return max_tx_link_speed;
}

public void setMax_tx_link_speed(int max_tx_link_speed) {
this.max_tx_link_speed = max_tx_link_speed;
}

public int getRx_link_speed() {
return rx_link_speed;
}

public void setRx_link_speed(int rx_link_speed) {
this.rx_link_speed = rx_link_speed;
}

public int getMax_rx_link_speed() {
return max_rx_link_speed;
}

public void setMax_rx_link_speed(int max_rx_link_speed) {
this.max_rx_link_speed = max_rx_link_speed;
}

public int getStandard() {
return standard;
}

public void setStandard(int standard) {
this.standard = standard;
}

public int getChannel_bandwidth() {
return channel_bandwidth;
}

public void setChannel_width(int channel_bandwidth) {
this.channel_bandwidth = channel_bandwidth;
}

/** Return a influx point representation of the wifi information
*
* @return Influx Point
*/
public com.influxdb.client.write.Point getWifiInformationPoint() {
Point point = new Point("WifiInformation");
point.time(System.currentTimeMillis(), WritePrecision.MS);
point.addField("SSID", getSsid());
point.addField("BSSID", getBssid());
point.addField("RSSI", getRssi());
point.addField("Frequency", getFrequency());
point.addField("Link Speed", getLink_speed());
point.addField("TX Link Speed", getTx_link_speed());
point.addField("Max Supported TX Speed", getMax_tx_link_speed());
point.addField("RX Link Speed", getRx_link_speed());
point.addField("Max Supported RX Speed", getMax_rx_link_speed());
point.addField("Standard", getStandardString());
point.addField("Channel Width", getChannelBandwithString());
return point;
}
}

Loading

0 comments on commit 93b9388

Please sign in to comment.