diff options
-rw-r--r-- | service/java/com/android/server/wifi/WifiNetworkSelector.java | 13 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java | 7 |
2 files changed, 14 insertions, 6 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkSelector.java b/service/java/com/android/server/wifi/WifiNetworkSelector.java index 07fc157d1..4a12b4219 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSelector.java +++ b/service/java/com/android/server/wifi/WifiNetworkSelector.java @@ -21,6 +21,7 @@ import android.annotation.Nullable; import android.content.Context; import android.net.NetworkKey; import android.net.wifi.ScanResult; +import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiInfo; import android.text.TextUtils; @@ -81,7 +82,7 @@ public class WifiNetworkSelector { /** * Interface for WiFi Network Evaluator * - * A network scorer evaulates all the networks from the scan results and + * A network scorer evaluates all the networks from the scan results and * recommends the best network in its category to connect or roam to. */ public interface NetworkEvaluator { @@ -110,7 +111,7 @@ public class WifiNetworkSelector { * disconnected * @param connected a flag to indicate if ClientModeImpl is in connected * state - * @param untrustedNetworkAllowed a flag to indidate if untrusted networks like + * @param untrustedNetworkAllowed a flag to indicate if untrusted networks like * ephemeral networks are allowed * @param connectableNetworks a list of the ScanDetail and WifiConfiguration * pair which is used by the WifiLastResortWatchdog @@ -137,12 +138,12 @@ public class WifiNetworkSelector { mWifiConfigManager.getConfiguredNetwork(wifiInfo.getNetworkId()); // Currently connected? - if (network == null) { + if (wifiInfo.getSupplicantState() != SupplicantState.COMPLETED) { localLog("No current connected network."); return false; } else { - localLog("Current connected network: " + network.SSID - + " , ID: " + network.networkId); + localLog("Current connected network: " + wifiInfo.getSSID() + + " , ID: " + wifiInfo.getNetworkId()); } int currentRssi = wifiInfo.getRssi(); @@ -156,7 +157,7 @@ public class WifiNetworkSelector { } // Ephemeral network is not qualified. - if (network.ephemeral) { + if (wifiInfo.isEphemeral()) { localLog("Current network is an ephemeral one."); return false; } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java index 6a0dc1305..e723bcc40 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSelectorTest.java @@ -25,6 +25,7 @@ import static org.mockito.Mockito.*; import android.content.Context; import android.net.wifi.ScanResult; +import android.net.wifi.SupplicantState; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration.NetworkSelectionStatus; import android.net.wifi.WifiInfo; @@ -179,6 +180,7 @@ public class WifiNetworkSelectorTest { private void setupWifiInfo() { // simulate a disconnected state + when(mWifiInfo.getSupplicantState()).thenReturn(SupplicantState.DISCONNECTED); when(mWifiInfo.is24GHz()).thenReturn(true); when(mWifiInfo.is5GHz()).thenReturn(false); when(mWifiInfo.getFrequency()).thenReturn(2400); @@ -360,6 +362,7 @@ public class WifiNetworkSelectorTest { // connect to test1 mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + when(mWifiInfo.getSupplicantState()).thenReturn(SupplicantState.COMPLETED); when(mWifiInfo.getNetworkId()).thenReturn(0); when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); when(mWifiInfo.is24GHz()).thenReturn(false); @@ -407,6 +410,7 @@ public class WifiNetworkSelectorTest { // connect to test1 mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + when(mWifiInfo.getSupplicantState()).thenReturn(SupplicantState.COMPLETED); when(mWifiInfo.getNetworkId()).thenReturn(0); when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); when(mWifiInfo.is24GHz()).thenReturn(false); @@ -454,6 +458,7 @@ public class WifiNetworkSelectorTest { // connect to test1 mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + when(mWifiInfo.getSupplicantState()).thenReturn(SupplicantState.COMPLETED); when(mWifiInfo.getNetworkId()).thenReturn(0); when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); when(mWifiInfo.is24GHz()).thenReturn(false); @@ -534,6 +539,7 @@ public class WifiNetworkSelectorTest { WifiConfiguration candidate = mWifiNetworkSelector.selectNetwork(scanDetails, blacklist, mWifiInfo, false, true, false); + when(mWifiInfo.getSupplicantState()).thenReturn(SupplicantState.COMPLETED); when(mWifiInfo.getNetworkId()).thenReturn(0); when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); when(mWifiInfo.is24GHz()).thenReturn(true); @@ -962,6 +968,7 @@ public class WifiNetworkSelectorTest { WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, scanDetails.get(0).getScanResult(), candidate); + when(mWifiInfo.getSupplicantState()).thenReturn(SupplicantState.COMPLETED); when(mWifiInfo.getNetworkId()).thenReturn(0); when(mWifiInfo.getBSSID()).thenReturn(bssids[0]); when(mWifiInfo.is24GHz()).thenReturn(!ScanResult.is5GHz(freqs[0])); |