summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-11-15 06:23:38 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-11-15 06:23:38 +0000
commitaf51f810c89bc9c54654db15c40c3ba86dc19789 (patch)
treefe7a4e192fdd3c064058442e341c841f811a6c0d
parent50bd2584aaeb6af15d8bfba12fe8c41994192ed3 (diff)
parente948775f919eb5282de73ac4aa5052ebd8055ce1 (diff)
downloadnet-android12-mainline-networkstack-release.tar.gz
Snap for 7914678 from e948775f919eb5282de73ac4aa5052ebd8055ce1 to mainline-networking-releaseandroid-mainline-12.0.0_r49android12-mainline-networkstack-release
Change-Id: Ib671f2e401e10a39ee359d75e3b778192e4fdabf
-rw-r--r--common/Android.bp55
-rw-r--r--common/device/com/android/net/module/util/BpfMap.java2
-rw-r--r--common/device/com/android/net/module/util/JniUtil.java35
-rw-r--r--common/native/README.md27
-rw-r--r--common/native/bpfmapjni/Android.bp4
-rw-r--r--common/tests/unit/Android.bp1
-rw-r--r--common/tests/unit/src/com/android/net/module/util/JniUtilTest.kt38
-rw-r--r--common/testutils/app/connectivitychecker/Android.bp6
8 files changed, 159 insertions, 9 deletions
diff --git a/common/Android.bp b/common/Android.bp
index f1e7c85e..68decf67 100644
--- a/common/Android.bp
+++ b/common/Android.bp
@@ -95,16 +95,37 @@ filegroup {
}
java_library {
- name: "net-utils-device-common-netlink",
- // TODO: Ipv6Utils and Struct stuff could be separated out of the netlink library into
- // an individual Struct library, and remove the net-utils-framework-common lib dependency.
- // But there is no need doing this at the moment.
+ name: "net-utils-device-common-bpf",
srcs: [
"device/com/android/net/module/util/BpfMap.java",
+ "device/com/android/net/module/util/JniUtil.java",
+ ],
+ sdk_version: "system_current",
+ min_sdk_version: "29",
+ visibility: [
+ "//frameworks/libs/net/common/tests:__subpackages__",
+ "//frameworks/libs/net/common/testutils:__subpackages__",
+ "//packages/modules/Connectivity:__subpackages__",
+ "//packages/modules/NetworkStack:__subpackages__",
+ ],
+ static_libs: [
+ "net-utils-device-common-struct",
+ ],
+ libs: [
+ "androidx.annotation_annotation",
+ ],
+ apex_available: [
+ "com.android.tethering",
+ "//apex_available:platform",
+ ],
+}
+
+java_library {
+ name: "net-utils-device-common-struct",
+ srcs: [
"device/com/android/net/module/util/HexDump.java",
"device/com/android/net/module/util/Ipv6Utils.java",
"device/com/android/net/module/util/Struct.java",
- "device/com/android/net/module/util/netlink/*.java",
"device/com/android/net/module/util/structs/*.java",
],
sdk_version: "system_current",
@@ -127,6 +148,30 @@ java_library {
}
java_library {
+ name: "net-utils-device-common-netlink",
+ srcs: [
+ "device/com/android/net/module/util/netlink/*.java",
+ ],
+ sdk_version: "system_current",
+ min_sdk_version: "29",
+ visibility: [
+ "//frameworks/libs/net/common/testutils:__subpackages__",
+ "//packages/modules/Connectivity:__subpackages__",
+ "//packages/modules/NetworkStack:__subpackages__",
+ ],
+ static_libs: [
+ "net-utils-device-common-struct",
+ ],
+ libs: [
+ "androidx.annotation_annotation",
+ ],
+ apex_available: [
+ "com.android.tethering",
+ "//apex_available:platform",
+ ],
+}
+
+java_library {
// TODO : this target should probably be folded into net-utils-device-common
name: "net-utils-device-common-ip",
srcs: [
diff --git a/common/device/com/android/net/module/util/BpfMap.java b/common/device/com/android/net/module/util/BpfMap.java
index aa741528..5f05c7c9 100644
--- a/common/device/com/android/net/module/util/BpfMap.java
+++ b/common/device/com/android/net/module/util/BpfMap.java
@@ -42,7 +42,7 @@ import java.util.function.BiConsumer;
*/
public class BpfMap<K extends Struct, V extends Struct> implements AutoCloseable {
static {
- System.loadLibrary("tetherutilsjni");
+ System.loadLibrary(JniUtil.getJniLibraryName(BpfMap.class.getPackage()));
}
// Following definitions from kernel include/uapi/linux/bpf.h
diff --git a/common/device/com/android/net/module/util/JniUtil.java b/common/device/com/android/net/module/util/JniUtil.java
new file mode 100644
index 00000000..5210a3ef
--- /dev/null
+++ b/common/device/com/android/net/module/util/JniUtil.java
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+package com.android.net.module.util;
+
+/**
+ * Utilities for modules to use jni.
+ */
+public final class JniUtil {
+ /**
+ * The method to find jni library accroding to the giving package name.
+ *
+ * The jni library name would be packageName + _jni.so. E.g.
+ * com_android_networkstack_tethering_util_jni for tethering,
+ * com_android_connectivity_util_jni for connectivity.
+ */
+ public static String getJniLibraryName(final Package pkg) {
+ final String libPrefix = pkg.getName().replaceAll("\\.", "_");
+
+ return libPrefix + "_jni";
+ }
+}
diff --git a/common/native/README.md b/common/native/README.md
new file mode 100644
index 00000000..18d19c46
--- /dev/null
+++ b/common/native/README.md
@@ -0,0 +1,27 @@
+# JNI
+As a general rule, jarjar every static library dependency used in a mainline module into the
+modules's namespace (especially if it is also used by other modules)
+
+Fully-qualified name of java class needs to be hard-coded into the JNI .so, because JNI_OnLoad
+does not take any parameters. This means that there needs to be a different .so target for each
+post-jarjared package, so for each module.
+
+This is the guideline to provide JNI library shared with modules:
+
+* provide a common java library in frameworks/libs/net with the Java class (e.g. BpfMap.java).
+
+* provide a common native library in frameworks/libs/net with the JNI and provide the native
+ register function with class_name parameter. See register_com_android_net_module_util_BpfMap
+ function in frameworks/libs/net/common/native/bpfmapjni/com_android_net_module_util_BpfMap.cpp
+ as an example.
+
+When you want to use JNI library from frameworks/lib/net:
+
+* Each module includes the java library (e.g. net-utils-device-common-bpf) and applies its jarjar
+ rules after build.
+
+* Each module creates a native library in their directory, which statically links against the
+ common native library (e.g. libnet_utils_device_common_bpf), and calls the native registered
+ function by hardcoding the post-jarjar class_name.
+
+
diff --git a/common/native/bpfmapjni/Android.bp b/common/native/bpfmapjni/Android.bp
index edbae7ce..b7af22d3 100644
--- a/common/native/bpfmapjni/Android.bp
+++ b/common/native/bpfmapjni/Android.bp
@@ -17,7 +17,7 @@ package {
}
cc_library_static {
- name: "libbpfmapjni",
+ name: "libnet_utils_device_common_bpfjni",
srcs: ["com_android_net_module_util_BpfMap.cpp"],
header_libs: [
"bpf_syscall_wrappers",
@@ -39,6 +39,6 @@ cc_library_static {
"//apex_available:platform",
],
visibility: [
- "//packages/modules/Connectivity/Tethering",
+ "//packages/modules/Connectivity:__subpackages__",
],
}
diff --git a/common/tests/unit/Android.bp b/common/tests/unit/Android.bp
index a9f9d70b..07a8200c 100644
--- a/common/tests/unit/Android.bp
+++ b/common/tests/unit/Android.bp
@@ -17,6 +17,7 @@ android_library {
"androidx.test.rules",
"mockito-target-extended-minus-junit4",
"net-utils-device-common",
+ "net-utils-device-common-bpf",
"net-tests-utils",
"netd-client",
],
diff --git a/common/tests/unit/src/com/android/net/module/util/JniUtilTest.kt b/common/tests/unit/src/com/android/net/module/util/JniUtilTest.kt
new file mode 100644
index 00000000..75740877
--- /dev/null
+++ b/common/tests/unit/src/com/android/net/module/util/JniUtilTest.kt
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+
+package com.android.net.module.util
+
+import androidx.test.filters.SmallTest
+import androidx.test.runner.AndroidJUnit4
+import kotlin.test.assertEquals
+import org.junit.Test
+import org.junit.runner.RunWith
+
+@RunWith(AndroidJUnit4::class)
+@SmallTest
+public final class JniUtilTest {
+ private val TEST_JAVA_UTIL_NAME = "java_util_jni"
+ private val TEST_ORG_JUNIT_NAME = "org_junit_jni"
+
+ @Test
+ fun testGetJniLibraryName() {
+ assertEquals(TEST_JAVA_UTIL_NAME,
+ JniUtil.getJniLibraryName(java.util.Set::class.java.getPackage()))
+ assertEquals(TEST_ORG_JUNIT_NAME,
+ JniUtil.getJniLibraryName(org.junit.Before::class.java.getPackage()))
+ }
+}
diff --git a/common/testutils/app/connectivitychecker/Android.bp b/common/testutils/app/connectivitychecker/Android.bp
index 55b585ae..79a4343f 100644
--- a/common/testutils/app/connectivitychecker/Android.bp
+++ b/common/testutils/app/connectivitychecker/Android.bp
@@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.
+package {
+ default_applicable_licenses: ["Android-Apache-2.0"],
+}
+
android_test_helper_app {
name: "ConnectivityChecker",
srcs: ["src/**/*.kt"],
@@ -26,4 +30,4 @@ android_test_helper_app {
"net-tests-utils",
],
host_required: ["net-tests-utils-host-common"],
-} \ No newline at end of file
+}