Search in sources :

Example 1 with CompareResult

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

the class ConnectivityService method updateRoutes.

/**
     * Add and remove routes using the old properties (null if not previously connected),
     * new properties (null if becoming disconnected).  May even be double null, which
     * is a noop.
     * Uses isLinkDefault to determine if default routes should be set or conversely if
     * host routes should be set to the dns servers
     * returns a boolean indicating the routes changed
     */
private boolean updateRoutes(LinkProperties newLp, LinkProperties curLp, boolean isLinkDefault) {
    Collection<RouteInfo> routesToAdd = null;
    CompareResult<InetAddress> dnsDiff = new CompareResult<InetAddress>();
    CompareResult<RouteInfo> routeDiff = new CompareResult<RouteInfo>();
    if (curLp != null) {
        // check for the delta between the current set and the new
        routeDiff = curLp.compareRoutes(newLp);
        dnsDiff = curLp.compareDnses(newLp);
    } else if (newLp != null) {
        routeDiff.added = newLp.getAllRoutes();
        dnsDiff.added = newLp.getDnses();
    }
    boolean routesChanged = (routeDiff.removed.size() != 0 || routeDiff.added.size() != 0);
    for (RouteInfo r : routeDiff.removed) {
        if (isLinkDefault || !r.isDefaultRoute()) {
            if (VDBG)
                log("updateRoutes: default remove route r=" + r);
            removeRoute(curLp, r, TO_DEFAULT_TABLE);
        }
        if (isLinkDefault == false) {
            // remove from a secondary route table
            removeRoute(curLp, r, TO_SECONDARY_TABLE);
        }
    }
    if (!isLinkDefault) {
        // handle DNS routes
        if (routesChanged) {
            // routes changed - remove all old dns entries and add new
            if (curLp != null) {
                for (InetAddress oldDns : curLp.getDnses()) {
                    removeRouteToAddress(curLp, oldDns);
                }
            }
            if (newLp != null) {
                for (InetAddress newDns : newLp.getDnses()) {
                    addRouteToAddress(newLp, newDns);
                }
            }
        } else {
            // no change in routes, check for change in dns themselves
            for (InetAddress oldDns : dnsDiff.removed) {
                removeRouteToAddress(curLp, oldDns);
            }
            for (InetAddress newDns : dnsDiff.added) {
                addRouteToAddress(newLp, newDns);
            }
        }
    }
    for (RouteInfo r : routeDiff.added) {
        if (isLinkDefault || !r.isDefaultRoute()) {
            addRoute(newLp, r, TO_DEFAULT_TABLE);
        } else {
            // add to a secondary route table
            addRoute(newLp, r, TO_SECONDARY_TABLE);
            // many radios add a default route even when we don't want one.
            // remove the default route unless somebody else has asked for it
            String ifaceName = newLp.getInterfaceName();
            if (TextUtils.isEmpty(ifaceName) == false && mAddedRoutes.contains(r) == false) {
                try {
                    mNetd.removeRoute(ifaceName, r);
                } catch (Exception e) {
                    // never crash - catch them all
                    if (DBG)
                        loge("Exception trying to remove a route: " + e);
                }
            }
        }
    }
    return routesChanged;
}
Also used : RouteInfo(android.net.RouteInfo) CompareResult(android.net.LinkProperties.CompareResult) 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) ActivityNotFoundException(android.content.ActivityNotFoundException)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)1 CompareResult (android.net.LinkProperties.CompareResult)1 RouteInfo (android.net.RouteInfo)1 RemoteException (android.os.RemoteException)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)1