summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Irfan Sheriff <isheriff@google.com> 2010-12-24 12:34:52 -0800
committer Android (Google) Code Review <android-gerrit@google.com> 2010-12-24 12:34:52 -0800
commitbccc78ffa57cb259010c25630055eef95c0e0c2c (patch)
treec9eafbb4a293fc0ba290e8e12b7ba5e3154d8aa4
parent13e8ba7095f2389428289e000b6d1d4ab559b7b8 (diff)
parent8e86b89860114386e6c43f55fc034a26798b73e2 (diff)
Merge "Enable networks on screen on"
-rw-r--r--services/java/com/android/server/WifiService.java1
-rw-r--r--wifi/java/android/net/wifi/SupplicantStateTracker.java26
-rw-r--r--wifi/java/android/net/wifi/WifiConfigStore.java8
-rw-r--r--wifi/java/android/net/wifi/WifiStateMachine.java63
4 files changed, 62 insertions, 36 deletions
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index ff703fda7064..a9d42e3fad5e 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -877,6 +877,7 @@ public class WifiService extends IWifiManager.Stub {
// because of any locks so clear that tracking immediately.
reportStartWorkSource();
mWifiStateMachine.enableRssiPolling(true);
+ mWifiStateMachine.enableAllNetworks();
updateWifiState();
} else if (action.equals(Intent.ACTION_SCREEN_OFF)) {
if (DBG) {
diff --git a/wifi/java/android/net/wifi/SupplicantStateTracker.java b/wifi/java/android/net/wifi/SupplicantStateTracker.java
index 08e46062c523..1a0050742a13 100644
--- a/wifi/java/android/net/wifi/SupplicantStateTracker.java
+++ b/wifi/java/android/net/wifi/SupplicantStateTracker.java
@@ -48,6 +48,9 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
/* Maximum retries on a password failure notification */
private static final int MAX_RETRIES_ON_PASSWORD_FAILURE = 2;
+ /* Tracks if networks have been disabled during a connection */
+ private boolean mNetworksDisabledDuringConnect = false;
+
private Context mContext;
private HierarchicalState mUninitializedState = new UninitializedState();
@@ -79,6 +82,16 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
start();
}
+ private void handleNetworkConnectionFailure(int netId) {
+ /* If other networks disabled during connection, enable them */
+ if (mNetworksDisabledDuringConnect) {
+ WifiConfigStore.enableAllNetworks();
+ mNetworksDisabledDuringConnect = false;
+ }
+ /* Disable failed network */
+ WifiConfigStore.disableNetwork(netId);
+ }
+
private void transitionOnSupplicantStateChange(StateChangeResult stateChangeResult) {
SupplicantState supState = (SupplicantState) stateChangeResult.state;
@@ -156,6 +169,9 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
case WifiStateMachine.CMD_RESET_SUPPLICANT_STATE:
transitionTo(mUninitializedState);
break;
+ case WifiStateMachine.CMD_CONNECT_NETWORK:
+ mNetworksDisabledDuringConnect = true;
+ break;
default:
Log.e(TAG, "Ignoring " + message);
break;
@@ -211,7 +227,7 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
if (mPasswordFailuresCount >= MAX_RETRIES_ON_PASSWORD_FAILURE) {
Log.d(TAG, "Failed to authenticate, disabling network " +
stateChangeResult.networkId);
- WifiConfigStore.disableNetwork(stateChangeResult.networkId);
+ handleNetworkConnectionFailure(stateChangeResult.networkId);
mPasswordFailuresCount = 0;
}
}
@@ -256,7 +272,7 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
if (mLoopDetectCount > MAX_SUPPLICANT_LOOP_ITERATIONS) {
Log.d(TAG, "Supplicant loop detected, disabling network " +
stateChangeResult.networkId);
- WifiConfigStore.disableNetwork(stateChangeResult.networkId);
+ handleNetworkConnectionFailure(stateChangeResult.networkId);
}
mLoopDetectIndex = state.ordinal();
sendSupplicantStateChangedBroadcast(state,
@@ -279,7 +295,11 @@ class SupplicantStateTracker extends HierarchicalStateMachine {
if (DBG) Log.d(TAG, getName() + "\n");
/* Reset password failure count */
mPasswordFailuresCount = 0;
- }
+ if (mNetworksDisabledDuringConnect) {
+ WifiConfigStore.enableAllNetworks();
+ mNetworksDisabledDuringConnect = false;
+ }
+ }
@Override
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
diff --git a/wifi/java/android/net/wifi/WifiConfigStore.java b/wifi/java/android/net/wifi/WifiConfigStore.java
index e650b8773b96..56bc5d773851 100644
--- a/wifi/java/android/net/wifi/WifiConfigStore.java
+++ b/wifi/java/android/net/wifi/WifiConfigStore.java
@@ -164,10 +164,12 @@ class WifiConfigStore {
* of configured networks indicates all networks as being enabled
*/
static void enableAllNetworks() {
+ boolean networkEnabledStateChanged = false;
synchronized (sConfiguredNetworks) {
for(WifiConfiguration config : sConfiguredNetworks.values()) {
if(config != null && config.status == Status.DISABLED) {
if(WifiNative.enableNetworkCommand(config.networkId, false)) {
+ networkEnabledStateChanged = true;
config.status = Status.ENABLED;
} else {
Log.e(TAG, "Enable network failed on " + config.networkId);
@@ -176,8 +178,10 @@ class WifiConfigStore {
}
}
- WifiNative.saveConfigCommand();
- sendConfiguredNetworksChangedBroadcast();
+ if (networkEnabledStateChanged) {
+ WifiNative.saveConfigCommand();
+ sendConfiguredNetworksChangedBroadcast();
+ }
}
/**
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 909ad434a6b0..f03a9e5680f8 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -161,10 +161,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
private SupplicantStateTracker mSupplicantStateTracker;
private WpsStateMachine mWpsStateMachine;
- /* Connection to a specific network involves disabling all networks,
- * this flag tracks if networks need to be re-enabled */
- private boolean mEnableAllNetworks = false;
-
private AlarmManager mAlarmManager;
private PendingIntent mScanIntent;
/* Tracks current frequency mode */
@@ -243,14 +239,16 @@ public class WifiStateMachine extends HierarchicalStateMachine {
static final int CMD_REMOVE_NETWORK = 53;
/* Enable a network. The device will attempt a connection to the given network. */
static final int CMD_ENABLE_NETWORK = 54;
+ /* Enable all networks */
+ static final int CMD_ENABLE_ALL_NETWORKS = 55;
/* Disable a network. The device does not attempt a connection to the given network. */
- static final int CMD_DISABLE_NETWORK = 55;
+ static final int CMD_DISABLE_NETWORK = 56;
/* Blacklist network. De-prioritizes the given BSSID for connection. */
- static final int CMD_BLACKLIST_NETWORK = 56;
+ static final int CMD_BLACKLIST_NETWORK = 57;
/* Clear the blacklist network list */
- static final int CMD_CLEAR_BLACKLIST = 57;
+ static final int CMD_CLEAR_BLACKLIST = 58;
/* Save configuration */
- static final int CMD_SAVE_CONFIG = 58;
+ static final int CMD_SAVE_CONFIG = 59;
/* Supplicant commands after driver start*/
/* Initiate a scan */
@@ -852,6 +850,10 @@ public class WifiStateMachine extends HierarchicalStateMachine {
sendMessage(obtainMessage(CMD_ENABLE_RSSI_POLL, enabled ? 1 : 0, 0));
}
+ public void enableAllNetworks() {
+ sendMessage(CMD_ENABLE_ALL_NETWORKS);
+ }
+
/**
* Start packet filtering
*/
@@ -1004,7 +1006,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
sb.append("mLastSignalLevel ").append(mLastSignalLevel).append(LS);
sb.append("mLastBssid ").append(mLastBssid).append(LS);
sb.append("mLastNetworkId ").append(mLastNetworkId).append(LS);
- sb.append("mEnableAllNetworks ").append(mEnableAllNetworks).append(LS);
sb.append("mReconnectCount ").append(mReconnectCount).append(LS);
sb.append("mIsScanMode ").append(mIsScanMode).append(LS);
sb.append("Supplicant status").append(LS)
@@ -1618,6 +1619,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SAVE_NETWORK:
case CMD_FORGET_NETWORK:
case CMD_RSSI_POLL:
+ case CMD_ENABLE_ALL_NETWORKS:
break;
case CMD_START_WPS:
WpsConfiguration config = (WpsConfiguration) message.obj;
@@ -1986,9 +1988,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
WifiConfiguration config;
+ boolean eventLoggingEnabled = true;
switch(message.what) {
case CMD_STOP_SUPPLICANT: /* Supplicant stopped by user */
- EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
Log.d(TAG, "stopping supplicant");
if (!WifiNative.stopSupplicant()) {
Log.e(TAG, "Failed to stop supplicant, issue kill");
@@ -2001,7 +2003,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
transitionTo(mSupplicantStoppingState);
break;
case SUP_DISCONNECTION_EVENT: /* Supplicant connection lost */
- EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
Log.e(TAG, "Connection lost, restart supplicant");
WifiNative.killSupplicant();
WifiNative.closeSupplicantConnection();
@@ -2012,6 +2013,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
sendMessageDelayed(CMD_START_SUPPLICANT, SUPPLICANT_RESTART_INTERVAL_MSECS);
break;
case SCAN_RESULTS_EVENT:
+ eventLoggingEnabled = false;
setScanResults(WifiNative.scanResultsCommand());
sendScanResultsAvailableBroadcast();
break;
@@ -2020,28 +2022,26 @@ public class WifiStateMachine extends HierarchicalStateMachine {
mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
break;
case CMD_ADD_OR_UPDATE_NETWORK:
- EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
config = (WifiConfiguration) message.obj;
mReplyChannel.replyToMessage(message, CMD_ADD_OR_UPDATE_NETWORK,
WifiConfigStore.addOrUpdateNetwork(config));
break;
case CMD_REMOVE_NETWORK:
- EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
ok = WifiConfigStore.removeNetwork(message.arg1);
mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
break;
case CMD_ENABLE_NETWORK:
- EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
ok = WifiConfigStore.enableNetwork(message.arg1, message.arg2 == 1);
mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
break;
+ case CMD_ENABLE_ALL_NETWORKS:
+ WifiConfigStore.enableAllNetworks();
+ break;
case CMD_DISABLE_NETWORK:
- EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
ok = WifiConfigStore.disableNetwork(message.arg1);
mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
break;
case CMD_BLACKLIST_NETWORK:
- EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
WifiNative.addToBlacklistCommand((String)message.obj);
break;
case CMD_CLEAR_BLACKLIST:
@@ -2065,7 +2065,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
/* Cannot start soft AP while in client mode */
case CMD_START_AP:
Log.d(TAG, "Failed to start soft AP with a running supplicant");
- EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
setWifiApState(WIFI_AP_STATE_FAILED);
break;
case CMD_SET_SCAN_MODE:
@@ -2081,6 +2080,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
default:
return NOT_HANDLED;
}
+ if (eventLoggingEnabled) {
+ EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
+ }
return HANDLED;
}
}
@@ -2201,6 +2203,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
@Override
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
+ boolean eventLoggingEnabled = true;
switch(message.what) {
case CMD_SET_SCAN_TYPE:
if (message.arg1 == SCAN_ACTIVE) {
@@ -2210,6 +2213,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
}
break;
case CMD_START_SCAN:
+ eventLoggingEnabled = false;
WifiNative.scanCommand(message.arg1 == SCAN_ACTIVE);
break;
case CMD_SET_HIGH_PERF_MODE:
@@ -2254,7 +2258,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
default:
return NOT_HANDLED;
}
- EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
+ if (eventLoggingEnabled) {
+ EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
+ }
return HANDLED;
}
@Override
@@ -2424,11 +2430,8 @@ public class WifiStateMachine extends HierarchicalStateMachine {
WifiConfigStore.selectNetwork(netId);
}
- /* Save a flag to indicate that we need to enable all
- * networks after supplicant indicates a network
- * state change event
- */
- mEnableAllNetworks = true;
+ /* The state tracker handles enabling networks upon completion/failure */
+ mSupplicantStateTracker.sendMessage(CMD_CONNECT_NETWORK);
WifiNative.reconnectCommand();
@@ -2669,6 +2672,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
@Override
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
+ boolean eventLoggingEnabled = true;
switch (message.what) {
case CMD_DISCONNECT:
WifiNative.disconnectCommand();
@@ -2692,6 +2696,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
}
break;
case CMD_START_SCAN:
+ eventLoggingEnabled = false;
/* When the network is connected, re-scanning can trigger
* a reconnection. Put it in scan-only mode during scan.
* When scan results are received, the mode is switched
@@ -2727,6 +2732,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case NETWORK_CONNECTION_EVENT:
break;
case CMD_RSSI_POLL:
+ eventLoggingEnabled = false;
if (message.arg1 == mRssiPollToken) {
// Get Info and continue polling
fetchRssiAndLinkSpeedNative();
@@ -2749,7 +2755,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
default:
return NOT_HANDLED;
}
- EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
+ if (eventLoggingEnabled) {
+ EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
+ }
return HANDLED;
}
}
@@ -2782,13 +2790,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
return HANDLED;
}
- @Override
- public void exit() {
- if (mEnableAllNetworks) {
- mEnableAllNetworks = false;
- WifiConfigStore.enableAllNetworks();
- }
- }
}
class DisconnectedState extends HierarchicalState {