Add binder call tetherOffloadGetStats

This binder call is separated from the existing call tetherGetStats
and used for for BPF tether stats.

Note that the default value of ifIndex of TetherStatsParcel.aidl is
applied for backward compatibility because it is added from this
commit.

Make netd modules to use netd_aidl_interface-unstable-cpp.
Both netd and libnetd_server use unstable aidl for new api
tetherOffload* and modified parcel TetherStatsParcel.

Generated with:
m netd_aidl_interface-update-api

Bug: 150736748
Test: atest
Original-Change: https://android-review.googlesource.com/1256108
Merged-In: Ie03834bc40992a4abdc8ef70150569982092b386
Change-Id: Ie03834bc40992a4abdc8ef70150569982092b386
diff --git a/server/NetdNativeService.cpp b/server/NetdNativeService.cpp
index a367a8c..732821b 100644
--- a/server/NetdNativeService.cpp
+++ b/server/NetdNativeService.cpp
@@ -436,6 +436,8 @@
 
 namespace {
 
+constexpr const int UNUSED_IFINDEX = 0;
+
 void tetherAddStatsByInterface(TetherController::TetherStats* tetherStatsParcel,
                                const TetherController::TetherStats& tetherStats) {
     if (tetherStatsParcel->extIface == tetherStats.extIface) {
@@ -453,6 +455,7 @@
     result.rxPackets = stats.rxPackets;
     result.txBytes = stats.txBytes;
     result.txPackets = stats.txPackets;
+    result.ifIndex = UNUSED_IFINDEX;
     return result;
 }
 
@@ -1260,5 +1263,37 @@
     return asBinderStatus(gCtls->tetherCtrl.removeOffloadRule(rule));
 }
 
+namespace {
+
+constexpr const char UNUSED_IFNAME[] = "";
+
+TetherStatsParcel toTetherStatsParcel(const TetherController::TetherOffloadStats& stats) {
+    TetherStatsParcel result;
+    result.iface = UNUSED_IFNAME;
+    result.rxBytes = stats.rxBytes;
+    result.rxPackets = stats.rxPackets;
+    result.txBytes = stats.txBytes;
+    result.txPackets = stats.txPackets;
+    result.ifIndex = stats.ifIndex;
+    return result;
+}
+
+}  // namespace
+
+binder::Status NetdNativeService::tetherOffloadGetStats(
+        std::vector<TetherStatsParcel>* tetherStatsParcelVec) {
+    NETD_LOCKING_RPC(gCtls->tetherCtrl.lock, PERM_NETWORK_STACK, PERM_MAINLINE_NETWORK_STACK);
+
+    tetherStatsParcelVec->clear();
+    const auto& statsList = gCtls->tetherCtrl.getTetherOffloadStats();
+    if (!isOk(statsList)) {
+        return asBinderStatus(statsList);
+    }
+    for (const auto& stats : statsList.value()) {
+        tetherStatsParcelVec->push_back(toTetherStatsParcel(stats));
+    }
+    return binder::Status::ok();
+}
+
 }  // namespace net
 }  // namespace android