use of com.android.internal.util.AsyncChannel in project android_frameworks_base by crdroidandroid.
the class BidirectionalAsyncChannel method connect.
public void connect(final Looper looper, final Messenger messenger, final Handler incomingMessageHandler) {
assertEquals("AsyncChannel must be disconnected to connect", ChannelState.DISCONNECTED, mState);
mChannel = new AsyncChannel();
Handler rawMessageHandler = new Handler(looper) {
@Override
public void handleMessage(Message msg) {
switch(msg.what) {
case AsyncChannel.CMD_CHANNEL_HALF_CONNECTED:
if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
Log.d(TAG, "Successfully half connected " + this);
mChannel.sendMessage(AsyncChannel.CMD_CHANNEL_FULL_CONNECTION);
mState = ChannelState.HALF_CONNECTED;
} else {
Log.d(TAG, "Failed to connect channel " + this);
mState = ChannelState.FAILURE;
mChannel = null;
}
break;
case AsyncChannel.CMD_CHANNEL_FULLY_CONNECTED:
mState = ChannelState.CONNECTED;
Log.d(TAG, "Channel fully connected" + this);
break;
case AsyncChannel.CMD_CHANNEL_DISCONNECTED:
mState = ChannelState.DISCONNECTED;
mChannel = null;
Log.d(TAG, "Channel disconnected" + this);
break;
default:
incomingMessageHandler.handleMessage(msg);
break;
}
}
};
mChannel.connect(null, rawMessageHandler, messenger);
}
Aggregations