Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cec60fa5 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by Gerrit Code Review
Browse files

Merge "Add SocketUtils for NetworkStack"

parents 171c9cdc 53b03140
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -3241,6 +3241,9 @@ package android.net {
    method public static void setThreadStatsTagApp();
    method public static void setThreadStatsTagBackup();
    method public static void setThreadStatsTagRestore();
    field public static final int TAG_SYSTEM_DHCP = -192; // 0xffffff40
    field public static final int TAG_SYSTEM_DHCP_SERVER = -186; // 0xffffff46
    field public static final int TAG_SYSTEM_PROBE = -190; // 0xffffff42
  }
  public class VpnService extends android.app.Service {
@@ -3266,6 +3269,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 boolean hasDataAccess();
    field public final int apfPacketFormat;
    field public final int apfVersionSupported;
@@ -3463,6 +3468,7 @@ package android.net.util {
  public class SocketUtils {
    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);
    method public static java.net.SocketAddress makePacketSocketAddress(short, int);
    method public static java.net.SocketAddress makePacketSocketAddress(int, byte[]);
+17 −0
Original line number Diff line number Diff line
@@ -692,6 +692,9 @@ package android.net {
    method public static long getLoopbackRxPackets();
    method public static long getLoopbackTxBytes();
    method public static long getLoopbackTxPackets();
    field public static final int TAG_SYSTEM_DHCP = -192; // 0xffffff40
    field public static final int TAG_SYSTEM_DHCP_SERVER = -186; // 0xffffff46
    field public static final int TAG_SYSTEM_PROBE = -190; // 0xffffff42
  }

}
@@ -700,6 +703,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 boolean hasDataAccess();
    field public final int apfPacketFormat;
    field public final int apfVersionSupported;
@@ -893,6 +898,18 @@ package android.net.metrics {

}

package android.net.util {

  public class SocketUtils {
    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);
    method public static java.net.SocketAddress makePacketSocketAddress(short, int);
    method public static java.net.SocketAddress makePacketSocketAddress(int, byte[]);
  }

}

package android.os {

  public static class Build.VERSION {
+6 −0
Original line number Diff line number Diff line
@@ -128,10 +128,14 @@ public class TrafficStats {
    public static final int TAG_SYSTEM_APP = 0xFFFFFF05;

    /** @hide */
    @SystemApi
    @TestApi
    public static final int TAG_SYSTEM_DHCP = 0xFFFFFF40;
    /** @hide */
    public static final int TAG_SYSTEM_NTP = 0xFFFFFF41;
    /** @hide */
    @SystemApi
    @TestApi
    public static final int TAG_SYSTEM_PROBE = 0xFFFFFF42;
    /** @hide */
    public static final int TAG_SYSTEM_NEIGHBOR = 0xFFFFFF43;
@@ -140,6 +144,8 @@ public class TrafficStats {
    /** @hide */
    public static final int TAG_SYSTEM_PAC = 0xFFFFFF45;
    /** @hide */
    @SystemApi
    @TestApi
    public static final int TAG_SYSTEM_DHCP_SERVER = 0xFFFFFF46;

    private static INetworkStatsService sStatsService;
+17 −0
Original line number Diff line number Diff line
@@ -18,6 +18,9 @@ package android.net.apf;

import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.content.Context;

import com.android.internal.R;

/**
 * APF program support capabilities.
@@ -74,4 +77,18 @@ public class ApfCapabilities {
    public boolean hasDataAccess() {
        return apfVersionSupported >= 4;
    }

    /**
     * @return Whether the APF Filter in the device should filter out IEEE 802.3 Frames.
     */
    public 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) {
        return context.getResources().getIntArray(R.array.config_apfEthTypeBlackList);
    }
}
+14 −2
Original line number Diff line number Diff line
@@ -20,13 +20,17 @@ import static android.system.OsConstants.SOL_SOCKET;
import static android.system.OsConstants.SO_BINDTODEVICE;

import android.annotation.SystemApi;
import android.annotation.TestApi;
import android.net.NetworkUtils;
import android.system.ErrnoException;
import android.system.NetlinkSocketAddress;
import android.system.Os;
import android.system.PacketSocketAddress;

import libcore.io.IoBridge;

import java.io.FileDescriptor;
import java.io.IOException;
import java.net.SocketAddress;

/**
@@ -34,6 +38,7 @@ import java.net.SocketAddress;
 * @hide
 */
@SystemApi
@TestApi
public class SocketUtils {
    /**
     * Create a raw datagram socket that is bound to an interface.
@@ -57,18 +62,25 @@ public class SocketUtils {
    }

    /**
     * Make a socket address to bind to packet sockets.
     * Make socket address that packet sockets can bind to.
     */
    public static SocketAddress makePacketSocketAddress(short protocol, int ifIndex) {
        return new PacketSocketAddress(protocol, ifIndex);
    }

    /**
     * Make a socket address to send raw packets.
     * Make a socket address that packet socket can send packets to.
     */
    public static SocketAddress makePacketSocketAddress(int ifIndex, byte[] hwAddr) {
        return new PacketSocketAddress(ifIndex, hwAddr);
    }

    /**
     * @see IoBridge#closeAndSignalBlockedThreads(FileDescriptor)
     */
    public static void closeSocket(FileDescriptor fd) throws IOException {
        IoBridge.closeAndSignalBlockedThreads(fd);
    }

    private SocketUtils() {}
}