Search in sources :

Example 6 with NetworkRequest

use of android.net.NetworkRequest in project platform_frameworks_base by android.

the class ConnectivityService method listenForNetwork.

@Override
public NetworkRequest listenForNetwork(NetworkCapabilities networkCapabilities, Messenger messenger, IBinder binder) {
    if (!hasWifiNetworkListenPermission(networkCapabilities)) {
        enforceAccessPermission();
    }
    NetworkCapabilities nc = new NetworkCapabilities(networkCapabilities);
    if (!ConnectivityManager.checkChangePermission(mContext)) {
        // Apps without the CHANGE_NETWORK_STATE permission can't use background networks, so
        // make all their listens include NET_CAPABILITY_FOREGROUND. That way, they will get
        // onLost and onAvailable callbacks when networks move in and out of the background.
        // There is no need to do this for requests because an app without CHANGE_NETWORK_STATE
        // can't request networks.
        nc.addCapability(NET_CAPABILITY_FOREGROUND);
    }
    NetworkRequest networkRequest = new NetworkRequest(nc, TYPE_NONE, nextNetworkRequestId(), NetworkRequest.Type.LISTEN);
    NetworkRequestInfo nri = new NetworkRequestInfo(messenger, networkRequest, binder);
    if (VDBG)
        log("listenForNetwork for " + nri);
    mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_LISTENER, nri));
    return networkRequest;
}
Also used : NetworkRequest(android.net.NetworkRequest) NetworkCapabilities(android.net.NetworkCapabilities)

Example 7 with NetworkRequest

use of android.net.NetworkRequest in project platform_frameworks_base by android.

the class ConnectivityService method createInternetRequestForTransport.

private NetworkRequest createInternetRequestForTransport(int transportType, NetworkRequest.Type type) {
    NetworkCapabilities netCap = new NetworkCapabilities();
    netCap.addCapability(NET_CAPABILITY_INTERNET);
    netCap.addCapability(NET_CAPABILITY_NOT_RESTRICTED);
    if (transportType > -1) {
        netCap.addTransportType(transportType);
    }
    return new NetworkRequest(netCap, TYPE_NONE, nextNetworkRequestId(), type);
}
Also used : NetworkRequest(android.net.NetworkRequest) NetworkCapabilities(android.net.NetworkCapabilities)

Example 8 with NetworkRequest

use of android.net.NetworkRequest in project platform_frameworks_base by android.

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);
            notifyNetworkAvailable(nai, nri);
        }
    }
}
Also used : NetworkRequest(android.net.NetworkRequest)

Example 9 with NetworkRequest

use of android.net.NetworkRequest in project platform_frameworks_base by android.

the class UpstreamNetworkMonitor method start.

public void start() {
    stop();
    final NetworkRequest listenAllRequest = new NetworkRequest.Builder().clearCapabilities().build();
    mListenAllCallback = new UpstreamNetworkCallback(CALLBACK_LISTEN_ALL);
    cm().registerNetworkCallback(listenAllRequest, mListenAllCallback, mHandler);
    mDefaultNetworkCallback = new UpstreamNetworkCallback(CALLBACK_TRACK_DEFAULT);
    cm().registerDefaultNetworkCallback(mDefaultNetworkCallback, mHandler);
}
Also used : NetworkRequest(android.net.NetworkRequest)

Example 10 with NetworkRequest

use of android.net.NetworkRequest in project platform_frameworks_base by android.

the class UpstreamNetworkMonitor method registerMobileNetworkRequest.

public void registerMobileNetworkRequest() {
    if (mMobileNetworkCallback != null) {
        Log.e(TAG, "registerMobileNetworkRequest() already registered");
        return;
    }
    // The following use of the legacy type system cannot be removed until
    // after upstream selection no longer finds networks by legacy type.
    // See also http://b/34364553 .
    final int legacyType = mDunRequired ? TYPE_MOBILE_DUN : TYPE_MOBILE_HIPRI;
    final NetworkRequest mobileUpstreamRequest = new NetworkRequest.Builder().setCapabilities(ConnectivityManager.networkCapabilitiesForType(legacyType)).build();
    // The existing default network and DUN callbacks will be notified.
    // Therefore, to avoid duplicate notifications, we only register a no-op.
    mMobileNetworkCallback = new UpstreamNetworkCallback(CALLBACK_MOBILE_REQUEST);
    // TODO: Change the timeout from 0 (no onUnavailable callback) to some
    // moderate callback timeout. This might be useful for updating some UI.
    // Additionally, we log a message to aid in any subsequent debugging.
    Log.d(TAG, "requesting mobile upstream network: " + mobileUpstreamRequest);
    cm().requestNetwork(mobileUpstreamRequest, mMobileNetworkCallback, 0, legacyType, mHandler);
}
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