Add layer tracing's MODE_GENERATED_BUGREPORT_ONLY

The generated layers trace can be quite large (100-400 MB), which is way above
the perfetto's field upload budget.

On the field (AOT) we want the layers trace to be generated only when a bugreport
is taken and not when a perfetto's field upload happens. We achieve it as follows:
- In the AOT configuration, enable the 'android.surfaceflinger_layers' data source
  with MODE_GENERATED_BUGREPORT_ONLY.
- When LayerTracing receives perfetto's OnFlush event and MODE_GENERATED_BUGREPORT_ONLY is enabled,
  generate the layers trace only if the OnFlush event is due to a bugreport being taken:
    args.flush_flags.reason() == perfetto::FlushFlags::Reason::kTraceClone &&
    args.flush_flags.clone_target() == perfetto::FlushFlags::CloneTarget::kBugreport

In a test environment instead, we can use MODE_GENERATED to test the layers trace generation
without having to take a bugreport.

Bug: b/293429094
Test: 1. Manually start the perfetto's android.surfaceflinger_layers data source
         with MODE_GENERATED_BUGREPORT_ONLY setting a high bugreport_score (e.g. 50000)
      2. Take a bugreport (adb bugreport)
      3. Verify that FS/data/misc/perfetto-traces/bugreport/systrace.pftrace (in the bugreport)
         contains the generated layers trace. E.g. inspect bugreport with go/winscope.
Change-Id: I5b3ce59cc762fd5a22170e677e48be987380c94e
diff --git a/services/surfaceflinger/Tracing/LayerDataSource.cpp b/services/surfaceflinger/Tracing/LayerDataSource.cpp
index 25e768e..ed1e2ec 100644
--- a/services/surfaceflinger/Tracing/LayerDataSource.cpp
+++ b/services/surfaceflinger/Tracing/LayerDataSource.cpp
@@ -51,8 +51,9 @@
     if (config.has_mode() && config.mode() != LayerTracing::Mode::MODE_UNSPECIFIED) {
         mMode = static_cast<LayerTracing::Mode>(config.mode());
     } else {
-        mMode = LayerTracing::Mode::MODE_GENERATED;
-        ALOGD("Received config with unspecified 'mode'. Using 'GENERATED' as default");
+        mMode = LayerTracing::Mode::MODE_GENERATED_BUGREPORT_ONLY;
+        ALOGD("Received config with unspecified 'mode'."
+              " Using 'MODE_GENERATED_BUGREPORT_ONLY' as default");
     }
 
     mFlags = 0;
@@ -68,10 +69,16 @@
     }
 }
 
-void LayerDataSource::OnFlush(const LayerDataSource::FlushArgs&) {
-    ALOGD("Received OnFlush event (mode = 0x%02x, flags = 0x%02x)", mMode, mFlags);
+void LayerDataSource::OnFlush(const LayerDataSource::FlushArgs& args) {
+    ALOGD("Received OnFlush event"
+          " (mode = 0x%02x, flags = 0x%02x, reason = 0x%" PRIx64 ", clone_target = 0x%0" PRIx64 ")",
+          mMode, mFlags, args.flush_flags.reason(), args.flush_flags.clone_target());
+
+    bool isBugreport = args.flush_flags.reason() == perfetto::FlushFlags::Reason::kTraceClone &&
+            args.flush_flags.clone_target() == perfetto::FlushFlags::CloneTarget::kBugreport;
+
     if (auto* p = mLayerTracing.load()) {
-        p->onFlush(mMode, mFlags);
+        p->onFlush(mMode, mFlags, isBugreport);
     }
 }