Search in sources :

Example 31 with NetworkAgentInfo

use of com.android.server.connectivity.NetworkAgentInfo 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 32 with NetworkAgentInfo

use of com.android.server.connectivity.NetworkAgentInfo in project android_frameworks_base by DirtyUnicorns.

the class ConnectivityService method getUnfilteredActiveNetworkState.

private NetworkState getUnfilteredActiveNetworkState(int uid) {
    NetworkAgentInfo nai = getDefaultNetwork();
    final Network[] networks = getVpnUnderlyingNetworks(uid);
    if (networks != null) {
        //                    first one.
        if (networks.length > 0) {
            nai = getNetworkAgentInfoForNetwork(networks[0]);
        } else {
            nai = null;
        }
    }
    if (nai != null) {
        return nai.getNetworkState();
    } else {
        return NetworkState.EMPTY;
    }
}
Also used : NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) Network(android.net.Network)

Example 33 with NetworkAgentInfo

use of com.android.server.connectivity.NetworkAgentInfo in project android_frameworks_base by DirtyUnicorns.

the class ConnectivityService method reportNetworkConnectivity.

@Override
public void reportNetworkConnectivity(Network network, boolean hasConnectivity) {
    enforceAccessPermission();
    enforceInternetPermission();
    NetworkAgentInfo nai;
    if (network == null) {
        nai = getDefaultNetwork();
    } else {
        nai = getNetworkAgentInfoForNetwork(network);
    }
    if (nai == null || nai.networkInfo.getState() == NetworkInfo.State.DISCONNECTING || nai.networkInfo.getState() == NetworkInfo.State.DISCONNECTED) {
        return;
    }
    // Revalidate if the app report does not match our current validated state.
    if (hasConnectivity == nai.lastValidated)
        return;
    final int uid = Binder.getCallingUid();
    if (DBG) {
        log("reportNetworkConnectivity(" + nai.network.netId + ", " + hasConnectivity + ") by " + uid);
    }
    synchronized (nai) {
        // rematchNetworkAndRequests() which is not meant to work on such networks.
        if (!nai.everConnected)
            return;
        if (isNetworkWithLinkPropertiesBlocked(nai.linkProperties, uid, false))
            return;
        nai.networkMonitor.sendMessage(NetworkMonitor.CMD_FORCE_REEVALUATION, uid);
    }
}
Also used : NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo)

Example 34 with NetworkAgentInfo

use of com.android.server.connectivity.NetworkAgentInfo in project android_frameworks_base by DirtyUnicorns.

the class ConnectivityService method updateDnses.

private void updateDnses(LinkProperties newLp, LinkProperties oldLp, int netId) {
    if (oldLp != null && newLp.isIdenticalDnses(oldLp)) {
        // no updating necessary
        return;
    }
    Collection<InetAddress> dnses = newLp.getDnsServers();
    if (DBG)
        log("Setting DNS servers for network " + netId + " to " + dnses);
    try {
        mNetd.setDnsConfigurationForNetwork(netId, NetworkUtils.makeStrings(dnses), newLp.getDomains());
    } catch (Exception e) {
        loge("Exception in setDnsConfigurationForNetwork: " + e);
    }
    final NetworkAgentInfo defaultNai = getDefaultNetwork();
    if (defaultNai != null && defaultNai.network.netId == netId) {
        setDefaultDnsSystemProperties(dnses);
    }
    flushVmDnsCache();
}
Also used : NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) InetAddress(java.net.InetAddress) RemoteException(android.os.RemoteException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 35 with NetworkAgentInfo

use of com.android.server.connectivity.NetworkAgentInfo in project android_frameworks_base by DirtyUnicorns.

the class ConnectivityService method reportInetCondition.

// 100 percent is full good, 0 is full bad.
@Override
public void reportInetCondition(int networkType, int percentage) {
    NetworkAgentInfo nai = mLegacyTypeTracker.getNetworkForType(networkType);
    if (nai == null)
        return;
    reportNetworkConnectivity(nai.network, percentage > 50);
}
Also used : NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo)

Aggregations

NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)162 LinkProperties (android.net.LinkProperties)40 Network (android.net.Network)25 NetworkPolicyManager.uidRulesToString (android.net.NetworkPolicyManager.uidRulesToString)21 NetworkCapabilities (android.net.NetworkCapabilities)20 NetworkInfo (android.net.NetworkInfo)15 NetworkRequest (android.net.NetworkRequest)15 NetworkState (android.net.NetworkState)15 RemoteException (android.os.RemoteException)14 UnknownHostException (java.net.UnknownHostException)14 AsyncChannel (com.android.internal.util.AsyncChannel)10 Vpn (com.android.server.connectivity.Vpn)10 ArrayList (java.util.ArrayList)10 FileNotFoundException (java.io.FileNotFoundException)9 IOException (java.io.IOException)9 InetAddress (java.net.InetAddress)9 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)9 Nullable (android.annotation.Nullable)5 PendingIntent (android.app.PendingIntent)5 Intent (android.content.Intent)5