diff options
author | Nate Jiang <qiangjiang@google.com> | 2020-03-05 06:02:46 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-03-05 06:02:46 +0000 |
commit | 8f5ba75b3d586f22f9f3037f91720ff3990b530b (patch) | |
tree | b3b5e76f88b1034c26a7695740228cd92c7e9c21 /tests | |
parent | 54e4e77e55cd42a349ce444c62c28d2bc2afbc08 (diff) | |
parent | 6911409691d6cae501d15c01e418e2d18a11e380 (diff) |
Merge "User disconnect block list" into rvc-dev
Diffstat (limited to 'tests')
7 files changed, 120 insertions, 41 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index 846b452d1..2e276e82a 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -893,6 +893,7 @@ public class ClientModeImplTest extends WifiBaseTest { mCmi.connect(null, config.networkId, mock(Binder.class), connectActionListener, 0, Binder.getCallingUid()); mLooper.dispatchAll(); + verify(mWifiConfigManager).userEnabledNetwork(config.networkId); verify(connectActionListener).onSuccess(); } diff --git a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java index 1ce8d6eae..82925a43f 100644 --- a/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/NetworkSuggestionNominatorTest.java @@ -408,8 +408,8 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest { assertTrue(connectableNetworks.isEmpty()); - verify(mWifiConfigManager, times(scanSsids.length)) - .wasEphemeralNetworkDeleted(anyString()); + verify(mWifiConfigManager, times(suggestionSsids.length)) + .isNetworkTemporarilyDisabledByUser(anyString()); verify(mWifiConfigManager).getConfiguredNetwork(eq( suggestions[0].wns.wifiConfiguration.getKey())); verify(mWifiConfigManager).addOrUpdateNetwork(any(), anyInt(), anyString()); @@ -466,8 +466,8 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest { validateConnectableNetworks(connectableNetworks, new String[] {scanSsids[0]}); // check for any saved networks. - verify(mWifiConfigManager, times(scanSsids.length)) - .wasEphemeralNetworkDeleted(anyString()); + verify(mWifiConfigManager, times(suggestionSsids.length)) + .isNetworkTemporarilyDisabledByUser(anyString()); verify(mWifiConfigManager) .getConfiguredNetwork(suggestions[0].wns.wifiConfiguration.getKey()); verify(mWifiConfigManager).addOrUpdateNetwork( @@ -513,7 +513,8 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest { // setup config manager interactions. setupAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration); // Network was disabled by the user. - when(mWifiConfigManager.wasEphemeralNetworkDeleted(suggestionSsids[0])).thenReturn(true); + when(mWifiConfigManager.isNetworkTemporarilyDisabledByUser(suggestionSsids[0])) + .thenReturn(true); List<Pair<ScanDetail, WifiConfiguration>> connectableNetworks = new ArrayList<>(); mNetworkSuggestionNominator.nominateNetworks( @@ -523,10 +524,11 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest { assertTrue(connectableNetworks.isEmpty()); - verify(mWifiConfigManager, times(scanSsids.length)).wasEphemeralNetworkDeleted(anyString()); - // Verify we did not try to add any new networks or other interactions with + verify(mWifiConfigManager, times(suggestionSsids.length)) + .isNetworkTemporarilyDisabledByUser(anyString()); + // Verify we did try to add any new networks or other interactions with // WifiConfigManager. - verifyNoMoreInteractions(mWifiConfigManager); + verifyAddToWifiConfigManager(suggestions[0].wns.wifiConfiguration); } /** @@ -580,8 +582,8 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest { assertTrue(connectableNetworks.isEmpty()); - verify(mWifiConfigManager, times(scanSsids.length)) - .wasEphemeralNetworkDeleted(anyString()); + verify(mWifiConfigManager, times(suggestionSsids.length)) + .isNetworkTemporarilyDisabledByUser(anyString()); verify(mWifiConfigManager).getConfiguredNetwork(eq( suggestions[0].wns.wifiConfiguration.getKey())); verify(mWifiConfigManager).addOrUpdateNetwork( @@ -649,8 +651,8 @@ public class NetworkSuggestionNominatorTest extends WifiBaseTest { validateConnectableNetworks(connectableNetworks, new String[] {scanSsids[0]}); - verify(mWifiConfigManager, times(scanSsids.length)) - .wasEphemeralNetworkDeleted(anyString()); + verify(mWifiConfigManager, times(suggestionSsids.length)) + .isNetworkTemporarilyDisabledByUser(anyString()); verify(mWifiConfigManager).getConfiguredNetwork(eq( suggestions[0].wns.wifiConfiguration.getKey())); verify(mWifiConfigManager).addOrUpdateNetwork( diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index 08c4eac9a..6e5147bd3 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -2964,7 +2964,7 @@ public class WifiConfigManagerTest extends WifiBaseTest { } assertTrue(sharedNetwork1Id != WifiConfiguration.INVALID_NETWORK_ID); assertTrue(sharedNetwork2Id != WifiConfiguration.INVALID_NETWORK_ID); - assertFalse(mWifiConfigManager.wasEphemeralNetworkDeleted(TEST_SSID)); + assertFalse(mWifiConfigManager.isNetworkTemporarilyDisabledByUser(TEST_SSID)); // Set up the user 2 store data that is loaded at user switch. List<WifiConfiguration> user2Networks = new ArrayList<WifiConfiguration>() { @@ -2992,7 +2992,7 @@ public class WifiConfigManagerTest extends WifiBaseTest { } assertEquals(sharedNetwork1Id, updatedSharedNetwork1Id); assertEquals(sharedNetwork2Id, updatedSharedNetwork2Id); - assertFalse(mWifiConfigManager.wasEphemeralNetworkDeleted(TEST_SSID)); + assertFalse(mWifiConfigManager.isNetworkTemporarilyDisabledByUser(TEST_SSID)); } /** @@ -4572,27 +4572,25 @@ public class WifiConfigManagerTest extends WifiBaseTest { /** * Verifies the deletion of ephemeral network using - * {@link WifiConfigManager#disableEphemeralNetwork(String)}. + * {@link WifiConfigManager#userTemporarilyDisabledNetwork(String)}. */ @Test - public void testDisableEphemeralNetwork() throws Exception { - WifiConfiguration ephemeralNetwork = WifiConfigurationTestUtil.createEphemeralNetwork(); + public void testUserDisableNetwork() throws Exception { + WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork(); List<WifiConfiguration> networks = new ArrayList<>(); - networks.add(ephemeralNetwork); - - verifyAddEphemeralNetworkToWifiConfigManager(ephemeralNetwork); - + networks.add(openNetwork); + verifyAddNetworkToWifiConfigManager(openNetwork); List<WifiConfiguration> retrievedNetworks = mWifiConfigManager.getConfiguredNetworksWithPasswords(); WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate( networks, retrievedNetworks); - verifyExpiryOfTimeout(ephemeralNetwork); + verifyExpiryOfTimeout(openNetwork); } /** * Verifies the disconnection of Passpoint network using - * {@link WifiConfigManager#disableEphemeralNetwork(String)}. + * {@link WifiConfigManager#userTemporarilyDisabledNetwork(String)}. */ @Test public void testDisablePasspointNetwork() throws Exception { @@ -4613,8 +4611,8 @@ public class WifiConfigManagerTest extends WifiBaseTest { /** * Verifies the disconnection of Passpoint network using - * {@link WifiConfigManager#disableEphemeralNetwork(String)} and ensures that any user choice - * set over other networks is removed. + * {@link WifiConfigManager#userTemporarilyDisabledNetwork(String)} and ensures that any user + * choice set over other networks is removed. */ @Test public void testDisablePasspointNetworkRemovesUserChoice() throws Exception { @@ -4636,32 +4634,71 @@ public class WifiConfigManagerTest extends WifiBaseTest { retrievedSavedNetwork.getNetworkSelectionStatus().getConnectChoice()); // Disable the passpoint network & ensure the user choice is now removed from saved network. - mWifiConfigManager.disableEphemeralNetwork(passpointNetwork.SSID); + mWifiConfigManager.userTemporarilyDisabledNetwork(passpointNetwork.FQDN); retrievedSavedNetwork = mWifiConfigManager.getConfiguredNetwork(savedNetwork.networkId); assertNull(retrievedSavedNetwork.getNetworkSelectionStatus().getConnectChoice()); } + @Test + public void testUserEnableDisabledNetwork() { + WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork(); + List<WifiConfiguration> networks = new ArrayList<>(); + networks.add(openNetwork); + verifyAddNetworkToWifiConfigManager(openNetwork); + List<WifiConfiguration> retrievedNetworks = + mWifiConfigManager.getConfiguredNetworksWithPasswords(); + WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate( + networks, retrievedNetworks); + + mWifiConfigManager.userTemporarilyDisabledNetwork(openNetwork.SSID); + assertTrue(mWifiConfigManager.isNetworkTemporarilyDisabledByUser(openNetwork.SSID)); + mWifiConfigManager.userEnabledNetwork(retrievedNetworks.get(0).networkId); + assertFalse(mWifiConfigManager.isNetworkTemporarilyDisabledByUser(openNetwork.SSID)); + } + + @Test + public void testUserAddOrUpdateSavedNetworkEnableNetwork() { + WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork(); + List<WifiConfiguration> networks = new ArrayList<>(); + networks.add(openNetwork); + mWifiConfigManager.userTemporarilyDisabledNetwork(openNetwork.SSID); + assertTrue(mWifiConfigManager.isNetworkTemporarilyDisabledByUser(openNetwork.SSID)); + + verifyAddNetworkToWifiConfigManager(openNetwork); + List<WifiConfiguration> retrievedNetworks = + mWifiConfigManager.getConfiguredNetworksWithPasswords(); + WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate( + networks, retrievedNetworks); + assertFalse(mWifiConfigManager.isNetworkTemporarilyDisabledByUser(openNetwork.SSID)); + } + private void verifyExpiryOfTimeout(WifiConfiguration config) { // Disable the ephemeral network. long disableTimeMs = 546643L; long currentTimeMs = disableTimeMs; when(mClock.getWallClockMillis()).thenReturn(currentTimeMs); - mWifiConfigManager.disableEphemeralNetwork(config.SSID); - + String network = config.isPasspoint() ? config.FQDN : config.SSID; + mWifiConfigManager.userTemporarilyDisabledNetwork(network); + // Before timer is triggered, timer will not expiry will enable network. + currentTimeMs = disableTimeMs + + WifiConfigManager.USER_DISCONNECT_NETWORK_BLOCK_EXPIRY_MS + 1; + when(mClock.getWallClockMillis()).thenReturn(currentTimeMs); + assertTrue(mWifiConfigManager.isNetworkTemporarilyDisabledByUser(network)); + for (int i = 0; i < WifiConfigManager.SCAN_RESULT_MISSING_COUNT_THRESHOLD; i++) { + mWifiConfigManager.updateUserDisabledList(new ArrayList<>()); + } // Before the expiry of timeout. - currentTimeMs = disableTimeMs + WifiConfigManager.DELETED_EPHEMERAL_SSID_EXPIRY_MS - 1; + currentTimeMs = currentTimeMs + + WifiConfigManager.USER_DISCONNECT_NETWORK_BLOCK_EXPIRY_MS - 1; when(mClock.getWallClockMillis()).thenReturn(currentTimeMs); - assertTrue(mWifiConfigManager.wasEphemeralNetworkDeleted(config.SSID)); - assertTrue(mWifiConfigManager.getConfiguredNetwork(config.networkId) - .getNetworkSelectionStatus().isNetworkPermanentlyDisabled()); + assertTrue(mWifiConfigManager.isNetworkTemporarilyDisabledByUser(network)); // After the expiry of timeout. - currentTimeMs = disableTimeMs + WifiConfigManager.DELETED_EPHEMERAL_SSID_EXPIRY_MS + 1; + currentTimeMs = currentTimeMs + + WifiConfigManager.USER_DISCONNECT_NETWORK_BLOCK_EXPIRY_MS + 1; when(mClock.getWallClockMillis()).thenReturn(currentTimeMs); - assertFalse(mWifiConfigManager.wasEphemeralNetworkDeleted(config.SSID)); - assertFalse(mWifiConfigManager.getConfiguredNetwork(config.networkId) - .getNetworkSelectionStatus().isNetworkPermanentlyDisabled()); + assertFalse(mWifiConfigManager.isNetworkTemporarilyDisabledByUser(network)); } private NetworkUpdateResult verifyAddOrUpdateNetworkWithProxySettingsAndPermissions( diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index acac4f2f4..a3424f39f 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -50,6 +50,8 @@ import android.util.LocalLog; import androidx.test.filters.SmallTest; +import com.android.server.wifi.hotspot2.PasspointManager; +import com.android.server.wifi.util.ScanResultUtil; import com.android.wifi.resources.R; import org.junit.After; @@ -68,8 +70,10 @@ import java.io.StringWriter; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.concurrent.Executor; import java.util.stream.Collectors; @@ -107,6 +111,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { when(mWifiInjector.getWifiScoreCard()).thenReturn(mWifiScoreCard); when(mWifiInjector.getWifiNetworkSuggestionsManager()) .thenReturn(mWifiNetworkSuggestionsManager); + when(mWifiInjector.getPasspointManager()).thenReturn(mPasspointManager); mWifiConnectivityManager = createConnectivityManager(); verify(mWifiConfigManager).addOnNetworkUpdateListener(anyObject()); mWifiConnectivityManager.setTrustedConnectionAllowed(true); @@ -175,6 +180,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { @Mock private WifiChannelUtilization mWifiChannelUtilization; @Mock private ScoringParams mScoringParams; @Mock private WifiScoreCard mWifiScoreCard; + @Mock private PasspointManager mPasspointManager; @Mock private WifiScoreCard.PerNetwork mPerNetwork; @Mock private WifiScoreCard.PerNetwork mPerNetwork1; @Mock WifiCandidates.Candidate mCandidate1; @@ -209,6 +215,8 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { private static final int TEST_FREQUENCY_3 = 5240; private static final int HIGH_MVMT_SCAN_DELAY_MS = 10000; private static final int HIGH_MVMT_RSSI_DELTA = 10; + private static final String TEST_FQDN = "FQDN"; + private static final String TEST_SSID = "SSID"; Context mockContext() { Context context = mock(Context.class); @@ -1682,6 +1690,37 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { } /** + * Verify when new scanResults are available, UserDisabledList will be updated. + */ + @Test + public void verifyUserDisabledListUpdated() { + mResources.setBoolean( + R.bool.config_wifi_framework_use_single_radio_chain_scan_results_network_selection, + true); + verify(mWifiConfigManager, never()).updateUserDisabledList(anyList()); + Set<String> updateNetworks = new HashSet<>(); + mScanData = createScanDataWithDifferentRadioChainInfos(); + int i = 0; + for (ScanResult scanResult : mScanData.getResults()) { + scanResult.SSID = TEST_SSID + i; + updateNetworks.add(ScanResultUtil.createQuotedSSID(scanResult.SSID)); + i++; + } + updateNetworks.add(TEST_FQDN); + mScanData.getResults()[0].setFlag(ScanResult.FLAG_PASSPOINT_NETWORK); + HashMap<String, Map<Integer, List<ScanResult>>> passpointNetworks = new HashMap<>(); + passpointNetworks.put(TEST_FQDN, new HashMap<>()); + when(mPasspointManager.getAllMatchingPasspointProfilesForScanResults(any())) + .thenReturn(passpointNetworks); + + mWifiConnectivityManager.forceConnectivityScan(WIFI_WORK_SOURCE); + ArgumentCaptor<ArrayList<String>> listArgumentCaptor = + ArgumentCaptor.forClass(ArrayList.class); + verify(mWifiConfigManager).updateUserDisabledList(listArgumentCaptor.capture()); + assertEquals(updateNetworks, new HashSet<>(listArgumentCaptor.getValue())); + } + + /** * Verify that a blacklisted BSSID becomes available only after * BSSID_BLACKLIST_EXPIRE_TIME_MS. */ diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java index 52c43ce7a..c25648d53 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkFactoryTest.java @@ -2120,7 +2120,7 @@ public class WifiNetworkFactoryTest extends WifiBaseTest { reset(mNetworkRequestMatchCallback, mWifiScanner, mAlarmManager, mClientModeImpl); // 2. Simulate user forgeting the network. - when(mWifiConfigManager.wasEphemeralNetworkDeleted( + when(mWifiConfigManager.isNetworkTemporarilyDisabledByUser( ScanResultUtil.createQuotedSSID(mTestScanDatas[0].getResults()[0].SSID))) .thenReturn(true); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index 36904e041..8ecac08bc 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -4102,7 +4102,7 @@ public class WifiServiceImplTest extends WifiBaseTest { verify(mPasspointManager).removeProvider(anyInt(), anyBoolean(), eq(config.getUniqueId()), isNull()); verify(mPasspointManager).clearAnqpRequestsAndFlushCache(); - verify(mWifiConfigManager).clearDeletedEphemeralNetworks(); + verify(mWifiConfigManager).clearUserTemporarilyDisabledList(); verify(mWifiConfigManager).removeAllEphemeralOrPasspointConfiguredNetworks(); verify(mClientModeImpl).clearNetworkRequestUserApprovedAccessPoints(); verify(mWifiNetworkSuggestionsManager).clear(); @@ -4482,7 +4482,7 @@ public class WifiServiceImplTest extends WifiBaseTest { anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_GRANTED); mWifiServiceImpl.disableEphemeralNetwork(new String(), TEST_PACKAGE_NAME); mLooper.dispatchAll(); - verify(mWifiConfigManager).disableEphemeralNetwork(anyString()); + verify(mWifiConfigManager).userTemporarilyDisabledNetwork(anyString()); } /** @@ -4495,7 +4495,7 @@ public class WifiServiceImplTest extends WifiBaseTest { anyInt(), anyInt())).thenReturn(PackageManager.PERMISSION_DENIED); mWifiServiceImpl.disableEphemeralNetwork(new String(), TEST_PACKAGE_NAME); mLooper.dispatchAll(); - verify(mWifiConfigManager, never()).disableEphemeralNetwork(anyString()); + verify(mWifiConfigManager, never()).userTemporarilyDisabledNetwork(anyString()); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelperTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelperTest.java index 0be5035ad..493be0fd9 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelperTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointNetworkNominateHelperTest.java @@ -516,7 +516,7 @@ public class PasspointNetworkNominateHelperTest { when(mWifiConfigManager.addOrUpdateNetwork(any(WifiConfiguration.class), anyInt())) .thenReturn(new NetworkUpdateResult(TEST_NETWORK_ID)); when(mWifiConfigManager.getConfiguredNetwork(TEST_NETWORK_ID)).thenReturn(TEST_CONFIG1); - when(mWifiConfigManager.wasEphemeralNetworkDeleted("\"" + TEST_SSID1 + "\"")) + when(mWifiConfigManager.isNetworkTemporarilyDisabledByUser(TEST_FQDN1)) .thenReturn(true); List<Pair<ScanDetail, WifiConfiguration>> candidates = mNominateHelper .getPasspointNetworkCandidates(scanDetails, false); |