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