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

Commit b3bc93fb authored by Remi NGUYEN VAN's avatar Remi NGUYEN VAN Committed by Automerger Merge Worker
Browse files

Merge "Move SocketUtils out of the connectivity module" am: 4eb9b18e

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1592273

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: Ib2d4b5574ba710eb50c438144e2b87f6c8954336
parents cc717d3c 4eb9b18e
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -6399,6 +6399,19 @@ package android.net.sip {
}
package android.net.util {
  public final class SocketUtils {
    method public static void bindSocketToInterface(@NonNull java.io.FileDescriptor, @NonNull String) throws android.system.ErrnoException;
    method public static void closeSocket(@Nullable java.io.FileDescriptor) throws java.io.IOException;
    method @NonNull public static java.net.SocketAddress makeNetlinkSocketAddress(int, int);
    method @NonNull public static java.net.SocketAddress makePacketSocketAddress(int, int);
    method @Deprecated @NonNull public static java.net.SocketAddress makePacketSocketAddress(int, @NonNull byte[]);
    method @NonNull public static java.net.SocketAddress makePacketSocketAddress(int, int, @NonNull byte[]);
  }
}
package android.net.vcn {
  public class VcnManager {
+2 −1
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;

import com.android.internal.net.NetworkUtilsInternal;
import com.android.internal.net.VpnConfig;

import java.net.DatagramSocket;
@@ -254,7 +255,7 @@ public class VpnService extends Service {
     * @return {@code true} on success.
     */
    public boolean protect(int socket) {
        return NetworkUtils.protectFromVpn(socket);
        return NetworkUtilsInternal.protectFromVpn(socket);
    }

    /**
+3 −2
Original line number Diff line number Diff line
@@ -22,12 +22,13 @@ import static android.system.OsConstants.SO_BINDTODEVICE;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.SystemApi;
import android.net.NetworkUtils;
import android.system.ErrnoException;
import android.system.NetlinkSocketAddress;
import android.system.Os;
import android.system.PacketSocketAddress;

import com.android.internal.net.NetworkUtilsInternal;

import libcore.io.IoBridge;

import java.io.FileDescriptor;
@@ -51,7 +52,7 @@ public final class SocketUtils {
        // of struct ifreq is a NULL-terminated interface name.
        // TODO: add a setsockoptString()
        Os.setsockoptIfreq(socket, SOL_SOCKET, SO_BINDTODEVICE, iface);
        NetworkUtils.protectFromVpn(socket);
        NetworkUtilsInternal.protectFromVpn(socket);
    }

    /**
+16 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import static android.system.OsConstants.AF_INET6;
import android.annotation.NonNull;
import android.system.Os;

import java.io.FileDescriptor;

/** @hide */
public class NetworkUtilsInternal {

@@ -35,6 +37,20 @@ public class NetworkUtilsInternal {
     */
    public static native void setAllowNetworkingForProcess(boolean allowNetworking);

    /**
     * Protect {@code fd} from VPN connections.  After protecting, data sent through
     * this socket will go directly to the underlying network, so its traffic will not be
     * forwarded through the VPN.
     */
    public static native boolean protectFromVpn(FileDescriptor fd);

    /**
     * Protect {@code socketfd} from VPN connections.  After protecting, data sent through
     * this socket will go directly to the underlying network, so its traffic will not be
     * forwarded through the VPN.
     */
    public static native boolean protectFromVpn(int socketfd);

    /**
     * Returns true if the hostname is weakly validated.
     * @param hostname Name of host to validate.
+1 −1
Original line number Diff line number Diff line
@@ -149,7 +149,7 @@ cc_library_shared {
                "android_os_VintfRuntimeInfo.cpp",
                "android_os_incremental_IncrementalManager.cpp",
                "android_net_LocalSocketImpl.cpp",
                "android_net_NetUtils.cpp",
                "android_net_NetworkUtils.cpp",
                "android_service_DataLoaderService.cpp",
                "android_util_AssetManager.cpp",
                "android_util_Binder.cpp",
Loading