WifiStateChangeService: exit after trying for 2 minutes

It was tried until it got an IP address, but that will only happen if there
is a wifi device configured.  Since WifiStateChangeService is started when
F-Droid starts, WifiStateChangeService could run for days if someone never
connected to WiFi in that time.

WifiStateChangeService is also started by NETWORK_STATE_CHANGED_ACTION so
it should start each time there is a change to the WiFi connection.
This commit is contained in:
Hans-Christoph Steiner 2018-01-29 22:47:20 +01:00
parent cbc0c39ec2
commit 21c88e282f

View File

@ -92,7 +92,7 @@ public class WifiStateChangeService extends IntentService {
WifiInfo wifiInfo = null;
int wifiState = wifiManager.getWifiState();
int retryCount = 0;
while (FDroidApp.ipAddressString == null) {
if (isInterrupted()) { // can be canceled by a change via WifiStateChangeReceiver
return;
@ -107,7 +107,7 @@ public class WifiStateChangeService extends IntentService {
try {
FDroidApp.subnetInfo = new SubnetUtils(FDroidApp.ipAddressString, netmask).getInfo();
} catch (IllegalArgumentException e) {
// catch this mystery error: "java.lang.IllegalArgumentException: Could not parse [null/24]"
// catch mystery: "java.lang.IllegalArgumentException: Could not parse [null/24]"
e.printStackTrace();
}
}
@ -123,6 +123,11 @@ public class WifiStateChangeService extends IntentService {
setIpInfoFromNetworkInterface();
}
if (retryCount > 120) {
return;
}
retryCount++;
if (FDroidApp.ipAddressString == null) {
Thread.sleep(1000);
Utils.debugLog(TAG, "waiting for an IP address...");