diff options
| author | Tyler Wear <twear@quicinc.com> | 2019-12-05 14:55:30 -0800 |
|---|---|---|
| committer | Aaron Huang <huangaaron@google.com> | 2020-03-11 13:33:10 +0800 |
| commit | c299f17c0c4708a6a6e1fe039eec343d854eb3ff (patch) | |
| tree | 52dc3f3b24a21dbc74354d4b41ffed8485d51f76 /core/java | |
| parent | ea79b2ec1905129c0c06e4dcf14e5a4a1defa170 (diff) | |
mtu: Add MTU parameter to Routes
- Change route to update existing route
- MTU parameter added to AddRoute
Bug: 142892223
Test: unit test
Change-Id: Ie339d0cee5be12c2232a4631fed61219a0facc64
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/net/LinkProperties.java | 36 | ||||
| -rw-r--r-- | core/java/android/net/RouteInfo.java | 20 |
2 files changed, 49 insertions, 7 deletions
diff --git a/core/java/android/net/LinkProperties.java b/core/java/android/net/LinkProperties.java index 732ceb560cab..02e9b5061fc9 100644 --- a/core/java/android/net/LinkProperties.java +++ b/core/java/android/net/LinkProperties.java @@ -674,17 +674,29 @@ public final class LinkProperties implements Parcelable { route.getDestination(), route.getGateway(), mIfaceName, - route.getType()); + route.getType(), + route.getMtu()); + } + + private int findRouteIndexByDestination(RouteInfo route) { + for (int i = 0; i < mRoutes.size(); i++) { + if (mRoutes.get(i).isSameDestinationAs(route)) { + return i; + } + } + return -1; } /** - * Adds a {@link RouteInfo} to this {@code LinkProperties}, if not present. If the - * {@link RouteInfo} had an interface name set and that differs from the interface set for this - * {@code LinkProperties} an {@link IllegalArgumentException} will be thrown. The proper + * Adds a {@link RouteInfo} to this {@code LinkProperties}, if a {@link RouteInfo} + * with the same destination exists with different properties (e.g., different MTU), + * it will be updated. If the {@link RouteInfo} had an interface name set and + * that differs from the interface set for this {@code LinkProperties} an + * {@link IllegalArgumentException} will be thrown. The proper * course is to add either un-named or properly named {@link RouteInfo}. * * @param route A {@link RouteInfo} to add to this object. - * @return {@code false} if the route was already present, {@code true} if it was added. + * @return {@code true} was added or updated, false otherwise. */ public boolean addRoute(@NonNull RouteInfo route) { String routeIface = route.getInterface(); @@ -694,11 +706,20 @@ public final class LinkProperties implements Parcelable { + " vs. " + mIfaceName); } route = routeWithInterface(route); - if (!mRoutes.contains(route)) { + + int i = findRouteIndexByDestination(route); + if (i == -1) { + // Route was not present. Add it. mRoutes.add(route); return true; + } else if (mRoutes.get(i).equals(route)) { + // Route was present and has same properties. Do nothing. + return false; + } else { + // Route was present and has different properties. Update it. + mRoutes.set(i, route); + return true; } - return false; } /** @@ -706,6 +727,7 @@ public final class LinkProperties implements Parcelable { * specify an interface and the interface must match the interface of this * {@code LinkProperties}, or it will not be removed. * + * @param route A {@link RouteInfo} specifying the route to remove. * @return {@code true} if the route was removed, {@code false} if it was not present. * * @hide diff --git a/core/java/android/net/RouteInfo.java b/core/java/android/net/RouteInfo.java index 2b9e9fe81b1b..fec2df412adb 100644 --- a/core/java/android/net/RouteInfo.java +++ b/core/java/android/net/RouteInfo.java @@ -527,6 +527,26 @@ public final class RouteInfo implements Parcelable { } /** + * Compares this RouteInfo object against the specified object and indicates if the + * destinations of both routes are equal. + * @return {@code true} if the route destinations are equal, {@code false} otherwise. + * + * @hide + */ + public boolean isSameDestinationAs(@Nullable Object obj) { + if (this == obj) return true; + + if (!(obj instanceof RouteInfo)) return false; + + RouteInfo target = (RouteInfo) obj; + + if (Objects.equals(mDestination, target.getDestination())) { + return true; + } + return false; + } + + /** * Returns a hashcode for this <code>RouteInfo</code> object. */ public int hashCode() { |
