Fix cannot create Nat-T keepalive on mobile data
Currently phone process fail to unparcel NattKeepalivePacketData
since it is not in framework. Moves NattKeepalivePacketData to
framework to make it can be utilized by telephony.
This change also removes the error feedback triggered by calling
add keepalive packet filter to an unsupported network agent. This
is misinterpreted by KeepaliveTracker that start keepalive is
failing.
Bug: 134048171
Test: 1. atest android.net.cts.ConnectivityManagerTest#testSocketKeepaliveLimitTelephony
2. atest android.net.cts.ConnectivityManagerTest
3. atest FrameworksNetTests
4. atest FrameworksTelephonyTests
Change-Id: If630d5b339aa722717258c721daa8ead8c431e2d
This commit is contained in:
@@ -19,9 +19,9 @@ package android.net;
|
|||||||
import static android.net.SocketKeepalive.ERROR_INVALID_IP_ADDRESS;
|
import static android.net.SocketKeepalive.ERROR_INVALID_IP_ADDRESS;
|
||||||
import static android.net.SocketKeepalive.ERROR_INVALID_PORT;
|
import static android.net.SocketKeepalive.ERROR_INVALID_PORT;
|
||||||
|
|
||||||
import android.annotation.NonNull;
|
|
||||||
import android.net.SocketKeepalive.InvalidPacketException;
|
import android.net.SocketKeepalive.InvalidPacketException;
|
||||||
import android.net.util.IpUtils;
|
import android.net.util.IpUtils;
|
||||||
|
import android.os.Parcel;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.system.OsConstants;
|
import android.system.OsConstants;
|
||||||
|
|
||||||
@@ -79,17 +79,40 @@ public final class NattKeepalivePacketData extends KeepalivePacketData implement
|
|||||||
return new NattKeepalivePacketData(srcAddress, srcPort, dstAddress, dstPort, buf.array());
|
return new NattKeepalivePacketData(srcAddress, srcPort, dstAddress, dstPort, buf.array());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/** Parcelable Implementation */
|
||||||
* Convert this NattKeepalivePacketData to a NattKeepalivePacketDataParcelable.
|
public int describeContents() {
|
||||||
*/
|
return 0;
|
||||||
@NonNull
|
}
|
||||||
public NattKeepalivePacketDataParcelable toStableParcelable() {
|
|
||||||
final NattKeepalivePacketDataParcelable parcel = new NattKeepalivePacketDataParcelable();
|
|
||||||
|
|
||||||
parcel.srcAddress = srcAddress.getAddress();
|
/** Write to parcel */
|
||||||
parcel.srcPort = srcPort;
|
public void writeToParcel(Parcel out, int flags) {
|
||||||
parcel.dstAddress = dstAddress.getAddress();
|
out.writeString(srcAddress.getHostAddress());
|
||||||
parcel.dstPort = dstPort;
|
out.writeString(dstAddress.getHostAddress());
|
||||||
return parcel;
|
out.writeInt(srcPort);
|
||||||
|
out.writeInt(dstPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Parcelable Creator */
|
||||||
|
public static final Parcelable.Creator<NattKeepalivePacketData> CREATOR =
|
||||||
|
new Parcelable.Creator<NattKeepalivePacketData>() {
|
||||||
|
public NattKeepalivePacketData createFromParcel(Parcel in) {
|
||||||
|
final InetAddress srcAddress =
|
||||||
|
InetAddresses.parseNumericAddress(in.readString());
|
||||||
|
final InetAddress dstAddress =
|
||||||
|
InetAddresses.parseNumericAddress(in.readString());
|
||||||
|
final int srcPort = in.readInt();
|
||||||
|
final int dstPort = in.readInt();
|
||||||
|
try {
|
||||||
|
return NattKeepalivePacketData.nattKeepalivePacket(srcAddress, srcPort,
|
||||||
|
dstAddress, dstPort);
|
||||||
|
} catch (InvalidPacketException e) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Invalid NAT-T keepalive data: " + e.error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NattKeepalivePacketData[] newArray(int size) {
|
||||||
|
return new NattKeepalivePacketData[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -510,7 +510,6 @@ public abstract class NetworkAgent extends Handler {
|
|||||||
* override this method.
|
* override this method.
|
||||||
*/
|
*/
|
||||||
protected void addKeepalivePacketFilter(Message msg) {
|
protected void addKeepalivePacketFilter(Message msg) {
|
||||||
onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_UNSUPPORTED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -519,7 +518,6 @@ public abstract class NetworkAgent extends Handler {
|
|||||||
* must override this method.
|
* must override this method.
|
||||||
*/
|
*/
|
||||||
protected void removeKeepalivePacketFilter(Message msg) {
|
protected void removeKeepalivePacketFilter(Message msg) {
|
||||||
onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_UNSUPPORTED);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -216,6 +216,7 @@ public class KeepaliveTracker {
|
|||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "KeepaliveInfo ["
|
return "KeepaliveInfo ["
|
||||||
|
+ " type=" + mType
|
||||||
+ " network=" + mNai.network
|
+ " network=" + mNai.network
|
||||||
+ " startedState=" + startedStateString(mStartedState)
|
+ " startedState=" + startedStateString(mStartedState)
|
||||||
+ " "
|
+ " "
|
||||||
|
|||||||
Reference in New Issue
Block a user