From 644849175102c8dcb0b24889718bb2527d0c66b8 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Mon, 29 Jan 2018 22:47:20 +0100 Subject: [PATCH] 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. --- .../org/fdroid/fdroid/net/WifiStateChangeService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/fdroid/fdroid/net/WifiStateChangeService.java b/app/src/main/java/org/fdroid/fdroid/net/WifiStateChangeService.java index b098220a7..fcd62ad6c 100644 --- a/app/src/main/java/org/fdroid/fdroid/net/WifiStateChangeService.java +++ b/app/src/main/java/org/fdroid/fdroid/net/WifiStateChangeService.java @@ -101,7 +101,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; @@ -116,7 +116,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(); } } @@ -132,6 +132,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...");