diff options
| author | Aaron Huang <huangaaron@google.com> | 2020-03-18 19:24:31 +0800 |
|---|---|---|
| committer | Aaron Huang <huangaaron@google.com> | 2020-03-24 10:55:18 +0000 |
| commit | 8e1ce70353bfad452b93d2d8c0c78f887f3069ff (patch) | |
| tree | 0ee36ca7593c3871b0a4b96607dea002d56c1e8c /core/java/android/net/KeepalivePacketData.java | |
| parent | 6982a7dc690508f5c428b05ac2e94a86920ed5e8 (diff) | |
API review: access field by method
- InvalidPacketException, public field should be a method so
add getter to get error code.
- KeepalivePacketData, public fields should be methods so
add getter for fields.
Bug: 151322799
Test: atest FrameworksNetTests
atest FrameworksWifiTests
atest FrameworksTelephonyTests: some failure in CarrierAppUtilsTest
Copy from ag/10731108
Change-Id: Id01e6135193716cc21bba11da529bf1507a954f7
Merged-In: Id01e6135193716cc21bba11da529bf1507a954f7
Diffstat (limited to 'core/java/android/net/KeepalivePacketData.java')
| -rw-r--r-- | core/java/android/net/KeepalivePacketData.java | 49 |
1 files changed, 38 insertions, 11 deletions
diff --git a/core/java/android/net/KeepalivePacketData.java b/core/java/android/net/KeepalivePacketData.java index 6c0ba2f63a80..e21cb44f72d8 100644 --- a/core/java/android/net/KeepalivePacketData.java +++ b/core/java/android/net/KeepalivePacketData.java @@ -19,6 +19,7 @@ package android.net; import static android.net.InvalidPacketException.ERROR_INVALID_IP_ADDRESS; import static android.net.InvalidPacketException.ERROR_INVALID_PORT; +import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.SystemApi; import android.net.util.IpUtils; @@ -37,17 +38,17 @@ public class KeepalivePacketData { /** Source IP address */ @NonNull - public final InetAddress srcAddress; + private final InetAddress mSrcAddress; /** Destination IP address */ @NonNull - public final InetAddress dstAddress; + private final InetAddress mDstAddress; /** Source port */ - public final int srcPort; + private final int mSrcPort; /** Destination port */ - public final int dstPort; + private final int mDstPort; /** Packet data. A raw byte string of packet data, not including the link-layer header. */ private final byte[] mPacket; @@ -60,13 +61,14 @@ public class KeepalivePacketData { /** * A holding class for data necessary to build a keepalive packet. */ - protected KeepalivePacketData(@NonNull InetAddress srcAddress, int srcPort, - @NonNull InetAddress dstAddress, int dstPort, - @NonNull byte[] data) throws InvalidPacketException { - this.srcAddress = srcAddress; - this.dstAddress = dstAddress; - this.srcPort = srcPort; - this.dstPort = dstPort; + protected KeepalivePacketData(@NonNull InetAddress srcAddress, + @IntRange(from = 0, to = 65535) int srcPort, @NonNull InetAddress dstAddress, + @IntRange(from = 0, to = 65535) int dstPort, + @NonNull byte[] data) throws InvalidPacketException { + this.mSrcAddress = srcAddress; + this.mDstAddress = dstAddress; + this.mSrcPort = srcPort; + this.mDstPort = dstPort; this.mPacket = data; // Check we have two IP addresses of the same family. @@ -83,6 +85,31 @@ public class KeepalivePacketData { } } + /** Get source IP address. */ + @NonNull + public InetAddress getSrcAddress() { + return mSrcAddress; + } + + /** Get destination IP address. */ + @NonNull + public InetAddress getDstAddress() { + return mDstAddress; + } + + /** Get source port number. */ + public int getSrcPort() { + return mSrcPort; + } + + /** Get destination port number. */ + public int getDstPort() { + return mDstPort; + } + + /** + * Returns a byte array of the given packet data. + */ @NonNull public byte[] getPacket() { return mPacket.clone(); |
