Add androidx.tracing to sysui

Test: build and capture trace
Bug: 267482189
Change-Id: I35d9dc6dde9383169e3377693116751274e4cf85
diff --git a/packages/SystemUI/Android.bp b/packages/SystemUI/Android.bp
index 62c6c1d..865b0df 100644
--- a/packages/SystemUI/Android.bp
+++ b/packages/SystemUI/Android.bp
@@ -173,6 +173,7 @@
         "androidx.palette_palette",
         "androidx.legacy_legacy-preference-v14",
         "androidx.leanback_leanback",
+        "androidx.tracing_tracing",
         "androidx.slice_slice-core",
         "androidx.slice_slice-view",
         "androidx.slice_slice-builders",
diff --git a/packages/SystemUI/src/com/android/systemui/util/TraceUtils.kt b/packages/SystemUI/src/com/android/systemui/util/TraceUtils.kt
index 64234c2..41c6b5d 100644
--- a/packages/SystemUI/src/com/android/systemui/util/TraceUtils.kt
+++ b/packages/SystemUI/src/com/android/systemui/util/TraceUtils.kt
@@ -16,20 +16,22 @@
 
 package com.android.systemui.util
 
-import android.os.Trace
+import android.os.Handler
 import android.os.TraceNameSupplier
+import androidx.tracing.Trace
 
 /**
- * Run a block within a [Trace] section.
- * Calls [Trace.beginSection] before and [Trace.endSection] after the passed block.
+ * Run a block within a [Trace] section. Calls [Trace.beginSection] before and [Trace.endSection]
+ * after the passed block. If tracing is disabled, it will run the block directly to avoid using an
+ * unnecessary try-finally block.
  */
 inline fun <T> traceSection(tag: String, block: () -> T): T =
-        if (Trace.isTagEnabled(Trace.TRACE_TAG_APP)) {
-            Trace.traceBegin(Trace.TRACE_TAG_APP, tag)
+        if (Trace.isEnabled()) {
+            Trace.beginSection(tag)
             try {
                 block()
             } finally {
-                Trace.traceEnd(Trace.TRACE_TAG_APP)
+                Trace.endSection()
             }
         } else {
             block()
@@ -42,8 +44,10 @@
         }
 
         /**
-         * Helper function for creating a Runnable object that implements TraceNameSupplier.
-         * This is useful for posting Runnables to Handlers with meaningful names.
+         * Helper function for creating a [Runnable] that implements [TraceNameSupplier]. This is
+         * useful when posting to a [Handler] so that the [Runnable] has a meaningful name in the
+         * trace. Otherwise, the class name of the [Runnable] is used, which is often something like
+         * `pkg.MyClass$$ExternalSyntheticLambda0`.
          */
         inline fun namedRunnable(tag: String, crossinline block: () -> Unit): Runnable {
             return object : Runnable, TraceNameSupplier {