From 962a2fb3d6f724e6f4f66cd210dbb74e15f757c1 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Sat, 9 May 2015 23:58:28 -0400 Subject: [PATCH] improve detection of hotspot mode hotspot mode is not well represented with the WifiState stuff. It can be active when the WifiState is DISABLED or UNKNOWN. Also, when switching from active wifi to hotspot mode, WIFI_STATE_DISABLING broadcasts will be sent, but WIFI_STATE_DISABLED/WIFI_STATE_UNKNOWN will not. --- .../fdroid/fdroid/net/WifiStateChangeService.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java b/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java index eca334673..bb90e1af4 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java +++ b/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java @@ -46,6 +46,8 @@ public class WifiStateChangeService extends Service { NetworkInfo is only passed via WifiStateChangeReceiver */ Log.i(TAG, "ni == " + ni + " wifiState == " + printWifiState(wifiState)); if (wifiState == WifiManager.WIFI_STATE_ENABLED + || wifiState == WifiManager.WIFI_STATE_DISABLING // might be switching to hotspot + || wifiState == WifiManager.WIFI_STATE_DISABLED // might be hotspot || wifiState == WifiManager.WIFI_STATE_UNKNOWN) { // might be hotspot if (asyncTask != null) { asyncTask.cancel(true); @@ -73,9 +75,15 @@ public class WifiStateChangeService extends Service { if (wifiState == WifiManager.WIFI_STATE_ENABLED) { wifiInfo = wifiManager.getConnectionInfo(); FDroidApp.ipAddressString = formatIpAddress(wifiInfo.getIpAddress()); - } else + } else if (wifiState == WifiManager.WIFI_STATE_DISABLED + || wifiState == WifiManager.WIFI_STATE_DISABLING) { + // try once to see if its a hotspot FDroidApp.ipAddressString = getIpAddressFromNetworkInterface(); - // TODO turning off a hotspot leaves wifiState as UNKNOWN with no IP, and this goes until next wifi change + if (FDroidApp.ipAddressString == null) + return null; + } else { // a hotspot can be active during WIFI_STATE_UNKNOWN + FDroidApp.ipAddressString = getIpAddressFromNetworkInterface(); + } Thread.sleep(1000); if (BuildConfig.DEBUG) { Log.d(TAG, "waiting for an IP address...");