From 2f5d10a29d17781e903eeddedb4a547e62c55524 Mon Sep 17 00:00:00 2001 From: Ningyuan Wang Date: Mon, 25 Sep 2017 14:46:38 -0700 Subject: Cherry-pick: Remove temporarily disabled networks from PNO list This also adds corresponding unit tests. Bug: 66910426 Test: compile, unit tests Merged-In: I58f7061887ebc1dd78d3941218653460f80abb1f Change-Id: I58f7061887ebc1dd78d3941218653460f80abb1f --- .../com/android/server/wifi/WifiConfigManager.java | 5 +-- .../android/server/wifi/WifiConfigManagerTest.java | 39 ++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index 75b39b261..06b53be85 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -2330,12 +2330,13 @@ public class WifiConfigManager { public List retrievePnoNetworkList() { List pnoList = new ArrayList<>(); List networks = new ArrayList<>(getInternalConfiguredNetworks()); - // Remove any permanently disabled networks. + // Remove any permanently or temporarily disabled networks. Iterator iter = networks.iterator(); while (iter.hasNext()) { WifiConfiguration config = iter.next(); if (config.ephemeral || config.isPasspoint() - || config.getNetworkSelectionStatus().isNetworkPermanentlyDisabled()) { + || config.getNetworkSelectionStatus().isNetworkPermanentlyDisabled() + || config.getNetworkSelectionStatus().isNetworkTemporaryDisabled()) { iter.remove(); } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index d14c8fc9f..7ce53629b 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -1518,6 +1518,45 @@ public class WifiConfigManagerTest { assertEquals(savedOpenNetwork.SSID, pnoNetworks.get(0).ssid); } + /** + * Verifies that the list of PNO networks does not contain any permanently or temporarily + * disabled networks. + * {@link WifiConfigManager#retrievePnoNetworkList()}. + */ + @Test + public void testRetrievePnoListDoesNotContainDisabledNetworks() throws Exception { + // Create and add 2 networks. + WifiConfiguration network1 = WifiConfigurationTestUtil.createEapNetwork(); + WifiConfiguration network2 = WifiConfigurationTestUtil.createPskNetwork(); + + NetworkUpdateResult result1 = verifyAddNetworkToWifiConfigManager(network1); + NetworkUpdateResult result2 = verifyAddNetworkToWifiConfigManager(network2); + + // Enable all of them. + verifyUpdateNetworkSelectionStatus( + result1.getNetworkId(), NetworkSelectionStatus.NETWORK_SELECTION_ENABLE, 0); + verifyUpdateNetworkSelectionStatus( + result2.getNetworkId(), NetworkSelectionStatus.NETWORK_SELECTION_ENABLE, 0); + + // Set network1 to temporarily disabled. The threshold for association rejection is 5, so + // disable it 5 times to actually mark it temporarily disabled. + int assocRejectReason = NetworkSelectionStatus.DISABLED_ASSOCIATION_REJECTION; + int assocRejectThreshold = + WifiConfigManager.NETWORK_SELECTION_DISABLE_THRESHOLD[assocRejectReason]; + for (int i = 1; i <= assocRejectThreshold; i++) { + verifyUpdateNetworkSelectionStatus(result1.getNetworkId(), assocRejectReason, i); + } + + // Set network 2 to permanently disabled. + verifyUpdateNetworkSelectionStatus( + result2.getNetworkId(), NetworkSelectionStatus.DISABLED_BY_WIFI_MANAGER, 0); + + // Retrieve the Pno network list & verify both networks are not included. + List pnoNetworks = + mWifiConfigManager.retrievePnoNetworkList(); + assertEquals(0, pnoNetworks.size()); + } + /** * Verifies the linking of networks when they have the same default GW Mac address in * {@link WifiConfigManager#getOrCreateScanDetailCacheForNetwork(WifiConfiguration)}. -- cgit v1.2.3