Loading core/jni/Android.bp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -195,7 +195,6 @@ cc_library_shared { "android_util_FileObserver.cpp", "android_util_FileObserver.cpp", "android/opengl/poly_clip.cpp", // TODO: .arm "android/opengl/poly_clip.cpp", // TODO: .arm "android/opengl/util.cpp", "android/opengl/util.cpp", "android_server_NetworkManagementSocketTagger.cpp", "android_ddm_DdmHandleNativeHeap.cpp", "android_ddm_DdmHandleNativeHeap.cpp", "android_backup_BackupDataInput.cpp", "android_backup_BackupDataInput.cpp", "android_backup_BackupDataOutput.cpp", "android_backup_BackupDataOutput.cpp", Loading Loading @@ -299,6 +298,8 @@ cc_library_shared { "libdl_android", "libdl_android", "libtimeinstate", "libtimeinstate", "server_configurable_flags", "server_configurable_flags", // TODO: delete when ConnectivityT moves to APEX. "libframework-connectivity-tiramisu-jni", ], ], export_shared_lib_headers: [ export_shared_lib_headers: [ // our headers include libnativewindow's public headers // our headers include libnativewindow's public headers Loading core/jni/AndroidRuntime.cpp +0 −2 Original line number Original line Diff line number Diff line Loading @@ -164,7 +164,6 @@ extern int register_android_text_AndroidCharacter(JNIEnv *env); extern int register_android_text_Hyphenator(JNIEnv *env); extern int register_android_text_Hyphenator(JNIEnv *env); extern int register_android_opengl_classes(JNIEnv *env); extern int register_android_opengl_classes(JNIEnv *env); extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env); extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env); extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env); extern int register_android_backup_BackupDataInput(JNIEnv *env); extern int register_android_backup_BackupDataInput(JNIEnv *env); extern int register_android_backup_BackupDataOutput(JNIEnv *env); extern int register_android_backup_BackupDataOutput(JNIEnv *env); extern int register_android_backup_FileBackupHelperBase(JNIEnv *env); extern int register_android_backup_FileBackupHelperBase(JNIEnv *env); Loading Loading @@ -1618,7 +1617,6 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_media_midi), REG_JNI(register_android_media_midi), REG_JNI(register_android_opengl_classes), REG_JNI(register_android_opengl_classes), REG_JNI(register_android_server_NetworkManagementSocketTagger), REG_JNI(register_android_ddm_DdmHandleNativeHeap), REG_JNI(register_android_ddm_DdmHandleNativeHeap), REG_JNI(register_android_backup_BackupDataInput), REG_JNI(register_android_backup_BackupDataInput), REG_JNI(register_android_backup_BackupDataOutput), REG_JNI(register_android_backup_BackupDataOutput), Loading packages/ConnectivityT/framework-t/Android.bp +31 −1 Original line number Original line Diff line number Diff line Loading @@ -39,7 +39,6 @@ filegroup { "src/android/net/TrafficStats.java", "src/android/net/TrafficStats.java", "src/android/net/UnderlyingNetworkInfo.*", "src/android/net/UnderlyingNetworkInfo.*", "src/android/net/netstats/**/*.*", "src/android/net/netstats/**/*.*", "src/com/android/server/NetworkManagementSocketTagger.java", ], ], path: "src", path: "src", visibility: [ visibility: [ Loading Loading @@ -176,3 +175,34 @@ filegroup { "//packages/modules/Connectivity:__subpackages__", "//packages/modules/Connectivity:__subpackages__", ], ], } } cc_library_shared { name: "libframework-connectivity-tiramisu-jni", min_sdk_version: "30", cflags: [ "-Wall", "-Werror", "-Wno-unused-parameter", // Don't warn about S API usage even with // min_sdk 30: the library is only loaded // on S+ devices "-Wno-unguarded-availability", "-Wthread-safety", ], srcs: [ "jni/android_net_TrafficStats.cpp", "jni/onload.cpp", ], shared_libs: [ "liblog", ], static_libs: [ "libnativehelper_compat_libc++", ], stl: "none", apex_available: [ "com.android.tethering", // TODO: remove when ConnectivityT moves to APEX. "//apex_available:platform", ], } core/jni/android_server_NetworkManagementSocketTagger.cpp→packages/ConnectivityT/framework-t/jni/android_net_TrafficStats.cpp +46 −0 Original line number Original line Diff line number Diff line /* /* * Copyright 2011, The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project * * * Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License. Loading @@ -14,60 +14,33 @@ * limitations under the License. * limitations under the License. */ */ #define LOG_TAG "NMST_QTagUidNative" #include <android/file_descriptor_jni.h> #include <android/multinetwork.h> #include <android/multinetwork.h> #include <cutils/qtaguid.h> #include <nativehelper/JNIHelp.h> #include <errno.h> #include <fcntl.h> #include <nativehelper/JNIPlatformHelp.h> #include <sys/socket.h> #include <sys/types.h> #include <utils/Log.h> #include <utils/misc.h> #include "jni.h" namespace android { namespace android { static jint tagSocketFd(JNIEnv* env, jclass, jobject fileDescriptor, static jint tagSocketFd(JNIEnv* env, jclass, jobject fileDescriptor, jint tag, jint uid) { jint tagNum, jint uid) { int fd = AFileDescriptor_getFd(env, fileDescriptor); int userFd = jniGetFDFromFileDescriptor(env, fileDescriptor); if (fd == -1) return -EBADF; return android_tag_socket_with_uid(fd, tag, uid); if (env->ExceptionCheck()) { ALOGE("Can't get FileDescriptor num"); return (jint)-1; } int res = android_tag_socket_with_uid(userFd, tagNum, uid); if (res < 0) { return (jint)-errno; } return (jint)res; } } static jint untagSocketFd(JNIEnv* env, jclass, jobject fileDescriptor) { static jint untagSocketFd(JNIEnv* env, jclass, jobject fileDescriptor) { int userFd = jniGetFDFromFileDescriptor(env, fileDescriptor); int fd = AFileDescriptor_getFd(env, fileDescriptor); if (fd == -1) return -EBADF; if (env->ExceptionCheck()) { return android_untag_socket(fd); ALOGE("Can't get FileDescriptor num"); return (jint)-1; } int res = android_untag_socket(userFd); if (res < 0) { return (jint)-errno; } return (jint)res; } } static const JNINativeMethod gQTagUidMethods[] = { static const JNINativeMethod gMethods[] = { /* name, signature, funcPtr */ { "native_tagSocketFd", "(Ljava/io/FileDescriptor;II)I", (void*) tagSocketFd }, { "native_tagSocketFd", "(Ljava/io/FileDescriptor;II)I", (void*) tagSocketFd }, { "native_untagSocketFd", "(Ljava/io/FileDescriptor;)I", (void*) untagSocketFd }, { "native_untagSocketFd", "(Ljava/io/FileDescriptor;)I", (void*) untagSocketFd }, }; }; int register_android_server_NetworkManagementSocketTagger(JNIEnv* env) { int register_android_net_TrafficStats(JNIEnv* env) { return jniRegisterNativeMethods(env, "com/android/server/NetworkManagementSocketTagger", gQTagUidMethods, NELEM(gQTagUidMethods)); return jniRegisterNativeMethods(env, "android/net/TrafficStats", gMethods, NELEM(gMethods)); } } }; }; // namespace android packages/ConnectivityT/framework-t/jni/onload.cpp 0 → 100644 +39 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "FrameworkConnectivityJNI" #include <log/log.h> #include <nativehelper/JNIHelp.h> namespace android { int register_android_net_TrafficStats(JNIEnv* env); extern "C" jint JNI_OnLoad(JavaVM* vm, void*) { JNIEnv *env; if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "ERROR: GetEnv failed"); return JNI_ERR; } if (register_android_net_TrafficStats(env) < 0) return JNI_ERR; return JNI_VERSION_1_6; } }; // namespace android Loading
core/jni/Android.bp +2 −1 Original line number Original line Diff line number Diff line Loading @@ -195,7 +195,6 @@ cc_library_shared { "android_util_FileObserver.cpp", "android_util_FileObserver.cpp", "android/opengl/poly_clip.cpp", // TODO: .arm "android/opengl/poly_clip.cpp", // TODO: .arm "android/opengl/util.cpp", "android/opengl/util.cpp", "android_server_NetworkManagementSocketTagger.cpp", "android_ddm_DdmHandleNativeHeap.cpp", "android_ddm_DdmHandleNativeHeap.cpp", "android_backup_BackupDataInput.cpp", "android_backup_BackupDataInput.cpp", "android_backup_BackupDataOutput.cpp", "android_backup_BackupDataOutput.cpp", Loading Loading @@ -299,6 +298,8 @@ cc_library_shared { "libdl_android", "libdl_android", "libtimeinstate", "libtimeinstate", "server_configurable_flags", "server_configurable_flags", // TODO: delete when ConnectivityT moves to APEX. "libframework-connectivity-tiramisu-jni", ], ], export_shared_lib_headers: [ export_shared_lib_headers: [ // our headers include libnativewindow's public headers // our headers include libnativewindow's public headers Loading
core/jni/AndroidRuntime.cpp +0 −2 Original line number Original line Diff line number Diff line Loading @@ -164,7 +164,6 @@ extern int register_android_text_AndroidCharacter(JNIEnv *env); extern int register_android_text_Hyphenator(JNIEnv *env); extern int register_android_text_Hyphenator(JNIEnv *env); extern int register_android_opengl_classes(JNIEnv *env); extern int register_android_opengl_classes(JNIEnv *env); extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env); extern int register_android_ddm_DdmHandleNativeHeap(JNIEnv *env); extern int register_android_server_NetworkManagementSocketTagger(JNIEnv* env); extern int register_android_backup_BackupDataInput(JNIEnv *env); extern int register_android_backup_BackupDataInput(JNIEnv *env); extern int register_android_backup_BackupDataOutput(JNIEnv *env); extern int register_android_backup_BackupDataOutput(JNIEnv *env); extern int register_android_backup_FileBackupHelperBase(JNIEnv *env); extern int register_android_backup_FileBackupHelperBase(JNIEnv *env); Loading Loading @@ -1618,7 +1617,6 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_media_midi), REG_JNI(register_android_media_midi), REG_JNI(register_android_opengl_classes), REG_JNI(register_android_opengl_classes), REG_JNI(register_android_server_NetworkManagementSocketTagger), REG_JNI(register_android_ddm_DdmHandleNativeHeap), REG_JNI(register_android_ddm_DdmHandleNativeHeap), REG_JNI(register_android_backup_BackupDataInput), REG_JNI(register_android_backup_BackupDataInput), REG_JNI(register_android_backup_BackupDataOutput), REG_JNI(register_android_backup_BackupDataOutput), Loading
packages/ConnectivityT/framework-t/Android.bp +31 −1 Original line number Original line Diff line number Diff line Loading @@ -39,7 +39,6 @@ filegroup { "src/android/net/TrafficStats.java", "src/android/net/TrafficStats.java", "src/android/net/UnderlyingNetworkInfo.*", "src/android/net/UnderlyingNetworkInfo.*", "src/android/net/netstats/**/*.*", "src/android/net/netstats/**/*.*", "src/com/android/server/NetworkManagementSocketTagger.java", ], ], path: "src", path: "src", visibility: [ visibility: [ Loading Loading @@ -176,3 +175,34 @@ filegroup { "//packages/modules/Connectivity:__subpackages__", "//packages/modules/Connectivity:__subpackages__", ], ], } } cc_library_shared { name: "libframework-connectivity-tiramisu-jni", min_sdk_version: "30", cflags: [ "-Wall", "-Werror", "-Wno-unused-parameter", // Don't warn about S API usage even with // min_sdk 30: the library is only loaded // on S+ devices "-Wno-unguarded-availability", "-Wthread-safety", ], srcs: [ "jni/android_net_TrafficStats.cpp", "jni/onload.cpp", ], shared_libs: [ "liblog", ], static_libs: [ "libnativehelper_compat_libc++", ], stl: "none", apex_available: [ "com.android.tethering", // TODO: remove when ConnectivityT moves to APEX. "//apex_available:platform", ], }
core/jni/android_server_NetworkManagementSocketTagger.cpp→packages/ConnectivityT/framework-t/jni/android_net_TrafficStats.cpp +46 −0 Original line number Original line Diff line number Diff line /* /* * Copyright 2011, The Android Open Source Project * Copyright (C) 2022 The Android Open Source Project * * * Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License. Loading @@ -14,60 +14,33 @@ * limitations under the License. * limitations under the License. */ */ #define LOG_TAG "NMST_QTagUidNative" #include <android/file_descriptor_jni.h> #include <android/multinetwork.h> #include <android/multinetwork.h> #include <cutils/qtaguid.h> #include <nativehelper/JNIHelp.h> #include <errno.h> #include <fcntl.h> #include <nativehelper/JNIPlatformHelp.h> #include <sys/socket.h> #include <sys/types.h> #include <utils/Log.h> #include <utils/misc.h> #include "jni.h" namespace android { namespace android { static jint tagSocketFd(JNIEnv* env, jclass, jobject fileDescriptor, static jint tagSocketFd(JNIEnv* env, jclass, jobject fileDescriptor, jint tag, jint uid) { jint tagNum, jint uid) { int fd = AFileDescriptor_getFd(env, fileDescriptor); int userFd = jniGetFDFromFileDescriptor(env, fileDescriptor); if (fd == -1) return -EBADF; return android_tag_socket_with_uid(fd, tag, uid); if (env->ExceptionCheck()) { ALOGE("Can't get FileDescriptor num"); return (jint)-1; } int res = android_tag_socket_with_uid(userFd, tagNum, uid); if (res < 0) { return (jint)-errno; } return (jint)res; } } static jint untagSocketFd(JNIEnv* env, jclass, jobject fileDescriptor) { static jint untagSocketFd(JNIEnv* env, jclass, jobject fileDescriptor) { int userFd = jniGetFDFromFileDescriptor(env, fileDescriptor); int fd = AFileDescriptor_getFd(env, fileDescriptor); if (fd == -1) return -EBADF; if (env->ExceptionCheck()) { return android_untag_socket(fd); ALOGE("Can't get FileDescriptor num"); return (jint)-1; } int res = android_untag_socket(userFd); if (res < 0) { return (jint)-errno; } return (jint)res; } } static const JNINativeMethod gQTagUidMethods[] = { static const JNINativeMethod gMethods[] = { /* name, signature, funcPtr */ { "native_tagSocketFd", "(Ljava/io/FileDescriptor;II)I", (void*) tagSocketFd }, { "native_tagSocketFd", "(Ljava/io/FileDescriptor;II)I", (void*) tagSocketFd }, { "native_untagSocketFd", "(Ljava/io/FileDescriptor;)I", (void*) untagSocketFd }, { "native_untagSocketFd", "(Ljava/io/FileDescriptor;)I", (void*) untagSocketFd }, }; }; int register_android_server_NetworkManagementSocketTagger(JNIEnv* env) { int register_android_net_TrafficStats(JNIEnv* env) { return jniRegisterNativeMethods(env, "com/android/server/NetworkManagementSocketTagger", gQTagUidMethods, NELEM(gQTagUidMethods)); return jniRegisterNativeMethods(env, "android/net/TrafficStats", gMethods, NELEM(gMethods)); } } }; }; // namespace android
packages/ConnectivityT/framework-t/jni/onload.cpp 0 → 100644 +39 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #define LOG_TAG "FrameworkConnectivityJNI" #include <log/log.h> #include <nativehelper/JNIHelp.h> namespace android { int register_android_net_TrafficStats(JNIEnv* env); extern "C" jint JNI_OnLoad(JavaVM* vm, void*) { JNIEnv *env; if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) { __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "ERROR: GetEnv failed"); return JNI_ERR; } if (register_android_net_TrafficStats(env) < 0) return JNI_ERR; return JNI_VERSION_1_6; } }; // namespace android