Search in sources :

Example 21 with AsyncChannel

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

the class ConnectivityService method registerNetworkAgent.

public int registerNetworkAgent(Messenger messenger, NetworkInfo networkInfo, LinkProperties linkProperties, NetworkCapabilities networkCapabilities, int currentScore, NetworkMisc networkMisc) {
    enforceConnectivityInternalPermission();
    // TODO: Instead of passing mDefaultRequest, provide an API to determine whether a Network
    // satisfies mDefaultRequest.
    final NetworkAgentInfo nai = new NetworkAgentInfo(messenger, new AsyncChannel(), new Network(reserveNetId()), new NetworkInfo(networkInfo), new LinkProperties(linkProperties), new NetworkCapabilities(networkCapabilities), currentScore, mContext, mTrackerHandler, new NetworkMisc(networkMisc), mDefaultRequest, this);
    synchronized (this) {
        nai.networkMonitor.systemReady = mSystemReady;
    }
    addValidationLogs(nai.networkMonitor.getValidationLogs(), nai.network, networkInfo.getExtraInfo());
    if (DBG)
        log("registerNetworkAgent " + nai);
    mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_AGENT, nai));
    return nai.network.netId;
}
Also used : NetworkMisc(android.net.NetworkMisc) NetworkInfo(android.net.NetworkInfo) NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) Network(android.net.Network) AsyncChannel(com.android.internal.util.AsyncChannel) LinkProperties(android.net.LinkProperties) NetworkCapabilities(android.net.NetworkCapabilities)

Example 22 with AsyncChannel

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

the class ConnectivityService method registerNetworkFactory.

@Override
public void registerNetworkFactory(Messenger messenger, String name) {
    enforceConnectivityInternalPermission();
    NetworkFactoryInfo nfi = new NetworkFactoryInfo(name, messenger, new AsyncChannel());
    mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_FACTORY, nfi));
}
Also used : AsyncChannel(com.android.internal.util.AsyncChannel)

Example 23 with AsyncChannel

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

the class ConnectivityService method handleAsyncChannelHalfConnect.

private void handleAsyncChannelHalfConnect(Message msg) {
    AsyncChannel ac = (AsyncChannel) msg.obj;
    if (mNetworkFactoryInfos.containsKey(msg.replyTo)) {
        if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
            if (VDBG)
                log("NetworkFactory connected");
            // A network factory has connected.  Send it all current NetworkRequests.
            for (NetworkRequestInfo nri : mNetworkRequests.values()) {
                if (nri.request.isListen())
                    continue;
                NetworkAgentInfo nai = mNetworkForRequestId.get(nri.request.requestId);
                ac.sendMessage(android.net.NetworkFactory.CMD_REQUEST_NETWORK, (nai != null ? nai.getCurrentScore() : 0), 0, nri.request);
            }
        } else {
            loge("Error connecting NetworkFactory");
            mNetworkFactoryInfos.remove(msg.obj);
        }
    } else if (mNetworkAgentInfos.containsKey(msg.replyTo)) {
        if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
            if (VDBG)
                log("NetworkAgent connected");
            // A network agent has requested a connection.  Establish the connection.
            mNetworkAgentInfos.get(msg.replyTo).asyncChannel.sendMessage(AsyncChannel.CMD_CHANNEL_FULL_CONNECTION);
        } else {
            loge("Error connecting NetworkAgent");
            NetworkAgentInfo nai = mNetworkAgentInfos.remove(msg.replyTo);
            if (nai != null) {
                final boolean wasDefault = isDefaultNetwork(nai);
                synchronized (mNetworkForNetId) {
                    mNetworkForNetId.remove(nai.network.netId);
                    mNetIdInUse.delete(nai.network.netId);
                }
                // Just in case.
                mLegacyTypeTracker.remove(nai, wasDefault);
            }
        }
    }
}
Also used : NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) AsyncChannel(com.android.internal.util.AsyncChannel)

Example 24 with AsyncChannel

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

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 25 with AsyncChannel

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

the class ConnectivityService method handleAsyncChannelHalfConnect.

private void handleAsyncChannelHalfConnect(Message msg) {
    AsyncChannel ac = (AsyncChannel) msg.obj;
    if (mNetworkFactoryInfos.containsKey(msg.replyTo)) {
        if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
            if (VDBG)
                log("NetworkFactory connected");
            // A network factory has connected.  Send it all current NetworkRequests.
            for (NetworkRequestInfo nri : mNetworkRequests.values()) {
                if (nri.request.isListen())
                    continue;
                NetworkAgentInfo nai = mNetworkForRequestId.get(nri.request.requestId);
                ac.sendMessage(android.net.NetworkFactory.CMD_REQUEST_NETWORK, (nai != null ? nai.getCurrentScore() : 0), 0, nri.request);
            }
        } else {
            loge("Error connecting NetworkFactory");
            mNetworkFactoryInfos.remove(msg.obj);
        }
    } else if (mNetworkAgentInfos.containsKey(msg.replyTo)) {
        if (msg.arg1 == AsyncChannel.STATUS_SUCCESSFUL) {
            if (VDBG)
                log("NetworkAgent connected");
            // A network agent has requested a connection.  Establish the connection.
            mNetworkAgentInfos.get(msg.replyTo).asyncChannel.sendMessage(AsyncChannel.CMD_CHANNEL_FULL_CONNECTION);
        } else {
            loge("Error connecting NetworkAgent");
            NetworkAgentInfo nai = mNetworkAgentInfos.remove(msg.replyTo);
            if (nai != null) {
                final boolean wasDefault = isDefaultNetwork(nai);
                synchronized (mNetworkForNetId) {
                    mNetworkForNetId.remove(nai.network.netId);
                    mNetIdInUse.delete(nai.network.netId);
                }
                // Just in case.
                mLegacyTypeTracker.remove(nai, wasDefault);
            }
        }
    }
}
Also used : NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) 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