diff options
-rw-r--r-- | service/java/com/android/server/wifi/WifiStateMachine.java | 6 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 32 |
2 files changed, 36 insertions, 2 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index fa22749bb..ef5eb027f 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -5300,6 +5300,8 @@ public class WifiStateMachine extends StateMachine { // selection status to temporarily disable the network. if (mWifiConfigManager.getLastSelectedNetwork() != config.networkId && !config.noInternetAccessExpected) { + Log.i(TAG, "Temporarily disabling network because of" + + "no-internet access"); mWifiConfigManager.updateNetworkSelectionStatus( config.networkId, WifiConfiguration.NetworkSelectionStatus @@ -5314,6 +5316,10 @@ public class WifiStateMachine extends StateMachine { config = getCurrentWifiConfiguration(); if (config != null) { // re-enable autojoin + mWifiConfigManager.updateNetworkSelectionStatus( + config.networkId, + WifiConfiguration.NetworkSelectionStatus + .NETWORK_SELECTION_ENABLE); mWifiConfigManager.setNetworkValidatedInternetAccess( config.networkId, true); } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index 8da8339b3..90f3e0775 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -17,6 +17,7 @@ package com.android.server.wifi; import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_NO_INTERNET_TEMPORARY; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.NETWORK_SELECTION_ENABLE; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -2523,9 +2524,9 @@ public class WifiStateMachineTest { currentNetwork.networkId = FRAMEWORK_NETWORK_ID; currentNetwork.noInternetAccessExpected = true; currentNetwork.numNoInternetAccessReports = 1; - when(mWifiConfigManager.getConfiguredNetwork(FRAMEWORK_NETWORK_ID + 1)) + when(mWifiConfigManager.getConfiguredNetwork(FRAMEWORK_NETWORK_ID)) .thenReturn(currentNetwork); - when(mWifiConfigManager.getLastSelectedNetwork()).thenReturn(FRAMEWORK_NETWORK_ID); + when(mWifiConfigManager.getLastSelectedNetwork()).thenReturn(FRAMEWORK_NETWORK_ID + 1); Message message = new Message(); message.what = NetworkAgent.CMD_REPORT_NETWORK_STATUS; @@ -2539,4 +2540,31 @@ public class WifiStateMachineTest { verify(mWifiConfigManager, never()).updateNetworkSelectionStatus( FRAMEWORK_NETWORK_ID, DISABLED_NO_INTERNET_TEMPORARY); } + + /** + * Verify that we enable the network when we detect validated internet access. + */ + @Test + public void verifyNetworkSelectionEnableOnInternetValidation() throws Exception { + // Simulate the first connection. + connect(); + ArgumentCaptor<Messenger> messengerCaptor = ArgumentCaptor.forClass(Messenger.class); + verify(mConnectivityManager).registerNetworkAgent(messengerCaptor.capture(), + any(NetworkInfo.class), any(LinkProperties.class), any(NetworkCapabilities.class), + anyInt(), any(NetworkMisc.class)); + + when(mWifiConfigManager.getLastSelectedNetwork()).thenReturn(FRAMEWORK_NETWORK_ID + 1); + + Message message = new Message(); + message.what = NetworkAgent.CMD_REPORT_NETWORK_STATUS; + message.arg1 = NetworkAgent.VALID_NETWORK; + message.obj = new Bundle(); + messengerCaptor.getValue().send(message); + mLooper.dispatchAll(); + + verify(mWifiConfigManager) + .setNetworkValidatedInternetAccess(FRAMEWORK_NETWORK_ID, true); + verify(mWifiConfigManager).updateNetworkSelectionStatus( + FRAMEWORK_NETWORK_ID, NETWORK_SELECTION_ENABLE); + } } |