diff options
4 files changed, 43 insertions, 10 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index 09b0b3483..0b70dbf4e 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -167,7 +167,7 @@ public class WifiConfigManager { /** * Invoked on saved network being permanently disabled. */ - void onSavedNetworkPermanentlyDisabled(int networkId); + void onSavedNetworkPermanentlyDisabled(int networkId, int disableReason); /** * Invoked on saved network being removed. */ @@ -175,7 +175,7 @@ public class WifiConfigManager { /** * Invoked on saved network being temporarily disabled. */ - void onSavedNetworkTemporarilyDisabled(int networkId); + void onSavedNetworkTemporarilyDisabled(int networkId, int disableReason); /** * Invoked on saved network being updated. */ @@ -1303,7 +1303,9 @@ public class WifiConfigManager { // Only need a valid time filled in for temporarily disabled networks. status.setDisableTime(mClock.getElapsedSinceBootMillis()); status.setNetworkSelectionDisableReason(disableReason); - if (mListener != null) mListener.onSavedNetworkTemporarilyDisabled(config.networkId); + if (mListener != null) { + mListener.onSavedNetworkTemporarilyDisabled(config.networkId, disableReason); + } } /** @@ -1317,7 +1319,9 @@ public class WifiConfigManager { status.setDisableTime( NetworkSelectionStatus.INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP); status.setNetworkSelectionDisableReason(disableReason); - if (mListener != null) mListener.onSavedNetworkPermanentlyDisabled(config.networkId); + if (mListener != null) { + mListener.onSavedNetworkPermanentlyDisabled(config.networkId, disableReason); + } } /** diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index aa4fd80df..d10d80013 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -16,6 +16,8 @@ package com.android.server.wifi; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_NO_INTERNET_TEMPORARY; + import static com.android.server.wifi.WifiStateMachine.WIFI_WORK_SOURCE; import android.app.AlarmManager; @@ -37,7 +39,6 @@ import android.util.Log; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; -import com.android.internal.util.ArrayUtils; import com.android.server.wifi.hotspot2.PasspointNetworkEvaluator; import com.android.server.wifi.util.ScanResultUtil; @@ -545,11 +546,12 @@ public class WifiConnectivityManager { updatePnoScan(); } @Override - public void onSavedNetworkTemporarilyDisabled(int networkId) { + public void onSavedNetworkTemporarilyDisabled(int networkId, int disableReason) { + if (disableReason == DISABLED_NO_INTERNET_TEMPORARY) return; mConnectivityHelper.removeNetworkIfCurrent(networkId); } @Override - public void onSavedNetworkPermanentlyDisabled(int networkId) { + public void onSavedNetworkPermanentlyDisabled(int networkId, int disableReason) { mConnectivityHelper.removeNetworkIfCurrent(networkId); updatePnoScan(); } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index 5b4917c7f..a4bc61aa1 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -628,12 +628,14 @@ public class WifiConfigManagerTest { for (int i = 1; i <= assocRejectThreshold; i++) { verifyUpdateNetworkSelectionStatus(result.getNetworkId(), assocRejectReason, i); } - verify(mWcmListener).onSavedNetworkTemporarilyDisabled(networkId); + verify(mWcmListener).onSavedNetworkTemporarilyDisabled( + networkId, NetworkSelectionStatus.DISABLED_ASSOCIATION_REJECTION); // Now set it to permanently disabled. verifyUpdateNetworkSelectionStatus( result.getNetworkId(), NetworkSelectionStatus.DISABLED_BY_WIFI_MANAGER, 0); - verify(mWcmListener).onSavedNetworkPermanentlyDisabled(networkId); + verify(mWcmListener).onSavedNetworkPermanentlyDisabled( + networkId, NetworkSelectionStatus.DISABLED_BY_WIFI_MANAGER); // Now set it back to enabled. verifyUpdateNetworkSelectionStatus( @@ -660,7 +662,8 @@ public class WifiConfigManagerTest { // disable it once to actually mark it temporarily disabled. verifyUpdateNetworkSelectionStatus( result.getNetworkId(), NetworkSelectionStatus.DISABLED_NO_INTERNET_TEMPORARY, 1); - verify(mWcmListener).onSavedNetworkTemporarilyDisabled(networkId); + verify(mWcmListener).onSavedNetworkTemporarilyDisabled( + networkId, NetworkSelectionStatus.DISABLED_NO_INTERNET_TEMPORARY); // Now set it back to enabled. verifyUpdateNetworkSelectionStatus( diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index 36530edb8..cb423617f 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -16,6 +16,9 @@ package com.android.server.wifi; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_FAILURE; +import static android.net.wifi.WifiConfiguration.NetworkSelectionStatus.DISABLED_NO_INTERNET_TEMPORARY; + import static com.android.server.wifi.WifiConfigurationTestUtil.generateWifiConfig; import static com.android.server.wifi.WifiStateMachine.WIFI_WORK_SOURCE; @@ -134,6 +137,8 @@ public class WifiConnectivityManagerTest { @Captor ArgumentCaptor<ScanResult> mCandidateScanResultCaptor; @Captor ArgumentCaptor<ArrayList<String>> mBssidBlacklistCaptor; @Captor ArgumentCaptor<ArrayList<String>> mSsidWhitelistCaptor; + @Captor ArgumentCaptor<WifiConfigManager.OnSavedNetworkUpdateListener> + mSavedNetworkUpdateListenerCaptor; private MockResources mResources; private int mFullScanMaxTxPacketRate; private int mFullScanMaxRxPacketRate; @@ -299,6 +304,8 @@ public class WifiConnectivityManagerTest { pnoNetworkList.add(pnoNetwork); when(wifiConfigManager.retrievePnoNetworkList()).thenReturn(pnoNetworkList); when(wifiConfigManager.retrievePnoNetworkList()).thenReturn(pnoNetworkList); + doNothing().when(wifiConfigManager).setOnSavedNetworkUpdateListener( + mSavedNetworkUpdateListenerCaptor.capture()); return wifiConfigManager; } @@ -2040,4 +2047,21 @@ public class WifiConnectivityManagerTest { assertTrue(capturedScanResults.contains(mScanData.getResults()[2])); assertTrue(capturedScanResults.contains(mScanData.getResults()[3])); } + + /** + * Disabling the network temporarily due to lack of internet is a special reason for which we + * don't want WCM to trigger a disconnect (by removing the network from supplicant). + */ + @Test + public void dontDisconnectIfNetworkTemporarilyDisabledDueToNoInternet() { + assertNotNull(mSavedNetworkUpdateListenerCaptor.getValue()); + + mSavedNetworkUpdateListenerCaptor.getValue() + .onSavedNetworkPermanentlyDisabled(0, DISABLED_AUTHENTICATION_FAILURE); + verify(mWifiConnectivityHelper).removeNetworkIfCurrent(0); + + mSavedNetworkUpdateListenerCaptor.getValue() + .onSavedNetworkPermanentlyDisabled(0, DISABLED_NO_INTERNET_TEMPORARY); + // Don't remove network. + } } |