no need for ipAddress int to be global, so make local

This will prevent ipAddressString and ipAddress from getting out of sync.
This commit is contained in:
Hans-Christoph Steiner 2014-05-06 20:05:28 -04:00
parent a58825d7ea
commit 2aa39311c2
2 changed files with 8 additions and 9 deletions

View File

@ -77,7 +77,6 @@ import javax.net.ssl.X509TrustManager;
public class FDroidApp extends Application {
// for the local repo on this device, all static since there is only one
public static int ipAddress = 0;
public static int port = 8888;
public static String ipAddressString = null;
public static String ssid = "";

View File

@ -39,19 +39,19 @@ public class WifiStateChangeService extends Service {
Log.i(TAG, "waiting for the wifi to be enabled...");
Thread.sleep(3000);
}
FDroidApp.ipAddress = wifiManager.getConnectionInfo().getIpAddress();
while (FDroidApp.ipAddress == 0) {
int ipAddress = wifiManager.getConnectionInfo().getIpAddress();
while (ipAddress == 0) {
Log.i(TAG, "waiting for an IP address...");
Thread.sleep(3000);
FDroidApp.ipAddress = wifiManager.getConnectionInfo().getIpAddress();
ipAddress = wifiManager.getConnectionInfo().getIpAddress();
}
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
FDroidApp.ipAddress = wifiInfo.getIpAddress();
ipAddress = wifiInfo.getIpAddress();
FDroidApp.ipAddressString = String.format(Locale.ENGLISH, "%d.%d.%d.%d",
(FDroidApp.ipAddress & 0xff),
(FDroidApp.ipAddress >> 8 & 0xff),
(FDroidApp.ipAddress >> 16 & 0xff),
(FDroidApp.ipAddress >> 24 & 0xff));
(ipAddress & 0xff),
(ipAddress >> 8 & 0xff),
(ipAddress >> 16 & 0xff),
(ipAddress >> 24 & 0xff));
FDroidApp.ssid = wifiInfo.getSSID().replaceAll("^\"(.*)\"$", "$1");
FDroidApp.bssid = wifiInfo.getBSSID();