diff options
Diffstat (limited to 'framework/src')
| -rw-r--r-- | framework/src/android/net/ConnectivityManager.java | 10 | ||||
| -rw-r--r-- | framework/src/android/net/NetworkCapabilities.java | 20 | ||||
| -rw-r--r-- | framework/src/android/net/QosSocketInfo.java | 45 |
3 files changed, 69 insertions, 6 deletions
diff --git a/framework/src/android/net/ConnectivityManager.java b/framework/src/android/net/ConnectivityManager.java index e25a85558c..a174fe34ce 100644 --- a/framework/src/android/net/ConnectivityManager.java +++ b/framework/src/android/net/ConnectivityManager.java @@ -995,21 +995,25 @@ public class ConnectivityManager { // LINT.ThenChange(packages/modules/Connectivity/service/native/include/Common.h) /** - * Specify default rule which may allow or drop packets depending on existing policy. + * A firewall rule which allows or drops packets depending on existing policy. + * Used by {@link #setUidFirewallRule(int, int, int)} to follow existing policy to handle + * specific uid's packets in specific firewall chain. * @hide */ @SystemApi(client = MODULE_LIBRARIES) public static final int FIREWALL_RULE_DEFAULT = 0; /** - * Specify allow rule which allows packets. + * A firewall rule which allows packets. Used by {@link #setUidFirewallRule(int, int, int)} to + * allow specific uid's packets in specific firewall chain. * @hide */ @SystemApi(client = MODULE_LIBRARIES) public static final int FIREWALL_RULE_ALLOW = 1; /** - * Specify deny rule which drops packets. + * A firewall rule which drops packets. Used by {@link #setUidFirewallRule(int, int, int)} to + * drop specific uid's packets in specific firewall chain. * @hide */ @SystemApi(client = MODULE_LIBRARIES) diff --git a/framework/src/android/net/NetworkCapabilities.java b/framework/src/android/net/NetworkCapabilities.java index f7f2f57f6e..97b1f32671 100644 --- a/framework/src/android/net/NetworkCapabilities.java +++ b/framework/src/android/net/NetworkCapabilities.java @@ -863,8 +863,11 @@ public final class NetworkCapabilities implements Parcelable { } /** - * Get the underlying networks of this network. If the caller is not system privileged, this is - * always redacted to null and it will be never useful to the caller. + * Get the underlying networks of this network. If the caller doesn't have one of + * {@link android.Manifest.permission.NETWORK_FACTORY}, + * {@link android.Manifest.permission.NETWORK_SETTINGS} and + * {@link NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}, this is always redacted to null and + * it will be never useful to the caller. * * @return <li>If the list is null, this network hasn't declared underlying networks.</li> * <li>If the list is empty, this network has declared that it has no underlying @@ -2650,7 +2653,7 @@ public final class NetworkCapabilities implements Parcelable { /** * Builder class for NetworkCapabilities. * - * This class is mainly for for {@link NetworkAgent} instances to use. Many fields in + * This class is mainly for {@link NetworkAgent} instances to use. Many fields in * the built class require holding a signature permission to use - mostly * {@link android.Manifest.permission.NETWORK_FACTORY}, but refer to the specific * description of each setter. As this class lives entirely in app space it does not @@ -3058,9 +3061,20 @@ public final class NetworkCapabilities implements Parcelable { /** * Set the underlying networks of this network. * + * <p>This API is mainly for {@link NetworkAgent}s who hold + * {@link android.Manifest.permission.NETWORK_FACTORY} to set its underlying networks. + * + * <p>The underlying networks are only visible for the receiver who has one of + * {@link android.Manifest.permission.NETWORK_FACTORY}, + * {@link android.Manifest.permission.NETWORK_SETTINGS} and + * {@link NetworkStack.PERMISSION_MAINLINE_NETWORK_STACK}. + * If the receiver doesn't have required permissions, the field will be cleared before + * sending to the caller.</p> + * * @param networks The underlying networks of this network. */ @NonNull + @RequiresPermission(android.Manifest.permission.NETWORK_FACTORY) public Builder setUnderlyingNetworks(@Nullable List<Network> networks) { mCaps.setUnderlyingNetworks(networks); return this; diff --git a/framework/src/android/net/QosSocketInfo.java b/framework/src/android/net/QosSocketInfo.java index a45d5075d6..39c2f334d3 100644 --- a/framework/src/android/net/QosSocketInfo.java +++ b/framework/src/android/net/QosSocketInfo.java @@ -16,6 +16,9 @@ package android.net; +import static android.system.OsConstants.SOCK_DGRAM; +import static android.system.OsConstants.SOCK_STREAM; + import android.annotation.NonNull; import android.annotation.Nullable; import android.annotation.SystemApi; @@ -24,6 +27,7 @@ import android.os.ParcelFileDescriptor; import android.os.Parcelable; import java.io.IOException; +import java.net.DatagramSocket; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.Socket; @@ -53,6 +57,8 @@ public final class QosSocketInfo implements Parcelable { @Nullable private final InetSocketAddress mRemoteSocketAddress; + private final int mSocketType; + /** * The {@link Network} the socket is on. * @@ -98,6 +104,16 @@ public final class QosSocketInfo implements Parcelable { } /** + * The socket type of the socket passed in when this QosSocketInfo object was constructed. + * + * @return the socket type of the socket. + * @hide + */ + public int getSocketType() { + return mSocketType; + } + + /** * Creates a {@link QosSocketInfo} given a {@link Network} and bound {@link Socket}. The * {@link Socket} must remain bound in order to receive {@link QosSession}s. * @@ -112,6 +128,32 @@ public final class QosSocketInfo implements Parcelable { mParcelFileDescriptor = ParcelFileDescriptor.fromSocket(socket); mLocalSocketAddress = new InetSocketAddress(socket.getLocalAddress(), socket.getLocalPort()); + mSocketType = SOCK_STREAM; + + if (socket.isConnected()) { + mRemoteSocketAddress = (InetSocketAddress) socket.getRemoteSocketAddress(); + } else { + mRemoteSocketAddress = null; + } + } + + /** + * Creates a {@link QosSocketInfo} given a {@link Network} and bound {@link DatagramSocket}. The + * {@link DatagramSocket} must remain bound in order to receive {@link QosSession}s. + * + * @param network the network + * @param socket the bound {@link DatagramSocket} + * @hide + */ + public QosSocketInfo(@NonNull final Network network, @NonNull final DatagramSocket socket) + throws IOException { + Objects.requireNonNull(socket, "socket cannot be null"); + + mNetwork = Objects.requireNonNull(network, "network cannot be null"); + mParcelFileDescriptor = ParcelFileDescriptor.fromDatagramSocket(socket); + mLocalSocketAddress = + new InetSocketAddress(socket.getLocalAddress(), socket.getLocalPort()); + mSocketType = SOCK_DGRAM; if (socket.isConnected()) { mRemoteSocketAddress = (InetSocketAddress) socket.getRemoteSocketAddress(); @@ -131,6 +173,8 @@ public final class QosSocketInfo implements Parcelable { final int remoteAddressLength = in.readInt(); mRemoteSocketAddress = remoteAddressLength == 0 ? null : readSocketAddress(in, remoteAddressLength); + + mSocketType = in.readInt(); } private @NonNull InetSocketAddress readSocketAddress(final Parcel in, final int addressLength) { @@ -170,6 +214,7 @@ public final class QosSocketInfo implements Parcelable { dest.writeByteArray(remoteAddress); dest.writeInt(mRemoteSocketAddress.getPort()); } + dest.writeInt(mSocketType); } @NonNull |
