diff options
author | Remi NGUYEN VAN <reminv@google.com> | 2021-02-18 00:03:53 +0900 |
---|---|---|
committer | Remi NGUYEN VAN <reminv@google.com> | 2021-03-01 16:50:08 +0900 |
commit | 914dca36eec8fed05d9c07523425a2411cfa60cc (patch) | |
tree | 6dedf94e6a4fc076328cbcea132878dcd3e0f555 /core/jni | |
parent | 3d31f1ead0151b55a5e493b58ad22adcc15c78eb (diff) |
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
Diffstat (limited to 'core/jni')
-rw-r--r-- | core/jni/Android.bp | 2 | ||||
-rw-r--r-- | core/jni/android_net_NetworkUtils.cpp (renamed from core/jni/android_net_NetUtils.cpp) | 13 | ||||
-rw-r--r-- | core/jni/com_android_internal_net_NetworkUtilsInternal.cpp | 13 |
3 files changed, 15 insertions, 13 deletions
diff --git a/core/jni/Android.bp b/core/jni/Android.bp index e58ad79de89e..afd19b63bc71 100644 --- a/core/jni/Android.bp +++ b/core/jni/Android.bp @@ -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", diff --git a/core/jni/android_net_NetUtils.cpp b/core/jni/android_net_NetworkUtils.cpp index e2af87ee1adf..750810840bde 100644 --- a/core/jni/android_net_NetUtils.cpp +++ b/core/jni/android_net_NetworkUtils.cpp @@ -14,7 +14,7 @@ * limitations under the License. */ -#define LOG_TAG "NetUtils" +#define LOG_TAG "NetworkUtils" #include <vector> @@ -123,15 +123,6 @@ static jint android_net_utils_bindSocketToNetwork(JNIEnv *env, jobject thiz, job return setNetworkForSocket(netId, AFileDescriptor_getFD(env, javaFd)); } -static jboolean android_net_utils_protectFromVpn(JNIEnv *env, jobject thiz, jint socket) -{ - return (jboolean) !protectFromVpn(socket); -} - -static jboolean android_net_utils_protectFromVpnWithFd(JNIEnv *env, jobject thiz, jobject javaFd) { - return android_net_utils_protectFromVpn(env, thiz, AFileDescriptor_getFD(env, javaFd)); -} - static jboolean android_net_utils_queryUserAccess(JNIEnv *env, jobject thiz, jint uid, jint netId) { return (jboolean) !queryUserAccess(uid, netId); @@ -276,8 +267,6 @@ static const JNINativeMethod gNetworkUtilMethods[] = { { "getBoundNetworkForProcess", "()I", (void*) android_net_utils_getBoundNetworkForProcess }, { "bindProcessToNetworkForHostResolution", "(I)Z", (void*) android_net_utils_bindProcessToNetworkForHostResolution }, { "bindSocketToNetwork", "(Ljava/io/FileDescriptor;I)I", (void*) android_net_utils_bindSocketToNetwork }, - { "protectFromVpn", "(I)Z", (void*) android_net_utils_protectFromVpn }, - { "protectFromVpn", "(Ljava/io/FileDescriptor;)Z", (void*) android_net_utils_protectFromVpnWithFd }, { "queryUserAccess", "(II)Z", (void*)android_net_utils_queryUserAccess }, { "attachDropAllBPFFilter", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_attachDropAllBPFFilter }, { "detachBPFFilter", "(Ljava/io/FileDescriptor;)V", (void*) android_net_utils_detachBPFFilter }, diff --git a/core/jni/com_android_internal_net_NetworkUtilsInternal.cpp b/core/jni/com_android_internal_net_NetworkUtilsInternal.cpp index 10fc18dcd386..980e12d0bb40 100644 --- a/core/jni/com_android_internal_net_NetworkUtilsInternal.cpp +++ b/core/jni/com_android_internal_net_NetworkUtilsInternal.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include <android/file_descriptor_jni.h> + #include "NetdClient.h" #include "core_jni_helpers.h" #include "jni.h" @@ -24,9 +26,20 @@ static void android_net_utils_setAllowNetworkingForProcess(JNIEnv *env, jobject setAllowNetworkingForProcess(hasConnectivity == JNI_TRUE); } +static jboolean android_net_utils_protectFromVpn(JNIEnv *env, jobject thiz, jint socket) { + return (jboolean)!protectFromVpn(socket); +} + +static jboolean android_net_utils_protectFromVpnWithFd(JNIEnv *env, jobject thiz, jobject javaFd) { + return android_net_utils_protectFromVpn(env, thiz, AFileDescriptor_getFD(env, javaFd)); +} + static const JNINativeMethod gNetworkUtilMethods[] = { {"setAllowNetworkingForProcess", "(Z)V", (void *)android_net_utils_setAllowNetworkingForProcess}, + {"protectFromVpn", "(I)Z", (void *)android_net_utils_protectFromVpn}, + {"protectFromVpn", "(Ljava/io/FileDescriptor;)Z", + (void *)android_net_utils_protectFromVpnWithFd}, }; int register_com_android_internal_net_NetworkUtilsInternal(JNIEnv *env) { |