Rename libnetdbpf to libnetworkstats

Two reason for renaming:
1. Avoid module name collision in sc-mainline-prod branch.
2. The libnetdbpf was misnamed before.

Bug: 202086915
Test: atest libnetworkstats_test FrameworksNetTests
      ConnectivityCoverageTests FrameworksNetSmokeTests
      CtsAppOpsTestCases
Change-Id: I87fcf4b1a9d58780a45743a9aa91b9b936e54266
diff --git a/TEST_MAPPING b/TEST_MAPPING
index ffbd1fc..780ba26 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -26,6 +26,9 @@
     },
     {
       "name": "traffic_controller_unit_test"
+    },
+    {
+      "name": "libnetworkstats_test"
     }
   ],
   "postsubmit": [
@@ -42,6 +45,9 @@
     {
       "name": "traffic_controller_unit_test",
       "keywords": ["netd-device-kernel-4.9", "netd-device-kernel-4.14"]
+    },
+    {
+      "name": "libnetworkstats_test"
     }
   ],
   "mainline-presubmit": [
@@ -61,6 +67,9 @@
     },
     {
       "name": "traffic_controller_unit_test[CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex]"
+    },
+    {
+      "name": "libnetworkstats_test[CaptivePortalLoginGoogle.apk+NetworkStackGoogle.apk+com.google.android.resolv.apex+com.google.android.tethering.apex]"
     }
   ],
   "mainline-postsubmit": [
diff --git a/bpf_progs/Android.bp b/bpf_progs/Android.bp
index e228df0..a7155fd 100644
--- a/bpf_progs/Android.bp
+++ b/bpf_progs/Android.bp
@@ -44,9 +44,8 @@
         "//frameworks/base/services/core/jni",
         "//packages/modules/Connectivity/Tethering",
         "//packages/modules/Connectivity/service/native",
+        "//packages/modules/Connectivity/service-t/native/libs/libnetworkstats",
         "//packages/modules/Connectivity/tests/unit/jni",
-        // TODO: remove system/netd/* when all BPF code is moved out of Netd.
-        "//system/netd/libnetdbpf",
         "//system/netd/server",
         "//system/netd/tests",
     ],
diff --git a/bpf_progs/bpf_shared.h b/bpf_progs/bpf_shared.h
index 8577d9d..f0df97b 100644
--- a/bpf_progs/bpf_shared.h
+++ b/bpf_progs/bpf_shared.h
@@ -20,7 +20,6 @@
 #include <linux/if_ether.h>
 #include <linux/in.h>
 #include <linux/in6.h>
-#include <netdutils/UidConstants.h>
 
 // This header file is shared by eBPF kernel programs (C) and netd (C++) and
 // some of the maps are also accessed directly from Java mainline module code.
diff --git a/bpf_progs/netd.c b/bpf_progs/netd.c
index 72ee431..f0af8b4 100644
--- a/bpf_progs/netd.c
+++ b/bpf_progs/netd.c
@@ -25,6 +25,7 @@
 #include <linux/ipv6.h>
 #include <linux/pkt_cls.h>
 #include <linux/tcp.h>
+#include <netdutils/UidConstants.h>
 #include <stdbool.h>
 #include <stdint.h>
 #include "bpf_net_helpers.h"
diff --git a/service-t/native/libs/libnetdbpf/Android.bp b/service-t/native/libs/libnetworkstats/Android.bp
similarity index 66%
rename from service-t/native/libs/libnetdbpf/Android.bp
rename to service-t/native/libs/libnetworkstats/Android.bp
index d586d68..bceeefa 100644
--- a/service-t/native/libs/libnetdbpf/Android.bp
+++ b/service-t/native/libs/libnetworkstats/Android.bp
@@ -15,16 +15,11 @@
 //
 
 package {
-    // See: http://go/android-license-faq
-    // A large-scale-change added 'default_applicable_licenses' to import
-    // all of the 'license_kinds' from "system_netd_license"
-    // to get the below license kinds:
-    //   SPDX-license-identifier-Apache-2.0
-    default_applicable_licenses: ["system_netd_license"],
+    default_applicable_licenses: ["Android-Apache-2.0"],
 }
 
 cc_library {
-    name: "libnetdbpf",
+    name: "libnetworkstats",
     vendor_available: false,
     host_supported: false,
     header_libs: ["bpf_connectivity_headers"],
@@ -34,30 +29,43 @@
     shared_libs: [
         "libbase",
         "liblog",
-        "libnetdutils",
     ],
     export_include_dirs: ["include"],
-    defaults: ["netd_defaults"],
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+        "-Wthread-safety",
+    ],
     sanitize: {
         cfi: true,
     },
+    apex_available: [
+        "//apex_available:platform",
+        "com.android.tethering",
+    ],
+    min_sdk_version: "30",
 }
 
 cc_test {
-    name: "libnetdbpf_test",
-    test_suites: ["device-tests"],
-    require_root: true,
+    name: "libnetworkstats_test",
+    test_suites: ["general-tests"],
+    require_root: true,  // required by setrlimitForTest()
     header_libs: ["bpf_connectivity_headers"],
     srcs: [
         "BpfNetworkStatsTest.cpp",
     ],
-    defaults: ["netd_defaults"],
+    cflags: [
+        "-Wall",
+        "-Werror",
+        "-Wno-unused-parameter",
+        "-Wthread-safety",
+    ],
     static_libs: ["libgmock"],
     shared_libs: [
         "libbase",
         "liblog",
-        "libnetdbpf",
-        "libnetdutils",
+        "libnetworkstats",
         "libutils",
     ],
 }
diff --git a/service-t/native/libs/libnetdbpf/BpfNetworkStats.cpp b/service-t/native/libs/libnetworkstats/BpfNetworkStats.cpp
similarity index 100%
rename from service-t/native/libs/libnetdbpf/BpfNetworkStats.cpp
rename to service-t/native/libs/libnetworkstats/BpfNetworkStats.cpp
diff --git a/service-t/native/libs/libnetdbpf/BpfNetworkStatsTest.cpp b/service-t/native/libs/libnetworkstats/BpfNetworkStatsTest.cpp
similarity index 99%
rename from service-t/native/libs/libnetdbpf/BpfNetworkStatsTest.cpp
rename to service-t/native/libs/libnetworkstats/BpfNetworkStatsTest.cpp
index fb8f0ec..03e6016 100644
--- a/service-t/native/libs/libnetdbpf/BpfNetworkStatsTest.cpp
+++ b/service-t/native/libs/libnetworkstats/BpfNetworkStatsTest.cpp
@@ -33,7 +33,6 @@
 #include <android-base/stringprintf.h>
 #include <android-base/strings.h>
 
-#include <netdutils/MockSyscalls.h>
 #include "bpf/BpfMap.h"
 #include "bpf/BpfUtils.h"
 #include "netdbpf/BpfNetworkStats.h"
diff --git a/service-t/native/libs/libnetdbpf/include/netdbpf/BpfNetworkStats.h b/service-t/native/libs/libnetworkstats/include/netdbpf/BpfNetworkStats.h
similarity index 100%
rename from service-t/native/libs/libnetdbpf/include/netdbpf/BpfNetworkStats.h
rename to service-t/native/libs/libnetworkstats/include/netdbpf/BpfNetworkStats.h
diff --git a/service/native/TrafficController.cpp b/service/native/TrafficController.cpp
index cac545d..97fcc43 100644
--- a/service/native/TrafficController.cpp
+++ b/service/native/TrafficController.cpp
@@ -40,6 +40,7 @@
 #include <android-base/unique_fd.h>
 #include <netdutils/StatusOr.h>
 #include <netdutils/Syscalls.h>
+#include <netdutils/UidConstants.h>
 #include <netdutils/Utils.h>
 #include <private/android_filesystem_config.h>
 
diff --git a/tests/unit/Android.bp b/tests/unit/Android.bp
index 48751f4..f95e79f 100644
--- a/tests/unit/Android.bp
+++ b/tests/unit/Android.bp
@@ -38,8 +38,8 @@
         "liblog",
         "liblzma",
         "libnativehelper",
-        "libnetdbpf",
         "libnetdutils",
+        "libnetworkstats",
         "libnetworkstatsfactorytestjni",
         "libpackagelistparser",
         "libpcre2",
diff --git a/tests/unit/jni/Android.bp b/tests/unit/jni/Android.bp
index fe971e7..0f71c13 100644
--- a/tests/unit/jni/Android.bp
+++ b/tests/unit/jni/Android.bp
@@ -24,7 +24,7 @@
         "libbpf_android",
         "liblog",
         "libnativehelper",
-        "libnetdbpf",
         "libnetdutils",
+        "libnetworkstats",
     ],
 }