more reliably set WiFi SSID in nearby/swap interfaces

Often times, the WiFi is properly setup, the IP address is showing, but the
SSID is showing as "No network yet".
This commit is contained in:
Hans-Christoph Steiner 2019-05-21 11:13:38 +02:00
parent 11e0c1926c
commit 5b610798c2

View File

@ -127,6 +127,7 @@ public class WifiStateChangeService extends IntentService {
if (wifiState == WifiManager.WIFI_STATE_ENABLED) {
wifiInfo = wifiManager.getConnectionInfo();
FDroidApp.ipAddressString = formatIpAddress(wifiInfo.getIpAddress());
setSsidFromWifiInfo(wifiInfo);
DhcpInfo dhcpInfo = wifiManager.getDhcpInfo();
if (dhcpInfo != null) {
String netmask = formatIpAddress(dhcpInfo.netmask);
@ -168,17 +169,7 @@ public class WifiStateChangeService extends IntentService {
return;
}
if (wifiInfo != null) {
String ssid = wifiInfo.getSSID();
Utils.debugLog(TAG, "Have wifi info, connected to " + ssid);
if (ssid != null) {
FDroidApp.ssid = ssid.replaceAll("^\"(.*)\"$", "$1");
}
String bssid = wifiInfo.getBSSID();
if (bssid != null) {
FDroidApp.bssid = bssid;
}
}
setSsidFromWifiInfo(wifiInfo);
String scheme;
if (Preferences.get().isLocalRepoHttpsEnabled()) {
@ -232,6 +223,20 @@ public class WifiStateChangeService extends IntentService {
}
}
private void setSsidFromWifiInfo(WifiInfo wifiInfo) {
if (wifiInfo != null) {
String ssid = wifiInfo.getSSID();
Utils.debugLog(TAG, "Have wifi info, connected to " + ssid);
if (ssid != null) {
FDroidApp.ssid = ssid.replaceAll("^\"(.*)\"$", "$1");
}
String bssid = wifiInfo.getBSSID();
if (bssid != null) {
FDroidApp.bssid = bssid;
}
}
}
/**
* Search for known Wi-Fi, Hotspot, and local network interfaces and get
* the IP Address info from it. This is necessary because network