Remove kMaxPushedAtomId from atoms_info.

Hardcode kMaxPushedAtomId in StatsdStats.

Bug: 154164020
Test: bit statsd_test:*
Change-Id: Ibca731d9783686a9e3caf0ad580e1d62038d68e2
diff --git a/cmds/statsd/src/atoms.proto b/cmds/statsd/src/atoms.proto
index b7ed6eb..13e7ac1 100644
--- a/cmds/statsd/src/atoms.proto
+++ b/cmds/statsd/src/atoms.proto
@@ -424,6 +424,9 @@
         UserLifecycleJourneyReported user_lifecycle_journey_reported = 264 [(module) = "framework"];
         UserLifecycleEventOccurred user_lifecycle_event_occurred = 265 [(module) = "framework"];
         SdkExtensionStatus sdk_extension_status = 354;
+
+        // StatsdStats tracks platform atoms with ids upto 500.
+        // Update StatsdStats::kMaxPushedAtomId when atom ids here approach that value.
     }
 
     // Pulled events will start at field 10000.
diff --git a/cmds/statsd/src/guardrail/StatsdStats.cpp b/cmds/statsd/src/guardrail/StatsdStats.cpp
index 2bd13d7..db637b1 100644
--- a/cmds/statsd/src/guardrail/StatsdStats.cpp
+++ b/cmds/statsd/src/guardrail/StatsdStats.cpp
@@ -119,7 +119,7 @@
 };
 
 StatsdStats::StatsdStats() {
-    mPushedAtomStats.resize(android::util::kMaxPushedAtomId + 1);
+    mPushedAtomStats.resize(kMaxPushedAtomId + 1);
     mStartTimeSec = getWallClockSec();
 }
 
@@ -448,7 +448,7 @@
 void StatsdStats::noteAtomLogged(int atomId, int32_t timeSec) {
     lock_guard<std::mutex> lock(mLock);
 
-    if (atomId <= android::util::kMaxPushedAtomId) {
+    if (atomId <= kMaxPushedAtomId) {
         mPushedAtomStats[atomId]++;
     } else {
         if (mNonPlatformPushedAtomStats.size() < kMaxNonPlatformPushedAtoms) {
diff --git a/cmds/statsd/src/guardrail/StatsdStats.h b/cmds/statsd/src/guardrail/StatsdStats.h
index 25794c8..ff31e9e 100644
--- a/cmds/statsd/src/guardrail/StatsdStats.h
+++ b/cmds/statsd/src/guardrail/StatsdStats.h
@@ -166,6 +166,10 @@
     // Maximum number of pushed atoms statsd stats will track above kMaxPushedAtomId.
     static const int kMaxNonPlatformPushedAtoms = 100;
 
+    // Maximum atom id value that we consider a platform pushed atom.
+    // This should be updated once highest pushed atom id in atoms.proto approaches this value.
+    static const int kMaxPushedAtomId = 500;
+
     // Atom id that is the start of the pulled atoms.
     static const int kPullAtomStartTag = 10000;
 
diff --git a/cmds/statsd/tests/guardrail/StatsdStats_test.cpp b/cmds/statsd/tests/guardrail/StatsdStats_test.cpp
index 00e8397..129fafa 100644
--- a/cmds/statsd/tests/guardrail/StatsdStats_test.cpp
+++ b/cmds/statsd/tests/guardrail/StatsdStats_test.cpp
@@ -254,8 +254,8 @@
 TEST(StatsdStatsTest, TestNonPlatformAtomLog) {
     StatsdStats stats;
     time_t now = time(nullptr);
-    int newAtom1 = android::util::kMaxPushedAtomId + 1;
-    int newAtom2 = android::util::kMaxPushedAtomId + 2;
+    int newAtom1 = StatsdStats::kMaxPushedAtomId + 1;
+    int newAtom2 = StatsdStats::kMaxPushedAtomId + 2;
 
     stats.noteAtomLogged(newAtom1, now + 1);
     stats.noteAtomLogged(newAtom1, now + 2);
diff --git a/tools/stats_log_api_gen/Collation.cpp b/tools/stats_log_api_gen/Collation.cpp
index 526876f..958e94e 100644
--- a/tools/stats_log_api_gen/Collation.cpp
+++ b/tools/stats_log_api_gen/Collation.cpp
@@ -478,7 +478,6 @@
 int collate_atoms(const Descriptor* descriptor, const string& moduleName, Atoms* atoms) {
     int errorCount = 0;
 
-    int maxPushedAtomId = 2;
     for (int i = 0; i < descriptor->field_count(); i++) {
         const FieldDescriptor* atomField = descriptor->field(i);
 
@@ -563,14 +562,8 @@
 
             atoms->non_chained_decls.insert(nonChainedAtomDecl);
         }
-
-        if (atomDecl->code < PULL_ATOM_START_ID && atomDecl->code > maxPushedAtomId) {
-            maxPushedAtomId = atomDecl->code;
-        }
     }
 
-    atoms->maxPushedAtomId = maxPushedAtomId;
-
     if (dbg) {
         printf("signatures = [\n");
         for (SignatureInfoMap::const_iterator it = atoms->signatureInfoMap.begin();
diff --git a/tools/stats_log_api_gen/Collation.h b/tools/stats_log_api_gen/Collation.h
index b513463e..043f8b1 100644
--- a/tools/stats_log_api_gen/Collation.h
+++ b/tools/stats_log_api_gen/Collation.h
@@ -191,7 +191,6 @@
     AtomDeclSet decls;
     AtomDeclSet non_chained_decls;
     SignatureInfoMap nonChainedSignatureInfoMap;
-    int maxPushedAtomId;
 };
 
 /**
diff --git a/tools/stats_log_api_gen/atoms_info_writer.cpp b/tools/stats_log_api_gen/atoms_info_writer.cpp
index b339950..58a91e4 100644
--- a/tools/stats_log_api_gen/atoms_info_writer.cpp
+++ b/tools/stats_log_api_gen/atoms_info_writer.cpp
@@ -25,12 +25,11 @@
 namespace android {
 namespace stats_log_api_gen {
 
-static void write_atoms_info_header_body(FILE* out, const Atoms& atoms) {
+static void write_atoms_info_header_body(FILE* out) {
     fprintf(out, "struct AtomsInfo {\n");
     fprintf(out, "  const static std::set<int> kAtomsWithAttributionChain;\n");
     fprintf(out, "  const static std::set<int> kWhitelistedAtoms;\n");
     fprintf(out, "};\n");
-    fprintf(out, "const static int kMaxPushedAtomId = %d;\n\n", atoms.maxPushedAtomId);
 }
 
 static void write_atoms_info_cpp_body(FILE* out, const Atoms& atoms) {
@@ -65,7 +64,7 @@
 
 }
 
-int write_atoms_info_header(FILE* out, const Atoms& atoms, const string& namespaceStr) {
+int write_atoms_info_header(FILE* out, const string& namespaceStr) {
     // Print prelude
     fprintf(out, "// This file is autogenerated\n");
     fprintf(out, "\n");
@@ -78,7 +77,7 @@
 
     write_namespace(out, namespaceStr);
 
-    write_atoms_info_header_body(out, atoms);
+    write_atoms_info_header_body(out);
 
     fprintf(out, "\n");
     write_closing_namespace(out, namespaceStr);
diff --git a/tools/stats_log_api_gen/atoms_info_writer.h b/tools/stats_log_api_gen/atoms_info_writer.h
index ffe9e43..09a4303 100644
--- a/tools/stats_log_api_gen/atoms_info_writer.h
+++ b/tools/stats_log_api_gen/atoms_info_writer.h
@@ -29,7 +29,7 @@
 int write_atoms_info_cpp(FILE* out, const Atoms& atoms, const string& namespaceStr,
                          const string& importHeader);
 
-int write_atoms_info_header(FILE* out, const Atoms& atoms, const string& namespaceStr);
+int write_atoms_info_header(FILE* out, const string& namespaceStr);
 
 }  // namespace stats_log_api_gen
 }  // namespace android
diff --git a/tools/stats_log_api_gen/main.cpp b/tools/stats_log_api_gen/main.cpp
index fda5736..136933b 100644
--- a/tools/stats_log_api_gen/main.cpp
+++ b/tools/stats_log_api_gen/main.cpp
@@ -229,7 +229,7 @@
             fprintf(stderr, "Unable to open file for write: %s\n", atomsInfoHeaderFilename.c_str());
             return 1;
         }
-        errorCount = android::stats_log_api_gen::write_atoms_info_header(out, atoms, cppNamespace);
+        errorCount = android::stats_log_api_gen::write_atoms_info_header(out, cppNamespace);
         fclose(out);
     }