Support QosCallback for UDP socket: Expose API&CTS
Expose API to use QoSCallback for UDP socket.
- Constructor of QosSocketInfo with DatagramSocket
- matchesProtocol(int protocol) in QosFilter
- Constructor of SocketNotConnectedException &
SocketRemoteAddressChangedException
Add CTS test cases for exposed API.
Bug: 233292861
Test: atest CtsNetTestCases
Change-Id: I52ff881b71b31c0f97c08200cd811205c25fcb44
diff --git a/framework/api/system-current.txt b/framework/api/system-current.txt
index f1298ce..8b35197 100644
--- a/framework/api/system-current.txt
+++ b/framework/api/system-current.txt
@@ -433,6 +433,7 @@
public abstract class QosFilter {
method @NonNull public abstract android.net.Network getNetwork();
method public abstract boolean matchesLocalAddress(@NonNull java.net.InetAddress, int, int);
+ method public boolean matchesProtocol(int);
method public abstract boolean matchesRemoteAddress(@NonNull java.net.InetAddress, int, int);
}
@@ -453,6 +454,7 @@
public final class QosSocketInfo implements android.os.Parcelable {
ctor public QosSocketInfo(@NonNull android.net.Network, @NonNull java.net.Socket) throws java.io.IOException;
+ ctor public QosSocketInfo(@NonNull android.net.Network, @NonNull java.net.DatagramSocket) throws java.io.IOException;
method public int describeContents();
method @NonNull public java.net.InetSocketAddress getLocalSocketAddress();
method @NonNull public android.net.Network getNetwork();
@@ -480,6 +482,14 @@
ctor public SocketNotBoundException();
}
+ public class SocketNotConnectedException extends java.lang.Exception {
+ ctor public SocketNotConnectedException();
+ }
+
+ public class SocketRemoteAddressChangedException extends java.lang.Exception {
+ ctor public SocketRemoteAddressChangedException();
+ }
+
public final class StaticIpConfiguration implements android.os.Parcelable {
ctor public StaticIpConfiguration();
ctor public StaticIpConfiguration(@Nullable android.net.StaticIpConfiguration);
diff --git a/framework/src/android/net/QosFilter.java b/framework/src/android/net/QosFilter.java
index 01dc4bb..a731b23 100644
--- a/framework/src/android/net/QosFilter.java
+++ b/framework/src/android/net/QosFilter.java
@@ -97,10 +97,15 @@
* Determines whether or not the parameter will be matched with this filter.
*
* @param protocol the protocol such as TCP or UDP included in IP packet filter set of a QoS
- * flow assigned on {@link Network}.
+ * flow assigned on {@link Network}. Only {@code IPPROTO_TCP} and {@code
+ * IPPROTO_UDP} currently supported.
* @return whether the parameters match the socket type of the filter
- * @hide
*/
- public abstract boolean matchesProtocol(int protocol);
+ // Since this method is added in U, it's required to be default method for binary compatibility
+ // with existing @SystemApi.
+ // IPPROTO_* are not compile-time constants, so they are not annotated with @IntDef.
+ public boolean matchesProtocol(int protocol) {
+ return false;
+ }
}
diff --git a/framework/src/android/net/QosSocketInfo.java b/framework/src/android/net/QosSocketInfo.java
index da9b356..1c3db23 100644
--- a/framework/src/android/net/QosSocketInfo.java
+++ b/framework/src/android/net/QosSocketInfo.java
@@ -144,7 +144,6 @@
*
* @param network the network
* @param socket the bound {@link DatagramSocket}
- * @hide
*/
public QosSocketInfo(@NonNull final Network network, @NonNull final DatagramSocket socket)
throws IOException {
diff --git a/framework/src/android/net/SocketNotConnectedException.java b/framework/src/android/net/SocketNotConnectedException.java
index fa2a615..a6357c7 100644
--- a/framework/src/android/net/SocketNotConnectedException.java
+++ b/framework/src/android/net/SocketNotConnectedException.java
@@ -16,13 +16,18 @@
package android.net;
+import android.annotation.SystemApi;
+
+import com.android.internal.annotations.VisibleForTesting;
+
/**
* Thrown when a previously bound socket becomes unbound.
*
* @hide
*/
+@SystemApi
public class SocketNotConnectedException extends Exception {
- /** @hide */
+ @VisibleForTesting
public SocketNotConnectedException() {
super("The socket is not connected");
}
diff --git a/framework/src/android/net/SocketRemoteAddressChangedException.java b/framework/src/android/net/SocketRemoteAddressChangedException.java
index ecaeebc..e13d5ed 100644
--- a/framework/src/android/net/SocketRemoteAddressChangedException.java
+++ b/framework/src/android/net/SocketRemoteAddressChangedException.java
@@ -16,13 +16,18 @@
package android.net;
+import android.annotation.SystemApi;
+
+import com.android.internal.annotations.VisibleForTesting;
+
/**
* Thrown when the local address of the socket has changed.
*
* @hide
*/
+@SystemApi
public class SocketRemoteAddressChangedException extends Exception {
- /** @hide */
+ @VisibleForTesting
public SocketRemoteAddressChangedException() {
super("The remote address of the socket changed");
}