summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/BssidBlocklistMonitor.java59
-rw-r--r--service/java/com/android/server/wifi/ClientModeImpl.java3
-rw-r--r--service/java/com/android/server/wifi/WifiConnectivityManager.java3
-rw-r--r--service/java/com/android/server/wifi/WifiScoreReport.java3
-rw-r--r--tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java17
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java8
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java8
8 files changed, 68 insertions, 35 deletions
diff --git a/service/java/com/android/server/wifi/BssidBlocklistMonitor.java b/service/java/com/android/server/wifi/BssidBlocklistMonitor.java
index 5b151d55f..96b70c39e 100644
--- a/service/java/com/android/server/wifi/BssidBlocklistMonitor.java
+++ b/service/java/com/android/server/wifi/BssidBlocklistMonitor.java
@@ -64,8 +64,15 @@ public class BssidBlocklistMonitor {
public static final int REASON_DHCP_FAILURE = 7;
// Abnormal disconnect error
public static final int REASON_ABNORMAL_DISCONNECT = 8;
+ // AP initiated disconnect for a given duration.
+ public static final int REASON_FRAMEWORK_DISCONNECT_MBO_OCE = 9;
+ // Avoid connecting to the failed AP when trying to reconnect on other available candidates.
+ public static final int REASON_FRAMEWORK_DISCONNECT_FAST_RECONNECT = 10;
+ // The connected scorer has disconnected this network.
+ public static final int REASON_FRAMEWORK_DISCONNECT_CONNECTED_SCORE = 11;
// Constant being used to keep track of how many failure reasons there are.
- public static final int NUMBER_REASON_CODES = 9;
+ public static final int NUMBER_REASON_CODES = 12;
+ public static final int INVALID_REASON = -1;
@IntDef(prefix = { "REASON_" }, value = {
REASON_AP_UNABLE_TO_HANDLE_NEW_STA,
@@ -75,7 +82,11 @@ public class BssidBlocklistMonitor {
REASON_ASSOCIATION_REJECTION,
REASON_ASSOCIATION_TIMEOUT,
REASON_AUTHENTICATION_FAILURE,
- REASON_DHCP_FAILURE
+ REASON_DHCP_FAILURE,
+ REASON_ABNORMAL_DISCONNECT,
+ REASON_FRAMEWORK_DISCONNECT_MBO_OCE,
+ REASON_FRAMEWORK_DISCONNECT_FAST_RECONNECT,
+ REASON_FRAMEWORK_DISCONNECT_CONNECTED_SCORE
})
@Retention(RetentionPolicy.SOURCE)
public @interface FailureReason {}
@@ -92,10 +103,11 @@ public class BssidBlocklistMonitor {
"REASON_ASSOCIATION_TIMEOUT",
"REASON_AUTHENTICATION_FAILURE",
"REASON_DHCP_FAILURE",
- "REASON_ABNORMAL_DISCONNECT"
+ "REASON_ABNORMAL_DISCONNECT",
+ "REASON_FRAMEWORK_DISCONNECT_MBO_OCE",
+ "REASON_FRAMEWORK_DISCONNECT_FAST_RECONNECT",
+ "REASON_FRAMEWORK_DISCONNECT_CONNECTED_SCORE"
};
- private static final String FAILURE_BSSID_BLOCKED_BY_FRAMEWORK_REASON_STRING =
- "BlockedByFramework";
private static final long ABNORMAL_DISCONNECT_RESET_TIME_MS = TimeUnit.HOURS.toMillis(3);
private static final String TAG = "BssidBlocklistMonitor";
@@ -161,10 +173,11 @@ public class BssidBlocklistMonitor {
mBssidStatusHistoryLogger.dump(pw);
}
- private void addToBlocklist(@NonNull BssidStatus entry, long durationMs, String reasonString) {
- entry.addToBlocklist(durationMs, reasonString);
+ private void addToBlocklist(@NonNull BssidStatus entry, long durationMs,
+ @FailureReason int reason) {
+ entry.addToBlocklist(durationMs, reason);
localLog(TAG + " addToBlocklist: bssid=" + entry.bssid + ", ssid=" + entry.ssid
- + ", durationMs=" + durationMs + ", reason=" + reasonString);
+ + ", durationMs=" + durationMs + ", reason=" + getFailureReasonString(reason));
}
/**
@@ -218,13 +231,18 @@ public class BssidBlocklistMonitor {
/**
* Block any attempts to auto-connect to the BSSID for the specified duration.
+ * This is meant to be used by features that need wifi to avoid a BSSID for a certain duration,
+ * and thus will not increase the failure streak counters.
+ * @param bssid identifies the AP to block.
+ * @param ssid identifies the SSID the AP belongs to.
+ * @param durationMs duration in millis to block.
+ * @param blockReason reason for blocking the BSSID.
*/
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) {
+ long durationMs, @FailureReason int blockReason) {
+ if (durationMs <= 0 || !isValidNetworkAndFailureReason(bssid, ssid, blockReason)) {
Log.e(TAG, "Invalid input: BSSID=" + bssid + ", SSID=" + ssid
- + ", durationMs=" + durationMs);
+ + ", durationMs=" + durationMs + ", blockReason=" + blockReason);
return;
}
BssidStatus status = getOrCreateBssidStatus(bssid, ssid);
@@ -233,11 +251,13 @@ public class BssidBlocklistMonitor {
// Return because this BSSID is already being blocked for a longer time.
return;
}
- addToBlocklist(status, durationMs, FAILURE_BSSID_BLOCKED_BY_FRAMEWORK_REASON_STRING);
+ addToBlocklist(status, durationMs, blockReason);
}
private String getFailureReasonString(@FailureReason int reasonCode) {
- if (reasonCode >= FAILURE_REASON_STRINGS.length) {
+ if (reasonCode == INVALID_REASON) {
+ return "INVALID_REASON";
+ } else if (reasonCode < 0 || reasonCode >= FAILURE_REASON_STRINGS.length) {
return "REASON_UNKNOWN";
}
return FAILURE_REASON_STRINGS[reasonCode];
@@ -298,7 +318,7 @@ public class BssidBlocklistMonitor {
}
addToBlocklist(entry,
getBlocklistDurationWithExponentialBackoff(currentStreak, baseBlockDurationMs),
- getFailureReasonString(reasonCode));
+ reasonCode);
mWifiScoreCard.incrementBssidBlocklistStreak(ssid, bssid, reasonCode);
return true;
}
@@ -593,7 +613,7 @@ public class BssidBlocklistMonitor {
public final String bssid;
public final String ssid;
public final int[] failureCount = new int[NUMBER_REASON_CODES];
- private String mBlockReason = ""; // reason of blocking for logging only
+ private int mBlockReason = INVALID_REASON; // reason of blocking this BSSID
// The following are used to flag how long this BSSID stays in the blocklist.
public boolean isInBlocklist;
@@ -616,8 +636,9 @@ public class BssidBlocklistMonitor {
/**
* Add this BSSID to blocklist for the specified duration.
* @param durationMs
+ * @param blockReason
*/
- public void addToBlocklist(long durationMs, String blockReason) {
+ public void addToBlocklist(long durationMs, @FailureReason int blockReason) {
isInBlocklist = true;
blocklistStartTimeMs = mClock.getWallClockMillis();
blocklistEndTimeMs = blocklistStartTimeMs + durationMs;
@@ -632,7 +653,7 @@ public class BssidBlocklistMonitor {
isInBlocklist = false;
blocklistStartTimeMs = 0;
blocklistEndTimeMs = 0;
- mBlockReason = "";
+ mBlockReason = INVALID_REASON;
localLog(TAG + " removeFromBlocklist BSSID=" + bssid);
}
@@ -643,7 +664,7 @@ public class BssidBlocklistMonitor {
sb.append(", SSID=" + ssid);
sb.append(", isInBlocklist=" + isInBlocklist);
if (isInBlocklist) {
- sb.append(", blockReason=" + mBlockReason);
+ sb.append(", blockReason=" + getFailureReasonString(mBlockReason));
mCalendar.setTimeInMillis(blocklistStartTimeMs);
sb.append(", blocklistStartTimeMs="
+ String.format("%tm-%td %tH:%tM:%tS.%tL", mCalendar, mCalendar,
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index fd79d8258..c73fe4bae 100644
--- a/service/java/com/android/server/wifi/ClientModeImpl.java
+++ b/service/java/com/android/server/wifi/ClientModeImpl.java
@@ -6295,7 +6295,8 @@ public class ClientModeImpl extends StateMachine {
duration = MboOceConstants.DEFAULT_BLACKLIST_DURATION_MS;
}
// Blacklist the current BSS
- mBssidBlocklistMonitor.blockBssidForDurationMs(bssid, ssid, duration);
+ mBssidBlocklistMonitor.blockBssidForDurationMs(bssid, ssid, duration,
+ BssidBlocklistMonitor.REASON_FRAMEWORK_DISCONNECT_MBO_OCE);
}
if (frameData.mStatus != MboOceConstants.BTM_RESPONSE_STATUS_ACCEPT) {
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java
index 131f4d1c1..a6f58fbe6 100644
--- a/service/java/com/android/server/wifi/WifiConnectivityManager.java
+++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java
@@ -1759,7 +1759,8 @@ public class WifiConnectivityManager {
// Make sure that the failed BSSID is blocked for at least TEMP_BSSID_BLOCK_DURATION
// to prevent the supplicant from trying it again.
mBssidBlocklistMonitor.blockBssidForDurationMs(bssid, ssid,
- TEMP_BSSID_BLOCK_DURATION);
+ TEMP_BSSID_BLOCK_DURATION,
+ BssidBlocklistMonitor.REASON_FRAMEWORK_DISCONNECT_FAST_RECONNECT);
connectToNetwork(candidate);
}
} catch (IllegalArgumentException e) {
diff --git a/service/java/com/android/server/wifi/WifiScoreReport.java b/service/java/com/android/server/wifi/WifiScoreReport.java
index 7819bba15..61809113c 100644
--- a/service/java/com/android/server/wifi/WifiScoreReport.java
+++ b/service/java/com/android/server/wifi/WifiScoreReport.java
@@ -631,7 +631,8 @@ public class WifiScoreReport {
>= MIN_TIME_TO_WAIT_BEFORE_BLOCKLIST_BSSID_MILLIS)) {
mBssidBlocklistMonitor.blockBssidForDurationMs(mWifiInfo.getBSSID(),
mWifiInfo.getSSID(),
- DURATION_TO_BLOCKLIST_BSSID_AFTER_FIRST_EXITING_MILLIS);
+ DURATION_TO_BLOCKLIST_BSSID_AFTER_FIRST_EXITING_MILLIS,
+ BssidBlocklistMonitor.REASON_FRAMEWORK_DISCONNECT_CONNECTED_SCORE);
mLastScoreBreachLowTimeMillis = INVALID_WALL_CLOCK_MILLIS;
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java
index 4d2db7b02..44303fe25 100644
--- a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java
@@ -47,6 +47,8 @@ public class BssidBlocklistMonitorTest {
private static final String TEST_BSSID_1 = "0a:08:5c:67:89:00";
private static final String TEST_BSSID_2 = "0a:08:5c:67:89:01";
private static final String TEST_BSSID_3 = "0a:08:5c:67:89:02";
+ private static final int TEST_FRAMEWORK_BLOCK_REASON =
+ BssidBlocklistMonitor.REASON_FRAMEWORK_DISCONNECT_MBO_OCE;
private static final int TEST_L2_FAILURE = BssidBlocklistMonitor.REASON_ASSOCIATION_REJECTION;
private static final int TEST_DHCP_FAILURE = BssidBlocklistMonitor.REASON_DHCP_FAILURE;
private static final long BASE_BLOCKLIST_DURATION = TimeUnit.MINUTES.toMillis(5); // 5 minutes
@@ -673,7 +675,8 @@ public class BssidBlocklistMonitorTest {
public void testBlockBssidForDurationMs() {
when(mClock.getWallClockMillis()).thenReturn(0L);
long testDuration = 5500L;
- mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, TEST_SSID_1, testDuration);
+ mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, TEST_SSID_1, testDuration,
+ TEST_FRAMEWORK_BLOCK_REASON);
assertEquals(1, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size());
// Verify that the BSSID is removed from blocklist by clearBssidBlocklistForSsid
@@ -682,7 +685,8 @@ public class BssidBlocklistMonitorTest {
assertEquals(1, mBssidBlocklistMonitor.getBssidStatusHistoryLoggerSize());
// Add the BSSID to blocklist again.
- mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, TEST_SSID_1, testDuration);
+ mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, TEST_SSID_1, testDuration,
+ TEST_FRAMEWORK_BLOCK_REASON);
assertEquals(1, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size());
// Verify that the BSSID is removed from blocklist once the specified duration is over.
@@ -699,15 +703,18 @@ public class BssidBlocklistMonitorTest {
// test invalid BSSID
when(mClock.getWallClockMillis()).thenReturn(0L);
long testDuration = 5500L;
- mBssidBlocklistMonitor.blockBssidForDurationMs(null, TEST_SSID_1, testDuration);
+ mBssidBlocklistMonitor.blockBssidForDurationMs(null, TEST_SSID_1, testDuration,
+ TEST_FRAMEWORK_BLOCK_REASON);
assertEquals(0, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size());
// test invalid SSID
- mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, null, testDuration);
+ mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, null, testDuration,
+ TEST_FRAMEWORK_BLOCK_REASON);
assertEquals(0, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size());
// test invalid duration
- mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, TEST_SSID_1, -1);
+ mBssidBlocklistMonitor.blockBssidForDurationMs(TEST_BSSID_1, TEST_SSID_1, -1,
+ TEST_FRAMEWORK_BLOCK_REASON);
assertEquals(0, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size());
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
index d23925424..b945a8b81 100644
--- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
@@ -4348,8 +4348,8 @@ public class ClientModeImplTest extends WifiBaseTest {
mLooper.dispatchAll();
verify(mWifiMetrics, times(1)).incrementSteeringRequestCountIncludingMboAssocRetryDelay();
- verify(mBssidBlocklistMonitor).blockBssidForDurationMs(sBSSID, sSSID,
- btmFrmData.mBlackListDurationMs);
+ verify(mBssidBlocklistMonitor).blockBssidForDurationMs(eq(sBSSID), eq(sSSID),
+ eq(btmFrmData.mBlackListDurationMs), anyInt());
}
/**
@@ -4372,8 +4372,8 @@ public class ClientModeImplTest extends WifiBaseTest {
mCmi.sendMessage(WifiMonitor.MBO_OCE_BSS_TM_HANDLING_DONE, btmFrmData);
mLooper.dispatchAll();
- verify(mBssidBlocklistMonitor, never()).blockBssidForDurationMs(sBSSID, sSSID,
- btmFrmData.mBlackListDurationMs);
+ verify(mBssidBlocklistMonitor, never()).blockBssidForDurationMs(eq(sBSSID), eq(sSSID),
+ eq(btmFrmData.mBlackListDurationMs), anyInt());
verify(mWifiConnectivityManager).forceConnectivityScan(ClientModeImpl.WIFI_WORK_SOURCE);
verify(mWifiMetrics, times(1)).incrementMboCellularSwitchRequestCount();
verify(mWifiMetrics, times(1))
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
index 9203a8d9b..6b953175a 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java
@@ -893,7 +893,7 @@ public class WifiConnectivityManagerTest extends WifiBaseTest {
CANDIDATE_SSID);
// Verify the failed BSSID is added to blocklist
verify(mBssidBlocklistMonitor).blockBssidForDurationMs(eq(CANDIDATE_BSSID),
- eq(CANDIDATE_SSID), anyLong());
+ eq(CANDIDATE_SSID), anyLong(), anyInt());
// Verify another connection starting
verify(mWifiNS).selectNetwork((List<WifiCandidates.Candidate>)
argThat(new WifiCandidatesListSizeMatcher(1)));
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
index 3c752f97a..182abbb4e 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiScoreReportTest.java
@@ -781,7 +781,8 @@ public class WifiScoreReportTest extends WifiBaseTest {
mLooper.dispatchAll();
mWifiScoreReport.stopConnectedNetworkScorer();
mLooper.dispatchAll();
- verify(mBssidBlocklistMonitor, never()).blockBssidForDurationMs(any(), any(), anyLong());
+ verify(mBssidBlocklistMonitor, never()).blockBssidForDurationMs(any(), any(), anyLong(),
+ anyInt());
}
/**
@@ -805,7 +806,7 @@ public class WifiScoreReportTest extends WifiBaseTest {
mLooper.dispatchAll();
mWifiScoreReport.stopConnectedNetworkScorer();
mLooper.dispatchAll();
- verify(mBssidBlocklistMonitor).blockBssidForDurationMs(any(), any(), anyLong());
+ verify(mBssidBlocklistMonitor).blockBssidForDurationMs(any(), any(), anyLong(), anyInt());
}
/**
@@ -831,7 +832,8 @@ public class WifiScoreReportTest extends WifiBaseTest {
mLooper.dispatchAll();
mWifiScoreReport.stopConnectedNetworkScorer();
mLooper.dispatchAll();
- verify(mBssidBlocklistMonitor, never()).blockBssidForDurationMs(any(), any(), anyLong());
+ verify(mBssidBlocklistMonitor, never()).blockBssidForDurationMs(any(), any(), anyLong(),
+ anyInt());
}
/**