summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/BssidBlocklistMonitor.java28
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java2
-rw-r--r--service/java/com/android/server/wifi/WifiConnectivityManager.java3
-rw-r--r--service/java/com/android/server/wifi/WifiMetrics.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java36
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java11
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java4
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java3
8 files changed, 73 insertions, 16 deletions
diff --git a/service/java/com/android/server/wifi/BssidBlocklistMonitor.java b/service/java/com/android/server/wifi/BssidBlocklistMonitor.java
index dffd77443..5b151d55f 100644
--- a/service/java/com/android/server/wifi/BssidBlocklistMonitor.java
+++ b/service/java/com/android/server/wifi/BssidBlocklistMonitor.java
@@ -18,6 +18,7 @@ package com.android.server.wifi;
import android.annotation.IntDef;
import android.annotation.NonNull;
+import android.annotation.Nullable;
import android.content.Context;
import android.net.wifi.WifiManager;
import android.util.ArrayMap;
@@ -448,11 +449,36 @@ public class BssidBlocklistMonitor {
* @param ssid
* @return the number of BSSIDs currently in the blocklist for the |ssid|.
*/
- public int getNumBlockedBssidsForSsid(@NonNull String ssid) {
+ public int updateAndGetNumBlockedBssidsForSsid(@NonNull String ssid) {
return (int) updateAndGetBssidBlocklistInternal()
.filter(entry -> ssid.equals(entry.ssid)).count();
}
+ private int getNumBlockedBssidsForSsid(@Nullable String ssid) {
+ if (ssid == null) {
+ return 0;
+ }
+ return (int) mBssidStatusMap.values().stream()
+ .filter(entry -> entry.isInBlocklist && ssid.equals(entry.ssid))
+ .count();
+ }
+
+ /**
+ * Overloaded version of updateAndGetBssidBlocklist.
+ * Accepts a @Nullable String ssid as input, and updates the firmware roaming
+ * configuration if the blocklist for the input ssid has been changed.
+ * @param ssid to update firmware roaming configuration for.
+ * @return Set of BSSIDs currently in the blocklist
+ */
+ public Set<String> updateAndGetBssidBlocklistForSsid(@Nullable String ssid) {
+ int numBefore = getNumBlockedBssidsForSsid(ssid);
+ Set<String> bssidBlocklist = updateAndGetBssidBlocklist();
+ if (getNumBlockedBssidsForSsid(ssid) != numBefore) {
+ updateFirmwareRoamingConfiguration(ssid);
+ }
+ return bssidBlocklist;
+ }
+
/**
* Gets the BSSIDs that are currently in the blocklist.
* @return Set of BSSIDs currently in the blocklist
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index 5b5c968c1..45a5d90b9 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -1801,7 +1801,7 @@ public class WifiConfigManager {
int disableReason = networkStatus.getNetworkSelectionDisableReason();
int blockedBssids = Math.min(MAX_BLOCKED_BSSID_PER_NETWORK,
mWifiInjector.getBssidBlocklistMonitor()
- .getNumBlockedBssidsForSsid(config.SSID));
+ .updateAndGetNumBlockedBssidsForSsid(config.SSID));
// if no BSSIDs are blocked then we should keep trying to connect to something
long disableTimeoutMs = 0;
if (blockedBssids > 0) {
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java
index 2ce0bc024..131f4d1c1 100644
--- a/service/java/com/android/server/wifi/WifiConnectivityManager.java
+++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java
@@ -304,7 +304,8 @@ public class WifiConnectivityManager {
updateUserDisabledList(scanDetails);
// Check if any blocklisted BSSIDs can be freed.
- Set<String> bssidBlocklist = mBssidBlocklistMonitor.updateAndGetBssidBlocklist();
+ Set<String> bssidBlocklist = mBssidBlocklistMonitor.updateAndGetBssidBlocklistForSsid(
+ mWifiInfo.getSSID());
if (mStateMachine.isSupplicantTransientState()) {
localLog(listenerName
diff --git a/service/java/com/android/server/wifi/WifiMetrics.java b/service/java/com/android/server/wifi/WifiMetrics.java
index a7544e031..6c2b5e369 100644
--- a/service/java/com/android/server/wifi/WifiMetrics.java
+++ b/service/java/com/android/server/wifi/WifiMetrics.java
@@ -1459,7 +1459,7 @@ public class WifiMetrics {
mScanResultRssiTimestampMillis = mClock.getElapsedSinceBootMillis();
}
mCurrentConnectionEvent.mConnectionEvent.numBssidInBlocklist =
- mBssidBlocklistMonitor.getNumBlockedBssidsForSsid(config.SSID);
+ mBssidBlocklistMonitor.updateAndGetNumBlockedBssidsForSsid(config.SSID);
mCurrentConnectionEvent.mConnectionEvent.networkType =
WifiMetricsProto.ConnectionEvent.TYPE_UNKNOWN;
mCurrentConnectionEvent.mConnectionEvent.isOsuProvisioned = false;
diff --git a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java
index 8cb2e376a..4d2db7b02 100644
--- a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java
@@ -164,13 +164,13 @@ public class BssidBlocklistMonitorTest {
}
/**
- * Verify getNumBlockedBssidsForSsid returns the correct number of blocked BSSIDs.
+ * Verify updateAndGetNumBlockedBssidsForSsid returns the correct number of blocked BSSIDs.
*/
@Test
- public void testGetNumBlockedBssidsForSsid() {
+ public void testUpdateAndGetNumBlockedBssidsForSsid() {
verifyAddMultipleBssidsToBlocklist();
- assertEquals(2, mBssidBlocklistMonitor.getNumBlockedBssidsForSsid(TEST_SSID_1));
- assertEquals(1, mBssidBlocklistMonitor.getNumBlockedBssidsForSsid(TEST_SSID_2));
+ assertEquals(2, mBssidBlocklistMonitor.updateAndGetNumBlockedBssidsForSsid(TEST_SSID_1));
+ assertEquals(1, mBssidBlocklistMonitor.updateAndGetNumBlockedBssidsForSsid(TEST_SSID_2));
}
/**
@@ -208,6 +208,34 @@ public class BssidBlocklistMonitorTest {
}
/**
+ * Verify that updateAndGetBssidBlocklist(ssid) updates firmware roaming configuration
+ * if a BSSID that belongs to the ssid is removed from blocklist.
+ */
+ @Test
+ public void testBssidRemovalUpdatesFirmwareConfiguration() {
+ verifyAddTestBssidToBlocklist();
+ when(mClock.getWallClockMillis()).thenReturn(BASE_BLOCKLIST_DURATION + 1);
+ assertEquals(0, mBssidBlocklistMonitor
+ .updateAndGetBssidBlocklistForSsid(TEST_SSID_1).size());
+ verify(mWifiConnectivityHelper).setFirmwareRoamingConfiguration(eq(new ArrayList<>()),
+ eq(new ArrayList<>()));
+ }
+
+ /**
+ * Verify that updateAndGetBssidBlocklist(ssid) does not update firmware roaming configuration
+ * if there are no BSSIDs belonging to the ssid removed from blocklist.
+ */
+ @Test
+ public void testBssidRemovalNotUpdateFirmwareConfiguration() {
+ verifyAddTestBssidToBlocklist();
+ when(mClock.getWallClockMillis()).thenReturn(BASE_BLOCKLIST_DURATION + 1);
+ assertEquals(0, mBssidBlocklistMonitor
+ .updateAndGetBssidBlocklistForSsid(TEST_SSID_2).size());
+ verify(mWifiConnectivityHelper, never()).setFirmwareRoamingConfiguration(
+ eq(new ArrayList<>()), eq(new ArrayList<>()));
+ }
+
+ /**
* Verify that when adding a AP that had already been failing (therefore has a blocklist
* streak), we are setting the blocklist duration using an exponential backoff technique.
*/
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 3de8cb98b..28fdade18 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -621,7 +621,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
return (int) mBssidStatusMap.entrySet().stream()
.filter(e -> e.getValue().equals(ssid)).count();
}
- }).when(mBssidBlocklistMonitor).getNumBlockedBssidsForSsid(
+ }).when(mBssidBlocklistMonitor).updateAndGetNumBlockedBssidsForSsid(
anyString());
// add bssid to the blocklist
mBssidStatusMap.put(TEST_BSSID, openNetwork.SSID);
@@ -649,7 +649,8 @@ public class WifiConfigManagerTest extends WifiBaseTest {
assertTrue(oldConfig.trusted);
assertNull(oldConfig.BSSID);
- assertEquals(0, mBssidBlocklistMonitor.getNumBlockedBssidsForSsid(openNetwork.SSID));
+ assertEquals(0, mBssidBlocklistMonitor.updateAndGetNumBlockedBssidsForSsid(
+ openNetwork.SSID));
}
/**
@@ -1375,7 +1376,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
for (int i = 1; i < MAX_BLOCKED_BSSID_PER_NETWORK + 1; i++) {
verifyDisableNetwork(result, disableReason);
int numBssidsInBlocklist = i;
- when(mBssidBlocklistMonitor.getNumBlockedBssidsForSsid(anyString()))
+ when(mBssidBlocklistMonitor.updateAndGetNumBlockedBssidsForSsid(anyString()))
.thenReturn(numBssidsInBlocklist);
timeout = WifiConfigManager.getNetworkSelectionDisableTimeoutMillis(disableReason)
* multiplier;
@@ -1386,7 +1387,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
// Verify one last time that the disable duration is capped at some maximum.
verifyDisableNetwork(result, disableReason);
- when(mBssidBlocklistMonitor.getNumBlockedBssidsForSsid(anyString()))
+ when(mBssidBlocklistMonitor.updateAndGetNumBlockedBssidsForSsid(anyString()))
.thenReturn(MAX_BLOCKED_BSSID_PER_NETWORK + 1);
verifyNetworkIsEnabledAfter(result.getNetworkId(),
TEST_ELAPSED_UPDATE_NETWORK_SELECTION_TIME_MILLIS + timeout);
@@ -1404,7 +1405,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
// Verify that with 0 BSSIDs in blocklist we enable the network immediately
verifyDisableNetwork(result, disableReason);
- when(mBssidBlocklistMonitor.getNumBlockedBssidsForSsid(anyString())).thenReturn(0);
+ when(mBssidBlocklistMonitor.updateAndGetNumBlockedBssidsForSsid(anyString())).thenReturn(0);
when(mClock.getElapsedSinceBootMillis())
.thenReturn(TEST_ELAPSED_UPDATE_NETWORK_SELECTION_TIME_MILLIS);
assertTrue(mWifiConfigManager.tryEnableNetwork(result.getNetworkId()));
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
index ba1c4f976..9203a8d9b 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
@@ -2211,9 +2211,9 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(true);
// Force a connectivity scan
- verify(mBssidBlocklistMonitor, never()).updateAndGetBssidBlocklist();
+ verify(mBssidBlocklistMonitor, never()).updateAndGetBssidBlocklistForSsid(anyString());
mWifiConnectivityManager.forceConnectivityScan(WIFI_WORK_SOURCE);
- verify(mBssidBlocklistMonitor).updateAndGetBssidBlocklist();
+ verify(mBssidBlocklistMonitor).updateAndGetBssidBlocklistForSsid(anyString());
}
/**
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
index 4e895e488..c2436a751 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiMetricsTest.java
@@ -1727,7 +1727,8 @@ public class WifiMetricsTest extends WifiBaseTest {
config.allowedKeyManagement = new BitSet();
when(config.getNetworkSelectionStatus()).thenReturn(
mock(WifiConfiguration.NetworkSelectionStatus.class));
- when(mBssidBlocklistMonitor.getNumBlockedBssidsForSsid(eq(config.SSID))).thenReturn(3);
+ when(mBssidBlocklistMonitor.updateAndGetNumBlockedBssidsForSsid(eq(config.SSID)))
+ .thenReturn(3);
mWifiMetrics.startConnectionEvent(config, "RED",
WifiMetricsProto.ConnectionEvent.ROAM_NONE);
mWifiMetrics.endConnectionEvent(