diff options
author | Roshan Pius <rpius@google.com> | 2018-05-22 07:16:36 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-05-22 07:16:36 -0700 |
commit | 452c389378b26a99e2d0a551ff3690db3fb6f3e1 (patch) | |
tree | 24eb1b2c344e36dd6378fdaaf65c7fb9d380d229 | |
parent | 0bdb0e4acbcab2a6464651493cfdaf60bc9f2180 (diff) | |
parent | 95eae9f3e621d3bd5f9b0b63b4c464533b4ba8cd (diff) |
WifiStateMachine: Re-enable network on internet validation
am: 95eae9f3e6
Change-Id: Iac54663962156c77acda85fdc3ef2df73c37e911
-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); + } } |