From 7c9b249046dc4bb393a592085fdb394699f31411 Mon Sep 17 00:00:00 2001 From: Nate Jiang Date: Mon, 15 Jul 2019 19:00:05 -0700 Subject: [NetworkSuggestion] remove all suggestion should trigger disconnect When App with "NETWORK_CARRIER_PROVISIONING" permission removes all suggestions, framework should disconnect connected network if suggested by this APP. Bug: 137597179 Test: atest android.net.wifi Test: atest com.android.server.wifi Test: acts WifiNetworkSuggestionTest Change-Id: I2e1193cdc6013028788b447e4da05d61cfa16e6d --- .../wifi/WifiNetworkSuggestionsManagerTest.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java index 8d33fae36..97a183370 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java @@ -1387,6 +1387,39 @@ public class WifiNetworkSuggestionsManagerTest { verify(mClientModeImpl).disconnectCommand(); } + /** + * Verify that we will disconnect from network when App has NetworkCarrierProvisioningPermission + * and removed all its suggestions by remove empty list. + */ + @Test + public void + testRemoveAllNetworkSuggestionsMatchingConnectionSuccessWithOneMatchCarrierProvision() { + WifiNetworkSuggestion networkSuggestion = new WifiNetworkSuggestion( + WifiConfigurationTestUtil.createOpenNetwork(), false, false, TEST_UID_1, + TEST_PACKAGE_1); + List networkSuggestionList = + new ArrayList() {{ + add(networkSuggestion); + }}; + when(mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(TEST_UID_1)) + .thenReturn(true); + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.add(networkSuggestionList, TEST_UID_1, + TEST_PACKAGE_1)); + mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1); + + // Simulate connecting to the network. + mWifiNetworkSuggestionsManager.handleConnectionAttemptEnded( + WifiMetrics.ConnectionEvent.FAILURE_NONE, networkSuggestion.wifiConfiguration, + TEST_BSSID); + + // Now remove all network suggestion and ensure we did trigger a disconnect. + assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS, + mWifiNetworkSuggestionsManager.remove(new ArrayList<>(), TEST_UID_1, + TEST_PACKAGE_1)); + verify(mClientModeImpl).disconnectCommand(); + } + /** * Verify that we do not disconnect from the network if there are network suggestion from -- cgit v1.2.3