Don't complain when finding no tether stats.

TetherController::addForwardChainStats returns an error if it
doesn't find any tethering stats. This was fine when we were
still using CommandListener, which would not attempt to fetch
the stats if tethering was not enabled.

Instead of returning an error when no stats are found, return
an error only if the output was empty (implying that no headers
were found and thus the required rules do not exist). If the
output contains headers but no stats, don't return an error.

Returning an error was a necessity in the previous code because
it had no unit or integration tests, but such measures are not
necessary now that we have test coverage.

Fix: 65550883
Bug: 65369386
Test: bullhead builds, boots
Test: netd_{unit,integration}_test pass
Change-Id: Ie32f4d941dd52c8dc9ff09fde26cc97cedf96bc3
diff --git a/server/TetherControllerTest.cpp b/server/TetherControllerTest.cpp
index 362af2f..b92dc24 100644
--- a/server/TetherControllerTest.cpp
+++ b/server/TetherControllerTest.cpp
@@ -234,11 +234,28 @@
 }
 
 TEST_F(TetherControllerTest, TestGetTetherStats) {
-    // If no filter is specified, both IPv4 and IPv6 counters must have at least one interface pair.
-    addIptablesRestoreOutput(kIPv4TetherCounters);
+    // Finding no headers is an error.
     ASSERT_FALSE(isOk(mTetherCtrl.getTetherStats()));
     clearIptablesRestoreOutput();
 
+    // Finding only v4 or only v6 headers is an error.
+    addIptablesRestoreOutput(kTetherCounterHeaders, "");
+    ASSERT_FALSE(isOk(mTetherCtrl.getTetherStats()));
+    clearIptablesRestoreOutput();
+
+    addIptablesRestoreOutput("", kTetherCounterHeaders);
+    ASSERT_FALSE(isOk(mTetherCtrl.getTetherStats()));
+    clearIptablesRestoreOutput();
+
+    // Finding headers but no stats is not an error.
+    addIptablesRestoreOutput(kTetherCounterHeaders, kTetherCounterHeaders);
+    StatusOr<TetherStatsList> result = mTetherCtrl.getTetherStats();
+    ASSERT_TRUE(isOk(result));
+    TetherStatsList actual = result.value();
+    ASSERT_EQ(0U, actual.size());
+    clearIptablesRestoreOutput();
+
+
     addIptablesRestoreOutput(kIPv6TetherCounters);
     ASSERT_FALSE(isOk(mTetherCtrl.getTetherStats()));
     clearIptablesRestoreOutput();
@@ -247,9 +264,9 @@
     addIptablesRestoreOutput(kIPv4TetherCounters, kIPv6TetherCounters);
     TetherStats expected0("wlan0", "rmnet0", 20002002, 20027, 10002373, 10026);
     TetherStats expected1("bt-pan", "rmnet0", 1708806, 1450, 107471, 1040);
-    StatusOr<TetherStatsList> result = mTetherCtrl.getTetherStats();
+    result = mTetherCtrl.getTetherStats();
     ASSERT_TRUE(isOk(result));
-    TetherStatsList actual = result.value();
+    actual = result.value();
     ASSERT_EQ(2U, actual.size());
     expectTetherStatsEqual(expected0, result.value()[0]);
     expectTetherStatsEqual(expected1, result.value()[1]);