summaryrefslogtreecommitdiffstats
path: root/wifi
diff options
context:
space:
mode:
authorIrfan Sheriff <isheriff@google.com>2012-04-30 15:51:40 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-04-30 15:51:40 -0700
commit8e8798d90a008e9262d14f26c4cf24fe552beab7 (patch)
tree77484e19b252824984bcfdf6073c175a1bdcb6d3 /wifi
parent2d589ffa1e8a2721f0d19f38a01337186561e559 (diff)
parentb3e96c527b8ac96e869bafeff5f7fab099e28396 (diff)
downloadframeworks_base-8e8798d90a008e9262d14f26c4cf24fe552beab7.zip
frameworks_base-8e8798d90a008e9262d14f26c4cf24fe552beab7.tar.gz
frameworks_base-8e8798d90a008e9262d14f26c4cf24fe552beab7.tar.bz2
Merge "Fix connect & save of invalid networks" into jb-dev
Diffstat (limited to 'wifi')
-rw-r--r--wifi/java/android/net/wifi/WifiConfigStore.java37
-rw-r--r--wifi/java/android/net/wifi/WifiStateMachine.java34
2 files changed, 27 insertions, 44 deletions
diff --git a/wifi/java/android/net/wifi/WifiConfigStore.java b/wifi/java/android/net/wifi/WifiConfigStore.java
index 3c761c8..e9f3480 100644
--- a/wifi/java/android/net/wifi/WifiConfigStore.java
+++ b/wifi/java/android/net/wifi/WifiConfigStore.java
@@ -194,31 +194,6 @@ class WifiConfigStore {
}
}
- /**
- * Selects the specified network config for connection. This involves
- * addition/update of the specified config, updating the priority of
- * all the networks and enabling the given network while disabling others.
- *
- * Selecting a network will leave the other networks disabled and
- * a call to enableAllNetworks() needs to be issued upon a connection
- * or a failure event from supplicant
- *
- * @param config The configuration details in WifiConfiguration
- * @return the networkId now associated with the specified configuration
- */
- int selectNetwork(WifiConfiguration config) {
- if (config != null) {
- NetworkUpdateResult result = addOrUpdateNetworkNative(config);
- int netId = result.getNetworkId();
- if (netId != INVALID_NETWORK_ID) {
- selectNetwork(netId);
- } else {
- loge("Failed to update network " + config);
- }
- return netId;
- }
- return INVALID_NETWORK_ID;
- }
/**
* Selects the specified network for connection. This involves
@@ -230,8 +205,11 @@ class WifiConfigStore {
* or a failure event from supplicant
*
* @param netId network to select for connection
+ * @return false if the network id is invalid
*/
- void selectNetwork(int netId) {
+ boolean selectNetwork(int netId) {
+ if (netId == INVALID_NETWORK_ID) return false;
+
// Reset the priority of each network at start or if it goes too high.
if (mLastPriority == -1 || mLastPriority > 1000000) {
for(WifiConfiguration config : mConfiguredNetworks.values()) {
@@ -256,6 +234,7 @@ class WifiConfigStore {
/* Avoid saving the config & sending a broadcast to prevent settings
* from displaying a disabled list of networks */
+ return true;
}
/**
@@ -265,6 +244,12 @@ class WifiConfigStore {
* @return network update result
*/
NetworkUpdateResult saveNetwork(WifiConfiguration config) {
+ // A new network cannot have null SSID
+ if (config == null || (config.networkId == INVALID_NETWORK_ID &&
+ config.SSID == null)) {
+ return new NetworkUpdateResult(INVALID_NETWORK_ID);
+ }
+
boolean newNetwork = (config.networkId == INVALID_NETWORK_ID);
NetworkUpdateResult result = addOrUpdateNetworkNative(config);
int netId = result.getNetworkId();
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 3503633..a85083d 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -2849,35 +2849,33 @@ public class WifiStateMachine extends StateMachine {
mWifiNative.reassociate();
break;
case WifiManager.CONNECT_NETWORK:
+ /* The connect message can contain a network id passed as arg1 on message or
+ * or a config passed as obj on message.
+ * For a new network, a config is passed to create and connect.
+ * For an existing network, a network id is passed
+ */
int netId = message.arg1;
WifiConfiguration config = (WifiConfiguration) message.obj;
- /* We connect to a specific network by issuing a select
- * to the WifiConfigStore. This enables the network,
- * while disabling all other networks in the supplicant.
- * Disabling a connected network will cause a disconnection
- * from the network. A reconnectCommand() will then initiate
- * a connection to the enabled network.
- */
+ /* Save the network config */
if (config != null) {
- netId = mWifiConfigStore.selectNetwork(config);
- } else {
- mWifiConfigStore.selectNetwork(netId);
+ NetworkUpdateResult result = mWifiConfigStore.saveNetwork(config);
+ netId = result.getNetworkId();
}
- /* The state tracker handles enabling networks upon completion/failure */
- mSupplicantStateTracker.sendMessage(WifiManager.CONNECT_NETWORK);
-
- if (mWifiNative.reconnect()) {
+ if (mWifiConfigStore.selectNetwork(netId) &&
+ mWifiNative.reconnect()) {
+ /* The state tracker handles enabling networks upon completion/failure */
+ mSupplicantStateTracker.sendMessage(WifiManager.CONNECT_NETWORK);
replyToMessage(message, WifiManager.CONNECT_NETWORK_SUCCEEDED);
+ /* Expect a disconnection from the old connection */
+ transitionTo(mDisconnectingState);
} else {
- loge("Failed to initiate connection");
+ loge("Failed to connect config: " + config + " netId: " + netId);
replyToMessage(message, WifiManager.CONNECT_NETWORK_FAILED,
WifiManager.ERROR);
+ break;
}
-
- /* Expect a disconnection from the old connection */
- transitionTo(mDisconnectingState);
break;
case WifiManager.START_WPS:
WpsInfo wpsInfo = (WpsInfo) message.obj;