Search in sources :

Example 6 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ParanoidAndroid.

the class WifiConfigStore method copyIpSettingsFromConfig.

private LinkProperties copyIpSettingsFromConfig(WifiConfiguration config) {
    LinkProperties linkProperties = new LinkProperties();
    linkProperties.setInterfaceName(config.linkProperties.getInterfaceName());
    for (LinkAddress linkAddr : config.linkProperties.getLinkAddresses()) {
        linkProperties.addLinkAddress(linkAddr);
    }
    for (RouteInfo route : config.linkProperties.getRoutes()) {
        linkProperties.addRoute(route);
    }
    for (InetAddress dns : config.linkProperties.getDnses()) {
        linkProperties.addDns(dns);
    }
    return linkProperties;
}
Also used : LinkAddress(android.net.LinkAddress) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Example 7 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ParanoidAndroid.

the class WifiConfigStore method writeIpAndProxyConfigurationsOnChange.

/* Compare current and new configuration and write to file on change */
private NetworkUpdateResult writeIpAndProxyConfigurationsOnChange(WifiConfiguration currentConfig, WifiConfiguration newConfig) {
    boolean ipChanged = false;
    boolean proxyChanged = false;
    LinkProperties linkProperties = null;
    switch(newConfig.ipAssignment) {
        case STATIC:
            Collection<LinkAddress> currentLinkAddresses = currentConfig.linkProperties.getLinkAddresses();
            Collection<LinkAddress> newLinkAddresses = newConfig.linkProperties.getLinkAddresses();
            Collection<InetAddress> currentDnses = currentConfig.linkProperties.getDnses();
            Collection<InetAddress> newDnses = newConfig.linkProperties.getDnses();
            Collection<RouteInfo> currentRoutes = currentConfig.linkProperties.getRoutes();
            Collection<RouteInfo> newRoutes = newConfig.linkProperties.getRoutes();
            boolean linkAddressesDiffer = (currentLinkAddresses.size() != newLinkAddresses.size()) || !currentLinkAddresses.containsAll(newLinkAddresses);
            boolean dnsesDiffer = (currentDnses.size() != newDnses.size()) || !currentDnses.containsAll(newDnses);
            boolean routesDiffer = (currentRoutes.size() != newRoutes.size()) || !currentRoutes.containsAll(newRoutes);
            if ((currentConfig.ipAssignment != newConfig.ipAssignment) || linkAddressesDiffer || dnsesDiffer || routesDiffer) {
                ipChanged = true;
            }
            break;
        case DHCP:
            if (currentConfig.ipAssignment != newConfig.ipAssignment) {
                ipChanged = true;
            }
            break;
        case UNASSIGNED:
            /* Ignore */
            break;
        default:
            loge("Ignore invalid ip assignment during write");
            break;
    }
    switch(newConfig.proxySettings) {
        case STATIC:
            ProxyProperties newHttpProxy = newConfig.linkProperties.getHttpProxy();
            ProxyProperties currentHttpProxy = currentConfig.linkProperties.getHttpProxy();
            if (newHttpProxy != null) {
                proxyChanged = !newHttpProxy.equals(currentHttpProxy);
            } else {
                proxyChanged = (currentHttpProxy != null);
            }
            break;
        case NONE:
            if (currentConfig.proxySettings != newConfig.proxySettings) {
                proxyChanged = true;
            }
            break;
        case UNASSIGNED:
            /* Ignore */
            break;
        default:
            loge("Ignore invalid proxy configuration during write");
            break;
    }
    if (!ipChanged) {
        linkProperties = copyIpSettingsFromConfig(currentConfig);
    } else {
        currentConfig.ipAssignment = newConfig.ipAssignment;
        linkProperties = copyIpSettingsFromConfig(newConfig);
        log("IP config changed SSID = " + currentConfig.SSID + " linkProperties: " + linkProperties.toString());
    }
    if (!proxyChanged) {
        linkProperties.setHttpProxy(currentConfig.linkProperties.getHttpProxy());
    } else {
        currentConfig.proxySettings = newConfig.proxySettings;
        linkProperties.setHttpProxy(newConfig.linkProperties.getHttpProxy());
        log("proxy changed SSID = " + currentConfig.SSID);
        if (linkProperties.getHttpProxy() != null) {
            log(" proxyProperties: " + linkProperties.getHttpProxy().toString());
        }
    }
    if (ipChanged || proxyChanged) {
        currentConfig.linkProperties = linkProperties;
        writeIpAndProxyConfigurations();
        sendConfiguredNetworksChangedBroadcast(currentConfig, WifiManager.CHANGE_REASON_CONFIG_CHANGE);
    }
    return new NetworkUpdateResult(ipChanged, proxyChanged);
}
Also used : LinkAddress(android.net.LinkAddress) ProxyProperties(android.net.ProxyProperties) NetworkUpdateResult(android.net.wifi.NetworkUpdateResult) RouteInfo(android.net.RouteInfo) LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Example 8 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ParanoidAndroid.

the class WifiStateMachine method sendLinkConfigurationChangedBroadcast.

private void sendLinkConfigurationChangedBroadcast() {
    Intent intent = new Intent(WifiManager.LINK_CONFIGURATION_CHANGED_ACTION);
    intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT);
    intent.putExtra(WifiManager.EXTRA_LINK_PROPERTIES, new LinkProperties(mLinkProperties));
    mContext.sendBroadcastAsUser(intent, UserHandle.ALL);
}
Also used : PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) LinkProperties(android.net.LinkProperties)

Example 9 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ParanoidAndroid.

the class WifiStateMachine method handleSuccessfulIpConfiguration.

private void handleSuccessfulIpConfiguration(DhcpResults dhcpResults) {
    // force update of signal strength
    mLastSignalLevel = -1;
    //Reset IP failure tracking
    mReconnectCount = 0;
    synchronized (mDhcpResultsLock) {
        mDhcpResults = dhcpResults;
    }
    LinkProperties linkProperties = dhcpResults.linkProperties;
    mWifiConfigStore.setLinkProperties(mLastNetworkId, new LinkProperties(linkProperties));
    InetAddress addr = null;
    Iterator<InetAddress> addrs = linkProperties.getAddresses().iterator();
    if (addrs.hasNext()) {
        addr = addrs.next();
    }
    mWifiInfo.setInetAddress(addr);
    mWifiInfo.setMeteredHint(dhcpResults.hasMeteredHint());
    if (getNetworkDetailedState() == DetailedState.CONNECTED) {
        //DHCP renewal in connected state
        linkProperties.setHttpProxy(mWifiConfigStore.getProxyProperties(mLastNetworkId));
        if (!linkProperties.equals(mLinkProperties)) {
            if (DBG) {
                log("Link configuration changed for netId: " + mLastNetworkId + " old: " + mLinkProperties + "new: " + linkProperties);
            }
            mLinkProperties = linkProperties;
            sendLinkConfigurationChangedBroadcast();
        }
    } else {
        configureLinkProperties();
    }
}
Also used : LinkProperties(android.net.LinkProperties) InetAddress(java.net.InetAddress)

Example 10 with LinkProperties

use of android.net.LinkProperties in project android_frameworks_base by ParanoidAndroid.

the class LinkPropertiesTest method testRouteInterfaces.

@SmallTest
public void testRouteInterfaces() {
    LinkAddress prefix = new LinkAddress(NetworkUtils.numericToInetAddress("2001:db8::"), 32);
    InetAddress address = NetworkUtils.numericToInetAddress(ADDRV6);
    // Add a route with no interface to a LinkProperties with no interface. No errors.
    LinkProperties lp = new LinkProperties();
    RouteInfo r = new RouteInfo(prefix, address, null);
    lp.addRoute(r);
    assertEquals(1, lp.getRoutes().size());
    assertAllRoutesHaveInterface(null, lp);
    // Add a route with an interface. Except an exception.
    r = new RouteInfo(prefix, address, "wlan0");
    try {
        lp.addRoute(r);
        fail("Adding wlan0 route to LP with no interface, expect exception");
    } catch (IllegalArgumentException expected) {
    }
    // Change the interface name. All the routes should change their interface name too.
    lp.setInterfaceName("rmnet0");
    assertAllRoutesHaveInterface("rmnet0", lp);
    // Now add a route with the wrong interface. This causes an exception too.
    try {
        lp.addRoute(r);
        fail("Adding wlan0 route to rmnet0 LP, expect exception");
    } catch (IllegalArgumentException expected) {
    }
    // If the interface name matches, the route is added.
    lp.setInterfaceName("wlan0");
    lp.addRoute(r);
    assertEquals(2, lp.getRoutes().size());
    assertAllRoutesHaveInterface("wlan0", lp);
    // Routes with null interfaces are converted to wlan0.
    r = RouteInfo.makeHostRoute(NetworkUtils.numericToInetAddress(ADDRV6), null);
    lp.addRoute(r);
    assertEquals(3, lp.getRoutes().size());
    assertAllRoutesHaveInterface("wlan0", lp);
    // Check comparisons work.
    LinkProperties lp2 = new LinkProperties(lp);
    assertAllRoutesHaveInterface("wlan0", lp);
    assertEquals(0, lp.compareRoutes(lp2).added.size());
    assertEquals(0, lp.compareRoutes(lp2).removed.size());
    lp2.setInterfaceName("p2p0");
    assertAllRoutesHaveInterface("p2p0", lp2);
    assertEquals(3, lp.compareRoutes(lp2).added.size());
    assertEquals(3, lp.compareRoutes(lp2).removed.size());
}
Also used : RouteInfo(android.net.RouteInfo) InetAddress(java.net.InetAddress) LinkProperties(android.net.LinkProperties) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

LinkProperties (android.net.LinkProperties)330 LinkAddress (android.net.LinkAddress)78 RouteInfo (android.net.RouteInfo)73 SmallTest (android.test.suitebuilder.annotation.SmallTest)68 InetAddress (java.net.InetAddress)56 Network (android.net.Network)43 NetworkInfo (android.net.NetworkInfo)40 NetworkAgentInfo (com.android.server.connectivity.NetworkAgentInfo)40 RemoteException (android.os.RemoteException)37 NetworkState (android.net.NetworkState)36 NetworkCapabilities (android.net.NetworkCapabilities)25 NetworkRequest (android.net.NetworkRequest)22 ArrayList (java.util.ArrayList)22 ProvisioningChange (android.net.LinkProperties.ProvisioningChange)20 Test (org.junit.Test)19 ConnectivityManager (android.net.ConnectivityManager)17 IpPrefix (android.net.IpPrefix)15 Inet6Address (java.net.Inet6Address)15 UnknownHostException (java.net.UnknownHostException)13 ApfFilter (android.net.apf.ApfFilter)12