Adjust overflow protection

Add a total limit for number of stats entries in stats map.
TrafficController will stop tagging sockets when the total limit is hit
to prevent losing per uid stats. After the stats map have more stats
entries then the limit in total, TrafficController will block all new
tagging requests and return -EMFILE until the map is cleaned up. Also
add some unit tests to verify this behavior.

Bug: 126620214
Test: TrafficControllerTest
Change-Id: Iff3ca09b58e9aee640d879ebdceb017b7e239cbc
diff --git a/server/TrafficController.h b/server/TrafficController.h
index cafc319..08a8000 100644
--- a/server/TrafficController.h
+++ b/server/TrafficController.h
@@ -217,6 +217,15 @@
 
     std::mutex mMutex;
 
+    // The limit on the number of stats entries a uid can have in the per uid stats map.
+    // TrafficController will block that specific uid from tagging new sockets after the limit is
+    // reached.
+    const uint32_t mPerUidStatsEntriesLimit;
+
+    // The limit on the total number of stats entries in the per uid stats map. TrafficController
+    // will block all tagging requests after the limit is reached.
+    const uint32_t mTotalUidStatsEntriesLimit;
+
     netdutils::Status loadAndAttachProgram(bpf_attach_type type, const char* path, const char* name,
                                            base::unique_fd& cg_fd);
 
@@ -229,6 +238,10 @@
     UidOwnerMatchType jumpOpToMatch(BandwidthController::IptJumpOp jumpHandling);
 
     bool hasUpdateDeviceStatsPermission(uid_t uid) REQUIRES(mMutex);
+
+    // For testing
+    TrafficController(uint32_t perUidLimit, uint32_t totalLimit);
+
     // For testing
     friend class TrafficControllerTest;
 };