Modernize string handling in BandwidthController

This change is preparation for removal of xt_quota2 in favor of NFLOG.
Note that the scope of changes is mostly limited to mechanical single
line changes from "const char*" to "const std::string&".

Test: as follows
    - built
    - flashed
    - booted
    - "runtest -x .../netd_unit_test.cpp" passes
    - "runtest -x .../netd_integration_test.cpp" passes
Bug: 38143143
Bug: 28362720

Change-Id: I56ba810ff6fa2f409e32d86508cfdb1a81a50a4e
diff --git a/server/BandwidthController.h b/server/BandwidthController.h
index 0a51346..b739841 100644
--- a/server/BandwidthController.h
+++ b/server/BandwidthController.h
@@ -18,7 +18,8 @@
 
 #include <list>
 #include <string>
-#include <utility>  // for pair
+#include <utility>
+#include <vector>
 
 #include <sysutils/SocketClient.h>
 #include <utils/RWLock.h>
@@ -31,9 +32,7 @@
 
     class TetherStats {
     public:
-        TetherStats(void)
-                : rxBytes(-1), rxPackets(-1),
-                    txBytes(-1), txPackets(-1) {};
+        TetherStats() = default;
         TetherStats(std::string intIfn, std::string extIfn,
                 int64_t rxB, int64_t rxP,
                 int64_t txB, int64_t txP)
@@ -44,14 +43,16 @@
         std::string intIface;
         /* External interface. Same as NatController's notion. */
         std::string extIface;
-        int64_t rxBytes, rxPackets;
-        int64_t txBytes, txPackets;
+        int64_t rxBytes = -1;
+        int64_t rxPackets = -1;
+        int64_t txBytes = -1;
+        int64_t txPackets = -1;
         /*
          * Allocates a new string representing this:
          * intIface extIface rx_bytes rx_packets tx_bytes tx_packets
          * The caller is responsible for free()'ing the returned ptr.
          */
-        char *getStatsLine(void) const;
+        std::string getStatsLine() const;
 
         bool addStatsIfMatch(const TetherStats& other) {
             if (intIface == other.intIface && extIface == other.extIface) {
@@ -67,19 +68,19 @@
 
     BandwidthController();
 
-    int setupIptablesHooks(void);
+    int setupIptablesHooks();
 
     int enableBandwidthControl(bool force);
-    int disableBandwidthControl(void);
+    int disableBandwidthControl();
     int enableDataSaver(bool enable);
 
-    int setInterfaceSharedQuota(const char *iface, int64_t bytes);
+    int setInterfaceSharedQuota(const std::string& iface, int64_t bytes);
     int getInterfaceSharedQuota(int64_t *bytes);
-    int removeInterfaceSharedQuota(const char *iface);
+    int removeInterfaceSharedQuota(const std::string& iface);
 
-    int setInterfaceQuota(const char *iface, int64_t bytes);
-    int getInterfaceQuota(const char *iface, int64_t *bytes);
-    int removeInterfaceQuota(const char *iface);
+    int setInterfaceQuota(const std::string& iface, int64_t bytes);
+    int getInterfaceQuota(const std::string& iface, int64_t* bytes);
+    int removeInterfaceQuota(const std::string& iface);
 
     int addNaughtyApps(int numUids, char *appUids[]);
     int removeNaughtyApps(int numUids, char *appUids[]);
@@ -87,15 +88,15 @@
     int removeNiceApps(int numUids, char *appUids[]);
 
     int setGlobalAlert(int64_t bytes);
-    int removeGlobalAlert(void);
-    int setGlobalAlertInForwardChain(void);
-    int removeGlobalAlertInForwardChain(void);
+    int removeGlobalAlert();
+    int setGlobalAlertInForwardChain();
+    int removeGlobalAlertInForwardChain();
 
     int setSharedAlert(int64_t bytes);
-    int removeSharedAlert(void);
+    int removeSharedAlert();
 
-    int setInterfaceAlert(const char *iface, int64_t bytes);
-    int removeInterfaceAlert(const char *iface);
+    int setInterfaceAlert(const std::string& iface, int64_t bytes);
+    int removeInterfaceAlert(const std::string& iface);
 
     /*
      * For single pair of ifaces, stats should have ifaceIn and ifaceOut initialized.
@@ -107,13 +108,13 @@
      */
     int getTetherStats(SocketClient *cli, TetherStats &stats, std::string &extraProcessingInfo);
 
-    static const char* LOCAL_INPUT;
-    static const char* LOCAL_FORWARD;
-    static const char* LOCAL_OUTPUT;
-    static const char* LOCAL_RAW_PREROUTING;
-    static const char* LOCAL_MANGLE_POSTROUTING;
+    static const char LOCAL_INPUT[];
+    static const char LOCAL_FORWARD[];
+    static const char LOCAL_OUTPUT[];
+    static const char LOCAL_RAW_PREROUTING[];
+    static const char LOCAL_MANGLE_POSTROUTING[];
 
-protected:
+  private:
     class QuotaInfo {
     public:
       QuotaInfo(std::string ifn, int64_t q, int64_t a)
@@ -135,37 +136,30 @@
     enum IptFailureLog { IptFailShow, IptFailHide = IptFailShow };
 #endif
 
-    int manipulateSpecialApps(int numUids, char *appStrUids[],
-                               const char *chain,
-                               IptJumpOp jumpHandling, IptOp appOp);
-    int manipulateNaughtyApps(int numUids, char *appStrUids[], IptOp appOp);
-    int manipulateNiceApps(int numUids, char *appStrUids[], IptOp appOp);
+    int manipulateSpecialApps(const std::vector<std::string>& appStrUids, const std::string& chain,
+                              IptJumpOp jumpHandling, IptOp appOp);
 
-    int prepCostlyIface(const char *ifn, QuotaType quotaType);
-    int cleanupCostlyIface(const char *ifn, QuotaType quotaType);
+    int prepCostlyIface(const std::string& ifn, QuotaType quotaType);
+    int cleanupCostlyIface(const std::string& ifn, QuotaType quotaType);
 
-    std::string makeIptablesSpecialAppCmd(IptOp op, int uid, const char *chain);
-    std::string makeIptablesQuotaCmd(IptFullOp op, const char *costName, int64_t quota);
+    std::string makeIptablesQuotaCmd(IptFullOp op, const std::string& costName, int64_t quota);
 
-    int runIptablesAlertCmd(IptOp op, const char *alertName, int64_t bytes);
-    int runIptablesAlertFwdCmd(IptOp op, const char *alertName, int64_t bytes);
+    int runIptablesAlertCmd(IptOp op, const std::string& alertName, int64_t bytes);
+    int runIptablesAlertFwdCmd(IptOp op, const std::string& alertName, int64_t bytes);
 
-    /* Runs for both ipv4 and ipv6 iptables */
-    int runCommands(int numCommands, const char *commands[], RunCmdErrHandling cmdErrHandling);
     /* Runs for both ipv4 and ipv6 iptables, appends -j REJECT --reject-with ...  */
-    static int runIpxtablesCmd(const char *cmd, IptJumpOp jumpHandling,
+    static int runIpxtablesCmd(const std::string& cmd, IptJumpOp jumpHandling,
                                IptFailureLog failureHandling = IptFailShow);
-    static int runIptablesCmd(const char *cmd, IptJumpOp jumpHandling, IptIpVer iptIpVer,
+    static int runIptablesCmd(const std::string& cmd, IptJumpOp jumpHandling, IptIpVer iptIpVer,
                               IptFailureLog failureHandling = IptFailShow);
 
-
     // Provides strncpy() + check overflow.
-    static int StrncpyAndCheck(char *buffer, const char *src, size_t buffSize);
+    static int StrncpyAndCheck(char* buffer, const std::string& src, size_t buffSize);
 
-    int updateQuota(const char *alertName, int64_t bytes);
+    int updateQuota(const std::string& alertName, int64_t bytes);
 
-    int setCostlyAlert(const char *costName, int64_t bytes, int64_t *alertBytes);
-    int removeCostlyAlert(const char *costName, int64_t *alertBytes);
+    int setCostlyAlert(const std::string& costName, int64_t bytes, int64_t* alertBytes);
+    int removeCostlyAlert(const std::string& costName, int64_t* alertBytes);
 
     typedef std::vector<TetherStats> TetherStatsList;