diff options
author | Nate Jiang <qiangjiang@google.com> | 2019-07-16 14:08:52 -0700 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-07-16 14:08:52 -0700 |
commit | 2cf53e6eaf439635452ce9a84b01716cd47f3b2f (patch) | |
tree | 3623217874e9e652044257abb897b7421e4eb3d6 | |
parent | a56585c17383ca34dad3a1ff80141226028331ed (diff) | |
parent | 7c9b249046dc4bb393a592085fdb394699f31411 (diff) |
[NetworkSuggestion] remove all suggestion should trigger disconnect
am: 7c9b249046
Change-Id: Ib83792d3a7ff8106f0c5ee2aeac8bb409b4795a9
-rw-r--r-- | service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java | 4 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java | 33 |
2 files changed, 37 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java index ec15e1c93..5ed0b7bdc 100644 --- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java +++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java @@ -654,6 +654,10 @@ public class WifiNetworkSuggestionsManager { return WifiManager.STATUS_NETWORK_SUGGESTIONS_ERROR_REMOVE_INVALID; } if (mWifiPermissionsUtil.checkNetworkCarrierProvisioningPermission(uid)) { + // empty list is used to clear everything for the app. + if (extNetworkSuggestions.isEmpty()) { + extNetworkSuggestions = new HashSet<>(perAppInfo.extNetworkSuggestions); + } triggerDisconnectIfServingNetworkSuggestionRemoved(extNetworkSuggestions); } removeInternal(extNetworkSuggestions, packageName, perAppInfo); 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<WifiNetworkSuggestion> networkSuggestionList = + new ArrayList<WifiNetworkSuggestion>() {{ + 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 |