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;
}
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);
}
}
}
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);
}
}
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));
}
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));
}
Aggregations