summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java4
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java33
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