From 80a67d1ff05a0bdeb990b35f3e1588a83e174374 Mon Sep 17 00:00:00 2001 From: xshu Date: Mon, 30 Mar 2020 17:10:29 -0700 Subject: Treat BSSIDs blocked by MBO same as other BSSIDs It's observed that APs sometimes tell the framework to block BSSIDs for durations longer than the user's expectation, causing confusion and frustration to the user because they are not connecting the the network. The fix will make BSSIDs blocked by MBO available again when the user tap on a network or toggles wifi. Bug: 152155058 Test: atest com.android.server.wifi Change-Id: I786b11d29f248f740719e7c6083ac945431c0246 --- .../android/server/wifi/BssidBlocklistMonitor.java | 20 ++++++-------------- .../server/wifi/BssidBlocklistMonitorTest.java | 13 +++++++------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/service/java/com/android/server/wifi/BssidBlocklistMonitor.java b/service/java/com/android/server/wifi/BssidBlocklistMonitor.java index 897090c82..70c919340 100644 --- a/service/java/com/android/server/wifi/BssidBlocklistMonitor.java +++ b/service/java/com/android/server/wifi/BssidBlocklistMonitor.java @@ -154,13 +154,10 @@ public class BssidBlocklistMonitor { pw.println("BssidBlocklistMonitor - Bssid blocklist End ----"); } - private void addToBlocklist(@NonNull BssidStatus entry, long durationMs, - boolean doNotClearUntilTimeout, String reasonString) { + private void addToBlocklist(@NonNull BssidStatus entry, long durationMs, String reasonString) { entry.addToBlocklist(durationMs); - entry.doNotClearUntilTimeout = doNotClearUntilTimeout; localLog(TAG + " addToBlocklist: bssid=" + entry.bssid + ", ssid=" + entry.ssid - + ", durationMs=" + durationMs + ", doNotClearUntilTimeout=" - + doNotClearUntilTimeout + ", reason=" + reasonString); + + ", durationMs=" + durationMs + ", reason=" + reasonString); } /** @@ -223,8 +220,7 @@ public class BssidBlocklistMonitor { // Return because this BSSID is already being blocked for a longer time. return; } - addToBlocklist(status, durationMs, true, - FAILURE_BSSID_BLOCKED_BY_FRAMEWORK_REASON_STRING); + addToBlocklist(status, durationMs, FAILURE_BSSID_BLOCKED_BY_FRAMEWORK_REASON_STRING); } private String getFailureReasonString(@FailureReason int reasonCode) { @@ -289,7 +285,7 @@ public class BssidBlocklistMonitor { } addToBlocklist(entry, getBlocklistDurationWithExponentialBackoff(currentStreak, baseBlockDurationMs), - false, getFailureReasonString(reasonCode)); + getFailureReasonString(reasonCode)); mWifiScoreCard.incrementBssidBlocklistStreak(ssid, bssid, reasonCode); return true; } @@ -403,8 +399,7 @@ public class BssidBlocklistMonitor { */ public void clearBssidBlocklistForSsid(@NonNull String ssid) { int prevSize = mBssidStatusMap.size(); - mBssidStatusMap.entrySet().removeIf(e -> !e.getValue().doNotClearUntilTimeout - && e.getValue().ssid.equals(ssid)); + mBssidStatusMap.entrySet().removeIf(e -> e.getValue().ssid.equals(ssid)); int diff = prevSize - mBssidStatusMap.size(); if (diff > 0) { localLog(TAG + " clearBssidBlocklistForSsid: SSID=" + ssid @@ -418,7 +413,7 @@ public class BssidBlocklistMonitor { public void clearBssidBlocklist() { if (mBssidStatusMap.size() > 0) { int prevSize = mBssidStatusMap.size(); - mBssidStatusMap.entrySet().removeIf(e -> !e.getValue().doNotClearUntilTimeout); + mBssidStatusMap.clear(); localLog(TAG + " clearBssidBlocklist: num BSSIDs cleared=" + (prevSize - mBssidStatusMap.size())); } @@ -506,9 +501,6 @@ public class BssidBlocklistMonitor { // The following are used to flag how long this BSSID stays in the blocklist. public boolean isInBlocklist; public long blocklistEndTimeMs; - // Indicate that this BSSID should not be removed from blacklist through other means - // such as |clearBssidBlocklist| and |clearBssidBlocklistForSsid| - public boolean doNotClearUntilTimeout; BssidStatus(String bssid, String ssid) { this.bssid = bssid; diff --git a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java index 00afa91f1..2567faa91 100644 --- a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java @@ -628,14 +628,15 @@ public class BssidBlocklistMonitorTest { when(mClock.getWallClockMillis()).thenReturn(0L); long testDuration = 5500L; mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, TEST_SSID_1, testDuration); + assertEquals(1, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size()); - // Verify that the BSSID is not removed from blocklist dispite of regular "clear" calls. - when(mClock.getWallClockMillis()).thenReturn(testDuration); - mBssidBlocklistMonitor.clearBssidBlocklist(); + // Verify that the BSSID is removed from blocklist by clearBssidBlocklistForSsid mBssidBlocklistMonitor.clearBssidBlocklistForSsid(TEST_SSID_1); - Set bssidList = mBssidBlocklistMonitor.updateAndGetBssidBlocklist(); - assertEquals(1, bssidList.size()); - assertTrue(bssidList.contains(TEST_BSSID_1)); + assertEquals(0, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size()); + + // Add the BSSID to blocklist again. + mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, TEST_SSID_1, testDuration); + assertEquals(1, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size()); // Verify that the BSSID is removed from blocklist once the specified duration is over. when(mClock.getWallClockMillis()).thenReturn(testDuration + 1); -- cgit v1.2.3