Move SocketUtils out of the connectivity module

SocketUtils contains system APIs for modules to interact for sockets,
wrapping internal APIs. It should be part of the platform to keep access
to the internal APIs.

This involves splitting NetworkUtils.protectVpn to NetworkUtilsInternal,
since SocketUtils and VpnService are the only users of that method.

The @UnsupportedAppUsage NetworkUtils.protectVpn has low usage
count, and is already available through VpnService.protect.

Bug: 181512874
Test: boots, VPN working
Change-Id: I7028d334975f7536c06afac7a22200c33db707ac
This commit is contained in:
Remi NGUYEN VAN
2021-02-18 00:03:53 +09:00
parent 3d31f1ead0
commit 914dca36ee
9 changed files with 49 additions and 45 deletions

View File

@@ -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.