Search in sources :

Example 61 with NetworkCapabilities

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

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

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

the class ConnectivityService method removeDataActivityTracking.

/**
     * Remove data activity tracking when network disconnects.
     */
private void removeDataActivityTracking(NetworkAgentInfo networkAgent) {
    final String iface = networkAgent.linkProperties.getInterfaceName();
    final NetworkCapabilities caps = networkAgent.networkCapabilities;
    if (iface != null && (caps.hasTransport(NetworkCapabilities.TRANSPORT_CELLULAR) || caps.hasTransport(NetworkCapabilities.TRANSPORT_WIFI))) {
        try {
            // the call fails silently if no idletimer setup for this interface
            mNetd.removeIdleTimer(iface);
        } catch (Exception e) {
            loge("Exception in removeDataActivityTracking " + e);
        }
    }
}
Also used : NetworkPolicyManager.uidRulesToString(android.net.NetworkPolicyManager.uidRulesToString) NetworkCapabilities(android.net.NetworkCapabilities) RemoteException(android.os.RemoteException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 63 with NetworkCapabilities

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

the class ConnectivityService method callCallbackForRequest.

private void callCallbackForRequest(NetworkRequestInfo nri, NetworkAgentInfo networkAgent, int notificationType, int arg1) {
    // Default request has no msgr
    if (nri.messenger == null)
        return;
    Bundle bundle = new Bundle();
    bundle.putParcelable(NetworkRequest.class.getSimpleName(), new NetworkRequest(nri.request));
    Message msg = Message.obtain();
    if (notificationType != ConnectivityManager.CALLBACK_UNAVAIL && notificationType != ConnectivityManager.CALLBACK_RELEASED) {
        bundle.putParcelable(Network.class.getSimpleName(), networkAgent.network);
    }
    switch(notificationType) {
        case ConnectivityManager.CALLBACK_LOSING:
            {
                msg.arg1 = arg1;
                break;
            }
        case ConnectivityManager.CALLBACK_CAP_CHANGED:
            {
                bundle.putParcelable(NetworkCapabilities.class.getSimpleName(), new NetworkCapabilities(networkAgent.networkCapabilities));
                break;
            }
        case ConnectivityManager.CALLBACK_IP_CHANGED:
            {
                bundle.putParcelable(LinkProperties.class.getSimpleName(), new LinkProperties(networkAgent.linkProperties));
                break;
            }
    }
    msg.what = notificationType;
    msg.setData(bundle);
    try {
        if (VDBG) {
            log("sending notification " + notifyTypeToName(notificationType) + " for " + nri.request);
        }
        nri.messenger.send(msg);
    } catch (RemoteException e) {
        // may occur naturally in the race of binder death.
        loge("RemoteException caught trying to send a callback msg for " + nri.request);
    }
}
Also used : Message(android.os.Message) WakeupMessage(com.android.internal.util.WakeupMessage) Bundle(android.os.Bundle) Network(android.net.Network) NetworkRequest(android.net.NetworkRequest) RemoteException(android.os.RemoteException) NetworkCapabilities(android.net.NetworkCapabilities) LinkProperties(android.net.LinkProperties)

Example 64 with NetworkCapabilities

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

the class ConnectivityManagerTest method verifyRestrictedMobileNetworkCapabilities.

static void verifyRestrictedMobileNetworkCapabilities(int legacyType, int capability) {
    final NetworkCapabilities nc = verifyNetworkCapabilities(legacyType, TRANSPORT_CELLULAR, capability, NET_CAPABILITY_NOT_VPN, NET_CAPABILITY_TRUSTED);
    assertFalse(nc.hasCapability(NET_CAPABILITY_INTERNET));
    assertFalse(nc.hasCapability(NET_CAPABILITY_NOT_RESTRICTED));
}
Also used : NetworkCapabilities(android.net.NetworkCapabilities)

Example 65 with NetworkCapabilities

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

the class ConnectivityManagerTest method testNetworkCapabilitiesForTypeMobileSupl.

@Test
public void testNetworkCapabilitiesForTypeMobileSupl() {
    final NetworkCapabilities nc = verifyNetworkCapabilities(ConnectivityManager.TYPE_MOBILE_SUPL, TRANSPORT_CELLULAR, NET_CAPABILITY_SUPL, NET_CAPABILITY_NOT_VPN, NET_CAPABILITY_TRUSTED);
    assertFalse(nc.hasCapability(NET_CAPABILITY_INTERNET));
}
Also used : NetworkCapabilities(android.net.NetworkCapabilities) SmallTest(android.support.test.filters.SmallTest) Test(org.junit.Test)

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