Sysprop for the count of active OOME tracing sessions

In order for ART code to call perfetto DataSource::Trace() we need to
wait for all data source instances to have completed their setup. To do
so, we need to know how many of them exist.

This introduces a new sysprop traced.oome_heap_session.count, writeable
by perfetto traced and readable by apps and system_server that can be
used to communicate this.

See go/art-oom-heap-dump for more details

Test: manual, atest HeapprofdJavaCtsTest
Bug: 269246893
Change-Id: Ib8220879a40854f98bc2f550ff2e7ebf3e077756
diff --git a/private/app.te b/private/app.te
index 49b8cde..b6b4714 100644
--- a/private/app.te
+++ b/private/app.te
@@ -52,6 +52,9 @@
 get_prop(appdomain, device_config_runtime_native_prop)
 get_prop(appdomain, device_config_runtime_native_boot_prop)
 
+# Allow the heap dump ART plugin to the count of sessions waiting for OOME
+get_prop(appdomain, traced_oome_heap_session_count_prop)
+
 # Allow to read ro.vendor.camera.extensions.enabled
 get_prop(appdomain, camera2_extensions_prop)
 
diff --git a/private/compat/33.0/33.0.ignore.cil b/private/compat/33.0/33.0.ignore.cil
index cd1b0d1..ea51f5b 100644
--- a/private/compat/33.0/33.0.ignore.cil
+++ b/private/compat/33.0/33.0.ignore.cil
@@ -50,6 +50,7 @@
     stats_config_data_file
     system_net_netd_service
     timezone_metadata_prop
+    traced_oome_heap_session_count_prop
     tuner_config_prop
     tuner_server_ctl_prop
     ublk_block_device
diff --git a/private/property_contexts b/private/property_contexts
index 593fdb8..0463728 100644
--- a/private/property_contexts
+++ b/private/property_contexts
@@ -221,6 +221,9 @@
 # heapprofd properties
 heapprofd.              u:object_r:heapprofd_prop:s0
 
+# traced properties
+traced.oome_heap_session.count u:object_r:traced_oome_heap_session_count_prop:s0 exact uint
+
 # servicemanager properties
 servicemanager.ready    u:object_r:servicemanager_prop:s0 exact bool
 
diff --git a/private/system_server.te b/private/system_server.te
index 8b1d124..2f9dc44 100644
--- a/private/system_server.te
+++ b/private/system_server.te
@@ -838,6 +838,9 @@
 # Write tuner.server.enable
 set_prop(system_server, tuner_server_ctl_prop)
 
+# Allow the heap dump ART plugin to the count of sessions waiting for OOME
+get_prop(appdomain, traced_oome_heap_session_count_prop)
+
 # Create a socket for connections from debuggerd.
 allow system_server system_ndebug_socket:sock_file create_file_perms;
 
diff --git a/private/traced.te b/private/traced.te
index 3029094..171e092 100644
--- a/private/traced.te
+++ b/private/traced.te
@@ -60,6 +60,11 @@
 set_prop(traced, system_trace_prop)
 # Allow to lazily start producers.
 set_prop(traced, traced_lazy_prop)
+# Allow tracking the count of sessions intercepting Java OutOfMemoryError
+# If there are such tracing sessions and an OutOfMemoryError is thrown by ART,
+# the hprof plugin intercepts the error, lazily registers a data source to
+# traced and collects a heap dump.
+set_prop(traced, traced_oome_heap_session_count_prop)
 
 # Allow traced to talk to statsd for logging metrics.
 unix_socket_send(traced, statsdw, statsd)
diff --git a/public/property.te b/public/property.te
index c41aa91..62b7695 100644
--- a/public/property.te
+++ b/public/property.te
@@ -93,6 +93,7 @@
 system_restricted_prop(surfaceflinger_display_prop)
 system_restricted_prop(system_boot_reason_prop)
 system_restricted_prop(system_jvmti_agent_prop)
+system_restricted_prop(traced_oome_heap_session_count_prop)
 system_restricted_prop(ab_update_gki_prop)
 system_restricted_prop(usb_prop)
 system_restricted_prop(userspace_reboot_exported_prop)