diff options
| author | Sarah Chin <sarahchin@google.com> | 2020-01-16 11:19:52 -0800 |
|---|---|---|
| committer | Sarah Chin <sarahchin@google.com> | 2020-01-21 20:29:47 -0800 |
| commit | 77a7ea65fdbb13fcfe68b8d8b0e7ed2eb4a7a37a (patch) | |
| tree | a2db30409415563d97c3722da3196b09bb538972 /core/java/android | |
| parent | e5b3e8e8f0820a73d557712fad3392ac712b6bbf (diff) | |
API changes for IPv6 MTU support
Change mtu->mtuV4 and add mtuV6 for DataProfile and DataCallResult
Add mtu to RouteInfo and update test
Test: atest FrameworksTelephonyTests
Bug: 146668814
Change-Id: I43c7e088e46e40f38d8114548e0fc4e39d7f91cb
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/net/RouteInfo.java | 61 |
1 files changed, 53 insertions, 8 deletions
diff --git a/core/java/android/net/RouteInfo.java b/core/java/android/net/RouteInfo.java index e08809457649..2b9e9fe81b1b 100644 --- a/core/java/android/net/RouteInfo.java +++ b/core/java/android/net/RouteInfo.java @@ -105,6 +105,11 @@ public final class RouteInfo implements Parcelable { */ private final int mType; + /** + * The maximum transmission unit size for this route. + */ + private final int mMtu; + // Derived data members. // TODO: remove these. @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) @@ -133,6 +138,31 @@ public final class RouteInfo implements Parcelable { @TestApi public RouteInfo(@Nullable IpPrefix destination, @Nullable InetAddress gateway, @Nullable String iface, @RouteType int type) { + this(destination, gateway, iface, type, 0); + } + + /** + * Constructs a RouteInfo object. + * + * If destination is null, then gateway must be specified and the + * constructed route is either the IPv4 default route <code>0.0.0.0</code> + * if the gateway is an instance of {@link Inet4Address}, or the IPv6 default + * route <code>::/0</code> if gateway is an instance of + * {@link Inet6Address}. + * <p> + * destination and gateway may not both be null. + * + * @param destination the destination prefix + * @param gateway the IP address to route packets through + * @param iface the interface name to send packets on + * @param type the type of this route + * @param mtu the maximum transmission unit size for this route + * + * @hide + */ + @SystemApi + public RouteInfo(@Nullable IpPrefix destination, @Nullable InetAddress gateway, + @Nullable String iface, @RouteType int type, int mtu) { switch (type) { case RTN_UNICAST: case RTN_UNREACHABLE: @@ -162,7 +192,7 @@ public final class RouteInfo implements Parcelable { } else { // no destination, no gateway. invalid. throw new IllegalArgumentException("Invalid arguments passed in: " + gateway + "," + - destination); + destination); } } // TODO: set mGateway to null if there is no gateway. This is more correct, saves space, and @@ -177,10 +207,10 @@ public final class RouteInfo implements Parcelable { } mHasGateway = (!gateway.isAnyLocalAddress()); - if ((destination.getAddress() instanceof Inet4Address && - (gateway instanceof Inet4Address == false)) || - (destination.getAddress() instanceof Inet6Address && - (gateway instanceof Inet6Address == false))) { + if ((destination.getAddress() instanceof Inet4Address + && !(gateway instanceof Inet4Address)) + || (destination.getAddress() instanceof Inet6Address + && !(gateway instanceof Inet6Address))) { throw new IllegalArgumentException("address family mismatch in RouteInfo constructor"); } mDestination = destination; // IpPrefix objects are immutable. @@ -188,6 +218,7 @@ public final class RouteInfo implements Parcelable { mInterface = iface; // Strings are immutable. mType = type; mIsHost = isHost(); + mMtu = mtu; } /** @@ -374,6 +405,17 @@ public final class RouteInfo implements Parcelable { } /** + * Retrieves the MTU size for this route. + * + * @return The MTU size, or 0 if it has not been set. + * @hide + */ + @SystemApi + public int getMtu() { + return mMtu; + } + + /** * Indicates if this route is a default route (ie, has no destination specified). * * @return {@code true} if the destination has a prefix length of 0. @@ -463,6 +505,7 @@ public final class RouteInfo implements Parcelable { val += " unknown type " + mType; } } + val += " mtu " + mMtu; return val; } @@ -480,7 +523,7 @@ public final class RouteInfo implements Parcelable { return Objects.equals(mDestination, target.getDestination()) && Objects.equals(mGateway, target.getGateway()) && Objects.equals(mInterface, target.getInterface()) && - mType == target.getType(); + mType == target.getType() && mMtu == target.getMtu(); } /** @@ -490,7 +533,7 @@ public final class RouteInfo implements Parcelable { return (mDestination.hashCode() * 41) + (mGateway == null ? 0 :mGateway.hashCode() * 47) + (mInterface == null ? 0 :mInterface.hashCode() * 67) - + (mType * 71); + + (mType * 71) + (mMtu * 89); } /** @@ -509,6 +552,7 @@ public final class RouteInfo implements Parcelable { dest.writeByteArray(gatewayBytes); dest.writeString(mInterface); dest.writeInt(mType); + dest.writeInt(mMtu); } /** @@ -527,8 +571,9 @@ public final class RouteInfo implements Parcelable { String iface = in.readString(); int type = in.readInt(); + int mtu = in.readInt(); - return new RouteInfo(dest, gateway, iface, type); + return new RouteInfo(dest, gateway, iface, type, mtu); } public RouteInfo[] newArray(int size) { |
