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:
parent
8a8ca2e6f7
commit
6448491751
@ -101,7 +101,7 @@ public class WifiStateChangeService extends IntentService {
|
|||||||
WifiInfo wifiInfo = null;
|
WifiInfo wifiInfo = null;
|
||||||
|
|
||||||
int wifiState = wifiManager.getWifiState();
|
int wifiState = wifiManager.getWifiState();
|
||||||
|
int retryCount = 0;
|
||||||
while (FDroidApp.ipAddressString == null) {
|
while (FDroidApp.ipAddressString == null) {
|
||||||
if (isInterrupted()) { // can be canceled by a change via WifiStateChangeReceiver
|
if (isInterrupted()) { // can be canceled by a change via WifiStateChangeReceiver
|
||||||
return;
|
return;
|
||||||
@ -116,7 +116,7 @@ public class WifiStateChangeService extends IntentService {
|
|||||||
try {
|
try {
|
||||||
FDroidApp.subnetInfo = new SubnetUtils(FDroidApp.ipAddressString, netmask).getInfo();
|
FDroidApp.subnetInfo = new SubnetUtils(FDroidApp.ipAddressString, netmask).getInfo();
|
||||||
} catch (IllegalArgumentException e) {
|
} 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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -132,6 +132,11 @@ public class WifiStateChangeService extends IntentService {
|
|||||||
setIpInfoFromNetworkInterface();
|
setIpInfoFromNetworkInterface();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (retryCount > 120) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
retryCount++;
|
||||||
|
|
||||||
if (FDroidApp.ipAddressString == null) {
|
if (FDroidApp.ipAddressString == null) {
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
Utils.debugLog(TAG, "waiting for an IP address...");
|
Utils.debugLog(TAG, "waiting for an IP address...");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user