From dd6ac245bb30bf99b3ef961f7b9fa3fe82261166 Mon Sep 17 00:00:00 2001 From: xshu Date: Tue, 21 Jul 2020 22:58:35 -0700 Subject: Update firmware roaming config for connected network Cherry-picked from: bced67a256fc7cd7fd001ec8445a651adf3a95fd Update the firmware configuration when the BSSID blocklist for the currently connected network changes. Bug: 161331429 Test: atest com.android.server.wifi Change-Id: I16c643beac6eaf21f9515032d470d0711c98fe5b Merged-In: I16c643beac6eaf21f9515032d470d0711c98fe5b --- .../android/server/wifi/BssidBlocklistMonitor.java | 28 +++++++++++++++++++++- .../com/android/server/wifi/WifiConfigManager.java | 2 +- .../server/wifi/WifiConnectivityManager.java | 3 ++- .../java/com/android/server/wifi/WifiMetrics.java | 2 +- 4 files changed, 31 insertions(+), 4 deletions(-) (limited to 'service') 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 updateAndGetBssidBlocklistForSsid(@Nullable String ssid) { + int numBefore = getNumBlockedBssidsForSsid(ssid); + Set 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 bssidBlocklist = mBssidBlocklistMonitor.updateAndGetBssidBlocklist(); + Set 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; -- cgit v1.2.3