Search in sources :

Example 31 with NetworkCapabilities

use of android.net.NetworkCapabilities in project android_frameworks_base by DirtyUnicorns.

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 32 with NetworkCapabilities

use of android.net.NetworkCapabilities in project android_frameworks_base by DirtyUnicorns.

the class ConnectivityService method pendingListenForNetwork.

@Override
public void pendingListenForNetwork(NetworkCapabilities networkCapabilities, PendingIntent operation) {
    checkNotNull(operation, "PendingIntent cannot be null.");
    if (!hasWifiNetworkListenPermission(networkCapabilities)) {
        enforceAccessPermission();
    }
    NetworkRequest networkRequest = new NetworkRequest(new NetworkCapabilities(networkCapabilities), TYPE_NONE, nextNetworkRequestId(), NetworkRequest.Type.LISTEN);
    NetworkRequestInfo nri = new NetworkRequestInfo(networkRequest, operation);
    if (VDBG)
        log("pendingListenForNetwork for " + nri);
    mHandler.sendMessage(mHandler.obtainMessage(EVENT_REGISTER_NETWORK_LISTENER, nri));
}
Also used : NetworkRequest(android.net.NetworkRequest) NetworkCapabilities(android.net.NetworkCapabilities)

Example 33 with NetworkCapabilities

use of android.net.NetworkCapabilities in project android_frameworks_base by DirtyUnicorns.

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 34 with NetworkCapabilities

use of android.net.NetworkCapabilities in project android_frameworks_base by DirtyUnicorns.

the class ConnectivityService method getDefaultNetworkCapabilitiesForUser.

@Override
public NetworkCapabilities[] getDefaultNetworkCapabilitiesForUser(int userId) {
    // The basic principle is: if an app's traffic could possibly go over a
    // network, without the app doing anything multinetwork-specific,
    // (hence, by "default"), then include that network's capabilities in
    // the array.
    //
    // In the normal case, app traffic only goes over the system's default
    // network connection, so that's the only network returned.
    //
    // With a VPN in force, some app traffic may go into the VPN, and thus
    // over whatever underlying networks the VPN specifies, while other app
    // traffic may go over the system default network (e.g.: a split-tunnel
    // VPN, or an app disallowed by the VPN), so the set of networks
    // returned includes the VPN's underlying networks and the system
    // default.
    enforceAccessPermission();
    HashMap<Network, NetworkCapabilities> result = new HashMap<Network, NetworkCapabilities>();
    NetworkAgentInfo nai = getDefaultNetwork();
    NetworkCapabilities nc = getNetworkCapabilitiesInternal(nai);
    if (nc != null) {
        result.put(nai.network, nc);
    }
    if (!mLockdownEnabled) {
        synchronized (mVpns) {
            Vpn vpn = mVpns.get(userId);
            if (vpn != null) {
                Network[] networks = vpn.getUnderlyingNetworks();
                if (networks != null) {
                    for (Network network : networks) {
                        nai = getNetworkAgentInfoForNetwork(network);
                        nc = getNetworkCapabilitiesInternal(nai);
                        if (nc != null) {
                            result.put(network, nc);
                        }
                    }
                }
            }
        }
    }
    NetworkCapabilities[] out = new NetworkCapabilities[result.size()];
    out = result.values().toArray(out);
    return out;
}
Also used : HashMap(java.util.HashMap) Vpn(com.android.server.connectivity.Vpn) NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) Network(android.net.Network) NetworkCapabilities(android.net.NetworkCapabilities)

Example 35 with NetworkCapabilities

use of android.net.NetworkCapabilities in project android_frameworks_base by DirtyUnicorns.

the class ConnectivityServiceTest method isForegroundNetwork.

private boolean isForegroundNetwork(MockNetworkAgent network) {
    NetworkCapabilities nc = mCm.getNetworkCapabilities(network.getNetwork());
    assertNotNull(nc);
    return nc.hasCapability(NET_CAPABILITY_FOREGROUND);
}
Also used : NetworkCapabilities(android.net.NetworkCapabilities)

Aggregations

NetworkCapabilities (android.net.NetworkCapabilities)114 NetworkRequest (android.net.NetworkRequest)53 Network (android.net.Network)27 RemoteException (android.os.RemoteException)25 LinkProperties (android.net.LinkProperties)23 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)20 NetworkInfo (android.net.NetworkInfo)18 ConnectivityManager (android.net.ConnectivityManager)15 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)15 SmallTest (android.test.suitebuilder.annotation.SmallTest)12 NetworkCallback (android.net.ConnectivityManager.NetworkCallback)10 NetworkState (android.net.NetworkState)8 HandlerThread (android.os.HandlerThread)8 NetworkMisc (android.net.NetworkMisc)5 IWifiManager (android.net.wifi.IWifiManager)5 WifiManager (android.net.wifi.WifiManager)5 Bundle (android.os.Bundle)5 Message (android.os.Message)5 ServiceState (android.telephony.ServiceState)5 SignalStrength (android.telephony.SignalStrength)5