Search in sources :

Example 6 with AsyncChannel

use of com.android.internal.util.AsyncChannel in project platform_frameworks_base by android.

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);
}
Also used : Message(android.os.Message) Handler(android.os.Handler) AsyncChannel(com.android.internal.util.AsyncChannel)

Example 7 with AsyncChannel

use of com.android.internal.util.AsyncChannel in project platform_frameworks_base by android.

the class WifiManager method getChannel.

private synchronized AsyncChannel getChannel() {
    if (mAsyncChannel == null) {
        Messenger messenger = getWifiServiceMessenger();
        if (messenger == null) {
            throw new IllegalStateException("getWifiServiceMessenger() returned null!  This is invalid.");
        }
        mAsyncChannel = new AsyncChannel();
        mConnected = new CountDownLatch(1);
        Handler handler = new ServiceHandler(mLooper);
        mAsyncChannel.connect(mContext, handler, messenger);
        try {
            mConnected.await();
        } catch (InterruptedException e) {
            Log.e(TAG, "interrupted wait at init");
        }
    }
    return mAsyncChannel;
}
Also used : Handler(android.os.Handler) AsyncChannel(com.android.internal.util.AsyncChannel) Messenger(android.os.Messenger) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 8 with AsyncChannel

use of com.android.internal.util.AsyncChannel in project XobotOS by xamarin.

the class MobileDataStateTracker method setPolicyDataEnable.

@Override
public void setPolicyDataEnable(boolean enabled) {
    if (DBG)
        log("setPolicyDataEnable(enabled=" + enabled + ")");
    final AsyncChannel channel = mDataConnectionTrackerAc;
    if (channel != null) {
        channel.sendMessage(CMD_SET_POLICY_DATA_ENABLE, enabled ? ENABLED : DISABLED);
        mPolicyDataEnabled = enabled;
    }
}
Also used : AsyncChannel(com.android.internal.util.AsyncChannel)

Example 9 with AsyncChannel

use of com.android.internal.util.AsyncChannel in project android_frameworks_base by DirtyUnicorns.

the class WifiManager method getChannel.

private synchronized AsyncChannel getChannel() {
    if (mAsyncChannel == null) {
        Messenger messenger = getWifiServiceMessenger();
        if (messenger == null) {
            throw new IllegalStateException("getWifiServiceMessenger() returned null!  This is invalid.");
        }
        mAsyncChannel = new AsyncChannel();
        mConnected = new CountDownLatch(1);
        Handler handler = new ServiceHandler(mLooper);
        mAsyncChannel.connect(mContext, handler, messenger);
        try {
            mConnected.await();
        } catch (InterruptedException e) {
            Log.e(TAG, "interrupted wait at init");
        }
    }
    return mAsyncChannel;
}
Also used : Handler(android.os.Handler) AsyncChannel(com.android.internal.util.AsyncChannel) Messenger(android.os.Messenger) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 10 with AsyncChannel

use of com.android.internal.util.AsyncChannel in project android_frameworks_base by DirtyUnicorns.

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);
}
Also used : Message(android.os.Message) Handler(android.os.Handler) AsyncChannel(com.android.internal.util.AsyncChannel)

Aggregations

AsyncChannel (com.android.internal.util.AsyncChannel)31 Handler (android.os.Handler)10 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)10 Messenger (android.os.Messenger)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 LinkProperties (android.net.LinkProperties)5 Network (android.net.Network)5 NetworkCapabilities (android.net.NetworkCapabilities)5 NetworkInfo (android.net.NetworkInfo)5 NetworkMisc (android.net.NetworkMisc)5 Message (android.os.Message)5 HandlerThread (android.os.HandlerThread)1