Commit cce5b9e0 authored by Vinit Deshpande's avatar Vinit Deshpande
Browse files

Fix connections to unintended networks

This change fixes a bug in Wifi state machine - it unintentionally
enables all the networks and results in connecting to a network that
may not have been chosen by AutoJoinController.

Bug: 18266514

Change-Id: I0d5d274819194c0eea4f3812d506a92899f3eb54
parent cce360ad
......@@ -2147,6 +2147,13 @@ public class WifiStateMachine extends StateMachine {
return mWifiNative.getNfcWpsConfigurationToken(netId);
}
void enableBackgroundScan(boolean enable) {
if (enable) {
mWifiConfigStore.enableAllNetworks();
}
mWifiNative.enableBackgroundScan(enable);
}
/**
* Blacklist a BSSID. This will avoid the AP if there are
* alternate APs to connect
......@@ -2951,7 +2958,8 @@ public class WifiStateMachine extends StateMachine {
+ " startBackgroundScanIfNeeded:" + startBackgroundScanIfNeeded);
if (startBackgroundScanIfNeeded) {
mWifiNative.enableBackgroundScan(mEnableBackgroundScan);
// to scan for them in background, we need all networks enabled
enableBackgroundScan(mEnableBackgroundScan);
}
if (DBG) log("handleScreenStateChanged Exit: " + screenOn);
......@@ -6331,7 +6339,7 @@ public class WifiStateMachine extends StateMachine {
} else if (didDisconnect) {
transitionTo(mDisconnectingState);
} else {
transitionTo(mDisconnectedState);
/* Already in disconnected state, nothing to change */
}
} else {
loge("Failed to connect config: " + config + " netId: " + netId);
......@@ -7653,14 +7661,12 @@ public class WifiStateMachine extends StateMachine {
/** clear the roaming state, if we were roaming, we failed */
mAutoRoaming = WifiAutoJoinController.AUTO_JOIN_IDLE;
// Reenable all networks, allow for hidden networks to be scanned
mWifiConfigStore.enableAllNetworks();
/**
* - screen dark and PNO supported => scan alarm disabled
* - everything else => scan alarm enabled with mDefaultFrameworkScanIntervalMs period
*/
if ((mScreenOn == false) && mEnableBackgroundScan) { //mEnableBackgroundScan) {
if ((mScreenOn == false) && mEnableBackgroundScan) {
/* If a regular scan result is pending, do not initiate background
* scan until the scan results are returned. This is needed because
* initiating a background scan will cancel the regular scan and
......@@ -7668,7 +7674,7 @@ public class WifiStateMachine extends StateMachine {
* cleared
*/
if (!mIsScanOngoing) {
mWifiNative.enableBackgroundScan(true);
enableBackgroundScan(true);
}
} else {
setScanAlarm(true, 200);
......@@ -7746,7 +7752,7 @@ public class WifiStateMachine extends StateMachine {
}
/* Disable background scan temporarily during a regular scan */
if (mEnableBackgroundScan) {
mWifiNative.enableBackgroundScan(false);
enableBackgroundScan(false);
}
/* Handled in parent state */
ret = NOT_HANDLED;
......@@ -7754,7 +7760,7 @@ public class WifiStateMachine extends StateMachine {
case WifiMonitor.SCAN_RESULTS_EVENT:
/* Re-enable background scan when a pending scan result is received */
if (mEnableBackgroundScan && mIsScanOngoing) {
mWifiNative.enableBackgroundScan(true);
enableBackgroundScan(true);
}
/* Handled in parent state */
ret = NOT_HANDLED;
......@@ -7799,7 +7805,7 @@ public class WifiStateMachine extends StateMachine {
public void exit() {
/* No need for a background scan upon exit from a disconnected state */
if (mEnableBackgroundScan) {
mWifiNative.enableBackgroundScan(false);
enableBackgroundScan(false);
}
mCurrentScanAlarmMs = 0;
setScanAlarm(false, 0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment