summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WakeupController.java2
-rw-r--r--service/java/com/android/server/wifi/WifiConnectivityManager.java2
-rw-r--r--service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java13
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java6
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java6
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java47
6 files changed, 68 insertions, 8 deletions
diff --git a/service/java/com/android/server/wifi/WakeupController.java b/service/java/com/android/server/wifi/WakeupController.java
index d9882dbf3..a92bdf7f1 100644
--- a/service/java/com/android/server/wifi/WakeupController.java
+++ b/service/java/com/android/server/wifi/WakeupController.java
@@ -347,7 +347,7 @@ public class WakeupController {
}
Set<WifiNetworkSuggestion> networkSuggestions =
- mWifiNetworkSuggestionsManager.getAllNetworkSuggestions();
+ mWifiNetworkSuggestionsManager.getAllApprovedNetworkSuggestions();
for (WifiNetworkSuggestion suggestion : networkSuggestions) {
// TODO(b/127799111): Do we need to filter the list similar to saved networks above?
goodNetworks.add(
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java
index 8470d0c7d..bcf162275 100644
--- a/service/java/com/android/server/wifi/WifiConnectivityManager.java
+++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java
@@ -1635,7 +1635,7 @@ public class WifiConnectivityManager {
}
Set<WifiNetworkSuggestion> suggestionsNetworks =
- mWifiNetworkSuggestionsManager.getAllNetworkSuggestions();
+ mWifiNetworkSuggestionsManager.getAllApprovedNetworkSuggestions();
// If total size not equal to 1, then no need to proceed
if (passpointNetworks.size() + savedNetworks.size() + suggestionsNetworks.size() != 1) {
return false;
diff --git a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
index f470039a7..5d5a7d782 100644
--- a/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
+++ b/service/java/com/android/server/wifi/WifiNetworkSuggestionsManager.java
@@ -1254,6 +1254,19 @@ public class WifiNetworkSuggestionsManager {
}
/**
+ * Returns a set of all network suggestions across all apps that have been approved by user.
+ */
+ public Set<WifiNetworkSuggestion> getAllApprovedNetworkSuggestions() {
+ final String activeScorerPackage = mNetworkScoreManager.getActiveScorerPackage();
+ return mActiveNetworkSuggestionsPerApp.values()
+ .stream()
+ .filter(e -> e.isApproved(activeScorerPackage))
+ .flatMap(e -> convertToWnsSet(e.extNetworkSuggestions)
+ .stream())
+ .collect(Collectors.toSet());
+ }
+
+ /**
* Get all user approved, non-passpoint networks from suggestion.
*/
public List<WifiConfiguration> getAllScanOptimizationSuggestionNetworks() {
diff --git a/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java b/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java
index 9824c5b23..3ac4adc3b 100644
--- a/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java
@@ -390,7 +390,7 @@ public class WakeupControllerTest extends WifiBaseTest {
WifiConfiguration wepNetwork = WifiConfigurationTestUtil.createWepNetwork();
WifiNetworkSuggestion wepNetworkSuggestion =
new WifiNetworkSuggestion(wepNetwork, null, false, false, true, true);
- when(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions())
+ when(mWifiNetworkSuggestionsManager.getAllApprovedNetworkSuggestions())
.thenReturn(new HashSet<>(Arrays.asList(
openNetworkSuggestion, wepNetworkSuggestion)));
@@ -432,7 +432,7 @@ public class WakeupControllerTest extends WifiBaseTest {
WifiConfiguration oweNetwork = WifiConfigurationTestUtil.createOweNetwork(quotedSsid2);
WifiNetworkSuggestion oweNetworkSuggestion =
new WifiNetworkSuggestion(oweNetwork, null, false, false, true, true);
- when(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions())
+ when(mWifiNetworkSuggestionsManager.getAllApprovedNetworkSuggestions())
.thenReturn(new HashSet<>(Arrays.asList(oweNetworkSuggestion)));
// scan results from most recent scan
@@ -530,7 +530,7 @@ public class WakeupControllerTest extends WifiBaseTest {
.createOpenNetwork(ScanResultUtil.createQuotedSSID(SAVED_SSID));
WifiNetworkSuggestion openNetworkSuggestion =
new WifiNetworkSuggestion(openNetwork, null, false, false, true, true);
- when(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions())
+ when(mWifiNetworkSuggestionsManager.getAllApprovedNetworkSuggestions())
.thenReturn(new HashSet<>(Collections.singletonList(openNetworkSuggestion)));
initializeWakeupController(true /* enabled */);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
index b01f2beb1..fe16b2833 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
@@ -109,7 +109,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
when(mWifiInjector.getWifiScanner()).thenReturn(mWifiScanner);
when(mWifiNetworkSuggestionsManager.retrieveHiddenNetworkList())
.thenReturn(new ArrayList<>());
- when(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions())
+ when(mWifiNetworkSuggestionsManager.getAllApprovedNetworkSuggestions())
.thenReturn(new HashSet<>());
when(mWifiInjector.getBssidBlocklistMonitor()).thenReturn(mBssidBlocklistMonitor);
when(mWifiInjector.getWifiChannelUtilizationScan()).thenReturn(mWifiChannelUtilization);
@@ -1497,7 +1497,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
when(mWifiNetworkSuggestion.getWifiConfiguration()).thenReturn(mSuggestionConfig);
Set<WifiNetworkSuggestion> suggestionNetworks = new HashSet<WifiNetworkSuggestion>();
suggestionNetworks.add(mWifiNetworkSuggestion);
- when(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions())
+ when(mWifiNetworkSuggestionsManager.getAllApprovedNetworkSuggestions())
.thenReturn(suggestionNetworks);
// Prepare for no saved networks
@@ -1548,7 +1548,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
when(mWifiNetworkSuggestion.getWifiConfiguration()).thenReturn(mSuggestionConfig);
Set<WifiNetworkSuggestion> suggestionNetworks = new HashSet<WifiNetworkSuggestion>();
suggestionNetworks.add(mWifiNetworkSuggestion);
- when(mWifiNetworkSuggestionsManager.getAllNetworkSuggestions())
+ when(mWifiNetworkSuggestionsManager.getAllApprovedNetworkSuggestions())
.thenReturn(suggestionNetworks);
// Prepare for a single passpoint network
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
index 897dca341..e7e866084 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNetworkSuggestionsManagerTest.java
@@ -4018,6 +4018,53 @@ public class WifiNetworkSuggestionsManagerTest extends WifiBaseTest {
}
/**
+ * Verify that we only return user approved suggestions.
+ */
+ @Test
+ public void testGetApprovedNetworkSuggestions() {
+ WifiConfiguration wifiConfiguration = WifiConfigurationTestUtil.createOpenNetwork();
+ WifiNetworkSuggestion networkSuggestion1 = new WifiNetworkSuggestion(
+ wifiConfiguration, null, false, false, true, true);
+ // Reuse the same network credentials to ensure they both match.
+ WifiNetworkSuggestion networkSuggestion2 = new WifiNetworkSuggestion(
+ wifiConfiguration, null, false, false, true, true);
+
+ List<WifiNetworkSuggestion> networkSuggestionList1 =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion1);
+ }};
+ List<WifiNetworkSuggestion> networkSuggestionList2 =
+ new ArrayList<WifiNetworkSuggestion>() {{
+ add(networkSuggestion2);
+ }};
+
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList1, TEST_UID_1,
+ TEST_PACKAGE_1, TEST_FEATURE));
+ assertEquals(WifiManager.STATUS_NETWORK_SUGGESTIONS_SUCCESS,
+ mWifiNetworkSuggestionsManager.add(networkSuggestionList2, TEST_UID_2,
+ TEST_PACKAGE_2, TEST_FEATURE));
+
+ // nothing approved, return empty.
+ assertTrue(mWifiNetworkSuggestionsManager.getAllApprovedNetworkSuggestions().isEmpty());
+
+ mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_1);
+ // only app 1 approved.
+ assertEquals(new HashSet<WifiNetworkSuggestion>() {{
+ add(networkSuggestion1);
+ }},
+ mWifiNetworkSuggestionsManager.getAllApprovedNetworkSuggestions());
+
+ mWifiNetworkSuggestionsManager.setHasUserApprovedForApp(true, TEST_PACKAGE_2);
+ // both app 1 & 2 approved.
+ assertEquals(new HashSet<WifiNetworkSuggestion>() {{
+ add(networkSuggestion1);
+ add(networkSuggestion2);
+ }},
+ mWifiNetworkSuggestionsManager.getAllApprovedNetworkSuggestions());
+ }
+
+ /**
* Helper function for creating a test configuration with user credential.
*
* @return {@link PasspointConfiguration}