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
This commit is contained in:
Sarah Chin
2020-01-16 11:19:52 -08:00
parent e5b3e8e8f0
commit 77a7ea65fd
5 changed files with 261 additions and 41 deletions

View File

@@ -6230,6 +6230,8 @@ package android.net {
public final class RouteInfo implements android.os.Parcelable {
ctor public RouteInfo(@Nullable android.net.IpPrefix, @Nullable java.net.InetAddress, @Nullable String, int);
ctor public RouteInfo(@Nullable android.net.IpPrefix, @Nullable java.net.InetAddress, @Nullable String, int, int);
method public int getMtu();
method public int getType();
field public static final int RTN_THROW = 9; // 0x9
field public static final int RTN_UNICAST = 1; // 0x1
@@ -12114,7 +12116,9 @@ package android.telephony.data {
method public int getId();
method @NonNull public String getInterfaceName();
method public int getLinkStatus();
method public int getMtu();
method @Deprecated public int getMtu();
method public int getMtuV4();
method public int getMtuV6();
method @NonNull public java.util.List<java.net.InetAddress> getPcscfAddresses();
method public int getProtocolType();
method public int getSuggestedRetryTime();
@@ -12136,7 +12140,9 @@ package android.telephony.data {
method @NonNull public android.telephony.data.DataCallResponse.Builder setId(int);
method @NonNull public android.telephony.data.DataCallResponse.Builder setInterfaceName(@NonNull String);
method @NonNull public android.telephony.data.DataCallResponse.Builder setLinkStatus(int);
method @NonNull public android.telephony.data.DataCallResponse.Builder setMtu(int);
method @Deprecated @NonNull public android.telephony.data.DataCallResponse.Builder setMtu(int);
method @NonNull public android.telephony.data.DataCallResponse.Builder setMtuV4(int);
method @NonNull public android.telephony.data.DataCallResponse.Builder setMtuV6(int);
method @NonNull public android.telephony.data.DataCallResponse.Builder setPcscfAddresses(@NonNull java.util.List<java.net.InetAddress>);
method @NonNull public android.telephony.data.DataCallResponse.Builder setProtocolType(int);
method @NonNull public android.telephony.data.DataCallResponse.Builder setSuggestedRetryTime(int);
@@ -12147,7 +12153,9 @@ package android.telephony.data {
method @NonNull public String getApn();
method public int getAuthType();
method public int getBearerBitmask();
method public int getMtu();
method @Deprecated public int getMtu();
method public int getMtuV4();
method public int getMtuV6();
method @Nullable public String getPassword();
method public int getProfileId();
method public int getProtocolType();
@@ -12172,7 +12180,9 @@ package android.telephony.data {
method @NonNull public android.telephony.data.DataProfile.Builder setApn(@NonNull String);
method @NonNull public android.telephony.data.DataProfile.Builder setAuthType(int);
method @NonNull public android.telephony.data.DataProfile.Builder setBearerBitmask(int);
method @NonNull public android.telephony.data.DataProfile.Builder setMtu(int);
method @Deprecated @NonNull public android.telephony.data.DataProfile.Builder setMtu(int);
method @NonNull public android.telephony.data.DataProfile.Builder setMtuV4(int);
method @NonNull public android.telephony.data.DataProfile.Builder setMtuV6(int);
method @NonNull public android.telephony.data.DataProfile.Builder setPassword(@NonNull String);
method @NonNull public android.telephony.data.DataProfile.Builder setPersistent(boolean);
method @NonNull public android.telephony.data.DataProfile.Builder setPreferred(boolean);

View File

@@ -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;
}
/**
@@ -373,6 +404,17 @@ public final class RouteInfo implements Parcelable {
return mType;
}
/**
* 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).
*
@@ -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) {

View File

@@ -78,6 +78,9 @@ public final class DataCallResponse implements Parcelable {
private final List<InetAddress> mGatewayAddresses;
private final List<InetAddress> mPcscfAddresses;
private final int mMtu;
private final int mMtuV4;
private final int mMtuV6;
private final int mVersion;
/**
* @param cause Data call fail cause. {@link DataFailCause#NONE} indicates no error.
@@ -97,9 +100,8 @@ public final class DataCallResponse implements Parcelable {
* "192.0.1.11 2001:db8::1". When null, the addresses represent point to point connections.
* @param pcscfAddresses A list of Proxy Call State Control Function address via PCO (Protocol
* Configuration Option) for IMS client.
* @param mtu MTU (maximum transmission unit) in bytes received from network. Zero or negative
* values means network has either not sent a value or sent an invalid value.
* either not sent a value or sent an invalid value.
* @param mtu MTU (maximum transmission unit) in bytes received from network.
* Zero or negative values means network has either not sent a value or sent an invalid value.
*
* @removed Use the {@link Builder()} instead.
*/
@@ -125,6 +127,34 @@ public final class DataCallResponse implements Parcelable {
mPcscfAddresses = (pcscfAddresses == null)
? new ArrayList<>() : new ArrayList<>(pcscfAddresses);
mMtu = mtu;
mMtuV4 = mMtuV6 = 0;
mVersion = 0;
}
/** @hide */
private DataCallResponse(@DataFailureCause int cause, int suggestedRetryTime, int id,
@LinkStatus int linkStatus, @ProtocolType int protocolType,
@Nullable String interfaceName, @Nullable List<LinkAddress> addresses,
@Nullable List<InetAddress> dnsAddresses, @Nullable List<InetAddress> gatewayAddresses,
@Nullable List<InetAddress> pcscfAddresses, int mtuV4, int mtuV6, int version) {
mCause = cause;
mSuggestedRetryTime = suggestedRetryTime;
mId = id;
mLinkStatus = linkStatus;
mProtocolType = protocolType;
mInterfaceName = (interfaceName == null) ? "" : interfaceName;
mAddresses = (addresses == null)
? new ArrayList<>() : new ArrayList<>(addresses);
mDnsAddresses = (dnsAddresses == null)
? new ArrayList<>() : new ArrayList<>(dnsAddresses);
mGatewayAddresses = (gatewayAddresses == null)
? new ArrayList<>() : new ArrayList<>(gatewayAddresses);
mPcscfAddresses = (pcscfAddresses == null)
? new ArrayList<>() : new ArrayList<>(pcscfAddresses);
mMtu = 0;
mMtuV4 = mtuV4;
mMtuV6 = mtuV6;
mVersion = version;
}
/** @hide */
@@ -145,6 +175,9 @@ public final class DataCallResponse implements Parcelable {
mPcscfAddresses = new ArrayList<>();
source.readList(mPcscfAddresses, InetAddress.class.getClassLoader());
mMtu = source.readInt();
mMtuV4 = source.readInt();
mMtuV6 = source.readInt();
mVersion = source.readInt();
}
/**
@@ -210,8 +243,29 @@ public final class DataCallResponse implements Parcelable {
/**
* @return MTU (maximum transmission unit) in bytes received from network. Zero or negative
* values means network has either not sent a value or sent an invalid value.
* @deprecated For IRadio 1.5 and up, use {@link #getMtuV4} or {@link #getMtuV6} instead.
*/
public int getMtu() { return mMtu; }
@Deprecated
public int getMtu() {
return mVersion < 5 ? mMtu : 0;
}
/**
* This replaces the deprecated method getMtu.
* @return MTU (maximum transmission unit) in bytes received from network, for IPv4.
* Zero or negative values means network has either not sent a value or sent an invalid value.
*/
public int getMtuV4() {
return mVersion < 5 ? 0 : mMtuV4;
}
/**
* @return MTU (maximum transmission unit) in bytes received from network, for IPv6.
* Zero or negative values means network has either not sent a value or sent an invalid value.
*/
public int getMtuV6() {
return mVersion < 5 ? 0 : mMtuV6;
}
@NonNull
@Override
@@ -229,6 +283,9 @@ public final class DataCallResponse implements Parcelable {
.append(" gateways=").append(mGatewayAddresses)
.append(" pcscf=").append(mPcscfAddresses)
.append(" mtu=").append(mMtu)
.append(" mtuV4=").append(mMtuV4)
.append(" mtuV6=").append(mMtuV6)
.append(" version=").append(mVersion)
.append("}");
return sb.toString();
}
@@ -256,14 +313,17 @@ public final class DataCallResponse implements Parcelable {
&& mGatewayAddresses.containsAll(other.mGatewayAddresses)
&& mPcscfAddresses.size() == other.mPcscfAddresses.size()
&& mPcscfAddresses.containsAll(other.mPcscfAddresses)
&& mMtu == other.mMtu;
&& mMtu == other.mMtu
&& mMtuV4 == other.mMtuV4
&& mMtuV6 == other.mMtuV6
&& mVersion == other.mVersion;
}
@Override
public int hashCode() {
return Objects.hash(mCause, mSuggestedRetryTime, mId, mLinkStatus, mProtocolType,
mInterfaceName, mAddresses, mDnsAddresses, mGatewayAddresses, mPcscfAddresses,
mMtu);
mMtu, mMtuV4, mMtuV6, mVersion);
}
@Override
@@ -284,6 +344,9 @@ public final class DataCallResponse implements Parcelable {
dest.writeList(mGatewayAddresses);
dest.writeList(mPcscfAddresses);
dest.writeInt(mMtu);
dest.writeInt(mMtuV4);
dest.writeInt(mMtuV6);
dest.writeInt(mVersion);
}
public static final @android.annotation.NonNull Parcelable.Creator<DataCallResponse> CREATOR =
@@ -336,6 +399,12 @@ public final class DataCallResponse implements Parcelable {
private int mMtu;
private int mMtuV4;
private int mMtuV6;
private int mVersion;
/**
* Default constructor for Builder.
*/
@@ -460,21 +529,63 @@ public final class DataCallResponse implements Parcelable {
* negative values means network has either not sent a value or sent an invalid value.
*
* @return The same instance of the builder.
* @deprecated For IRadio 1.5 and up, use {@link #setMtuV4} or {@link #setMtuV6} instead.
*/
public @NonNull Builder setMtu(int mtu) {
mMtu = mtu;
return this;
}
/**
* Set maximum transmission unit of the data connection, for IPv4.
*
* @param mtu MTU (maximum transmission unit) in bytes received from network. Zero or
* negative values means network has either not sent a value or sent an invalid value.
*
* @return The same instance of the builder.
*/
public @NonNull Builder setMtuV4(int mtu) {
mMtuV4 = mtu;
return this;
}
/**
* Set maximum transmission unit of the data connection, for IPv6.
*
* @param mtu MTU (maximum transmission unit) in bytes received from network. Zero or
* negative values means network has either not sent a value or sent an invalid value.
*
* @return The same instance of the builder.
*/
public @NonNull Builder setMtuV6(int mtu) {
mMtuV6 = mtu;
return this;
}
/**
* Set the IRadio version for this DataCallResponse
* @hide
*/
public @NonNull Builder setVersion(int version) {
mVersion = version;
return this;
}
/**
* Build the DataCallResponse.
*
* @return the DataCallResponse object.
*/
public @NonNull DataCallResponse build() {
return new DataCallResponse(mCause, mSuggestedRetryTime, mId, mLinkStatus,
mProtocolType, mInterfaceName, mAddresses, mDnsAddresses, mGatewayAddresses,
mPcscfAddresses, mMtu);
if (mVersion >= 5) {
return new DataCallResponse(mCause, mSuggestedRetryTime, mId, mLinkStatus,
mProtocolType, mInterfaceName, mAddresses, mDnsAddresses, mGatewayAddresses,
mPcscfAddresses, mMtuV4, mMtuV6, mVersion);
} else {
return new DataCallResponse(mCause, mSuggestedRetryTime, mId, mLinkStatus,
mProtocolType, mInterfaceName, mAddresses, mDnsAddresses, mGatewayAddresses,
mPcscfAddresses, mMtu);
}
}
}
}

View File

@@ -96,7 +96,9 @@ public final class DataProfile implements Parcelable {
@NetworkTypeBitMask
private final int mBearerBitmask;
private final int mMtu;
private final int mMtuV4;
private final int mMtuV6;
private final boolean mPersistent;
@@ -104,12 +106,11 @@ public final class DataProfile implements Parcelable {
/** @hide */
private DataProfile(int profileId, String apn, @ProtocolType int protocolType, int authType,
String userName, String password, int type, int maxConnectionsTime,
int maxConnections, int waitTime, boolean enabled,
@ApnType int supportedApnTypesBitmask,
@ProtocolType int roamingProtocolType,
@NetworkTypeBitMask int bearerBitmask, int mtu, boolean persistent,
boolean preferred) {
String userName, String password, int type, int maxConnectionsTime,
int maxConnections, int waitTime, boolean enabled,
@ApnType int supportedApnTypesBitmask, @ProtocolType int roamingProtocolType,
@NetworkTypeBitMask int bearerBitmask, int mtuV4, int mtuV6, boolean persistent,
boolean preferred) {
this.mProfileId = profileId;
this.mApn = apn;
this.mProtocolType = protocolType;
@@ -128,7 +129,8 @@ public final class DataProfile implements Parcelable {
this.mSupportedApnTypesBitmask = supportedApnTypesBitmask;
this.mRoamingProtocolType = roamingProtocolType;
this.mBearerBitmask = bearerBitmask;
this.mMtu = mtu;
this.mMtuV4 = mtuV4;
this.mMtuV6 = mtuV6;
this.mPersistent = persistent;
this.mPreferred = preferred;
}
@@ -148,7 +150,8 @@ public final class DataProfile implements Parcelable {
mSupportedApnTypesBitmask = source.readInt();
mRoamingProtocolType = source.readInt();
mBearerBitmask = source.readInt();
mMtu = source.readInt();
mMtuV4 = source.readInt();
mMtuV6 = source.readInt();
mPersistent = source.readBoolean();
mPreferred = source.readBoolean();
}
@@ -237,8 +240,21 @@ public final class DataProfile implements Parcelable {
/**
* @return The maximum transmission unit (MTU) size in bytes.
* @deprecated use {@link #getMtuV4} or {@link #getMtuV6} instead.
*/
public int getMtu() { return mMtu; }
@Deprecated
public int getMtu() { return mMtuV4; }
/**
* This replaces the deprecated method getMtu.
* @return The maximum transmission unit (MTU) size in bytes, for IPv4.
*/
public int getMtuV4() { return mMtuV4; }
/**
* @return The maximum transmission unit (MTU) size in bytes, for IPv6.
*/
public int getMtuV6() { return mMtuV6; }
/**
* @return {@code true} if modem must persist this data profile.
@@ -265,8 +281,8 @@ public final class DataProfile implements Parcelable {
(mApn + "/" + mUserName + "/" + mPassword)) + "/" + mType + "/"
+ mMaxConnectionsTime + "/" + mMaxConnections + "/"
+ mWaitTime + "/" + mEnabled + "/" + mSupportedApnTypesBitmask + "/"
+ mRoamingProtocolType + "/" + mBearerBitmask + "/" + mMtu + "/" + mPersistent + "/"
+ mPreferred;
+ mRoamingProtocolType + "/" + mBearerBitmask + "/" + mMtuV4 + "/" + mMtuV6 + "/"
+ mPersistent + "/" + mPreferred;
}
@Override
@@ -285,7 +301,8 @@ public final class DataProfile implements Parcelable {
dest.writeInt(mSupportedApnTypesBitmask);
dest.writeInt(mRoamingProtocolType);
dest.writeInt(mBearerBitmask);
dest.writeInt(mMtu);
dest.writeInt(mMtuV4);
dest.writeInt(mMtuV6);
dest.writeBoolean(mPersistent);
dest.writeBoolean(mPreferred);
}
@@ -319,7 +336,8 @@ public final class DataProfile implements Parcelable {
&& mSupportedApnTypesBitmask == that.mSupportedApnTypesBitmask
&& mRoamingProtocolType == that.mRoamingProtocolType
&& mBearerBitmask == that.mBearerBitmask
&& mMtu == that.mMtu
&& mMtuV4 == that.mMtuV4
&& mMtuV6 == that.mMtuV6
&& mPersistent == that.mPersistent
&& mPreferred == that.mPreferred
&& Objects.equals(mApn, that.mApn)
@@ -331,8 +349,8 @@ public final class DataProfile implements Parcelable {
public int hashCode() {
return Objects.hash(mProfileId, mApn, mProtocolType, mAuthType, mUserName, mPassword, mType,
mMaxConnectionsTime, mMaxConnections, mWaitTime, mEnabled,
mSupportedApnTypesBitmask, mRoamingProtocolType, mBearerBitmask, mMtu, mPersistent,
mPreferred);
mSupportedApnTypesBitmask, mRoamingProtocolType, mBearerBitmask, mMtuV4, mMtuV6,
mPersistent, mPreferred);
}
/**
@@ -384,7 +402,9 @@ public final class DataProfile implements Parcelable {
@NetworkTypeBitMask
private int mBearerBitmask;
private int mMtu;
private int mMtuV4;
private int mMtuV6;
private boolean mPersistent;
@@ -567,9 +587,33 @@ public final class DataProfile implements Parcelable {
*
* @param mtu The maximum transmission unit (MTU) size in bytes.
* @return The same instance of the builder.
* @deprecated use {@link #setMtuV4} or {@link #setMtuV6} instead.
*/
public @NonNull Builder setMtu(int mtu) {
mMtu = mtu;
mMtuV4 = mMtuV6 = mtu;
return this;
}
/**
* Set the maximum transmission unit (MTU) size in bytes, for IPv4.
* This replaces the deprecated method setMtu.
*
* @param mtu The maximum transmission unit (MTU) size in bytes.
* @return The same instance of the builder.
*/
public @NonNull Builder setMtuV4(int mtu) {
mMtuV4 = mtu;
return this;
}
/**
* Set the maximum transmission unit (MTU) size in bytes, for IPv6.
*
* @param mtu The maximum transmission unit (MTU) size in bytes.
* @return The same instance of the builder.
*/
public @NonNull Builder setMtuV6(int mtu) {
mMtuV6 = mtu;
return this;
}
@@ -606,7 +650,7 @@ public final class DataProfile implements Parcelable {
public @NonNull DataProfile build() {
return new DataProfile(mProfileId, mApn, mProtocolType, mAuthType, mUserName, mPassword,
mType, mMaxConnectionsTime, mMaxConnections, mWaitTime, mEnabled,
mSupportedApnTypesBitmask, mRoamingProtocolType, mBearerBitmask, mMtu,
mSupportedApnTypesBitmask, mRoamingProtocolType, mBearerBitmask, mMtuV4, mMtuV6,
mPersistent, mPreferred);
}
}

View File

@@ -258,6 +258,16 @@ public class RouteInfoTest extends TestCase {
assertParcelingIsLossless(r);
r = new RouteInfo(Prefix("192.0.2.0/24"), null, "wlan0");
assertParcelSane(r, 6);
assertParcelSane(r, 7);
}
public void testMtu() {
RouteInfo r;
r = new RouteInfo(Prefix("0.0.0.0/0"), Address("0.0.0.0"), "wlan0",
RouteInfo.RTN_UNICAST, 1500);
assertEquals(1500, r.getMtu());
r = new RouteInfo(Prefix("0.0.0.0/0"), Address("0.0.0.0"), "wlan0");
assertEquals(0, r.getMtu());
}
}