summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/BssidBlocklistMonitor.java9
-rw-r--r--tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java20
2 files changed, 29 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/BssidBlocklistMonitor.java b/service/java/com/android/server/wifi/BssidBlocklistMonitor.java
index 96770443d..dffd77443 100644
--- a/service/java/com/android/server/wifi/BssidBlocklistMonitor.java
+++ b/service/java/com/android/server/wifi/BssidBlocklistMonitor.java
@@ -220,6 +220,12 @@ public class BssidBlocklistMonitor {
*/
public void blockBssidForDurationMs(@NonNull String bssid, @NonNull String ssid,
long durationMs) {
+ if (bssid == null || ssid == null || WifiManager.UNKNOWN_SSID.equals(ssid)
+ || bssid.equals(ClientModeImpl.SUPPLICANT_BSSID_ANY) || durationMs <= 0) {
+ Log.e(TAG, "Invalid input: BSSID=" + bssid + ", SSID=" + ssid
+ + ", durationMs=" + durationMs);
+ return;
+ }
BssidStatus status = getOrCreateBssidStatus(bssid, ssid);
if (status.isInBlocklist
&& status.blocklistEndTimeMs - mClock.getWallClockMillis() > durationMs) {
@@ -407,6 +413,9 @@ public class BssidBlocklistMonitor {
int prevSize = mBssidStatusMap.size();
mBssidStatusMap.entrySet().removeIf(e -> {
BssidStatus status = e.getValue();
+ if (status.ssid == null) {
+ return false;
+ }
if (status.ssid.equals(ssid)) {
mBssidStatusHistoryLogger.add(status, "clearBssidBlocklistForSsid");
return true;
diff --git a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java
index 4369a831b..8cb2e376a 100644
--- a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java
@@ -662,4 +662,24 @@ public class BssidBlocklistMonitorTest {
assertEquals(0, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size());
assertEquals(2, mBssidBlocklistMonitor.getBssidStatusHistoryLoggerSize());
}
+
+ /**
+ * Verify that invalid inputs are handled and result in no-op.
+ */
+ @Test
+ public void testBlockBssidForDurationMsInvalidInputs() {
+ // test invalid BSSID
+ when(mClock.getWallClockMillis()).thenReturn(0L);
+ long testDuration = 5500L;
+ mBssidBlocklistMonitor.blockBssidForDurationMs(null, TEST_SSID_1, testDuration);
+ assertEquals(0, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size());
+
+ // test invalid SSID
+ mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, null, testDuration);
+ assertEquals(0, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size());
+
+ // test invalid duration
+ mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, TEST_SSID_1, -1);
+ assertEquals(0, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size());
+ }
}