Change removeNetowrk to a synchronous channel call.

Change-ID: Iad0380d56972826615e044fa2aaee418b617d732
This commit is contained in:
Wink Saville
2010-10-20 15:37:41 -07:00
parent 1b35f942ec
commit 4b7ba09c8b
2 changed files with 71 additions and 9 deletions

View File

@@ -65,6 +65,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import com.android.internal.app.IBatteryStats;
import com.android.internal.util.AsyncChannel;
import com.android.server.am.BatteryStatsService;
import com.android.internal.R;
@@ -197,6 +198,45 @@ public class WifiService extends IWifiManager.Stub {
*/
private int mNumScansSinceNetworkStateChange;
/**
* Asynchronous channel to WifiStateMachine
*/
private AsyncChannel mChannel;
/**
* TODO: Possibly change WifiService into an AsyncService.
*/
private class WifiServiceHandler extends Handler {
private AsyncChannel mWshChannel;
WifiServiceHandler(android.os.Looper looper, Context context) {
super(looper);
mWshChannel = new AsyncChannel();
mWshChannel.connect(context, this, mWifiStateMachine.getHandler(), 0);
}
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED: {
if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
mChannel = mWshChannel;
} else {
Slog.d(TAG, "WifiServicehandler.handleMessage could not connect error=" +
msg.arg1);
mChannel = null;
}
break;
}
default: {
Slog.d(TAG, "WifiServicehandler.handleMessage ignoring msg=" + msg);
break;
}
}
}
}
WifiServiceHandler mHandler;
/**
* Temporary for computing UIDS that are responsible for starting WIFI.
* Protected by mWifiStateTracker lock.
@@ -218,6 +258,7 @@ public class WifiService extends IWifiManager.Stub {
HandlerThread wifiThread = new HandlerThread("WifiService");
wifiThread.start();
mHandler = new WifiServiceHandler(wifiThread.getLooper(), context);
mContext.registerReceiver(
new BroadcastReceiver() {
@@ -602,7 +643,12 @@ public class WifiService extends IWifiManager.Stub {
*/
public boolean removeNetwork(int netId) {
enforceChangePermission();
return mWifiStateMachine.syncRemoveNetwork(netId);
if (mChannel != null) {
return mWifiStateMachine.syncRemoveNetwork(mChannel, netId);
} else {
Slog.e(TAG, "mChannel is not initialized");
return false;
}
}
/**

View File

@@ -70,6 +70,7 @@ import android.bluetooth.BluetoothProfile;
import android.content.Intent;
import android.content.Context;
import com.android.internal.app.IBatteryStats;
import com.android.internal.util.AsyncChannel;
import com.android.internal.util.HierarchicalState;
import com.android.internal.util.HierarchicalStateMachine;
@@ -148,6 +149,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
* and load configuration afterwards */
private boolean mWpsStarted = false;
// Channel for sending replies.
private AsyncChannel mReplyChannel = new AsyncChannel();
// Event log tags (must be in sync with event-log-tags)
private static final int EVENTLOG_WIFI_STATE_CHANGED = 50021;
private static final int EVENTLOG_WIFI_EVENT_HANDLED = 50022;
@@ -301,7 +305,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
/* Start Wi-Fi protected setup */
private static final int CMD_START_WPS = 93;
/**
* Interval in milliseconds between polling for connection
* status items that are not sent via asynchronous events.
@@ -699,8 +702,21 @@ public class WifiStateMachine extends HierarchicalStateMachine {
*
* @param networkId id of the network to be removed
*/
public boolean syncRemoveNetwork(int networkId) {
return sendSyncMessage(obtainMessage(CMD_REMOVE_NETWORK, networkId, 0)).boolValue;
public boolean syncRemoveNetwork(AsyncChannel channel, int networkId) {
Message resultMsg = channel.sendMessageSynchronously(CMD_REMOVE_NETWORK, networkId);
boolean result = resultMsg.arg1 != 0;
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 {
@@ -1583,7 +1599,6 @@ public class WifiStateMachine extends HierarchicalStateMachine {
break;
/* Synchronous call returns */
case CMD_PING_SUPPLICANT:
case CMD_REMOVE_NETWORK:
case CMD_ENABLE_NETWORK:
case CMD_DISABLE_NETWORK:
case CMD_ADD_OR_UPDATE_NETWORK:
@@ -1598,6 +1613,9 @@ public class WifiStateMachine extends HierarchicalStateMachine {
syncParams.mSyncReturn.stringValue = null;
notifyOnMsgObject(message);
break;
case CMD_REMOVE_NETWORK:
removeNetworkReply(message, false);
break;
case CMD_ENABLE_RSSI_POLL:
mEnableRssiPolling = (message.arg1 == 1);
mSupplicantStateTracker.sendMessage(CMD_ENABLE_RSSI_POLL);
@@ -2023,10 +2041,8 @@ public class WifiStateMachine extends HierarchicalStateMachine {
break;
case CMD_REMOVE_NETWORK:
EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);
syncParams = (SyncParams) message.obj;
syncParams.mSyncReturn.boolValue = WifiConfigStore.removeNetwork(
message.arg1);
notifyOnMsgObject(message);
boolean ok = WifiConfigStore.removeNetwork(message.arg1);
removeNetworkReply(message, ok);
break;
case CMD_ENABLE_NETWORK:
EventLog.writeEvent(EVENTLOG_WIFI_EVENT_HANDLED, message.what);