Separate bpf and struct util from netlink util library
1. Separate bpf and struct libraries from netlink library.
2. Rename bpfmap jni library to respect its java side library.
3. Add README to explain the rules of adding shared jni library.
4. Also allow packages/modules/Connectivity to use bpf library.
Bug: 205088391
Test: atest TetheringTests
atest CtsTetheringTest
atest TetheringPrivilegedTests
atest ConnectivityCoverageTests
Change-Id: I6e668818bede63b241cd901c0967f401613ddaf6
diff --git a/staticlibs/Android.bp b/staticlibs/Android.bp
index 93084cc..68decf6 100644
--- a/staticlibs/Android.bp
+++ b/staticlibs/Android.bp
@@ -95,17 +95,37 @@
}
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/JniUtil.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",
@@ -128,6 +148,30 @@
}
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/staticlibs/native/README.md b/staticlibs/native/README.md
new file mode 100644
index 0000000..18d19c4
--- /dev/null
+++ b/staticlibs/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/staticlibs/native/bpfmapjni/Android.bp b/staticlibs/native/bpfmapjni/Android.bp
index edbae7c..b7af22d 100644
--- a/staticlibs/native/bpfmapjni/Android.bp
+++ b/staticlibs/native/bpfmapjni/Android.bp
@@ -17,7 +17,7 @@
}
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 @@
"//apex_available:platform",
],
visibility: [
- "//packages/modules/Connectivity/Tethering",
+ "//packages/modules/Connectivity:__subpackages__",
],
}
diff --git a/staticlibs/tests/unit/Android.bp b/staticlibs/tests/unit/Android.bp
index a9f9d70..07a8200 100644
--- a/staticlibs/tests/unit/Android.bp
+++ b/staticlibs/tests/unit/Android.bp
@@ -17,6 +17,7 @@
"androidx.test.rules",
"mockito-target-extended-minus-junit4",
"net-utils-device-common",
+ "net-utils-device-common-bpf",
"net-tests-utils",
"netd-client",
],