protos: Add android_track_event extensions

For now, this just defines extensions for:
* binder service name
* binder interface name
* apex name

Bug: 348584514
Change-Id: I90bda744190590c6f03b731f44aecafc83e59b81
diff --git a/Android.bp b/Android.bp
index 3b2b37b..fe5dbfa 100644
--- a/Android.bp
+++ b/Android.bp
@@ -2643,6 +2643,7 @@
         "perfetto_protos_third_party_simpleperf_zero_gen_headers",
         "perfetto_protos_third_party_statsd_config_zero_gen_headers",
         "perfetto_src_base_version_gen_h",
+        "perfetto_src_trace_processor_importers_proto_gen_cc_android_track_event_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_chrome_track_event_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_config_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_statsd_atoms_descriptor",
@@ -5478,6 +5479,49 @@
     ],
 }
 
+// GN: //protos/perfetto/trace/android:android_track_event_descriptor
+genrule {
+    name: "perfetto_protos_perfetto_trace_android_android_track_event_descriptor",
+    srcs: [
+        "protos/perfetto/trace/android/android_track_event.proto",
+        "protos/perfetto/trace/track_event/chrome_active_processes.proto",
+        "protos/perfetto/trace/track_event/chrome_application_state_info.proto",
+        "protos/perfetto/trace/track_event/chrome_compositor_scheduler_state.proto",
+        "protos/perfetto/trace/track_event/chrome_content_settings_event_info.proto",
+        "protos/perfetto/trace/track_event/chrome_frame_reporter.proto",
+        "protos/perfetto/trace/track_event/chrome_histogram_sample.proto",
+        "protos/perfetto/trace/track_event/chrome_keyed_service.proto",
+        "protos/perfetto/trace/track_event/chrome_latency_info.proto",
+        "protos/perfetto/trace/track_event/chrome_legacy_ipc.proto",
+        "protos/perfetto/trace/track_event/chrome_message_pump.proto",
+        "protos/perfetto/trace/track_event/chrome_mojo_event_info.proto",
+        "protos/perfetto/trace/track_event/chrome_process_descriptor.proto",
+        "protos/perfetto/trace/track_event/chrome_renderer_scheduler_state.proto",
+        "protos/perfetto/trace/track_event/chrome_thread_descriptor.proto",
+        "protos/perfetto/trace/track_event/chrome_user_event.proto",
+        "protos/perfetto/trace/track_event/chrome_window_handle_event_info.proto",
+        "protos/perfetto/trace/track_event/counter_descriptor.proto",
+        "protos/perfetto/trace/track_event/debug_annotation.proto",
+        "protos/perfetto/trace/track_event/log_message.proto",
+        "protos/perfetto/trace/track_event/pixel_modem.proto",
+        "protos/perfetto/trace/track_event/process_descriptor.proto",
+        "protos/perfetto/trace/track_event/range_of_interest.proto",
+        "protos/perfetto/trace/track_event/screenshot.proto",
+        "protos/perfetto/trace/track_event/source_location.proto",
+        "protos/perfetto/trace/track_event/task_execution.proto",
+        "protos/perfetto/trace/track_event/thread_descriptor.proto",
+        "protos/perfetto/trace/track_event/track_descriptor.proto",
+        "protos/perfetto/trace/track_event/track_event.proto",
+    ],
+    tools: [
+        "aprotoc",
+    ],
+    cmd: "mkdir -p $(genDir)/external/perfetto/ && $(location aprotoc) --proto_path=external/perfetto --descriptor_set_out=$(out) $(in)",
+    out: [
+        "perfetto_protos_perfetto_trace_android_android_track_event_descriptor.bin",
+    ],
+}
+
 // GN: //protos/perfetto/trace/android:cpp
 filegroup {
     name: "perfetto_protos_perfetto_trace_android_cpp",
@@ -12399,6 +12443,21 @@
     ],
 }
 
+// GN: //src/trace_processor/importers/proto:gen_cc_android_track_event_descriptor
+genrule {
+    name: "perfetto_src_trace_processor_importers_proto_gen_cc_android_track_event_descriptor",
+    srcs: [
+        ":perfetto_protos_perfetto_trace_android_android_track_event_descriptor",
+    ],
+    cmd: "$(location tools/gen_cc_proto_descriptor.py) --gen_dir=$(genDir) --cpp_out=$(out) $(in)",
+    out: [
+        "src/trace_processor/importers/proto/android_track_event.descriptor.h",
+    ],
+    tool_files: [
+        "tools/gen_cc_proto_descriptor.py",
+    ],
+}
+
 // GN: //src/trace_processor/importers/proto:gen_cc_chrome_track_event_descriptor
 genrule {
     name: "perfetto_src_trace_processor_importers_proto_gen_cc_chrome_track_event_descriptor",
@@ -15445,6 +15504,7 @@
         "perfetto_src_protozero_testing_messages_subpackage_zero_gen_headers",
         "perfetto_src_protozero_testing_messages_zero_gen_headers",
         "perfetto_src_trace_processor_gen_cc_test_messages_descriptor",
+        "perfetto_src_trace_processor_importers_proto_gen_cc_android_track_event_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_chrome_track_event_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_config_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_statsd_atoms_descriptor",
@@ -16296,6 +16356,7 @@
         "perfetto_protos_third_party_pprof_zero_gen_headers",
         "perfetto_protos_third_party_simpleperf_zero_gen_headers",
         "perfetto_src_base_version_gen_h",
+        "perfetto_src_trace_processor_importers_proto_gen_cc_android_track_event_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_chrome_track_event_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_config_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_statsd_atoms_descriptor",
@@ -16494,6 +16555,7 @@
         "perfetto_protos_perfetto_trace_track_event_zero_gen_headers",
         "perfetto_protos_perfetto_trace_translation_zero_gen_headers",
         "perfetto_protos_third_party_simpleperf_zero_gen_headers",
+        "perfetto_src_trace_processor_importers_proto_gen_cc_android_track_event_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_chrome_track_event_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_track_event_descriptor",
         "perfetto_src_trace_processor_tables_tables_python",
@@ -16700,6 +16762,7 @@
         "perfetto_protos_third_party_pprof_zero_gen_headers",
         "perfetto_protos_third_party_simpleperf_zero_gen_headers",
         "perfetto_src_base_version_gen_h",
+        "perfetto_src_trace_processor_importers_proto_gen_cc_android_track_event_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_chrome_track_event_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_config_descriptor",
         "perfetto_src_trace_processor_importers_proto_gen_cc_statsd_atoms_descriptor",
diff --git a/BUILD b/BUILD
index babfde3..d55ddb3 100644
--- a/BUILD
+++ b/BUILD
@@ -355,6 +355,7 @@
                ":src_base_base",
                ":src_base_version",
                ":src_trace_processor_containers_containers",
+               ":src_trace_processor_importers_proto_gen_cc_android_track_event_descriptor",
                ":src_trace_processor_importers_proto_gen_cc_chrome_track_event_descriptor",
                ":src_trace_processor_importers_proto_gen_cc_config_descriptor",
                ":src_trace_processor_importers_proto_gen_cc_statsd_atoms_descriptor",
@@ -1867,6 +1868,17 @@
     ],
 )
 
+# GN target: //src/trace_processor/importers/proto:gen_cc_android_track_event_descriptor
+perfetto_cc_proto_descriptor(
+    name = "src_trace_processor_importers_proto_gen_cc_android_track_event_descriptor",
+    deps = [
+        ":protos_perfetto_trace_android_android_track_event_descriptor",
+    ],
+    outs = [
+        "src/trace_processor/importers/proto/android_track_event.descriptor.h",
+    ],
+)
+
 # GN target: //src/trace_processor/importers/proto:gen_cc_chrome_track_event_descriptor
 perfetto_cc_proto_descriptor(
     name = "src_trace_processor_importers_proto_gen_cc_chrome_track_event_descriptor",
@@ -4873,6 +4885,34 @@
     ],
 )
 
+# GN target: //protos/perfetto/trace/android:android_track_event_descriptor
+perfetto_proto_descriptor(
+    name = "protos_perfetto_trace_android_android_track_event_descriptor",
+    deps = [
+        ":protos_perfetto_trace_android_android_track_event_protos",
+    ],
+    outs = [
+        "protos_perfetto_trace_android_android_track_event_descriptor.bin",
+    ],
+)
+
+# GN target: //protos/perfetto/trace/android:android_track_event_source_set
+perfetto_proto_library(
+    name = "protos_perfetto_trace_android_android_track_event_protos",
+    srcs = [
+        "protos/perfetto/trace/android/android_track_event.proto",
+    ],
+    visibility = [
+        PERFETTO_CONFIG.proto_library_visibility,
+    ],
+    deps = [
+        ":protos_perfetto_trace_track_event_protos",
+    ],
+    exports = [
+        ":protos_perfetto_trace_track_event_protos",
+    ],
+)
+
 # GN target: //protos/perfetto/trace/android:source_set
 perfetto_proto_library(
     name = "protos_perfetto_trace_android_protos",
@@ -6254,6 +6294,7 @@
                ":protozero",
                ":src_base_base",
                ":src_trace_processor_containers_containers",
+               ":src_trace_processor_importers_proto_gen_cc_android_track_event_descriptor",
                ":src_trace_processor_importers_proto_gen_cc_chrome_track_event_descriptor",
                ":src_trace_processor_importers_proto_gen_cc_config_descriptor",
                ":src_trace_processor_importers_proto_gen_cc_statsd_atoms_descriptor",
@@ -6427,6 +6468,7 @@
                ":src_base_http_http",
                ":src_base_version",
                ":src_trace_processor_containers_containers",
+               ":src_trace_processor_importers_proto_gen_cc_android_track_event_descriptor",
                ":src_trace_processor_importers_proto_gen_cc_chrome_track_event_descriptor",
                ":src_trace_processor_importers_proto_gen_cc_config_descriptor",
                ":src_trace_processor_importers_proto_gen_cc_statsd_atoms_descriptor",
@@ -6668,6 +6710,7 @@
                ":src_base_base",
                ":src_base_version",
                ":src_trace_processor_containers_containers",
+               ":src_trace_processor_importers_proto_gen_cc_android_track_event_descriptor",
                ":src_trace_processor_importers_proto_gen_cc_chrome_track_event_descriptor",
                ":src_trace_processor_importers_proto_gen_cc_config_descriptor",
                ":src_trace_processor_importers_proto_gen_cc_statsd_atoms_descriptor",
diff --git a/include/perfetto/public/protos/trace/android/android_track_event.pzc.h b/include/perfetto/public/protos/trace/android/android_track_event.pzc.h
new file mode 100644
index 0000000..40384e5
--- /dev/null
+++ b/include/perfetto/public/protos/trace/android/android_track_event.pzc.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2023 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// Autogenerated by the ProtoZero C compiler plugin.
+// Invoked by tools/gen_c_protos
+// DO NOT EDIT.
+#ifndef INCLUDE_PERFETTO_PUBLIC_PROTOS_TRACE_ANDROID_ANDROID_TRACK_EVENT_PZC_H_
+#define INCLUDE_PERFETTO_PUBLIC_PROTOS_TRACE_ANDROID_ANDROID_TRACK_EVENT_PZC_H_
+
+#include <stdbool.h>
+#include <stdint.h>
+
+#include "perfetto/public/pb_macros.h"
+#include "perfetto/public/protos/trace/track_event/track_event.pzc.h"
+
+PERFETTO_PB_EXTENSION_FIELD(perfetto_protos_AndroidTrackEvent,
+                            perfetto_protos_TrackEvent,
+                            STRING,
+                            const char*,
+                            binder_service_name,
+                            2001);
+PERFETTO_PB_EXTENSION_FIELD(perfetto_protos_AndroidTrackEvent,
+                            perfetto_protos_TrackEvent,
+                            STRING,
+                            const char*,
+                            binder_interface_name,
+                            2002);
+PERFETTO_PB_EXTENSION_FIELD(perfetto_protos_AndroidTrackEvent,
+                            perfetto_protos_TrackEvent,
+                            STRING,
+                            const char*,
+                            apex_name,
+                            2003);
+#endif  // INCLUDE_PERFETTO_PUBLIC_PROTOS_TRACE_ANDROID_ANDROID_TRACK_EVENT_PZC_H_
diff --git a/protos/perfetto/trace/android/BUILD.gn b/protos/perfetto/trace/android/BUILD.gn
index 50af2b2..ebcc0c2 100644
--- a/protos/perfetto/trace/android/BUILD.gn
+++ b/protos/perfetto/trace/android/BUILD.gn
@@ -110,3 +110,21 @@
   sources = [ "winscope.proto" ]
   import_dirs = [ "${perfetto_protobuf_src_dir}" ]
 }
+
+# Android track_event extensions
+perfetto_proto_library("android_track_event_@TYPE@") {
+  proto_generators = [ "source_set" ]
+  public_deps = [ "../track_event:@TYPE@" ]
+  sources = [
+    "android_track_event.proto",
+  ]
+}
+
+perfetto_proto_library("android_track_event_@TYPE@") {
+  proto_generators = [ "descriptor" ]
+  generate_descriptor = "android_track_event.descriptor"
+  sources = [
+    "android_track_event.proto",
+  ]
+  deps = [ ":android_track_event_source_set" ]
+}
diff --git a/protos/perfetto/trace/android/android_track_event.proto b/protos/perfetto/trace/android/android_track_event.proto
new file mode 100644
index 0000000..bb560c4
--- /dev/null
+++ b/protos/perfetto/trace/android/android_track_event.proto
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2024 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+syntax = "proto2";
+
+import public "protos/perfetto/trace/track_event/track_event.proto";
+
+package perfetto.protos;
+
+message AndroidTrackEvent {
+  // Usable range: [2001, 2999]
+  // Next id: 2004
+  extend TrackEvent {
+    // The name of a binder service.
+    optional string binder_service_name = 2001;
+    // The name of a binder interface.
+    optional string binder_interface_name = 2002;
+    // The name of an apex.
+    optional string apex_name = 2003;
+  }
+}
diff --git a/protos/perfetto/trace/perfetto_trace.proto b/protos/perfetto/trace/perfetto_trace.proto
index 1203043..79c48ad 100644
--- a/protos/perfetto/trace/perfetto_trace.proto
+++ b/protos/perfetto/trace/perfetto_trace.proto
@@ -12800,8 +12800,11 @@
   extensions 1000 to 1999;
   // Extension range reserved for https://b.corp.google.com/issues/301227627.
   extensions 2000 to 2000;
+  // Extension range reserved for android:
+  // protos/perfetto/trace/android/android_track_event.proto
+  extensions 2001 to 2999;
   // Extension range for future use.
-  extensions 2001 to 9899;
+  extensions 3000 to 9899;
   // Reserved for Perfetto unit and integration tests.
   extensions 9900 to 10000;
 
diff --git a/protos/perfetto/trace/track_event/track_event.proto b/protos/perfetto/trace/track_event/track_event.proto
index 2b9d35c..f7792f6 100644
--- a/protos/perfetto/trace/track_event/track_event.proto
+++ b/protos/perfetto/trace/track_event/track_event.proto
@@ -289,8 +289,11 @@
   extensions 1000 to 1999;
   // Extension range reserved for https://b.corp.google.com/issues/301227627.
   extensions 2000 to 2000;
+  // Extension range reserved for android:
+  // protos/perfetto/trace/android/android_track_event.proto
+  extensions 2001 to 2999;
   // Extension range for future use.
-  extensions 2001 to 9899;
+  extensions 3000 to 9899;
   // Reserved for Perfetto unit and integration tests.
   extensions 9900 to 10000;
 
diff --git a/src/trace_processor/BUILD.gn b/src/trace_processor/BUILD.gn
index 802f9bc..bddffc0 100644
--- a/src/trace_processor/BUILD.gn
+++ b/src/trace_processor/BUILD.gn
@@ -124,6 +124,7 @@
     "importers/fuchsia:fuchsia_record",
     "importers/memory_tracker:graph_processor",
     "importers/perf:tracker",
+    "importers/proto:gen_cc_android_track_event_descriptor",
     "importers/proto:gen_cc_chrome_track_event_descriptor",
     "importers/proto:gen_cc_track_event_descriptor",
     "importers/proto:minimal",
diff --git a/src/trace_processor/importers/proto/BUILD.gn b/src/trace_processor/importers/proto/BUILD.gn
index da6cdee..1551d9b 100644
--- a/src/trace_processor/importers/proto/BUILD.gn
+++ b/src/trace_processor/importers/proto/BUILD.gn
@@ -258,6 +258,11 @@
   descriptor_target = "../../../../protos/third_party/chromium:descriptor"
 }
 
+perfetto_cc_proto_descriptor("gen_cc_android_track_event_descriptor") {
+  descriptor_name = "android_track_event.descriptor"
+  descriptor_target = "../../../../protos/perfetto/trace/android:android_track_event_descriptor"
+}
+
 perfetto_cc_proto_descriptor("gen_cc_config_descriptor") {
   descriptor_name = "config.descriptor"
   descriptor_target = "../../../../protos/perfetto/config:descriptor"
diff --git a/src/trace_processor/trace_processor_context.cc b/src/trace_processor/trace_processor_context.cc
index cdf250c..239cf78 100644
--- a/src/trace_processor/trace_processor_context.cc
+++ b/src/trace_processor/trace_processor_context.cc
@@ -40,6 +40,7 @@
 #include "src/trace_processor/importers/common/stack_profile_tracker.h"
 #include "src/trace_processor/importers/common/track_tracker.h"
 #include "src/trace_processor/importers/ftrace/ftrace_module.h"
+#include "src/trace_processor/importers/proto/android_track_event.descriptor.h"
 #include "src/trace_processor/importers/proto/chrome_track_event.descriptor.h"
 #include "src/trace_processor/importers/proto/multi_machine_trace_manager.h"
 #include "src/trace_processor/importers/proto/perf_sample_tracker.h"
@@ -92,6 +93,12 @@
         kChromeTrackEventDescriptor.data(), kChromeTrackEventDescriptor.size());
 
     PERFETTO_DCHECK(status.ok());
+
+    status = descriptor_pool_->AddFromFileDescriptorSet(
+        kAndroidTrackEventDescriptor.data(),
+        kAndroidTrackEventDescriptor.size());
+
+    PERFETTO_DCHECK(status.ok());
   }
 
   slice_tracker->SetOnSliceBeginCallback(
diff --git a/tools/gen_c_protos b/tools/gen_c_protos
index c62a48f..fd12cdd 100755
--- a/tools/gen_c_protos
+++ b/tools/gen_c_protos
@@ -30,6 +30,7 @@
       'protos/perfetto/config/data_source_config.proto',
       'protos/perfetto/config/trace_config.proto',
       'protos/perfetto/config/track_event/track_event_config.proto',
+      'protos/perfetto/trace/android/android_track_event.proto',
       'protos/perfetto/trace/clock_snapshot.proto',
       'protos/perfetto/trace/interned_data/interned_data.proto',
       'protos/perfetto/trace/test_event.proto',