From 8fb75e39167538aaf79ca4fa234ee3564fae97ba Mon Sep 17 00:00:00 2001 From: markchien Date: Thu, 11 Nov 2021 17:53:56 +0800 Subject: [PATCH] Add bpf jni into connectivity module This is the preparing CL for connectivity module to use bpf. Bug: 179733303 Bug: 205088391 Test: atest ConnectivityCoverageTests Change-Id: Ibe49d7f671b5050461e2c63c080d9457ad76c26c --- Tethering/apex/Android.bp | 5 ++- service/Android.bp | 28 ++++++++++++++ .../com_android_net_module_util/onload.cpp | 37 +++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 service/jni/com_android_net_module_util/onload.cpp diff --git a/Tethering/apex/Android.bp b/Tethering/apex/Android.bp index 7863572c52..c4ee87b342 100644 --- a/Tethering/apex/Android.bp +++ b/Tethering/apex/Android.bp @@ -49,7 +49,10 @@ apex { ], multilib: { first: { - jni_libs: ["libservice-connectivity"], + jni_libs: [ + "libservice-connectivity", + "libcom_android_connectivity_com_android_net_module_util_jni" + ], }, both: { jni_libs: ["libframework-connectivity-jni"], diff --git a/service/Android.bp b/service/Android.bp index b595ef2727..1ec7daa0e8 100644 --- a/service/Android.bp +++ b/service/Android.bp @@ -19,6 +19,33 @@ package { default_applicable_licenses: ["Android-Apache-2.0"], } +// The library name match the service-connectivity jarjar rules that put the JNI utils in the +// com.android.connectivity.com.android.net.module.util package. +cc_library_shared { + name: "libcom_android_connectivity_com_android_net_module_util_jni", + min_sdk_version: "30", + cflags: [ + "-Wall", + "-Werror", + "-Wno-unused-parameter", + "-Wthread-safety", + ], + srcs: [ + "jni/com_android_net_module_util/onload.cpp", + ], + stl: "libc++_static", + static_libs: [ + "libnet_utils_device_common_bpfjni", + ], + shared_libs: [ + "liblog", + "libnativehelper", + ], + apex_available: [ + "com.android.tethering", + ], +} + cc_library_shared { name: "libservice-connectivity", min_sdk_version: "30", @@ -69,6 +96,7 @@ java_library { "modules-utils-build", "modules-utils-shell-command-handler", "net-utils-device-common", + "net-utils-device-common-bpf", "net-utils-device-common-netlink", "net-utils-framework-common", "netd-client", diff --git a/service/jni/com_android_net_module_util/onload.cpp b/service/jni/com_android_net_module_util/onload.cpp new file mode 100644 index 0000000000..1d17622f44 --- /dev/null +++ b/service/jni/com_android_net_module_util/onload.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2021 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. + */ + +#include +#include + +namespace android { + +int register_com_android_net_module_util_BpfMap(JNIEnv* env, char const* class_name); + +extern "C" jint JNI_OnLoad(JavaVM* vm, void*) { + JNIEnv *env; + if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_6) != JNI_OK) { + ALOGE("GetEnv failed"); + return JNI_ERR; + } + + if (register_com_android_net_module_util_BpfMap(env, + "com/android/connectivity/com/android/net/module/util/BpfMap") < 0) return JNI_ERR; + + return JNI_VERSION_1_6; +} + +};