Merge "Add NetworkUtils utilities to SystemApi" am: 9cc31061fe

am: ca1d65e707

Change-Id: I978bdb626c1f4c8bbe736c8bad1c74fb6a67b4b5
This commit is contained in:
Remi NGUYEN VAN
2019-01-29 03:29:01 -08:00
committed by android-build-merger
8 changed files with 78 additions and 7 deletions

View File

@@ -3088,12 +3088,14 @@ package android.net {
public final class IpPrefix implements android.os.Parcelable {
ctor public IpPrefix(java.net.InetAddress, int);
ctor public IpPrefix(String);
}
public class LinkAddress implements android.os.Parcelable {
ctor public LinkAddress(java.net.InetAddress, int, int, int);
ctor public LinkAddress(java.net.InetAddress, int);
ctor public LinkAddress(String);
ctor public LinkAddress(String, int, int);
method public boolean isGlobalPreferred();
method public boolean isIPv4();
method public boolean isIPv6();
@@ -3104,6 +3106,7 @@ package android.net {
ctor public LinkProperties();
ctor public LinkProperties(android.net.LinkProperties);
method public boolean addDnsServer(java.net.InetAddress);
method public boolean addLinkAddress(android.net.LinkAddress);
method public boolean addRoute(android.net.RouteInfo);
method public void clear();
method @Nullable public android.net.IpPrefix getNat64Prefix();
@@ -3118,6 +3121,7 @@ package android.net {
method public boolean isProvisioned();
method public boolean isReachable(java.net.InetAddress);
method public boolean removeDnsServer(java.net.InetAddress);
method public boolean removeLinkAddress(android.net.LinkAddress);
method public boolean removeRoute(android.net.RouteInfo);
method public void setDnsServers(java.util.Collection<java.net.InetAddress>);
method public void setDomains(String);
@@ -3134,6 +3138,7 @@ package android.net {
}
public class Network implements android.os.Parcelable {
ctor public Network(android.net.Network);
method public android.net.Network getPrivateDnsBypassingCopy();
}
@@ -3269,8 +3274,8 @@ package android.net.apf {
public class ApfCapabilities {
ctor public ApfCapabilities(int, int, int);
method public boolean getApfDrop8023Frames(android.content.Context);
method public int[] getApfEthTypeBlackList(android.content.Context);
method public static boolean getApfDrop8023Frames(android.content.Context);
method public static int[] getApfEthTypeBlackList(android.content.Context);
method public boolean hasDataAccess();
field public final int apfPacketFormat;
field public final int apfVersionSupported;
@@ -3467,6 +3472,10 @@ package android.net.metrics {
package android.net.util {
public class SocketUtils {
method public static void addArpEntry(java.net.Inet4Address, android.net.MacAddress, String, java.io.FileDescriptor) throws java.io.IOException;
method public static void attachControlPacketFilter(java.io.FileDescriptor, int) throws java.net.SocketException;
method public static void attachDhcpFilter(java.io.FileDescriptor) throws java.net.SocketException;
method public static void attachRaFilter(java.io.FileDescriptor, int) throws java.net.SocketException;
method public static void bindSocketToInterface(java.io.FileDescriptor, String) throws android.system.ErrnoException;
method public static void closeSocket(java.io.FileDescriptor) throws java.io.IOException;
method public static java.net.SocketAddress makeNetlinkSocketAddress(int, int);

View File

@@ -613,6 +613,7 @@ package android.net {
public final class IpPrefix implements android.os.Parcelable {
ctor public IpPrefix(java.net.InetAddress, int);
ctor public IpPrefix(String);
}
public final class IpSecManager {
@@ -621,6 +622,9 @@ package android.net {
public class LinkAddress implements android.os.Parcelable {
ctor public LinkAddress(java.net.InetAddress, int, int, int);
ctor public LinkAddress(java.net.InetAddress, int);
ctor public LinkAddress(String);
ctor public LinkAddress(String, int, int);
method public boolean isGlobalPreferred();
method public boolean isIPv4();
method public boolean isIPv6();
@@ -630,6 +634,7 @@ package android.net {
public final class LinkProperties implements android.os.Parcelable {
ctor public LinkProperties(android.net.LinkProperties);
method public boolean addDnsServer(java.net.InetAddress);
method public boolean addLinkAddress(android.net.LinkAddress);
method @Nullable public android.net.IpPrefix getNat64Prefix();
method public java.util.List<java.net.InetAddress> getPcscfServers();
method public String getTcpBufferSizes();
@@ -642,6 +647,7 @@ package android.net {
method public boolean isProvisioned();
method public boolean isReachable(java.net.InetAddress);
method public boolean removeDnsServer(java.net.InetAddress);
method public boolean removeLinkAddress(android.net.LinkAddress);
method public boolean removeRoute(android.net.RouteInfo);
method public void setNat64Prefix(android.net.IpPrefix);
method public void setPcscfServers(java.util.Collection<java.net.InetAddress>);
@@ -652,6 +658,7 @@ package android.net {
}
public class Network implements android.os.Parcelable {
ctor public Network(android.net.Network);
method public android.net.Network getPrivateDnsBypassingCopy();
}
@@ -703,8 +710,8 @@ package android.net.apf {
public class ApfCapabilities {
ctor public ApfCapabilities(int, int, int);
method public boolean getApfDrop8023Frames(android.content.Context);
method public int[] getApfEthTypeBlackList(android.content.Context);
method public static boolean getApfDrop8023Frames(android.content.Context);
method public static int[] getApfEthTypeBlackList(android.content.Context);
method public boolean hasDataAccess();
field public final int apfPacketFormat;
field public final int apfVersionSupported;
@@ -901,6 +908,10 @@ package android.net.metrics {
package android.net.util {
public class SocketUtils {
method public static void addArpEntry(java.net.Inet4Address, android.net.MacAddress, String, java.io.FileDescriptor) throws java.io.IOException;
method public static void attachControlPacketFilter(java.io.FileDescriptor, int) throws java.net.SocketException;
method public static void attachDhcpFilter(java.io.FileDescriptor) throws java.net.SocketException;
method public static void attachRaFilter(java.io.FileDescriptor, int) throws java.net.SocketException;
method public static void bindSocketToInterface(java.io.FileDescriptor, String) throws android.system.ErrnoException;
method public static void closeSocket(java.io.FileDescriptor) throws java.io.IOException;
method public static java.net.SocketAddress makeNetlinkSocketAddress(int, int);

View File

@@ -104,6 +104,8 @@ public final class IpPrefix implements Parcelable {
*
* @hide
*/
@SystemApi
@TestApi
public IpPrefix(String prefix) {
// We don't reuse the (InetAddress, int) constructor because "error: call to this must be
// first statement in constructor". We could factor out setting the member variables to an

View File

@@ -176,6 +176,7 @@ public class LinkAddress implements Parcelable {
* @hide
*/
@SystemApi
@TestApi
public LinkAddress(InetAddress address, int prefixLength) {
this(address, prefixLength, 0, 0);
this.scope = scopeForUnicastAddress(address);
@@ -199,6 +200,7 @@ public class LinkAddress implements Parcelable {
* @hide
*/
@SystemApi
@TestApi
public LinkAddress(String address) {
this(address, 0, 0);
this.scope = scopeForUnicastAddress(this.address);
@@ -212,6 +214,8 @@ public class LinkAddress implements Parcelable {
* @param scope The address scope.
* @hide
*/
@SystemApi
@TestApi
public LinkAddress(String address, int flags, int scope) {
// This may throw an IllegalArgumentException; catching it is the caller's responsibility.
// TODO: consider rejecting mapped IPv4 addresses such as "::ffff:192.0.2.5/24".

View File

@@ -287,7 +287,8 @@ public final class LinkProperties implements Parcelable {
* @return true if {@code address} was added or updated, false otherwise.
* @hide
*/
@UnsupportedAppUsage
@SystemApi
@TestApi
public boolean addLinkAddress(LinkAddress address) {
if (address == null) {
return false;
@@ -315,6 +316,8 @@ public final class LinkProperties implements Parcelable {
* @return true if the address was removed, false if it did not exist.
* @hide
*/
@SystemApi
@TestApi
public boolean removeLinkAddress(LinkAddress toRemove) {
int i = findLinkAddressIndex(toRemove);
if (i >= 0) {

View File

@@ -123,6 +123,8 @@ public class Network implements Parcelable {
/**
* @hide
*/
@SystemApi
@TestApi
public Network(Network that) {
this(that.netId, that.mPrivateDnsBypass);
}

View File

@@ -81,14 +81,14 @@ public class ApfCapabilities {
/**
* @return Whether the APF Filter in the device should filter out IEEE 802.3 Frames.
*/
public boolean getApfDrop8023Frames(Context context) {
public static boolean getApfDrop8023Frames(Context context) {
return context.getResources().getBoolean(R.bool.config_apfDrop802_3Frames);
}
/**
* @return An array of blacklisted EtherType, packets with EtherTypes within it will be dropped.
*/
public int[] getApfEthTypeBlackList(Context context) {
public static int[] getApfEthTypeBlackList(Context context) {
return context.getResources().getIntArray(R.array.config_apfEthTypeBlackList);
}
}

View File

@@ -21,6 +21,7 @@ import static android.system.OsConstants.SO_BINDTODEVICE;
import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.net.MacAddress;
import android.net.NetworkUtils;
import android.system.ErrnoException;
import android.system.NetlinkSocketAddress;
@@ -31,7 +32,9 @@ import libcore.io.IoBridge;
import java.io.FileDescriptor;
import java.io.IOException;
import java.net.Inet4Address;
import java.net.SocketAddress;
import java.net.SocketException;
/**
* Collection of utilities to interact with raw sockets.
@@ -82,5 +85,42 @@ public class SocketUtils {
IoBridge.closeAndSignalBlockedThreads(fd);
}
/**
* Attaches a socket filter that accepts DHCP packets to the given socket.
*/
public static void attachDhcpFilter(FileDescriptor fd) throws SocketException {
NetworkUtils.attachDhcpFilter(fd);
}
/**
* Attaches a socket filter that accepts ICMPv6 router advertisements to the given socket.
* @param fd the socket's {@link FileDescriptor}.
* @param packetType the hardware address type, one of ARPHRD_*.
*/
public static void attachRaFilter(FileDescriptor fd, int packetType) throws SocketException {
NetworkUtils.attachRaFilter(fd, packetType);
}
/**
* Attaches a socket filter that accepts L2-L4 signaling traffic required for IP connectivity.
*
* This includes: all ARP, ICMPv6 RS/RA/NS/NA messages, and DHCPv4 exchanges.
*
* @param fd the socket's {@link FileDescriptor}.
* @param packetType the hardware address type, one of ARPHRD_*.
*/
public static void attachControlPacketFilter(FileDescriptor fd, int packetType)
throws SocketException {
NetworkUtils.attachControlPacketFilter(fd, packetType);
}
/**
* Add an entry into the ARP cache.
*/
public static void addArpEntry(Inet4Address ipv4Addr, MacAddress ethAddr, String ifname,
FileDescriptor fd) throws IOException {
NetworkUtils.addArpEntry(ipv4Addr, ethAddr, ifname, fd);
}
private SocketUtils() {}
}