Reland: Reland: Add statsd logging to perfetto_cmd

This reverts commit 64f2e052525af1d1c06eb5eea7348346db6c0819.

Reason for revert: Required code is present in aosp as of aosp/1181211

Change-Id: I3747992a319cdd7a0b8c225fa2c916fe60e06c1f
diff --git a/Android.bp b/Android.bp
index 635cfab..30779ac 100644
--- a/Android.bp
+++ b/Android.bp
@@ -299,6 +299,7 @@
     ":perfetto_src_base_base",
     ":perfetto_src_base_unix_socket",
     ":perfetto_src_ipc_ipc",
+    ":perfetto_src_perfetto_cmd_perfetto_atoms",
     ":perfetto_src_protozero_protozero",
     ":perfetto_src_traced_probes_android_log_android_log",
     ":perfetto_src_traced_probes_data_source",
@@ -380,6 +381,7 @@
   srcs: [
     ":perfetto_src_android_internal_android_internal",
     ":perfetto_src_android_internal_headers",
+    ":perfetto_src_perfetto_cmd_perfetto_atoms",
   ],
   shared_libs: [
     "android.hardware.atrace@1.0",
@@ -387,14 +389,17 @@
     "android.hardware.power.stats@1.0",
     "libbase",
     "libbinder",
+    "libcutils",
     "libhidlbase",
     "libincident",
     "liblog",
     "libservices",
+    "libstatssocket",
     "libutils",
   ],
   static_libs: [
     "libhealthhalutils",
+    "libstatslog_perfetto",
   ],
   export_include_dirs: [
     "include",
@@ -617,6 +622,7 @@
     ":perfetto_src_base_base",
     ":perfetto_src_base_unix_socket",
     ":perfetto_src_ipc_ipc",
+    ":perfetto_src_perfetto_cmd_perfetto_atoms",
     ":perfetto_src_perfetto_cmd_perfetto_cmd",
     ":perfetto_src_perfetto_cmd_protos_gen",
     ":perfetto_src_perfetto_cmd_trigger_producer",
@@ -883,6 +889,7 @@
     ":perfetto_src_base_test_support",
     ":perfetto_src_base_unix_socket",
     ":perfetto_src_ipc_ipc",
+    ":perfetto_src_perfetto_cmd_perfetto_atoms",
     ":perfetto_src_profiling_memory_client",
     ":perfetto_src_profiling_memory_daemon",
     ":perfetto_src_profiling_memory_end_to_end_tests",
@@ -4024,6 +4031,7 @@
     "src/android_internal/health_hal.cc",
     "src/android_internal/incident_service.cc",
     "src/android_internal/power_stats_hal.cc",
+    "src/android_internal/statsd_logging.cc",
   ],
 }
 
@@ -4222,6 +4230,11 @@
   ],
 }
 
+// GN: //src/perfetto_cmd:perfetto_atoms
+filegroup {
+  name: "perfetto_src_perfetto_cmd_perfetto_atoms",
+}
+
 // GN: //src/perfetto_cmd:perfetto_cmd
 filegroup {
   name: "perfetto_src_perfetto_cmd_perfetto_cmd",
@@ -5539,6 +5552,7 @@
     ":perfetto_src_ipc_test_messages_cpp_gen",
     ":perfetto_src_ipc_test_messages_ipc_gen",
     ":perfetto_src_ipc_unittests",
+    ":perfetto_src_perfetto_cmd_perfetto_atoms",
     ":perfetto_src_perfetto_cmd_perfetto_cmd",
     ":perfetto_src_perfetto_cmd_protos_gen",
     ":perfetto_src_perfetto_cmd_trigger_producer",
@@ -6299,4 +6313,39 @@
   defaults: [
     "perfetto_defaults",
   ],
+}
+
+cc_library_static {
+    name: "libstatslog_perfetto",
+    generated_sources: ["statslog_perfetto.cpp"],
+    generated_headers: ["statslog_perfetto.h"],
+    cflags: [
+        "-Wall",
+        "-Werror",
+    ],
+    export_generated_headers: ["statslog_perfetto.h"],
+    shared_libs: [
+        "libcutils",
+        "liblog",
+        "libstatssocket",
+        "libutils",
+    ],
+}
+
+genrule {
+    name: "statslog_perfetto.h",
+    tools: ["stats-log-api-gen"],
+    cmd: "$(location stats-log-api-gen) --header $(genDir)/statslog_perfetto.h --module perfetto --namespace perfetto,android_internal",
+    out: [
+        "statslog_perfetto.h",
+    ],
+}
+
+genrule {
+    name: "statslog_perfetto.cpp",
+    tools: ["stats-log-api-gen"],
+    cmd: "$(location stats-log-api-gen) --cpp $(genDir)/statslog_perfetto.cpp --module perfetto --namespace perfetto,android_internal --importHeader statslog_perfetto.h",
+    out: [
+        "statslog_perfetto.cpp",
+    ],
 }
\ No newline at end of file