Apply the dns and route diff which we get a change

bug:5008973
Change-Id: Ib99e43d9d852452cc1f2aea6bef07bbd194f28cc
This commit is contained in:
Robert Greenwalt 2011-07-14 14:28:05 -07:00
commit e8d2a4a8a0
2 changed files with 221 additions and 177 deletions

View file

@ -57,16 +57,16 @@ public class LinkProperties implements Parcelable {
private Collection<RouteInfo> mRoutes = new ArrayList<RouteInfo>();
private ProxyProperties mHttpProxy;
public static class CompareAddressesResult {
public ArrayList<LinkAddress> removed = new ArrayList<LinkAddress>();
public ArrayList<LinkAddress> added = new ArrayList<LinkAddress>();
public static class CompareResult<T> {
public ArrayList<T> removed = new ArrayList<T>();
public ArrayList<T> added = new ArrayList<T>();
@Override
public String toString() {
String retVal = "removedAddresses=[";
for (LinkAddress addr : removed) retVal += addr.toString() + ",";
retVal += "] addedAddresses=[";
for (LinkAddress addr : added) retVal += addr.toString() + ",";
String retVal = "removed=[";
for (T addr : removed) retVal += addr.toString() + ",";
retVal += "] added=[";
for (T addr : added) retVal += addr.toString() + ",";
retVal += "]";
return retVal;
}
@ -263,10 +263,10 @@ public class LinkProperties implements Parcelable {
* mLinkAddress which would then result in target and mLinkAddresses
* being the same list.
*
* @param target is a new list of addresses
* @param target is a LinkProperties with the new list of addresses
* @return the removed and added lists.
*/
public CompareAddressesResult compareAddresses(LinkProperties target) {
public CompareResult<LinkAddress> compareAddresses(LinkProperties target) {
/*
* Duplicate the LinkAddresses into removed, we will be removing
* address which are common between mLinkAddresses and target
@ -274,17 +274,81 @@ public class LinkProperties implements Parcelable {
* are in target but not in mLinkAddresses are placed in the
* addedAddresses.
*/
CompareAddressesResult result = new CompareAddressesResult();
CompareResult<LinkAddress> result = new CompareResult<LinkAddress>();
result.removed = new ArrayList<LinkAddress>(mLinkAddresses);
result.added.clear();
for (LinkAddress newAddress : target.getLinkAddresses()) {
if (! result.removed.remove(newAddress)) {
result.added.add(newAddress);
if (target != null) {
for (LinkAddress newAddress : target.getLinkAddresses()) {
if (! result.removed.remove(newAddress)) {
result.added.add(newAddress);
}
}
}
return result;
}
/**
* Return two lists, a list of dns addresses that would be removed from
* mDnses and a list of addresses that would be added to
* mDnses which would then result in target and mDnses
* being the same list.
*
* @param target is a LinkProperties with the new list of dns addresses
* @return the removed and added lists.
*/
public CompareResult<InetAddress> compareDnses(LinkProperties target) {
/*
* Duplicate the InetAddresses into removed, we will be removing
* dns address which are common between mDnses and target
* leaving the addresses that are different. And dns address which
* are in target but not in mDnses are placed in the
* addedAddresses.
*/
CompareResult<InetAddress> result = new CompareResult<InetAddress>();
result.removed = new ArrayList<InetAddress>(mDnses);
result.added.clear();
if (target != null) {
for (InetAddress newAddress : target.getDnses()) {
if (! result.removed.remove(newAddress)) {
result.added.add(newAddress);
}
}
}
return result;
}
/**
* Return two lists, a list of routes that would be removed from
* mRoutes and a list of routes that would be added to
* mRoutes which would then result in target and mRoutes
* being the same list.
*
* @param target is a LinkProperties with the new list of routes
* @return the removed and added lists.
*/
public CompareResult<RouteInfo> compareRoutes(LinkProperties target) {
/*
* Duplicate the RouteInfos into removed, we will be removing
* routes which are common between mDnses and target
* leaving the routes that are different. And route address which
* are in target but not in mRoutes are placed in added.
*/
CompareResult<RouteInfo> result = new CompareResult<RouteInfo>();
result.removed = new ArrayList<RouteInfo>(mRoutes);
result.added.clear();
if (target != null) {
for (RouteInfo r : target.getRoutes()) {
if (! result.removed.remove(r)) {
result.added.add(r);
}
}
}
return result;
}
@Override
/**
* generate hashcode based on significant fields

View file

@ -43,6 +43,7 @@ public class RouteInfo implements Parcelable {
private final InetAddress mGateway;
private final boolean mIsDefault;
private final boolean mIsHost;
public RouteInfo(LinkAddress destination, InetAddress gateway) {
if (destination == null) {
@ -68,6 +69,7 @@ public class RouteInfo implements Parcelable {
destination.getNetworkPrefixLength()), destination.getNetworkPrefixLength());
mGateway = gateway;
mIsDefault = isDefault();
mIsHost = isHost();
}
public RouteInfo(InetAddress gateway) {
@ -88,6 +90,10 @@ public class RouteInfo implements Parcelable {
}
}
private boolean isHost() {
return (mGateway.equals(Inet4Address.ANY) || mGateway.equals(Inet6Address.ANY));
}
private boolean isDefault() {
boolean val = false;
if (mGateway != null) {
@ -100,6 +106,7 @@ public class RouteInfo implements Parcelable {
return val;
}
public LinkAddress getDestination() {
return mDestination;
}
@ -112,6 +119,10 @@ public class RouteInfo implements Parcelable {
return mIsDefault;
}
public boolean isHostRoute() {
return mIsHost;
}
public String toString() {
String val = "";
if (mDestination != null) val = mDestination.toString();