Search in sources :

Example 71 with NetworkRequest

use of android.net.NetworkRequest in project android_frameworks_base by AOSPA.

the class ConnectivityService method processListenRequests.

private void processListenRequests(NetworkAgentInfo nai, boolean capabilitiesChanged) {
    // For consistency with previous behaviour, send onLost callbacks before onAvailable.
    for (NetworkRequestInfo nri : mNetworkRequests.values()) {
        NetworkRequest nr = nri.request;
        if (!nr.isListen())
            continue;
        if (nai.isSatisfyingRequest(nr.requestId) && !nai.satisfies(nr)) {
            nai.removeRequest(nri.request.requestId);
            callCallbackForRequest(nri, nai, ConnectivityManager.CALLBACK_LOST, 0);
        }
    }
    if (capabilitiesChanged) {
        notifyNetworkCallbacks(nai, ConnectivityManager.CALLBACK_CAP_CHANGED);
    }
    for (NetworkRequestInfo nri : mNetworkRequests.values()) {
        NetworkRequest nr = nri.request;
        if (!nr.isListen())
            continue;
        if (nai.satisfies(nr) && !nai.isSatisfyingRequest(nr.requestId)) {
            nai.addRequest(nr);
            notifyNetworkCallback(nai, nri);
        }
    }
}
Also used : NetworkRequest(android.net.NetworkRequest)

Example 72 with NetworkRequest

use of android.net.NetworkRequest in project android_frameworks_base by AOSPA.

the class ConnectivityService method sendUpdatedScoreToFactories.

private void sendUpdatedScoreToFactories(NetworkAgentInfo nai) {
    for (int i = 0; i < nai.numNetworkRequests(); i++) {
        NetworkRequest nr = nai.requestAt(i);
        // Don't send listening requests to factories. b/17393458
        if (nr.isListen())
            continue;
        sendUpdatedScoreToFactories(nr, nai.getCurrentScore());
    }
}
Also used : NetworkRequest(android.net.NetworkRequest)

Example 73 with NetworkRequest

use of android.net.NetworkRequest in project android_frameworks_base by AOSPA.

the class ConnectivityService method requestNetwork.

@Override
public NetworkRequest requestNetwork(NetworkCapabilities networkCapabilities, Messenger messenger, int timeoutMs, IBinder binder, int legacyType) {
    final NetworkRequest.Type type = (networkCapabilities == null) ? NetworkRequest.Type.TRACK_DEFAULT : NetworkRequest.Type.REQUEST;
    // the system default network.
    if (type == NetworkRequest.Type.TRACK_DEFAULT) {
        networkCapabilities = new NetworkCapabilities(mDefaultRequest.networkCapabilities);
        enforceAccessPermission();
    } else {
        networkCapabilities = new NetworkCapabilities(networkCapabilities);
        enforceNetworkRequestPermissions(networkCapabilities);
        // TODO: this is incorrect. We mark the request as metered or not depending on the state
        // of the app when the request is filed, but we never change the request if the app
        // changes network state. http://b/29964605
        enforceMeteredApnPolicy(networkCapabilities);
    }
    ensureRequestableCapabilities(networkCapabilities);
    if (timeoutMs < 0 || timeoutMs > ConnectivityManager.MAX_NETWORK_REQUEST_TIMEOUT_MS) {
        throw new IllegalArgumentException("Bad timeout specified");
    }
    if (NetworkCapabilities.MATCH_ALL_REQUESTS_NETWORK_SPECIFIER.equals(networkCapabilities.getNetworkSpecifier())) {
        throw new IllegalArgumentException("Invalid network specifier - must not be '" + NetworkCapabilities.MATCH_ALL_REQUESTS_NETWORK_SPECIFIER + "'");
    }
    NetworkRequest networkRequest = new NetworkRequest(networkCapabilities, legacyType, nextNetworkRequestId(), type);
    NetworkRequestInfo nri = new NetworkRequestInfo(messenger, networkRequest, binder);
    if (DBG)
        log("requestNetwork for " + nri);
    mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_REQUEST, nri));
    if (timeoutMs > 0) {
        mHandler.sendMessageDelayed(mHandler.obtainMessage(EVENT_TIMEOUT_NETWORK_REQUEST, nri), timeoutMs);
    }
    return networkRequest;
}
Also used : NetworkRequest(android.net.NetworkRequest) NetworkCapabilities(android.net.NetworkCapabilities)

Example 74 with NetworkRequest

use of android.net.NetworkRequest in project android_frameworks_base by AOSPA.

the class ConnectivityService method notifyNetworkCallbacks.

protected void notifyNetworkCallbacks(NetworkAgentInfo networkAgent, int notifyType, int arg1) {
    if (VDBG)
        log("notifyType " + notifyTypeToName(notifyType) + " for " + networkAgent.name());
    for (int i = 0; i < networkAgent.numNetworkRequests(); i++) {
        NetworkRequest nr = networkAgent.requestAt(i);
        NetworkRequestInfo nri = mNetworkRequests.get(nr);
        if (VDBG)
            log(" sending notification for " + nr);
        // a network that no longer satisfies the listen?
        if (nri.mPendingIntent == null) {
            callCallbackForRequest(nri, networkAgent, notifyType, arg1);
        } else {
            sendPendingIntentForRequest(nri, networkAgent, notifyType);
        }
    }
}
Also used : NetworkRequest(android.net.NetworkRequest)

Example 75 with NetworkRequest

use of android.net.NetworkRequest in project android_frameworks_base by AOSPA.

the class ConnectivityService method teardownUnneededNetwork.

private void teardownUnneededNetwork(NetworkAgentInfo nai) {
    if (nai.numRequestNetworkRequests() != 0) {
        for (int i = 0; i < nai.numNetworkRequests(); i++) {
            NetworkRequest nr = nai.requestAt(i);
            // Ignore listening requests.
            if (nr.isListen())
                continue;
            loge("Dead network still had at least " + nr);
            break;
        }
    }
    nai.asyncChannel.disconnect();
}
Also used : NetworkRequest(android.net.NetworkRequest)

Aggregations

NetworkRequest (android.net.NetworkRequest)158 NetworkCapabilities (android.net.NetworkCapabilities)48 SmallTest (android.test.suitebuilder.annotation.SmallTest)43 ConditionVariable (android.os.ConditionVariable)24 LargeTest (android.test.suitebuilder.annotation.LargeTest)21 RemoteException (android.os.RemoteException)20 NetworkCallback (android.net.ConnectivityManager.NetworkCallback)18 Network (android.net.Network)16 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)15 LinkProperties (android.net.LinkProperties)14 ArrayList (java.util.ArrayList)9 ContentResolver (android.content.ContentResolver)8 HandlerThread (android.os.HandlerThread)8 MockContentResolver (android.test.mock.MockContentResolver)8 ConnectivityManager (android.net.ConnectivityManager)6 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)6 Intent (android.content.Intent)5 Bundle (android.os.Bundle)5 Message (android.os.Message)5 IBatteryStats (com.android.internal.app.IBatteryStats)5