summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java2
-rw-r--r--core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiClientTest.java186
-rw-r--r--services/java/com/android/server/WifiService.java35
-rw-r--r--wifi/java/android/net/wifi/WifiStateMachine.java294
4 files changed, 294 insertions, 223 deletions
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java
index 6adfc74..3a78f26 100644
--- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerUnitTestRunner.java
@@ -20,6 +20,7 @@ import android.os.Bundle;
import android.test.InstrumentationTestRunner;
import android.test.InstrumentationTestSuite;
import android.util.Log;
+import com.android.connectivitymanagertest.unit.WifiClientTest;
import com.android.connectivitymanagertest.unit.WifiSoftAPTest;
import junit.framework.TestSuite;
@@ -35,6 +36,7 @@ public class ConnectivityManagerUnitTestRunner extends InstrumentationTestRunner
@Override
public TestSuite getAllTests() {
TestSuite suite = new InstrumentationTestSuite(this);
+ suite.addTestSuite(WifiClientTest.class);
suite.addTestSuite(WifiSoftAPTest.class);
return suite;
}
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiClientTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiClientTest.java
new file mode 100644
index 0000000..6717bda
--- /dev/null
+++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/unit/WifiClientTest.java
@@ -0,0 +1,186 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.connectivitymanagertest.unit;
+
+import android.content.BroadcastReceiver;
+import android.content.Intent;
+import android.content.Context;
+import android.app.Instrumentation;
+import android.os.Handler;
+import android.os.Message;
+import android.net.wifi.WifiManager;
+import android.net.wifi.WifiConfiguration;
+import android.net.wifi.WifiConfiguration.KeyMgmt;
+import android.net.wifi.WifiConfiguration.Status;
+
+import android.test.suitebuilder.annotation.LargeTest;
+import android.test.AndroidTestCase;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import android.util.Log;
+
+/**
+ * Test wifi client
+ */
+public class WifiClientTest extends AndroidTestCase {
+
+ private WifiManager mWifiManager;
+ private final String TAG = "WifiClientTest";
+
+ //10s delay for turning on wifi
+ private static final int DELAY = 10000;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
+ mWifiManager.setWifiEnabled(true);
+ assertNotNull(mWifiManager);
+ }
+
+ private void sleepAfterWifiEnable() {
+ try {
+ Thread.sleep(DELAY);
+ } catch (Exception e) {
+ fail("Sleep timeout " + e);
+ }
+ }
+
+ // Test case 1: add/remove a open network
+ @LargeTest
+ public void testAddRemoveNetwork() {
+ WifiConfiguration config = new WifiConfiguration();
+ config.SSID = "\"TestSSID1\"";
+ config.allowedKeyManagement.set(KeyMgmt.NONE);
+
+ //add
+ int netId = mWifiManager.addNetwork(config);
+ assertTrue(netId != -1);
+
+ //check config list
+ List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
+ boolean found = false;
+ for (WifiConfiguration c : configList) {
+ if (c.networkId == netId) {
+ found = true;
+ }
+ }
+ assertTrue(found);
+
+ //remove
+ boolean ret = mWifiManager.removeNetwork(netId);
+ assertTrue(ret);
+
+ //check config list
+ configList = mWifiManager.getConfiguredNetworks();
+ found = false;
+ for (WifiConfiguration c : configList) {
+ if (c.networkId == netId) {
+ found = true;
+ }
+ }
+
+ assertFalse(found);
+ }
+
+ // Test case 2: enable/disable a open network
+ @LargeTest
+ public void testEnableDisableNetwork() {
+ WifiConfiguration config = new WifiConfiguration();
+ config.SSID = "\"TestSSID2\"";
+ config.allowedKeyManagement.set(KeyMgmt.NONE);
+
+ //add
+ int netId = mWifiManager.addNetwork(config);
+ assertTrue(netId != -1);
+
+ //enable network and disable others
+ boolean ret = mWifiManager.enableNetwork(netId, true);
+ assertTrue(ret);
+
+ //check config list
+ List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
+ for (WifiConfiguration c : configList) {
+ if (c.networkId == netId) {
+ assertTrue(c.status == Status.ENABLED);
+ } else {
+ assertFalse(c.status == Status.ENABLED);
+ }
+ }
+
+ //disable network
+ ret = mWifiManager.disableNetwork(netId);
+ assertTrue(ret);
+
+ //check config list
+ configList = mWifiManager.getConfiguredNetworks();
+ for (WifiConfiguration c : configList) {
+ if (c.networkId == netId) {
+ assertTrue(c.status == Status.DISABLED);
+ }
+ }
+ }
+
+ // Test case 3: ping supplicant
+ @LargeTest
+ public void testPingSupplicant() {
+ assertTrue(mWifiManager.pingSupplicant());
+ mWifiManager.setWifiEnabled(false);
+ sleepAfterWifiEnable();
+
+ assertFalse(mWifiManager.pingSupplicant());
+ mWifiManager.setWifiEnabled(true);
+ sleepAfterWifiEnable();
+ }
+
+ // Test case 4: save config
+ @LargeTest
+ public void testSaveConfig() {
+ WifiConfiguration config = new WifiConfiguration();
+ config.SSID = "\"TestSSID3\"";
+ config.allowedKeyManagement.set(KeyMgmt.NONE);
+
+ //add
+ int netId = mWifiManager.addNetwork(config);
+ assertTrue(netId != -1);
+
+ mWifiManager.saveConfiguration();
+
+ //restart wifi
+ mWifiManager.setWifiEnabled(false);
+ mWifiManager.setWifiEnabled(true);
+
+ sleepAfterWifiEnable();
+
+ //check config list
+ List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
+ boolean found = false;
+ for (WifiConfiguration c : configList) {
+ if (c.SSID.equals("TestSSID3")) {
+ found = true;
+ }
+ }
+ assertTrue(found);
+
+ //restore config
+ boolean ret = mWifiManager.removeNetwork(netId);
+ assertTrue(ret);
+ mWifiManager.saveConfiguration();
+ }
+}
diff --git a/services/java/com/android/server/WifiService.java b/services/java/com/android/server/WifiService.java
index 2008215..55d69f0 100644
--- a/services/java/com/android/server/WifiService.java
+++ b/services/java/com/android/server/WifiService.java
@@ -423,7 +423,12 @@ public class WifiService extends IWifiManager.Stub {
*/
public boolean pingSupplicant() {
enforceAccessPermission();
- return mWifiStateMachine.syncPingSupplicant();
+ if (mChannel != null) {
+ return mWifiStateMachine.syncPingSupplicant(mChannel);
+ } else {
+ Slog.e(TAG, "mChannel is not initialized");
+ return false;
+ }
}
/**
@@ -634,7 +639,12 @@ public class WifiService extends IWifiManager.Stub {
*/
public int addOrUpdateNetwork(WifiConfiguration config) {
enforceChangePermission();
- return mWifiStateMachine.syncAddOrUpdateNetwork(config);
+ if (mChannel != null) {
+ return mWifiStateMachine.syncAddOrUpdateNetwork(mChannel, config);
+ } else {
+ Slog.e(TAG, "mChannel is not initialized");
+ return -1;
+ }
}
/**
@@ -662,7 +672,12 @@ public class WifiService extends IWifiManager.Stub {
*/
public boolean enableNetwork(int netId, boolean disableOthers) {
enforceChangePermission();
- return mWifiStateMachine.syncEnableNetwork(netId, disableOthers);
+ if (mChannel != null) {
+ return mWifiStateMachine.syncEnableNetwork(mChannel, netId, disableOthers);
+ } else {
+ Slog.e(TAG, "mChannel is not initialized");
+ return false;
+ }
}
/**
@@ -673,7 +688,12 @@ public class WifiService extends IWifiManager.Stub {
*/
public boolean disableNetwork(int netId) {
enforceChangePermission();
- return mWifiStateMachine.syncDisableNetwork(netId);
+ if (mChannel != null) {
+ return mWifiStateMachine.syncDisableNetwork(mChannel, netId);
+ } else {
+ Slog.e(TAG, "mChannel is not initialized");
+ return false;
+ }
}
/**
@@ -708,7 +728,12 @@ public class WifiService extends IWifiManager.Stub {
public boolean saveConfiguration() {
boolean result = true;
enforceChangePermission();
- return mWifiStateMachine.syncSaveConfig();
+ if (mChannel != null) {
+ return mWifiStateMachine.syncSaveConfig(mChannel);
+ } else {
+ Slog.e(TAG, "mChannel is not initialized");
+ return false;
+ }
}
/**
diff --git a/wifi/java/android/net/wifi/WifiStateMachine.java b/wifi/java/android/net/wifi/WifiStateMachine.java
index 6bd67cc..3531749 100644
--- a/wifi/java/android/net/wifi/WifiStateMachine.java
+++ b/wifi/java/android/net/wifi/WifiStateMachine.java
@@ -279,18 +279,10 @@ public class WifiStateMachine extends HierarchicalStateMachine {
private static final int CMD_ENABLE_RSSI_POLL = 82;
/* RSSI poll */
private static final int CMD_RSSI_POLL = 83;
- /* Get current RSSI */
- private static final int CMD_GET_RSSI = 84;
- /* Get approx current RSSI */
- private static final int CMD_GET_RSSI_APPROX = 85;
- /* Get link speed on connection */
- private static final int CMD_GET_LINK_SPEED = 86;
- /* Radio mac address */
- private static final int CMD_GET_MAC_ADDR = 87;
/* Set up packet filtering */
- private static final int CMD_START_PACKET_FILTERING = 88;
+ private static final int CMD_START_PACKET_FILTERING = 84;
/* Clear packet filter */
- private static final int CMD_STOP_PACKET_FILTERING = 89;
+ private static final int CMD_STOP_PACKET_FILTERING = 85;
/* Connect to a specified network (network id
* or WifiConfiguration) This involves increasing
* the priority of the network, enabling the network
@@ -299,21 +291,23 @@ public class WifiStateMachine extends HierarchicalStateMachine {
* an existing network. All the networks get enabled
* upon a successful connection or a failure.
*/
- private static final int CMD_CONNECT_NETWORK = 90;
+ private static final int CMD_CONNECT_NETWORK = 86;
/* Save the specified network. This involves adding
* an enabled network (if new) and updating the
* config and issuing a save on supplicant config.
*/
- private static final int CMD_SAVE_NETWORK = 91;
+ private static final int CMD_SAVE_NETWORK = 87;
/* Delete the specified network. This involves
* removing the network and issuing a save on
* supplicant config.
*/
- private static final int CMD_FORGET_NETWORK = 92;
+ private static final int CMD_FORGET_NETWORK = 88;
/* Start Wi-Fi protected setup push button configuration */
- private static final int CMD_START_WPS_PBC = 93;
- /* Start Wi-Fi protected setup pin method configuration */
- private static final int CMD_START_WPS_PIN = 94;
+ private static final int CMD_START_WPS_PBC = 89;
+ /* Start Wi-Fi protected setup pin method configuration with pin obtained from AP */
+ private static final int CMD_START_WPS_PIN_FROM_AP = 90;
+ /* Start Wi-Fi protected setup pin method configuration with pin obtained from device */
+ private static final int CMD_START_WPS_PIN_FROM_DEVICE = 91;
/**
* Interval in milliseconds between polling for connection
* status items that are not sent via asynchronous events.
@@ -334,6 +328,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
/* 2.4GHz allows 802.11B/G operation */
private static final int BAND_2G = 2;
+ private static final int SUCCESS = 1;
+ private static final int FAILURE = -1;
+
/**
* The maximum number of times we will retry a connection to an access point
* for which we have failed in acquiring an IP address from DHCP. A value of
@@ -519,8 +516,11 @@ public class WifiStateMachine extends HierarchicalStateMachine {
/**
* TODO: doc
*/
- public boolean syncPingSupplicant() {
- return sendSyncMessage(CMD_PING_SUPPLICANT).boolValue;
+ public boolean syncPingSupplicant(AsyncChannel channel) {
+ Message resultMsg = channel.sendMessageSynchronously(CMD_PING_SUPPLICANT);
+ boolean result = (resultMsg.arg1 != FAILURE);
+ resultMsg.recycle();
+ return result;
}
/**
@@ -698,8 +698,11 @@ public class WifiStateMachine extends HierarchicalStateMachine {
*
* @return network id of the new network
*/
- public int syncAddOrUpdateNetwork(WifiConfiguration config) {
- return sendSyncMessage(CMD_ADD_OR_UPDATE_NETWORK, config).intValue;
+ public int syncAddOrUpdateNetwork(AsyncChannel channel, WifiConfiguration config) {
+ Message resultMsg = channel.sendMessageSynchronously(CMD_ADD_OR_UPDATE_NETWORK, config);
+ int result = resultMsg.arg1;
+ resultMsg.recycle();
+ return result;
}
public List<WifiConfiguration> syncGetConfiguredNetworks() {
@@ -713,39 +716,24 @@ public class WifiStateMachine extends HierarchicalStateMachine {
*/
public boolean syncRemoveNetwork(AsyncChannel channel, int networkId) {
Message resultMsg = channel.sendMessageSynchronously(CMD_REMOVE_NETWORK, networkId);
- boolean result = resultMsg.arg1 != 0;
+ boolean result = (resultMsg.arg1 != FAILURE);
resultMsg.recycle();
return result;
}
/**
- * Return the result of a removeNetwork
- *
- * @param srcMsg is the original message
- * @param result is true if successfully removed
- */
- private void removeNetworkReply(Message srcMsg, boolean result) {
- mReplyChannel.replyToMessage(srcMsg, CMD_REMOVE_NETWORK, result ? 1 : 0);
- }
-
- private class EnableNetParams {
- private int netId;
- private boolean disableOthers;
- EnableNetParams(int n, boolean b) {
- netId = n;
- disableOthers = b;
- }
- }
- /**
* Enable a network
*
* @param netId network id of the network
* @param disableOthers true, if all other networks have to be disabled
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
- public boolean syncEnableNetwork(int netId, boolean disableOthers) {
- return sendSyncMessage(CMD_ENABLE_NETWORK,
- new EnableNetParams(netId, disableOthers)).boolValue;
+ public boolean syncEnableNetwork(AsyncChannel channel, int netId, boolean disableOthers) {
+ Message resultMsg = channel.sendMessageSynchronously(CMD_ENABLE_NETWORK, netId,
+ disableOthers ? 1 : 0);
+ boolean result = (resultMsg.arg1 != FAILURE);
+ resultMsg.recycle();
+ return result;
}
/**
@@ -754,8 +742,11 @@ public class WifiStateMachine extends HierarchicalStateMachine {
* @param netId network id of the network
* @return {@code true} if the operation succeeds, {@code false} otherwise
*/
- public boolean syncDisableNetwork(int netId) {
- return sendSyncMessage(obtainMessage(CMD_DISABLE_NETWORK, netId, 0)).boolValue;
+ public boolean syncDisableNetwork(AsyncChannel channel, int netId) {
+ Message resultMsg = channel.sendMessageSynchronously(CMD_DISABLE_NETWORK, netId);
+ boolean result = (resultMsg.arg1 != FAILURE);
+ resultMsg.recycle();
+ return result;
}
/**
@@ -801,11 +792,11 @@ public class WifiStateMachine extends HierarchicalStateMachine {
}
public void startWpsWithPinFromAccessPoint(String bssid, int apPin) {
- sendMessage(obtainMessage(CMD_START_WPS_PIN, apPin, 0, bssid));
+ sendMessage(obtainMessage(CMD_START_WPS_PIN_FROM_AP, apPin, 0, bssid));
}
public int syncStartWpsWithPinFromDevice(AsyncChannel channel, String bssid) {
- Message resultMsg = channel.sendMessageSynchronously(CMD_START_WPS_PIN, bssid);
+ Message resultMsg = channel.sendMessageSynchronously(CMD_START_WPS_PIN_FROM_DEVICE, bssid);
int result = resultMsg.arg1;
resultMsg.recycle();
return result;
@@ -814,41 +805,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
public void enableRssiPolling(boolean enabled) {
sendMessage(obtainMessage(CMD_ENABLE_RSSI_POLL, enabled ? 1 : 0, 0));
}
- /**
- * Get RSSI to currently connected network
- *
- * @return RSSI value, -1 on failure
- */
- public int syncGetRssi() {
- return sendSyncMessage(CMD_GET_RSSI).intValue;
- }
-
- /**
- * Get approx RSSI to currently connected network
- *
- * @return RSSI value, -1 on failure
- */
- public int syncGetRssiApprox() {
- return sendSyncMessage(CMD_GET_RSSI_APPROX).intValue;
- }
-
- /**
- * Get link speed to currently connected network
- *
- * @return link speed, -1 on failure
- */
- public int syncGetLinkSpeed() {
- return sendSyncMessage(CMD_GET_LINK_SPEED).intValue;
- }
-
- /**
- * Get MAC address of radio
- *
- * @return MAC address, null on failure
- */
- public String syncGetMacAddress() {
- return sendSyncMessage(CMD_GET_MAC_ADDR).stringValue;
- }
/**
* Start packet filtering
@@ -943,8 +899,11 @@ public class WifiStateMachine extends HierarchicalStateMachine {
*
* TODO: deprecate this
*/
- public boolean syncSaveConfig() {
- return sendSyncMessage(CMD_SAVE_CONFIG).boolValue;
+ public boolean syncSaveConfig(AsyncChannel channel) {
+ Message resultMsg = channel.sendMessageSynchronously(CMD_SAVE_CONFIG);
+ boolean result = (resultMsg.arg1 != FAILURE);
+ resultMsg.recycle();
+ return result;
}
/**
@@ -1018,73 +977,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
* Internal private functions
********************************************************/
- class SyncReturn {
- boolean boolValue;
- int intValue;
- String stringValue;
- Object objValue;
- }
-
- class SyncParams {
- Object mParameter;
- SyncReturn mSyncReturn;
- SyncParams() {
- mSyncReturn = new SyncReturn();
- }
- SyncParams(Object p) {
- mParameter = p;
- mSyncReturn = new SyncReturn();
- }
- }
-
- /**
- * message.obj is used to store SyncParams
- */
- private SyncReturn syncedSend(Message msg) {
- SyncParams syncParams = (SyncParams) msg.obj;
- synchronized(syncParams) {
- if (DBG) Log.d(TAG, "syncedSend " + msg);
- sendMessage(msg);
- try {
- syncParams.wait();
- } catch (InterruptedException e) {
- Log.e(TAG, "sendSyncMessage: unexpected interruption of wait()");
- return null;
- }
- }
- return syncParams.mSyncReturn;
- }
-
- private SyncReturn sendSyncMessage(Message msg) {
- SyncParams syncParams = new SyncParams();
- msg.obj = syncParams;
- return syncedSend(msg);
- }
-
- private SyncReturn sendSyncMessage(int what, Object param) {
- SyncParams syncParams = new SyncParams(param);
- Message msg = obtainMessage(what, syncParams);
- return syncedSend(msg);
- }
-
-
- private SyncReturn sendSyncMessage(int what) {
- return sendSyncMessage(obtainMessage(what));
- }
-
- private void notifyOnMsgObject(Message msg) {
- SyncParams syncParams = (SyncParams) msg.obj;
- if (syncParams != null) {
- synchronized(syncParams) {
- if (DBG) Log.d(TAG, "notifyOnMsgObject " + msg);
- syncParams.notify();
- }
- }
- else {
- Log.e(TAG, "Error! syncParams in notifyOnMsgObject is null");
- }
- }
-
private void setWifiState(int wifiState) {
final int previousWifiState = mWifiState.get();
@@ -1620,7 +1512,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
@Override
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
- SyncParams syncParams;
switch (message.what) {
case CMD_SET_BLUETOOTH_HEADSET_PROXY:
mBluetoothHeadset = (BluetoothHeadset) message.obj;
@@ -1633,19 +1524,10 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_ENABLE_NETWORK:
case CMD_DISABLE_NETWORK:
case CMD_ADD_OR_UPDATE_NETWORK:
- case CMD_GET_RSSI:
- case CMD_GET_RSSI_APPROX:
- case CMD_GET_LINK_SPEED:
- case CMD_GET_MAC_ADDR:
- case CMD_SAVE_CONFIG:
- syncParams = (SyncParams) message.obj;
- syncParams.mSyncReturn.boolValue = false;
- syncParams.mSyncReturn.intValue = -1;
- syncParams.mSyncReturn.stringValue = null;
- notifyOnMsgObject(message);
- break;
case CMD_REMOVE_NETWORK:
- removeNetworkReply(message, false);
+ case CMD_SAVE_CONFIG:
+ case CMD_START_WPS_PIN_FROM_DEVICE:
+ mReplyChannel.replyToMessage(message, message.what, FAILURE);
break;
case CMD_ENABLE_RSSI_POLL:
mEnableRssiPolling = (message.arg1 == 1);
@@ -1687,7 +1569,7 @@ public class WifiStateMachine extends HierarchicalStateMachine {
case CMD_SAVE_NETWORK:
case CMD_FORGET_NETWORK:
case CMD_START_WPS_PBC:
- case CMD_START_WPS_PIN:
+ case CMD_START_WPS_PIN_FROM_AP:
break;
default:
Log.e(TAG, "Error! unhandled message" + message);
@@ -2032,7 +1914,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
@Override
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
- SyncParams syncParams;
WifiConfiguration config;
switch(message.what) {
case CMD_STOP_SUPPLICANT: /* Supplicant stopped by user */
@@ -2060,36 +1941,29 @@ public class WifiStateMachine extends HierarchicalStateMachine {
sendScanResultsAvailableBroadcast();
break;
case CMD_PING_SUPPLICANT:
- syncParams = (SyncParams) message.obj;
- syncParams.mSyncReturn.boolValue = WifiNative.pingCommand();
- notifyOnMsgObject(message);
+ boolean ok = WifiNative.pingCommand();
+ mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
break;
case CMD_ADD_OR_UPDATE_NETWORK:
EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
- syncParams = (SyncParams) message.obj;
- config = (WifiConfiguration) syncParams.mParameter;
- syncParams.mSyncReturn.intValue = WifiConfigStore.addOrUpdateNetwork(config);
- notifyOnMsgObject(message);
+ 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);
- boolean ok = WifiConfigStore.removeNetwork(message.arg1);
- removeNetworkReply(message, ok);
+ 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);
- syncParams = (SyncParams) message.obj;
- EnableNetParams enableNetParams = (EnableNetParams) syncParams.mParameter;
- syncParams.mSyncReturn.boolValue = WifiConfigStore.enableNetwork(
- enableNetParams.netId, enableNetParams.disableOthers);
- notifyOnMsgObject(message);
+ ok = WifiConfigStore.enableNetwork(message.arg1, message.arg2 == 1);
+ mReplyChannel.replyToMessage(message, message.what, ok ? SUCCESS : FAILURE);
break;
case CMD_DISABLE_NETWORK:
EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
- syncParams = (SyncParams) message.obj;
- syncParams.mSyncReturn.boolValue = WifiConfigStore.disableNetwork(
- message.arg1);
- notifyOnMsgObject(message);
+ 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);
@@ -2099,9 +1973,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
WifiNative.clearBlacklistCommand();
break;
case CMD_SAVE_CONFIG:
- syncParams = (SyncParams) message.obj;
- syncParams.mSyncReturn.boolValue = WifiConfigStore.saveConfig();
- notifyOnMsgObject(message);
+ ok = WifiConfigStore.saveConfig();
+ mReplyChannel.replyToMessage(message, CMD_SAVE_CONFIG, ok ? SUCCESS : FAILURE);
+
// Inform the backup manager about a data change
IBackupManager ibm = IBackupManager.Stub.asInterface(
ServiceManager.getService(Context.BACKUP_SERVICE));
@@ -2113,11 +1987,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
}
}
break;
- case CMD_GET_MAC_ADDR:
- syncParams = (SyncParams) message.obj;
- syncParams.mSyncReturn.stringValue = WifiNative.getMacAddressCommand();
- notifyOnMsgObject(message);
- break;
/* Cannot start soft AP while in client mode */
case CMD_START_AP:
Log.d(TAG, "Failed to start soft AP with a running supplicant");
@@ -2207,7 +2076,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
@Override
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
- SyncParams syncParams;
switch(message.what) {
case CMD_SET_SCAN_TYPE:
if (message.arg1 == SCAN_ACTIVE) {
@@ -2333,7 +2201,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
@Override
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
- SyncParams syncParams;
switch(message.what) {
case CMD_SET_SCAN_MODE:
if (message.arg1 == SCAN_ONLY_MODE) {
@@ -2374,7 +2241,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
@Override
public boolean processMessage(Message message) {
if (DBG) Log.d(TAG, getName() + message.toString() + "\n");
- SyncParams syncParams;
StateChangeResult stateChangeResult;
switch(message.what) {
case PASSWORD_MAY_BE_INCORRECT_EVENT:
@@ -2449,18 +2315,25 @@ public class WifiStateMachine extends HierarchicalStateMachine {
transitionTo(mDisconnectingState);
}
break;
- case CMD_START_WPS_PIN:
+ case CMD_START_WPS_PIN_FROM_AP:
bssid = (String) message.obj;
int apPin = message.arg1;
- int pin;
- if (apPin != 0) {
- /* WPS pin from access point */
- success = WifiConfigStore.startWpsWithPinFromAccessPoint(bssid, apPin);
- } else {
- pin = WifiConfigStore.startWpsWithPinFromDevice(bssid);
- success = (pin != -1);
- mReplyChannel.replyToMessage(message, CMD_START_WPS_PIN, pin);
+
+ /* WPS pin from access point */
+ success = WifiConfigStore.startWpsWithPinFromAccessPoint(bssid, apPin);
+
+ if (success) {
+ mWpsStarted = true;
+ /* Expect a disconnection from the old connection */
+ transitionTo(mDisconnectingState);
}
+ break;
+ case CMD_START_WPS_PIN_FROM_DEVICE:
+ bssid = (String) message.obj;
+ int pin = WifiConfigStore.startWpsWithPinFromDevice(bssid);
+ success = (pin != FAILURE);
+ mReplyChannel.replyToMessage(message, CMD_START_WPS_PIN_FROM_DEVICE, pin);
+
if (success) {
mWpsStarted = true;
/* Expect a disconnection from the old connection */
@@ -2491,21 +2364,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
handleNetworkDisconnect();
transitionTo(mDisconnectedState);
break;
- case CMD_GET_RSSI:
- syncParams = (SyncParams) message.obj;
- syncParams.mSyncReturn.intValue = WifiNative.getRssiCommand();
- notifyOnMsgObject(message);
- break;
- case CMD_GET_RSSI_APPROX:
- syncParams = (SyncParams) message.obj;
- syncParams.mSyncReturn.intValue = WifiNative.getRssiApproxCommand();
- notifyOnMsgObject(message);
- break;
- case CMD_GET_LINK_SPEED:
- syncParams = (SyncParams) message.obj;
- syncParams.mSyncReturn.intValue = WifiNative.getLinkSpeedCommand();
- notifyOnMsgObject(message);
- break;
default:
return NOT_HANDLED;
}