diff options
author | Randy Pan <zpan@google.com> | 2017-02-27 12:19:40 -0800 |
---|---|---|
committer | Randy Pan <zpan@google.com> | 2017-03-28 11:59:10 -0700 |
commit | ab8c62a5c348702090aceee23de12945cc3fdb0d (patch) | |
tree | dabdd782db2ad428f1d5c21faea7f989f1947070 /service | |
parent | b6686e9d42895f9c2b9f4278cd892149bee04e3a (diff) |
Firmware roaming configuration management
Clear the BSSID blacklist when starting/stopping
WifiConnectivityManager or when we are about to connect
to a user or app specified network. Write the new roaming
configuration to firmware when the BSSID blacklist is
updated and both WifiConnectivityManager and Wifi client
mode are enabled.
Bug: 35642221
Test: runtest.sh and manual tests
Change-Id: I841c30f9218b4615252f9a75490a480e2f2d0265
Diffstat (limited to 'service')
-rw-r--r-- | service/java/com/android/server/wifi/WifiConnectivityManager.java | 142 | ||||
-rw-r--r-- | service/java/com/android/server/wifi/WifiStateMachine.java | 1 |
2 files changed, 117 insertions, 26 deletions
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index 626a0cafa..6e32f9b31 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -30,6 +30,7 @@ import android.net.wifi.WifiScanner.ScanSettings; import android.os.Handler; import android.os.Looper; import android.util.LocalLog; +import android.util.Log; import com.android.internal.R; import com.android.internal.annotations.VisibleForTesting; @@ -125,6 +126,9 @@ public class WifiConnectivityManager { private static final int PASSPOINT_NETWORK_EVALUATOR_PRIORITY = 2; private static final int RECOMMENDED_NETWORK_EVALUATOR_PRIORITY = 3; + // Log tag for this class + private static final String TAG = "WifiConnectivityManager"; + private final WifiStateMachine mStateMachine; private final WifiScanner mScanner; private final WifiConfigManager mConfigManager; @@ -1030,7 +1034,16 @@ public class WifiConnectivityManager { localLog("setUserConnectChoice: netId=" + netId); mNetworkSelector.setUserConnectChoice(netId); + } + + /** + * Handler to prepare for connection to a user or app specified network + */ + public void prepareForForcedConnection(int netId) { + localLog("prepareForForcedConnection: netId=" + netId); + clearConnectionAttemptTimeStamps(); + clearBssidBlacklist(); } /** @@ -1059,7 +1072,7 @@ public class WifiConnectivityManager { } // Update the bssid's blacklist status when it is disabled because of - // assocation rejection. + // association rejection. BssidBlacklistStatus status = mBssidBlacklist.get(bssid); if (status == null) { // First time for this BSSID @@ -1096,16 +1109,21 @@ public class WifiConnectivityManager { return false; } - boolean updated = updateBssidBlacklist(bssid, enable, reasonCode); + if (!updateBssidBlacklist(bssid, enable, reasonCode)) { + return false; + } - if (updated && !enable) { - // Disabling a BSSID can happen when the AP candidate to connect to has - // no capacity for new stations. We start another scan immediately so that - // WifiNetworkSelector can give us another candidate to connect to. + // Blacklist was updated, so update firmware roaming configuration. + updateFirmwareRoamingConfiguration(); + + if (!enable) { + // Disabling a BSSID can happen when connection to the AP was rejected. + // We start another scan immediately so that WifiNetworkSelector can + // give us another candidate to connect to. startConnectivityScan(SCAN_IMMEDIATELY); } - return updated; + return true; } /** @@ -1132,12 +1150,52 @@ public class WifiConnectivityManager { } /** + * Update firmware roaming configuration if the firmware roaming feature is supported. + * Compile and write the BSSID blacklist only. TODO(b/36488259): SSID whitelist is always + * empty for now. + */ + private void updateFirmwareRoamingConfiguration() { + if (!mConnectivityHelper.isFirmwareRoamingSupported()) { + return; + } + + int maxBlacklistSize = mConnectivityHelper.getMaxNumBlacklistBssid(); + if (maxBlacklistSize <= 0) { + Log.wtf(TAG, "Invalid max BSSID blacklist size: " + maxBlacklistSize); + return; + } + + ArrayList<String> blacklistedBssids = new ArrayList<String>(buildBssidBlacklist()); + int blacklistSize = blacklistedBssids.size(); + + if (blacklistSize > maxBlacklistSize) { + Log.wtf(TAG, "Attempt to write " + blacklistSize + " blacklisted BSSIDs, max size is " + + maxBlacklistSize); + + blacklistedBssids = new ArrayList<String>(blacklistedBssids.subList(0, + maxBlacklistSize)); + localLog("Trim down BSSID blacklist size from " + blacklistSize + " to " + + blacklistedBssids.size()); + } + + if (!mConnectivityHelper.setFirmwareRoamingConfiguration(blacklistedBssids, + new ArrayList<String>())) { // TODO(b/36488259): SSID whitelist management. + localLog("Failed to set firmware roaming configuration."); + } + } + + /** * Refresh the BSSID blacklist * * Go through the BSSID blacklist and check if a BSSID has been blacklisted for * BSSID_BLACKLIST_EXPIRE_TIME_MS. If yes, re-enable it. */ private void refreshBssidBlacklist() { + if (mBssidBlacklist.isEmpty()) { + return; + } + + boolean updated = false; Iterator<BssidBlacklistStatus> iter = mBssidBlacklist.values().iterator(); Long currentTimeStamp = mClock.getElapsedSinceBootMillis(); @@ -1146,8 +1204,57 @@ public class WifiConnectivityManager { if (status.isBlacklisted && ((currentTimeStamp - status.blacklistedTimeStamp) >= BSSID_BLACKLIST_EXPIRE_TIME_MS)) { iter.remove(); + updated = true; } } + + if (updated) { + updateFirmwareRoamingConfiguration(); + } + } + + /** + * Clear the BSSID blacklist + */ + private void clearBssidBlacklist() { + mBssidBlacklist.clear(); + updateFirmwareRoamingConfiguration(); + } + + /** + * Start WifiConnectivityManager + */ + private void start() { + mConnectivityHelper.getFirmwareRoamingInfo(); + clearBssidBlacklist(); + startConnectivityScan(SCAN_IMMEDIATELY); + } + + /** + * Stop and reset WifiConnectivityManager + */ + private void stop() { + stopConnectivityScan(); + clearBssidBlacklist(); + resetLastPeriodicSingleScanTimeStamp(); + mLastConnectionAttemptBssid = null; + mWaitForFullBandScanResults = false; + } + + /** + * Update WifiConnectivityManager running state + * + * Start WifiConnectivityManager only if both Wifi and WifiConnectivityManager + * are enabled, otherwise stop it. + */ + private void updateRunningState() { + if (mWifiEnabled && mWifiConnectivityManagerEnabled) { + localLog("Starting up WifiConnectivityManager"); + start(); + } else { + localLog("Stopping WifiConnectivityManager"); + stop(); + } } /** @@ -1157,16 +1264,8 @@ public class WifiConnectivityManager { localLog("Set WiFi " + (enable ? "enabled" : "disabled")); mWifiEnabled = enable; + updateRunningState(); - if (!mWifiEnabled) { - stopConnectivityScan(); - resetLastPeriodicSingleScanTimeStamp(); - mLastConnectionAttemptBssid = null; - mWaitForFullBandScanResults = false; - } else if (mWifiConnectivityManagerEnabled) { - mConnectivityHelper.getFirmwareRoamingInfo(); - startConnectivityScan(SCAN_IMMEDIATELY); - } } /** @@ -1176,16 +1275,7 @@ public class WifiConnectivityManager { localLog("Set WiFiConnectivityManager " + (enable ? "enabled" : "disabled")); mWifiConnectivityManagerEnabled = enable; - - if (!mWifiConnectivityManagerEnabled) { - stopConnectivityScan(); - resetLastPeriodicSingleScanTimeStamp(); - mLastConnectionAttemptBssid = null; - mWaitForFullBandScanResults = false; - } else if (mWifiEnabled) { - mConnectivityHelper.getFirmwareRoamingInfo(); - startConnectivityScan(SCAN_IMMEDIATELY); - } + updateRunningState(); } @VisibleForTesting diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index af119209b..1e94f8e47 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -1287,6 +1287,7 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss // reconnection unless it was forced. logi("connectToUserSelectNetwork already connecting/connected=" + netId); } else { + mWifiConnectivityManager.prepareForForcedConnection(netId); startConnectToNetwork(netId, SUPPLICANT_BSSID_ANY); } return true; |