Swap TX and RX in addForwardChainStats for clarity.

Bug: 32163131
Bug: 64995262
Test: netd_{unit,integration}_test pass
Test: tethering data usage UI reflects actual data usage
Change-Id: Icf5b66972d91e9e45e40d7b4989a15f970a78461
diff --git a/server/NetdNativeService.cpp b/server/NetdNativeService.cpp
index ec4360a..e541bd5 100644
--- a/server/NetdNativeService.cpp
+++ b/server/NetdNativeService.cpp
@@ -296,24 +296,10 @@
         for (int i = 0; i < INetd::TETHER_STATS_ARRAY_SIZE; i++) statsVector.push_back(0);
     }
 
-    // Note: currently, TetherController::addForwardChainStats swaps TX and RX counters.
-    // Specifically, when parsing iptables counters like this:
-    //
-    // Chain tetherctrl_counters (0 references)
-    //     pkts      bytes target     prot opt in     out     source               destination
-    //     4107   214602 RETURN     all  --  rndis0 rmnet_data0  0.0.0.0/0            0.0.0.0/0
-    //     6937 10361624 RETURN     all  --  rmnet_data0 rndis0  0.0.0.0/0            0.0.0.0/0
-    //
-    // it will return a TetherStatsList with one element that has intIface rndis0 and extIface
-    // rmnet_data0 (correct) but with rxBytes=214602 and txBytes=10361624 (swapped). Because the
-    // code in getTetherStats and the corresponding code in NetworkManagementService swaps the
-    // counters again, this all works.
-    //
-    // TODO: once "bandwidth gettetherstats" is gone, swap the counters in addForwardChainStats.
-    statsVector[INetd::TETHER_STATS_RX_BYTES]   += stats.txBytes;
-    statsVector[INetd::TETHER_STATS_RX_PACKETS] += stats.txPackets;
-    statsVector[INetd::TETHER_STATS_TX_BYTES]   += stats.rxBytes;
-    statsVector[INetd::TETHER_STATS_TX_PACKETS] += stats.rxPackets;
+    statsVector[INetd::TETHER_STATS_RX_BYTES]   += stats.rxBytes;
+    statsVector[INetd::TETHER_STATS_RX_PACKETS] += stats.rxPackets;
+    statsVector[INetd::TETHER_STATS_TX_BYTES]   += stats.txBytes;
+    statsVector[INetd::TETHER_STATS_TX_PACKETS] += stats.txPackets;
 
     bundle->putLongVector(iface, statsVector);
 }
diff --git a/server/TetherController.cpp b/server/TetherController.cpp
index 3f6efe9..13cf1d8 100644
--- a/server/TetherController.cpp
+++ b/server/TetherController.cpp
@@ -692,12 +692,12 @@
             ALOGV("0Filter RX iface_in=%s iface_out=%s rx_bytes=%" PRId64" rx_packets=%" PRId64" ", iface0, iface1, bytes, packets);
             stats.intIface = iface0;
             stats.extIface = iface1;
-            stats.rxPackets = packets;
-            stats.rxBytes = bytes;
-        } else if (stats.intIface == iface1 && stats.extIface == iface0) {
-            ALOGV("0Filter TX iface_in=%s iface_out=%s rx_bytes=%" PRId64" rx_packets=%" PRId64" ", iface0, iface1, bytes, packets);
             stats.txPackets = packets;
             stats.txBytes = bytes;
+        } else if (stats.intIface == iface1 && stats.extIface == iface0) {
+            ALOGV("0Filter TX iface_in=%s iface_out=%s rx_bytes=%" PRId64" rx_packets=%" PRId64" ", iface0, iface1, bytes, packets);
+            stats.rxPackets = packets;
+            stats.rxBytes = bytes;
         }
         if (stats.rxBytes != -1 && stats.txBytes != -1) {
             ALOGV("rx_bytes=%" PRId64" tx_bytes=%" PRId64, stats.rxBytes, stats.txBytes);
diff --git a/server/TetherControllerTest.cpp b/server/TetherControllerTest.cpp
index 5043d12..362af2f 100644
--- a/server/TetherControllerTest.cpp
+++ b/server/TetherControllerTest.cpp
@@ -245,8 +245,8 @@
 
     // IPv4 and IPv6 counters are properly added together.
     addIptablesRestoreOutput(kIPv4TetherCounters, kIPv6TetherCounters);
-    TetherStats expected0("wlan0", "rmnet0", 10002373, 10026, 20002002, 20027);
-    TetherStats expected1("bt-pan", "rmnet0", 107471, 1040, 1708806, 1450);
+    TetherStats expected0("wlan0", "rmnet0", 20002002, 20027, 10002373, 10026);
+    TetherStats expected1("bt-pan", "rmnet0", 1708806, 1450, 107471, 1040);
     StatusOr<TetherStatsList> result = mTetherCtrl.getTetherStats();
     ASSERT_TRUE(isOk(result));
     TetherStatsList actual = result.value();
@@ -270,7 +270,7 @@
     counterLines.resize(4);
     std::string counters = Join(counterLines, "\n") + "\n";
     addIptablesRestoreOutput(counters, counters);
-    TetherStats expected1_0("wlan0", "rmnet0", 4746, 52, 4004, 54);
+    TetherStats expected1_0("wlan0", "rmnet0", 4004, 54, 4746, 52);
     result = mTetherCtrl.getTetherStats();
     ASSERT_TRUE(isOk(result));
     actual = result.value();