summaryrefslogtreecommitdiffstats
path: root/wifi/java/android
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2010-12-21 09:44:15 -0800
committerIrfan Sheriff <isheriff@google.com>2010-12-22 14:43:13 -0800
commitb45e726bf5df9650e8a67a7c05bf2f41f414c07d (patch)
tree4adb26cf1c76f1295b42a194b59eebc5fa9aae03 /wifi/java/android
parent3d808115791f85a3f0fc9c070ec48b2df41d70a9 (diff)
downloadframeworks_base-b45e726bf5df9650e8a67a7c05bf2f41f414c07d.zip
frameworks_base-b45e726bf5df9650e8a67a7c05bf2f41f414c07d.tar.gz
frameworks_base-b45e726bf5df9650e8a67a7c05bf2f41f414c07d.tar.bz2
Fix wifi broadcasts
Add the missing wifi disable broadcast and also send out supplicant disconnect on shutdown. Added unit test cases. Bug: 3294055 Change-Id: Ia56a8ec9d17784c5aac5b8b369c04837f9057c54
Diffstat (limited to 'wifi/java/android')
-rw-r--r--wifi/java/android/net/wifi/SupplicantStateTracker.java37
-rw-r--r--wifi/java/android/net/wifi/WifiStateMachine.java50
2 files changed, 48 insertions, 39 deletions
diff --git a/wifi/java/android/net/wifi/SupplicantStateTracker.java b/wifi/java/android/net/wifi/SupplicantStateTracker.java
index f823314..08e4606 100644
--- a/wifi/java/android/net/wifi/SupplicantStateTracker.java
+++ b/wifi/java/android/net/wifi/SupplicantStateTracker.java
@@ -79,11 +79,6 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
start();
}
- public void resetSupplicantState() {
- transitionTo(mUninitializedState);
- }
-
-
private void transitionOnSupplicantStateChange(StateChangeResult stateChangeResult) {
SupplicantState supState = (SupplicantState) stateChangeResult.state;
@@ -121,11 +116,11 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
}
}
- private void sendSupplicantStateChangedBroadcast(StateChangeResult sc, boolean failedAuth) {
+ private void sendSupplicantStateChangedBroadcast(SupplicantState state, boolean failedAuth) {
Intent intent = new Intent(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT
| Intent.FLAG_RECEIVER_REPLACE_PENDING);
- intent.putExtra(WifiManager.EXTRA_NEW_STATE, (Parcelable)sc.state);
+ intent.putExtra(WifiManager.EXTRA_NEW_STATE, (Parcelable) state);
if (failedAuth) {
intent.putExtra(
WifiManager.EXTRA_SUPPLICANT_ERROR,
@@ -153,11 +148,14 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
break;
case WifiStateMachine.SUPPLICANT_STATE_CHANGE_EVENT:
StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
- sendSupplicantStateChangedBroadcast(stateChangeResult,
- mAuthFailureInSupplicantBroadcast);
+ SupplicantState state = stateChangeResult.state;
+ sendSupplicantStateChangedBroadcast(state, mAuthFailureInSupplicantBroadcast);
mAuthFailureInSupplicantBroadcast = false;
transitionOnSupplicantStateChange(stateChangeResult);
break;
+ case WifiStateMachine.CMD_RESET_SUPPLICANT_STATE:
+ transitionTo(mUninitializedState);
+ break;
default:
Log.e(TAG, "Ignoring " + message);
break;
@@ -166,6 +164,14 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
}
}
+ /*
+ * This indicates that the supplicant state as seen
+ * by the framework is not initialized yet. We are
+ * in this state right after establishing a control
+ * channel connection before any supplicant events
+ * or after we have lost the control channel
+ * connection to the supplicant
+ */
class UninitializedState extends HierarchicalState {
@Override
public void enter() {
@@ -239,7 +245,7 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
switch (message.what) {
case WifiStateMachine.SUPPLICANT_STATE_CHANGE_EVENT:
StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
- SupplicantState state = (SupplicantState) stateChangeResult.state;
+ SupplicantState state = stateChangeResult.state;
if (state == SupplicantState.ASSOCIATING ||
state == SupplicantState.ASSOCIATED ||
state == SupplicantState.FOUR_WAY_HANDSHAKE ||
@@ -253,7 +259,7 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
WifiConfigStore.disableNetwork(stateChangeResult.networkId);
}
mLoopDetectIndex = state.ordinal();
- sendSupplicantStateChangedBroadcast(stateChangeResult,
+ sendSupplicantStateChangedBroadcast(state,
mAuthFailureInSupplicantBroadcast);
} else {
//Have the DefaultState handle the transition
@@ -280,9 +286,8 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
switch(message.what) {
case WifiStateMachine.SUPPLICANT_STATE_CHANGE_EVENT:
StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
- SupplicantState state = (SupplicantState) stateChangeResult.state;
- sendSupplicantStateChangedBroadcast(stateChangeResult,
- mAuthFailureInSupplicantBroadcast);
+ SupplicantState state = stateChangeResult.state;
+ sendSupplicantStateChangedBroadcast(state, mAuthFailureInSupplicantBroadcast);
/* Ignore a re-auth in completed state */
if (state == SupplicantState.ASSOCIATING ||
state == SupplicantState.ASSOCIATED ||
@@ -293,6 +298,10 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
}
transitionOnSupplicantStateChange(stateChangeResult);
break;
+ case WifiStateMachine.CMD_RESET_SUPPLICANT_STATE:
+ sendSupplicantStateChangedBroadcast(SupplicantState.DISCONNECTED, false);
+ transitionTo(mUninitializedState);
+ break;
default:
return NOT_HANDLED;
}
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 17a35c4..909ad43 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -326,13 +326,16 @@ public class WifiStateMachine extends HierarchicalStateMachine {
/* Set the frequency band */
static final int CMD_SET_FREQUENCY_BAND = 90;
- /* Commands from the SupplicantStateTracker */
+ /* Commands from/to the SupplicantStateTracker */
/* Indicates whether a wifi network is available for connection */
- static final int CMD_SET_NETWORK_AVAILABLE = 111;
+ static final int CMD_SET_NETWORK_AVAILABLE = 111;
+ /* Reset the supplicant state tracker */
+ static final int CMD_RESET_SUPPLICANT_STATE = 112;
+
/* Commands/events reported by WpsStateMachine */
/* Indicates the completion of WPS activity */
- static final int WPS_COMPLETED_EVENT = 121;
+ static final int WPS_COMPLETED_EVENT = 121;
private static final int CONNECT_MODE = 1;
private static final int SCAN_ONLY_MODE = 2;
@@ -1453,20 +1456,17 @@ public class WifiStateMachine extends HierarchicalStateMachine {
********************************************************/
/**
- * A structure for supplying information about a supplicant state
- * change in the STATE_CHANGE event message that comes from the
- * WifiMonitor
- * thread.
+ * Stores supplicant state change information passed from WifiMonitor
*/
static class StateChangeResult {
- StateChangeResult(int networkId, String BSSID, Object state) {
+ StateChangeResult(int networkId, String BSSID, SupplicantState state) {
this.state = state;
this.BSSID = BSSID;
this.networkId = networkId;
}
int networkId;
String BSSID;
- Object state;
+ SupplicantState state;
}
/**
@@ -1505,11 +1505,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
*/
void notifyNetworkStateChange(DetailedState newState, String BSSID, int networkId) {
if (newState == NetworkInfo.DetailedState.CONNECTED) {
- sendMessage(obtainMessage(NETWORK_CONNECTION_EVENT,
- new StateChangeResult(networkId, BSSID, newState)));
+ sendMessage(obtainMessage(NETWORK_CONNECTION_EVENT, networkId, 0, BSSID));
} else {
- sendMessage(obtainMessage(NETWORK_DISCONNECTION_EVENT,
- new StateChangeResult(networkId, BSSID, newState)));
+ sendMessage(obtainMessage(NETWORK_DISCONNECTION_EVENT, networkId, 0, BSSID));
}
}
@@ -1755,7 +1753,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
if(WifiNative.startSupplicant()) {
Log.d(TAG, "Supplicant start successful");
mWifiMonitor.startMonitoring();
- setWifiState(WIFI_STATE_ENABLED);
transitionTo(mSupplicantStartingState);
} else {
Log.e(TAG, "Failed to start supplicant!");
@@ -1914,8 +1911,11 @@ public class WifiStateMachine extends HierarchicalStateMachine {
switch(message.what) {
case SUP_CONNECTION_EVENT:
Log.d(TAG, "Supplicant connection established");
+ setWifiState(WIFI_STATE_ENABLED);
mSupplicantRestartCount = 0;
- mSupplicantStateTracker.resetSupplicantState();
+ /* Reset the supplicant state to indicate the supplicant
+ * state is not known at this time */
+ mSupplicantStateTracker.sendMessage(CMD_RESET_SUPPLICANT_STATE);
/* Initialize data structures */
mLastBssid = null;
mLastNetworkId = -1;
@@ -1944,7 +1944,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
Log.e(TAG, "Failed " + mSupplicantRestartCount +
" times to start supplicant, unload driver");
transitionTo(mDriverLoadedState);
- sendMessage(CMD_UNLOAD_DRIVER);
+ sendMessage(obtainMessage(CMD_UNLOAD_DRIVER, WIFI_STATE_UNKNOWN, 0));
}
break;
case CMD_LOAD_DRIVER:
@@ -1995,8 +1995,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
WifiNative.killSupplicant();
}
handleNetworkDisconnect();
+ setWifiState(WIFI_STATE_DISABLING);
sendSupplicantConnectionChangedBroadcast(false);
- mSupplicantStateTracker.resetSupplicantState();
+ mSupplicantStateTracker.sendMessage(CMD_RESET_SUPPLICANT_STATE);
transitionTo(mSupplicantStoppingState);
break;
case SUP_DISCONNECTION_EVENT: /* Supplicant connection lost */
@@ -2006,7 +2007,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
WifiNative.closeSupplicantConnection();
handleNetworkDisconnect();
sendSupplicantConnectionChangedBroadcast(false);
- mSupplicantStateTracker.resetSupplicantState();
+ mSupplicantStateTracker.sendMessage(CMD_RESET_SUPPLICANT_STATE);
transitionTo(mDriverLoadedState);
sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS);
break;
@@ -2380,7 +2381,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
break;
case SUPPLICANT_STATE_CHANGE_EVENT:
stateChangeResult = (StateChangeResult) message.obj;
- SupplicantState state = (SupplicantState) stateChangeResult.state;
+ SupplicantState state = stateChangeResult.state;
// Supplicant state change
// [31-13] Reserved for future use
// [8 - 0] Supplicant state (as defined in SupplicantState.java)
@@ -2445,13 +2446,13 @@ public class WifiStateMachine extends HierarchicalStateMachine {
return NOT_HANDLED;
case NETWORK_CONNECTION_EVENT:
Log.d(TAG,"Network connection established");
- stateChangeResult = (StateChangeResult) message.obj;
+ mLastNetworkId = message.arg1;
+ mLastBssid = (String) message.obj;
//TODO: make supplicant modification to push this in events
mWifiInfo.setSSID(fetchSSID());
- mWifiInfo.setBSSID(mLastBssid = stateChangeResult.BSSID);
- mWifiInfo.setNetworkId(stateChangeResult.networkId);
- mLastNetworkId = stateChangeResult.networkId;
+ mWifiInfo.setBSSID(mLastBssid);
+ mWifiInfo.setNetworkId(mLastNetworkId);
/* send event to CM & network change broadcast */
setNetworkDetailedState(DetailedState.OBTAINING_IPADDR);
sendNetworkStateChangeBroadcast(mLastBssid);
@@ -2825,8 +2826,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
break;
case SUPPLICANT_STATE_CHANGE_EVENT:
StateChangeResult stateChangeResult = (StateChangeResult) message.obj;
- SupplicantState state = (SupplicantState) stateChangeResult.state;
- setNetworkDetailedState(WifiInfo.getDetailedStateOf(state));
+ setNetworkDetailedState(WifiInfo.getDetailedStateOf(stateChangeResult.state));
/* DriverStartedState does the rest of the handling */
return NOT_HANDLED;
default: