Search in sources :

Example 41 with Network

use of android.net.Network in project android_frameworks_base by crdroidandroid.

the class OSUManager method wnmRemediate.

// !!! Consistently check passpoint match.
// !!! Convert to a one-thread thread-pool
public void wnmRemediate(long bssid, String url, PasspointMatch match) throws IOException, SAXException {
    WifiConfiguration config = mWifiNetworkAdapter.getActiveWifiConfig();
    HomeSP homeSP = MOManager.buildSP(config.getMoTree());
    if (homeSP == null) {
        throw new IOException("Remediation request for unidentified Passpoint network " + config.networkId);
    }
    Network network = mWifiNetworkAdapter.getCurrentNetwork();
    if (network == null) {
        throw new IOException("Failed to determine current network");
    }
    WifiInfo wifiInfo = mWifiNetworkAdapter.getConnectionInfo();
    if (wifiInfo == null || Utils.parseMac(wifiInfo.getBSSID()) != bssid) {
        throw new IOException("Mismatching BSSID");
    }
    Log.d(TAG, "WNM Remediation on " + network.netId + " FQDN " + homeSP.getFQDN());
    doRemediate(url, network, homeSP, false);
}
Also used : HomeSP(com.android.hotspot2.pps.HomeSP) WifiConfiguration(android.net.wifi.WifiConfiguration) Network(android.net.Network) IOException(java.io.IOException) WifiInfo(android.net.wifi.WifiInfo)

Example 42 with Network

use of android.net.Network in project android_frameworks_base by AOSPA.

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 43 with Network

use of android.net.Network in project android_frameworks_base by AOSPA.

the class NetworkTest method testZeroIsObviousForDebugging.

@SmallTest
public void testZeroIsObviousForDebugging() {
    Network zero = new Network(0);
    assertEquals(0, zero.hashCode());
    assertEquals(0, zero.getNetworkHandle());
    assertEquals("0", zero.toString());
}
Also used : Network(android.net.Network) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 44 with Network

use of android.net.Network in project android_frameworks_base by AOSPA.

the class ConnectivityService method getAllNetworkState.

@Override
public NetworkState[] getAllNetworkState() {
    // Require internal since we're handing out IMSI details
    enforceConnectivityInternalPermission();
    final ArrayList<NetworkState> result = Lists.newArrayList();
    for (Network network : getAllNetworks()) {
        final NetworkAgentInfo nai = getNetworkAgentInfoForNetwork(network);
        if (nai != null) {
            result.add(nai.getNetworkState());
        }
    }
    return result.toArray(new NetworkState[result.size()]);
}
Also used : NetworkAgentInfo(com.android.server.connectivity.NetworkAgentInfo) Network(android.net.Network) NetworkState(android.net.NetworkState)

Example 45 with Network

use of android.net.Network in project NetGuard by M66B.

the class Util method getDefaultDNS.

public static List<String> getDefaultDNS(Context context) {
    String dns1 = null;
    String dns2 = null;
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.N) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        Network an = cm.getActiveNetwork();
        if (an != null) {
            LinkProperties lp = cm.getLinkProperties(an);
            if (lp != null) {
                List<InetAddress> dns = lp.getDnsServers();
                if (dns != null) {
                    if (dns.size() > 0)
                        dns1 = dns.get(0).getHostAddress();
                    if (dns.size() > 1)
                        dns2 = dns.get(1).getHostAddress();
                    for (InetAddress d : dns) Log.i(TAG, "DNS from LP: " + d.getHostAddress());
                }
            }
        }
    } else {
        dns1 = jni_getprop("net.dns1");
        dns2 = jni_getprop("net.dns2");
    }
    List<String> listDns = new ArrayList<>();
    listDns.add(TextUtils.isEmpty(dns1) ? "8.8.8.8" : dns1);
    listDns.add(TextUtils.isEmpty(dns2) ? "8.8.4.4" : dns2);
    return listDns;
}
Also used : ConnectivityManager(android.net.ConnectivityManager) Network(android.net.Network) ArrayList(java.util.ArrayList) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Aggregations

Network (android.net.Network)92 SmallTest (android.test.suitebuilder.annotation.SmallTest)28 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)25 NetworkCapabilities (android.net.NetworkCapabilities)22 NetworkRequest (android.net.NetworkRequest)18 NetworkInfo (android.net.NetworkInfo)17 LinkProperties (android.net.LinkProperties)16 ConnectivityManager (android.net.ConnectivityManager)11 NetworkCallback (android.net.ConnectivityManager.NetworkCallback)11 Test (org.junit.Test)7 InetAddress (java.net.InetAddress)6 Nullable (android.annotation.Nullable)5 NetworkMisc (android.net.NetworkMisc)5 NetworkState (android.net.NetworkState)5 WifiConfiguration (android.net.wifi.WifiConfiguration)5 WifiInfo (android.net.wifi.WifiInfo)5 ConditionVariable (android.os.ConditionVariable)5 WebSettings (android.webkit.WebSettings)5 HomeSP (com.android.hotspot2.pps.HomeSP)5 LegacyVpnInfo (com.android.internal.net.LegacyVpnInfo)5