From 63d07d75868e56f3fd40a4a1747b5af09528451a Mon Sep 17 00:00:00 2001
From: Hector Dearman <hjd@google.com>
Date: Wed, 5 Sep 2018 15:21:54 +0100
Subject: [PATCH] Make system_server atrace category work with traced_probes

Historically most uses of atrace happen via the shell domain.

There are two exceptions:
- boot tracing
- traced_probes

We need to get feature parity, so atrace has the same behavior
when is invoked either via shell or from its own domain (e.g.
via traced_probes that has an auto_trans rule into atrace on exec).
Atrace works by setting system properties to enable tracing from userspace
then poking all the binder services to read the system properties (see [1]) so
enabling the system_server category requires the ability to call binder
methods on the system_server.

For more use cases see b/113127224

[1]: https://android.googlesource.com/platform/frameworks/native/+/9ead54bed65d486fe435793cbe98ed8b4786f7be/cmds/atrace/atrace.cpp#545

Bug: 113127224
Test: Add an atrace category to the Perfetto config and confirm the data
shows up.

Cherry-picked from aosp/747608

Change-Id: Id077eff960ffb1cdd7b0ce84b21ac9ef70444a4a
Merged-In: Id077eff960ffb1cdd7b0ce84b21ac9ef70444a4a
---
 prebuilts/api/28.0/private/atrace.te | 2 ++
 private/atrace.te                    | 2 ++
 2 files changed, 4 insertions(+)

diff --git a/prebuilts/api/28.0/private/atrace.te b/prebuilts/api/28.0/private/atrace.te
index 630935da0..1b86d3e1d 100644
--- a/prebuilts/api/28.0/private/atrace.te
+++ b/prebuilts/api/28.0/private/atrace.te
@@ -22,6 +22,8 @@ set_prop(atrace, debug_prop)
 binder_use(atrace)
 allow atrace healthd:binder call;
 allow atrace surfaceflinger:binder call;
+allow atrace system_server:binder call;
+
 get_prop(atrace, hwservicemanager_prop)
 
 allow atrace {
diff --git a/private/atrace.te b/private/atrace.te
index 630935da0..1b86d3e1d 100644
--- a/private/atrace.te
+++ b/private/atrace.te
@@ -22,6 +22,8 @@ set_prop(atrace, debug_prop)
 binder_use(atrace)
 allow atrace healthd:binder call;
 allow atrace surfaceflinger:binder call;
+allow atrace system_server:binder call;
+
 get_prop(atrace, hwservicemanager_prop)
 
 allow atrace {
-- 
GitLab