Merge "Fix cannot create Nat-T keepalive on mobile data" into qt-dev
am: eabafd5ceb Change-Id: I580b4dd2e493430e8420ca0907f9cf7d1d5a8773
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
* Copyright (C) 2019 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,9 +19,9 @@ package android.net;
|
||||
import static android.net.SocketKeepalive.ERROR_INVALID_IP_ADDRESS;
|
||||
import static android.net.SocketKeepalive.ERROR_INVALID_PORT;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.net.SocketKeepalive.InvalidPacketException;
|
||||
import android.net.util.IpUtils;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
import android.system.OsConstants;
|
||||
|
||||
@@ -79,17 +79,40 @@ public final class NattKeepalivePacketData extends KeepalivePacketData implement
|
||||
return new NattKeepalivePacketData(srcAddress, srcPort, dstAddress, dstPort, buf.array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this NattKeepalivePacketData to a NattKeepalivePacketDataParcelable.
|
||||
*/
|
||||
@NonNull
|
||||
public NattKeepalivePacketDataParcelable toStableParcelable() {
|
||||
final NattKeepalivePacketDataParcelable parcel = new NattKeepalivePacketDataParcelable();
|
||||
/** Parcelable Implementation */
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
parcel.srcAddress = srcAddress.getAddress();
|
||||
parcel.srcPort = srcPort;
|
||||
parcel.dstAddress = dstAddress.getAddress();
|
||||
parcel.dstPort = dstPort;
|
||||
return parcel;
|
||||
/** Write to parcel */
|
||||
public void writeToParcel(Parcel out, int flags) {
|
||||
out.writeString(srcAddress.getHostAddress());
|
||||
out.writeString(dstAddress.getHostAddress());
|
||||
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.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
protected void removeKeepalivePacketFilter(Message msg) {
|
||||
onSocketKeepaliveEvent(msg.arg1, SocketKeepalive.ERROR_UNSUPPORTED);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -216,6 +216,7 @@ public class KeepaliveTracker {
|
||||
|
||||
public String toString() {
|
||||
return "KeepaliveInfo ["
|
||||
+ " type=" + mType
|
||||
+ " network=" + mNai.network
|
||||
+ " startedState=" + startedStateString(mStartedState)
|
||||
+ " "
|
||||
|
||||
Reference in New Issue
Block a user