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

Commit 249da094 authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN
Browse files

Add utils connect, setsockopt, bind, sendTo

The utilities are not supported as public API but required as SystemApi
for the NetworkStack.

Test: flashed, boots, WiFi works
Bug: 112869080
Change-Id: Ia64b3bf9c6c33cf61bed76469ea9963b550bed2b
parent 5c5f1ba9
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -3476,11 +3476,15 @@ package android.net.util {
    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 bindSocket(java.io.FileDescriptor, java.net.SocketAddress) throws android.system.ErrnoException, 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 void connectSocket(java.io.FileDescriptor, java.net.SocketAddress) throws android.system.ErrnoException, java.net.SocketException;
    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[]);
    method public static void sendTo(java.io.FileDescriptor, byte[], int, int, int, java.net.SocketAddress) throws android.system.ErrnoException, java.net.SocketException;
    method public static void setSocketTimeValueOption(java.io.FileDescriptor, int, int, long) throws android.system.ErrnoException;
  }
}
+4 −0
Original line number Diff line number Diff line
@@ -912,11 +912,15 @@ package android.net.util {
    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 bindSocket(java.io.FileDescriptor, java.net.SocketAddress) throws android.system.ErrnoException, 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 void connectSocket(java.io.FileDescriptor, java.net.SocketAddress) throws android.system.ErrnoException, java.net.SocketException;
    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[]);
    method public static void sendTo(java.io.FileDescriptor, byte[], int, int, int, java.net.SocketAddress) throws android.system.ErrnoException, java.net.SocketException;
    method public static void setSocketTimeValueOption(java.io.FileDescriptor, int, int, long) throws android.system.ErrnoException;
  }

}
+33 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.system.ErrnoException;
import android.system.NetlinkSocketAddress;
import android.system.Os;
import android.system.PacketSocketAddress;
import android.system.StructTimeval;

import libcore.io.IoBridge;

@@ -78,6 +79,38 @@ public class SocketUtils {
        return new PacketSocketAddress(ifIndex, hwAddr);
    }

    /**
     * Set an option on a socket that takes a time value argument.
     */
    public static void setSocketTimeValueOption(
            FileDescriptor fd, int level, int option, long millis) throws ErrnoException {
        Os.setsockoptTimeval(fd, level, option, StructTimeval.fromMillis(millis));
    }

    /**
     * Bind a socket to the specified address.
     */
    public static void bindSocket(FileDescriptor fd, SocketAddress addr)
            throws ErrnoException, SocketException {
        Os.bind(fd, addr);
    }

    /**
     * Connect a socket to the specified address.
     */
    public static void connectSocket(FileDescriptor fd, SocketAddress addr)
            throws ErrnoException, SocketException {
        Os.connect(fd, addr);
    }

    /**
     * Send a message on a socket, using the specified SocketAddress.
     */
    public static void sendTo(FileDescriptor fd, byte[] bytes, int byteOffset, int byteCount,
            int flags, SocketAddress addr) throws ErrnoException, SocketException {
        Os.sendto(fd, bytes, byteOffset, byteCount, flags, addr);
    }

    /**
     * @see IoBridge#closeAndSignalBlockedThreads(FileDescriptor)
     */