Fixing the BandwidthController unit test

The BandwidthController unit test cannot directly use gCtrl->trafficCtrl
to check if the bpf stats feature is avaliable. Rewrite the
getBpfStatsStatus() function of BandwidthController so it is also
functioning when in BandwidthController unit tests.

Bug: 72111305
Test: ./netd_unit_test
Change-Id: Ie60ed384b7f8d42b8e1f3417949d46895bea6572
diff --git a/server/BandwidthController.cpp b/server/BandwidthController.cpp
index e79a595..ffedaf6 100644
--- a/server/BandwidthController.cpp
+++ b/server/BandwidthController.cpp
@@ -207,10 +207,7 @@
  */
 
 const std::vector<std::string> getBasicAccountingCommands() {
-    bool useBpf = android::net::gCtls->trafficCtrl.checkBpfStatsEnable();
-    //TODO: remove this when xt_bpf kernel support is ready
-    useBpf = false;
-
+    bool useBpf = BandwidthController::getBpfStatsStatus();
     const std::vector<std::string> ipt_basic_accounting_commands = {
         "*filter",
         // Prevents IPSec double counting (ESP and UDP-encap-ESP respectively)
@@ -269,6 +266,14 @@
 
 }  // namespace
 
+bool BandwidthController::getBpfStatsStatus() {
+    bool useBpf = (access(XT_BPF_INGRESS_PROG_PATH, F_OK) != -1) &&
+                  (access(XT_BPF_EGRESS_PROG_PATH, F_OK) != -1);
+    // TODO: remove this when xt_bpf kernel support is ready
+    useBpf = false;
+    return useBpf;
+}
+
 BandwidthController::BandwidthController() {
 }