From 95eae9f3e621d3bd5f9b0b63b4c464533b4ba8cd Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Fri, 18 May 2018 17:06:40 -0700 Subject: WifiStateMachine: Re-enable network on internet validation Once the network has validated internet access, re-enable network selection status to clear out any blacklist. This will handle cases where the network had no-internet temporarily and then re-established internet connectivity. Also, added an explicit log when network is being disabled because of no-internet. Bug: 72635747 Test: Unit tests Test: Manually verified that network was re-enabled when internet connectivity was restored (when there were no other saved networks around) Change-Id: I0de3c0e8c842efe56b1ab0fd2fb89bd2874e7285 --- .../com/android/server/wifi/WifiStateMachine.java | 6 ++++ .../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 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); + } } -- cgit v1.2.3