Move trace utils to tracinglib

Create new library, tracinglib, for storing common tracing utils,
including support for tracing of Kotlin coroutines.

Also, update package name of tracinglib from
com.android.systemui.tracing to com.android.app.tracing.

Flag: NONE
Test: Build and flash device, behavior is same before and after
Bug: 289353932
Change-Id: I08cc8a07fe1790e68149983ab877079300255a0b
diff --git a/packages/SystemUI/shared/Android.bp b/packages/SystemUI/shared/Android.bp
index 9c368eb..5b59e7d 100644
--- a/packages/SystemUI/shared/Android.bp
+++ b/packages/SystemUI/shared/Android.bp
@@ -53,6 +53,7 @@
         "SystemUIPluginLib",
         "SystemUIUnfoldLib",
         "SystemUISharedLib-Keyguard",
+        "tracinglib",
         "androidx.dynamicanimation_dynamicanimation",
         "androidx.concurrent_concurrent-futures",
         "androidx.lifecycle_lifecycle-runtime-ktx",
diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/animation/DisableSubpixelTextTransitionListener.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/animation/DisableSubpixelTextTransitionListener.kt
index 7719246..637ce5f 100644
--- a/packages/SystemUI/shared/src/com/android/systemui/shared/animation/DisableSubpixelTextTransitionListener.kt
+++ b/packages/SystemUI/shared/src/com/android/systemui/shared/animation/DisableSubpixelTextTransitionListener.kt
@@ -19,7 +19,7 @@
 import android.view.ViewGroup
 import android.widget.TextView
 import androidx.core.view.forEach
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 import com.android.systemui.unfold.UnfoldTransitionProgressProvider.TransitionProgressListener
 import java.lang.ref.WeakReference
 
diff --git a/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceContextElement.kt b/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceContextElement.kt
deleted file mode 100644
index 7d1b65a..0000000
--- a/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceContextElement.kt
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.
- */
-
-package com.android.systemui.tracing
-
-import com.android.systemui.tracing.TraceUtils.Companion.instant
-import com.android.systemui.tracing.TraceUtils.Companion.traceCoroutine
-import kotlin.coroutines.CoroutineContext
-import kotlinx.coroutines.CopyableThreadContextElement
-import kotlinx.coroutines.CoroutineDispatcher
-import kotlinx.coroutines.DelicateCoroutinesApi
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-
-/**
- * Used for safely persisting [TraceData] state when coroutines are suspended and resumed.
- *
- * This is internal machinery for [traceCoroutine]. It cannot be made `internal` or `private`
- * because [traceCoroutine] is a Public-API inline function.
- *
- * @see traceCoroutine
- */
-@OptIn(DelicateCoroutinesApi::class)
-@ExperimentalCoroutinesApi
-class TraceContextElement(private val traceData: TraceData = TraceData()) :
-    CopyableThreadContextElement<TraceData?> {
-
-    companion object Key : CoroutineContext.Key<TraceContextElement>
-
-    override val key: CoroutineContext.Key<TraceContextElement> = Key
-
-    @OptIn(ExperimentalStdlibApi::class)
-    override fun updateThreadContext(context: CoroutineContext): TraceData? {
-        val oldState = threadLocalTrace.get()
-        oldState?.endAllOnThread()
-        threadLocalTrace.set(traceData)
-        instant("resuming ${context[CoroutineDispatcher]}")
-        traceData.beginAllOnThread()
-        return oldState
-    }
-
-    @OptIn(ExperimentalStdlibApi::class)
-    override fun restoreThreadContext(context: CoroutineContext, oldState: TraceData?) {
-        instant("suspending ${context[CoroutineDispatcher]}")
-        traceData.endAllOnThread()
-        threadLocalTrace.set(oldState)
-        oldState?.beginAllOnThread()
-    }
-
-    override fun copyForChild(): CopyableThreadContextElement<TraceData?> {
-        return TraceContextElement(traceData.copy())
-    }
-
-    override fun mergeForChild(overwritingElement: CoroutineContext.Element): CoroutineContext {
-        return TraceContextElement(traceData.copy())
-    }
-}
diff --git a/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceData.kt b/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceData.kt
deleted file mode 100644
index b68d38c..0000000
--- a/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceData.kt
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * 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.
- */
-
-package com.android.systemui.tracing
-
-import android.os.Build
-import android.util.Log
-import com.android.systemui.tracing.TraceUtils.Companion.beginSlice
-import com.android.systemui.tracing.TraceUtils.Companion.endSlice
-import com.android.systemui.tracing.TraceUtils.Companion.traceCoroutine
-import kotlin.random.Random
-
-/**
- * Used for giving each thread a unique [TraceData] for thread-local storage. `null` by default.
- * [threadLocalTrace] can only be used when it is paired with a [TraceContextElement].
- *
- * This ThreadLocal will be `null` if either 1) we aren't in a coroutine, or 2) the coroutine we are
- * in does not have a [TraceContextElement].
- *
- * This is internal machinery for [traceCoroutine]. It cannot be made `internal` or `private`
- * because [traceCoroutine] is a Public-API inline function.
- *
- * @see traceCoroutine
- */
-val threadLocalTrace = ThreadLocal<TraceData?>()
-
-/**
- * Used for storing trace sections so that they can be added and removed from the currently running
- * thread when the coroutine is suspended and resumed.
- *
- * This is internal machinery for [traceCoroutine]. It cannot be made `internal` or `private`
- * because [traceCoroutine] is a Public-API inline function.
- *
- * @see traceCoroutine
- */
-class TraceData {
-    private var slices = mutableListOf<TraceSection>()
-
-    /** Adds current trace slices back to the current thread. Called when coroutine is resumed. */
-    fun beginAllOnThread() {
-        slices.forEach { beginSlice(it.name) }
-    }
-
-    /**
-     * Removes all current trace slices from the current thread. Called when coroutine is suspended.
-     */
-    fun endAllOnThread() {
-        for (i in 0..slices.size) {
-            endSlice()
-        }
-    }
-
-    /**
-     * Creates a new trace section with a unique ID and adds it to the current trace data. The slice
-     * will also be added to the current thread immediately. This slice will not propagate to parent
-     * coroutines, or to child coroutines that have already started. The unique ID is used to verify
-     * that the [endSpan] is corresponds to a [beginSpan].
-     */
-    fun beginSpan(name: String): Int {
-        val newSlice = TraceSection(name, Random.nextInt(FIRST_VALID_SPAN, Int.MAX_VALUE))
-        slices.add(newSlice)
-        beginSlice(name)
-        return newSlice.id
-    }
-
-    /**
-     * Used by [TraceContextElement] when launching a child coroutine so that the child coroutine's
-     * state is isolated from the parent.
-     */
-    fun copy(): TraceData {
-        return TraceData().also { it.slices.addAll(slices) }
-    }
-
-    /**
-     * Ends the trace section and validates it corresponds with an earlier call to [beginSpan]. The
-     * trace slice will immediately be removed from the current thread. This information will not
-     * propagate to parent coroutines, or to child coroutines that have already started.
-     */
-    fun endSpan(id: Int) {
-        val v = slices.removeLast()
-        if (v.id != id) {
-            if (STRICT_MODE) {
-                throw IllegalArgumentException(errorMsg)
-            } else if (Log.isLoggable(TAG, Log.VERBOSE)) {
-                Log.v(TAG, errorMsg)
-            }
-        }
-        endSlice()
-    }
-
-    companion object {
-        private const val TAG = "TraceData"
-        const val INVALID_SPAN = -1
-        const val FIRST_VALID_SPAN = 1
-
-        /**
-         * If true, throw an exception instead of printing a warning when trace sections beginnings
-         * and ends are mismatched.
-         */
-        private val STRICT_MODE = Build.IS_ENG
-
-        private const val errorMsg =
-            "Mismatched trace section. This likely means you are accessing the trace local " +
-                "storage (threadLocalTrace) without a corresponding CopyableThreadContextElement." +
-                " This could happen if you are using a global dispatcher like Dispatchers.IO." +
-                " To fix this, use one of the coroutine contexts provided by the dagger scope " +
-                "(e.g. \"@Main CoroutineContext\")."
-    }
-}
diff --git a/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceSection.kt b/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceSection.kt
deleted file mode 100644
index 469d9a2..0000000
--- a/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceSection.kt
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.
- */
-
-package com.android.systemui.tracing
-
-import com.android.systemui.tracing.TraceUtils.Companion.traceCoroutine
-
-/**
- * Represents a section of code executing in a coroutine. This can be split up into multiple slices
- * on different threads as the coroutine is suspended and resumed.
- *
- * This is internal machinery for [traceCoroutine]. It cannot be made `internal` or `private`
- * because [traceCoroutine] is a Public-API inline function.
- *
- * @param name the name of the slice to appear on the current thread's track.
- * @param id used for matching the beginning and end of trace sections and validating correctness
- * @see traceCoroutine
- */
-data class TraceSection(
-    val name: String,
-    val id: Int,
-)
diff --git a/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceStateLogger.kt b/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceStateLogger.kt
deleted file mode 100644
index 3e235f5..0000000
--- a/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceStateLogger.kt
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.
- */
-
-package com.android.systemui.tracing
-
-import android.os.Trace
-
-/**
- * Utility class used to log state changes easily in a track with a custom name.
- *
- * Example of usage:
- * ```kotlin
- * class MyClass {
- *    val screenStateLogger = TraceStateLogger("Screen state")
- *
- *    fun onTurnedOn() { screenStateLogger.log("on") }
- *    fun onTurnedOff() { screenStateLogger.log("off") }
- * }
- * ```
- *
- * This creates a new slice in a perfetto trace only if the state is different than the previous
- * one.
- */
-class TraceStateLogger(
-    private val trackName: String,
-    private val logOnlyIfDifferent: Boolean = true,
-    private val instantEvent: Boolean = true
-) {
-
-    private var previousValue: String? = null
-
-    /** If needed, logs the value to a track with name [trackName]. */
-    fun log(newValue: String) {
-        if (instantEvent) {
-            Trace.instantForTrack(Trace.TRACE_TAG_APP, trackName, newValue)
-        }
-        if (logOnlyIfDifferent && previousValue == newValue) return
-        Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_APP, trackName, 0)
-        Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_APP, trackName, newValue, 0)
-        previousValue = newValue
-    }
-}
diff --git a/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceUtils.kt b/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceUtils.kt
deleted file mode 100644
index 12a20ae..0000000
--- a/packages/SystemUI/shared/src/com/android/systemui/tracing/TraceUtils.kt
+++ /dev/null
@@ -1,418 +0,0 @@
-/*
- * 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.
- */
-
-package com.android.systemui.tracing
-
-import android.os.Trace
-import android.os.TraceNameSupplier
-import android.util.Log
-import com.android.systemui.tracing.TraceData.Companion.FIRST_VALID_SPAN
-import com.android.systemui.tracing.TraceData.Companion.INVALID_SPAN
-import java.util.concurrent.atomic.AtomicInteger
-import kotlin.coroutines.CoroutineContext
-import kotlin.coroutines.EmptyCoroutineContext
-import kotlin.coroutines.coroutineContext
-import kotlin.random.Random
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Deferred
-import kotlinx.coroutines.ExperimentalCoroutinesApi
-import kotlinx.coroutines.Job
-import kotlinx.coroutines.async
-import kotlinx.coroutines.launch
-import kotlinx.coroutines.runBlocking
-import kotlinx.coroutines.withContext
-
-/**
- * Run a block within a [Trace] section. Calls [Trace.beginSection] before and [Trace.endSection]
- * after the passed block.
- */
-inline fun <T> traceSection(tag: String, block: () -> T): T =
-    if (Trace.isTagEnabled(Trace.TRACE_TAG_APP)) {
-        Trace.traceBegin(Trace.TRACE_TAG_APP, tag)
-        try {
-            block()
-        } finally {
-            Trace.traceEnd(Trace.TRACE_TAG_APP)
-        }
-    } else {
-        block()
-    }
-
-class TraceUtils {
-    companion object {
-        const val TAG = "TraceUtils"
-        private const val DEBUG_COROUTINE_TRACING = false
-        const val DEFAULT_TRACK_NAME = "AsyncTraces"
-
-        inline fun traceRunnable(tag: String, crossinline block: () -> Unit): Runnable {
-            return Runnable { traceSection(tag) { block() } }
-        }
-
-        /**
-         * Helper function for creating a Runnable object that implements TraceNameSupplier.
-         *
-         * This is useful for posting Runnables to Handlers with meaningful names.
-         */
-        inline fun namedRunnable(tag: String, crossinline block: () -> Unit): Runnable {
-            return object : Runnable, TraceNameSupplier {
-                override fun getTraceName(): String = tag
-                override fun run() = block()
-            }
-        }
-
-        /**
-         * Cookie used for async traces. Shouldn't be public, but to use it inside inline methods
-         * there is no other way around.
-         */
-        val lastCookie = AtomicInteger(0)
-
-        /**
-         * Creates an async slice in a track called "AsyncTraces".
-         *
-         * This can be used to trace coroutine code. Note that all usages of this method will appear
-         * under a single track.
-         */
-        inline fun <T> traceAsync(method: String, block: () -> T): T =
-            traceAsync(DEFAULT_TRACK_NAME, method, block)
-
-        /**
-         * Creates an async slice in a track with [trackName] while [block] runs.
-         *
-         * This can be used to trace coroutine code. [method] will be the name of the slice,
-         * [trackName] of the track. The track is one of the rows visible in a perfetto trace inside
-         * SystemUI process.
-         */
-        inline fun <T> traceAsync(trackName: String, method: String, block: () -> T): T {
-            val cookie = lastCookie.incrementAndGet()
-            Trace.asyncTraceForTrackBegin(Trace.TRACE_TAG_APP, trackName, method, cookie)
-            try {
-                return block()
-            } finally {
-                Trace.asyncTraceForTrackEnd(Trace.TRACE_TAG_APP, trackName, cookie)
-            }
-        }
-
-        /**
-         * Convenience function for calling [CoroutineScope.launch] with [traceCoroutine] enable
-         * tracing.
-         *
-         * @see traceCoroutine
-         */
-        inline fun CoroutineScope.launch(
-            crossinline spanName: () -> String,
-            context: CoroutineContext = EmptyCoroutineContext,
-            // TODO(b/306457056): DO NOT pass CoroutineStart; doing so will regress .odex size
-            crossinline block: suspend CoroutineScope.() -> Unit
-        ): Job = launch(context) { traceCoroutine(spanName) { block() } }
-
-        /**
-         * Convenience function for calling [CoroutineScope.launch] with [traceCoroutine] enable
-         * tracing.
-         *
-         * @see traceCoroutine
-         */
-        inline fun CoroutineScope.launch(
-            spanName: String,
-            context: CoroutineContext = EmptyCoroutineContext,
-            // TODO(b/306457056): DO NOT pass CoroutineStart; doing so will regress .odex size
-            crossinline block: suspend CoroutineScope.() -> Unit
-        ): Job = launch(context) { traceCoroutine(spanName) { block() } }
-
-        /**
-         * Convenience function for calling [CoroutineScope.async] with [traceCoroutine] enable
-         * tracing
-         *
-         * @see traceCoroutine
-         */
-        inline fun <T> CoroutineScope.async(
-            crossinline spanName: () -> String,
-            context: CoroutineContext = EmptyCoroutineContext,
-            // TODO(b/306457056): DO NOT pass CoroutineStart; doing so will regress .odex size
-            crossinline block: suspend CoroutineScope.() -> T
-        ): Deferred<T> = async(context) { traceCoroutine(spanName) { block() } }
-
-        /**
-         * Convenience function for calling [CoroutineScope.async] with [traceCoroutine] enable
-         * tracing.
-         *
-         * @see traceCoroutine
-         */
-        inline fun <T> CoroutineScope.async(
-            spanName: String,
-            context: CoroutineContext = EmptyCoroutineContext,
-            // TODO(b/306457056): DO NOT pass CoroutineStart; doing so will regress .odex size
-            crossinline block: suspend CoroutineScope.() -> T
-        ): Deferred<T> = async(context) { traceCoroutine(spanName) { block() } }
-
-        /**
-         * Convenience function for calling [runBlocking] with [traceCoroutine] to enable tracing.
-         *
-         * @see traceCoroutine
-         */
-        inline fun <T> runBlocking(
-            crossinline spanName: () -> String,
-            context: CoroutineContext,
-            crossinline block: suspend () -> T
-        ): T = runBlocking(context) { traceCoroutine(spanName) { block() } }
-
-        /**
-         * Convenience function for calling [runBlocking] with [traceCoroutine] to enable tracing.
-         *
-         * @see traceCoroutine
-         */
-        inline fun <T> runBlocking(
-            spanName: String,
-            context: CoroutineContext,
-            crossinline block: suspend CoroutineScope.() -> T
-        ): T = runBlocking(context) { traceCoroutine(spanName) { block() } }
-
-        /**
-         * Convenience function for calling [withContext] with [traceCoroutine] to enable tracing.
-         *
-         * @see traceCoroutine
-         */
-        suspend inline fun <T> withContext(
-            spanName: String,
-            context: CoroutineContext,
-            crossinline block: suspend CoroutineScope.() -> T
-        ): T = withContext(context) { traceCoroutine(spanName) { block() } }
-
-        /**
-         * Convenience function for calling [withContext] with [traceCoroutine] to enable tracing.
-         *
-         * @see traceCoroutine
-         */
-        suspend inline fun <T> withContext(
-            crossinline spanName: () -> String,
-            context: CoroutineContext,
-            crossinline block: suspend CoroutineScope.() -> T
-        ): T = withContext(context) { traceCoroutine(spanName) { block() } }
-
-        /**
-         * A hacky way to propagate the value of the COROUTINE_TRACING flag for static usage in this
-         * file. It should only every be set to true during startup. Once true, it cannot be set to
-         * false again.
-         */
-        var coroutineTracingIsEnabled = false
-            set(v) {
-                if (v) field = true
-            }
-
-        /**
-         * Traces a section of work of a `suspend` [block]. The trace sections will appear on the
-         * thread that is currently executing the [block] of work. If the [block] is suspended, all
-         * trace sections added using this API will end until the [block] is resumed, which could
-         * happen either on this thread or on another thread. If a child coroutine is started, it
-         * will inherit the trace sections of its parent. The child will continue to print these
-         * trace sections whether or not the parent coroutine is still running them.
-         *
-         * The current [CoroutineContext] must have a [TraceContextElement] for this API to work.
-         * Otherwise, the trace sections will be dropped.
-         *
-         * For example, in the following trace, Thread #1 ran some work, suspended, then continued
-         * working on Thread #2. Meanwhile, Thread #2 created a new child coroutine which inherited
-         * its trace sections. Then, the original coroutine resumed on Thread #1 before ending.
-         * Meanwhile Thread #3 is still printing trace sections from its parent because they were
-         * copied when it was created. There is no way for the parent to communicate to the child
-         * that it marked these slices as completed. While this might seem counterintuitive, it
-         * allows us to pinpoint the origin of the child coroutine's work.
-         *
-         * ```
-         * Thread #1 | [==== Slice A ====]                        [==== Slice A ====]
-         *           |       [==== B ====]                        [=== B ===]
-         * --------------------------------------------------------------------------------------
-         * Thread #2 |                    [====== Slice A ======]
-         *           |                    [========= B =========]
-         *           |                        [===== C ======]
-         * --------------------------------------------------------------------------------------
-         * Thread #3 |                            [== Slice A ==]                [== Slice A ==]
-         *           |                            [===== B =====]                [===== B =====]
-         *           |                            [===== C =====]                [===== C =====]
-         *           |                                                               [=== D ===]
-         * ```
-         *
-         * @param name The name of the code section to appear in the trace
-         * @see endSlice
-         * @see traceCoroutine
-         */
-        @OptIn(ExperimentalCoroutinesApi::class)
-        suspend inline fun <T> traceCoroutine(
-            spanName: Lazy<String>,
-            crossinline block: suspend () -> T
-        ): T {
-            // For coroutine tracing to work, trace spans must be added and removed even when
-            // tracing is not active (i.e. when TRACE_TAG_APP is disabled). Otherwise, when the
-            // coroutine resumes when tracing is active, we won't know its name.
-            val tracer = getTraceData(spanName)
-            val coroutineSpanCookie = tracer?.beginSpan(spanName.value) ?: INVALID_SPAN
-
-            // For now, also trace to "AsyncTraces". This will allow us to verify the correctness
-            // of the COROUTINE_TRACING feature flag.
-            val asyncTraceCookie =
-                if (Trace.isTagEnabled(Trace.TRACE_TAG_APP))
-                    Random.nextInt(FIRST_VALID_SPAN, Int.MAX_VALUE)
-                else INVALID_SPAN
-            if (asyncTraceCookie != INVALID_SPAN) {
-                Trace.asyncTraceForTrackBegin(
-                    Trace.TRACE_TAG_APP,
-                    DEFAULT_TRACK_NAME,
-                    spanName.value,
-                    asyncTraceCookie
-                )
-            }
-            try {
-                return block()
-            } finally {
-                if (asyncTraceCookie != INVALID_SPAN) {
-                    Trace.asyncTraceForTrackEnd(
-                        Trace.TRACE_TAG_APP,
-                        DEFAULT_TRACK_NAME,
-                        asyncTraceCookie
-                    )
-                }
-                tracer?.endSpan(coroutineSpanCookie)
-            }
-        }
-
-        @OptIn(ExperimentalCoroutinesApi::class)
-        suspend fun getTraceData(spanName: Lazy<String>): TraceData? {
-            if (!coroutineTracingIsEnabled) {
-                logVerbose("Experimental flag COROUTINE_TRACING is off", spanName)
-            } else if (coroutineContext[TraceContextElement] == null) {
-                logVerbose("Current CoroutineContext is missing TraceContextElement", spanName)
-            } else {
-                return threadLocalTrace.get().also {
-                    if (it == null) logVerbose("ThreadLocal TraceData is null", spanName)
-                }
-            }
-            return null
-        }
-
-        private fun logVerbose(logMessage: String, spanName: Lazy<String>) {
-            if (DEBUG_COROUTINE_TRACING && Log.isLoggable(TAG, Log.VERBOSE)) {
-                Log.v(TAG, "$logMessage. Dropping trace section: \"${spanName.value}\"")
-            }
-        }
-
-        /** @see traceCoroutine */
-        suspend inline fun <T> traceCoroutine(
-            spanName: String,
-            crossinline block: suspend () -> T
-        ): T = traceCoroutine(lazyOf(spanName)) { block() }
-
-        /** @see traceCoroutine */
-        suspend inline fun <T> traceCoroutine(
-            crossinline spanName: () -> String,
-            crossinline block: suspend () -> T
-        ): T = traceCoroutine(lazy(LazyThreadSafetyMode.PUBLICATION) { spanName() }) { block() }
-
-        /**
-         * Writes a trace message to indicate that a given section of code has begun running __on
-         * the current thread__. This must be followed by a corresponding call to [endSlice] in a
-         * reasonably short amount of time __on the same thread__ (i.e. _before_ the thread becomes
-         * idle again and starts running other, unrelated work).
-         *
-         * Calls to [beginSlice] and [endSlice] may be nested, and they will render in Perfetto as
-         * follows:
-         * ```
-         * Thread #1 | [==========================]
-         *           |       [==============]
-         *           |           [====]
-         * ```
-         *
-         * This function is provided for convenience to wrap a call to [Trace.traceBegin], which is
-         * more verbose to call than [Trace.beginSection], but has the added benefit of not throwing
-         * an [IllegalArgumentException] if the provided string is longer than 127 characters. We
-         * use the term "slice" instead of "section" to be consistent with Perfetto.
-         *
-         * # Avoiding malformed traces
-         *
-         * Improper usage of this API will lead to malformed traces with long slices that sometimes
-         * never end. This will look like the following:
-         * ```
-         * Thread #1 | [===================================================================== ...
-         *           |       [==============]         [====================================== ...
-         *           |           [=======]              [======]       [===================== ...
-         *           |                                                       [=======]
-         * ```
-         *
-         * To avoid this, [beginSlice] and [endSlice] should never be called from `suspend` blocks
-         * (instead, use [traceCoroutine] for tracing suspending functions). While it would be
-         * technically okay to call from a suspending function if that function were to only wrap
-         * non-suspending blocks with [beginSlice] and [endSlice], doing so is risky because suspend
-         * calls could be mistakenly added to that block as the code is refactored.
-         *
-         * Additionally, it is _not_ okay to call [beginSlice] when registering a callback and match
-         * it with a call to [endSlice] inside that callback, even if the callback runs on the same
-         * thread. Doing so would cause malformed traces because the [beginSlice] wasn't closed
-         * before the thread became idle and started running unrelated work.
-         *
-         * @param sliceName The name of the code section to appear in the trace
-         * @see endSlice
-         * @see traceCoroutine
-         */
-        fun beginSlice(sliceName: String) {
-            Trace.traceBegin(Trace.TRACE_TAG_APP, sliceName)
-        }
-
-        /**
-         * Writes a trace message to indicate that a given section of code has ended. This call must
-         * be preceded by a corresponding call to [beginSlice]. See [beginSlice] for important
-         * information regarding usage.
-         *
-         * @see beginSlice
-         * @see traceCoroutine
-         */
-        fun endSlice() {
-            Trace.traceEnd(Trace.TRACE_TAG_APP)
-        }
-
-        /**
-         * Writes a trace message indicating that an instant event occurred on the current thread.
-         * Unlike slices, instant events have no duration and do not need to be matched with another
-         * call. Perfetto will display instant events using an arrow pointing to the timestamp they
-         * occurred:
-         * ```
-         * Thread #1 | [==============]               [======]
-         *           |     [====]                        ^
-         *           |        ^
-         * ```
-         *
-         * @param eventName The name of the event to appear in the trace.
-         */
-        fun instant(eventName: String) {
-            Trace.instant(Trace.TRACE_TAG_APP, eventName)
-        }
-
-        /**
-         * Writes a trace message indicating that an instant event occurred on the given track.
-         * Unlike slices, instant events have no duration and do not need to be matched with another
-         * call. Perfetto will display instant events using an arrow pointing to the timestamp they
-         * occurred:
-         * ```
-         * Async  | [==============]               [======]
-         *  Track |     [====]                        ^
-         *   Name |        ^
-         * ```
-         *
-         * @param trackName The track where the event should appear in the trace.
-         * @param eventName The name of the event to appear in the trace.
-         */
-        fun instantForTrack(trackName: String, eventName: String) {
-            Trace.instantForTrack(Trace.TRACE_TAG_APP, trackName, eventName)
-        }
-    }
-}
diff --git a/packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt b/packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt
index 52923a7..345f15c 100644
--- a/packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/authentication/domain/interactor/AuthenticationInteractor.kt
@@ -16,6 +16,8 @@
 
 package com.android.systemui.authentication.domain.interactor
 
+import com.android.app.tracing.TraceUtils.Companion.async
+import com.android.app.tracing.TraceUtils.Companion.withContext
 import com.android.internal.widget.LockPatternView
 import com.android.internal.widget.LockscreenCredential
 import com.android.systemui.authentication.data.model.AuthenticationMethodModel as DataLayerAuthenticationMethodModel
@@ -27,8 +29,6 @@
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.dagger.qualifiers.Background
 import com.android.systemui.deviceentry.data.repository.DeviceEntryRepository
-import com.android.systemui.tracing.TraceUtils.Companion.async
-import com.android.systemui.tracing.TraceUtils.Companion.withContext
 import com.android.systemui.user.data.repository.UserRepository
 import com.android.systemui.util.time.SystemClock
 import javax.inject.Inject
diff --git a/packages/SystemUI/src/com/android/systemui/biometrics/SideFpsController.kt b/packages/SystemUI/src/com/android/systemui/biometrics/SideFpsController.kt
index 949c117..10e7227 100644
--- a/packages/SystemUI/src/com/android/systemui/biometrics/SideFpsController.kt
+++ b/packages/SystemUI/src/com/android/systemui/biometrics/SideFpsController.kt
@@ -53,6 +53,7 @@
 import com.airbnb.lottie.LottieProperty
 import com.airbnb.lottie.model.KeyPath
 import com.android.app.animation.Interpolators
+import com.android.app.tracing.traceSection
 import com.android.internal.annotations.VisibleForTesting
 import com.android.keyguard.KeyguardPINView
 import com.android.systemui.Dumpable
@@ -63,7 +64,6 @@
 import com.android.systemui.dagger.qualifiers.Main
 import com.android.systemui.dump.DumpManager
 import com.android.systemui.res.R
-import com.android.systemui.tracing.traceSection
 import com.android.systemui.util.boundsOnScreen
 import com.android.systemui.util.concurrency.DelayableExecutor
 import java.io.PrintWriter
diff --git a/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt b/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt
index 2ba687b..9e54b5c 100644
--- a/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt
+++ b/packages/SystemUI/src/com/android/systemui/display/data/repository/DisplayRepository.kt
@@ -26,12 +26,12 @@
 import android.os.Trace
 import android.util.Log
 import android.view.Display
+import com.android.app.tracing.traceSection
 import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.dagger.qualifiers.Background
 import com.android.systemui.display.data.DisplayEvent
-import com.android.systemui.tracing.traceSection
 import com.android.systemui.util.Compile
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineDispatcher
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/CustomizationProvider.kt b/packages/SystemUI/src/com/android/systemui/keyguard/CustomizationProvider.kt
index 4b98526..c490ce7 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/CustomizationProvider.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/CustomizationProvider.kt
@@ -30,13 +30,13 @@
 import android.os.Binder
 import android.os.Bundle
 import android.util.Log
+import com.android.app.tracing.TraceUtils.Companion.runBlocking
 import com.android.systemui.SystemUIAppComponentFactoryBase
 import com.android.systemui.SystemUIAppComponentFactoryBase.ContextAvailableCallback
 import com.android.systemui.dagger.qualifiers.Main
 import com.android.systemui.keyguard.domain.interactor.KeyguardQuickAffordanceInteractor
 import com.android.systemui.keyguard.ui.preview.KeyguardRemotePreviewManager
 import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract
-import com.android.systemui.tracing.TraceUtils.Companion.runBlocking
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineDispatcher
 
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/LifecycleScreenStatusProvider.kt b/packages/SystemUI/src/com/android/systemui/keyguard/LifecycleScreenStatusProvider.kt
index 5c1b731..f9b89b1 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/LifecycleScreenStatusProvider.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/LifecycleScreenStatusProvider.kt
@@ -17,7 +17,7 @@
 
 import com.android.systemui.unfold.updates.screen.ScreenStatusProvider
 import com.android.systemui.unfold.updates.screen.ScreenStatusProvider.ScreenListener
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 import javax.inject.Inject
 import javax.inject.Singleton
 
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt
index 0e795ae..c4962a1 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/FromLockscreenTransitionInteractor.kt
@@ -18,6 +18,7 @@
 
 import android.animation.ValueAnimator
 import com.android.app.animation.Interpolators
+import com.android.app.tracing.TraceUtils.Companion.launch
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.flags.FeatureFlags
@@ -31,7 +32,6 @@
 import com.android.systemui.keyguard.shared.model.TransitionState
 import com.android.systemui.power.domain.interactor.PowerInteractor
 import com.android.systemui.shade.data.repository.ShadeRepository
-import com.android.systemui.tracing.TraceUtils.Companion.launch
 import com.android.systemui.util.kotlin.Utils.Companion.toQuad
 import com.android.systemui.util.kotlin.Utils.Companion.toTriple
 import com.android.systemui.util.kotlin.sample
diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractor.kt
index fbe92e3..448411e 100644
--- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractor.kt
+++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardQuickAffordanceInteractor.kt
@@ -22,6 +22,7 @@
 import android.content.Context
 import android.content.Intent
 import android.util.Log
+import com.android.app.tracing.TraceUtils.Companion.withContext
 import com.android.internal.widget.LockPatternUtils
 import com.android.systemui.animation.DialogLaunchAnimator
 import com.android.systemui.animation.Expandable
@@ -48,7 +49,6 @@
 import com.android.systemui.shared.customization.data.content.CustomizationProviderContract as Contract
 import com.android.systemui.statusbar.phone.SystemUIDialog
 import com.android.systemui.statusbar.policy.KeyguardStateController
-import com.android.systemui.tracing.TraceUtils.Companion.withContext
 import dagger.Lazy
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineDispatcher
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt
index 601aebe..3e8b49d 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/pipeline/MediaDataManager.kt
@@ -56,6 +56,7 @@
 import android.util.Log
 import android.util.Pair as APair
 import androidx.media.utils.MediaConstants
+import com.android.app.tracing.traceSection
 import com.android.internal.annotations.Keep
 import com.android.internal.logging.InstanceId
 import com.android.keyguard.KeyguardUpdateMonitor
@@ -86,7 +87,6 @@
 import com.android.systemui.statusbar.NotificationMediaManager.isConnectingState
 import com.android.systemui.statusbar.NotificationMediaManager.isPlayingState
 import com.android.systemui.statusbar.notification.row.HybridGroupManager
-import com.android.systemui.tracing.traceSection
 import com.android.systemui.tuner.TunerService
 import com.android.systemui.util.Assert
 import com.android.systemui.util.Utils
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt
index d3bc61b..a252470 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaCarouselController.kt
@@ -34,6 +34,7 @@
 import androidx.annotation.VisibleForTesting
 import androidx.lifecycle.Lifecycle
 import androidx.lifecycle.repeatOnLifecycle
+import com.android.app.tracing.traceSection
 import com.android.internal.logging.InstanceId
 import com.android.keyguard.KeyguardUpdateMonitor
 import com.android.keyguard.KeyguardUpdateMonitorCallback
@@ -66,7 +67,6 @@
 import com.android.systemui.statusbar.notification.collection.provider.OnReorderingAllowedListener
 import com.android.systemui.statusbar.notification.collection.provider.VisualStabilityProvider
 import com.android.systemui.statusbar.policy.ConfigurationController
-import com.android.systemui.tracing.traceSection
 import com.android.systemui.util.Utils
 import com.android.systemui.util.animation.UniqueObjectHostView
 import com.android.systemui.util.animation.requiresRemeasuring
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHierarchyManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHierarchyManager.kt
index f3d41aa..d9ff36f 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHierarchyManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHierarchyManager.kt
@@ -34,6 +34,7 @@
 import android.view.ViewGroupOverlay
 import androidx.annotation.VisibleForTesting
 import com.android.app.animation.Interpolators
+import com.android.app.tracing.traceSection
 import com.android.keyguard.KeyguardViewController
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Main
@@ -53,7 +54,6 @@
 import com.android.systemui.statusbar.policy.ConfigurationController
 import com.android.systemui.statusbar.policy.KeyguardStateController
 import com.android.systemui.statusbar.policy.SplitShadeStateController
-import com.android.systemui.tracing.traceSection
 import com.android.systemui.util.animation.UniqueObjectHostView
 import com.android.systemui.util.settings.SecureSettings
 import javax.inject.Inject
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHostStatesManager.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHostStatesManager.kt
index 0129c49..1f711cf 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHostStatesManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHostStatesManager.kt
@@ -16,8 +16,8 @@
 
 package com.android.systemui.media.controls.ui
 
+import com.android.app.tracing.traceSection
 import com.android.systemui.dagger.SysUISingleton
-import com.android.systemui.tracing.traceSection
 import com.android.systemui.util.animation.MeasurementOutput
 import javax.inject.Inject
 
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaViewController.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaViewController.kt
index 6b82746..1ec43c5 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaViewController.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaViewController.kt
@@ -20,6 +20,7 @@
 import android.content.res.Configuration
 import androidx.annotation.VisibleForTesting
 import androidx.constraintlayout.widget.ConstraintSet
+import com.android.app.tracing.traceSection
 import com.android.systemui.media.controls.models.GutsViewHolder
 import com.android.systemui.media.controls.models.player.MediaViewHolder
 import com.android.systemui.media.controls.models.recommendation.RecommendationViewHolder
@@ -27,7 +28,6 @@
 import com.android.systemui.media.controls.util.MediaFlags
 import com.android.systemui.res.R
 import com.android.systemui.statusbar.policy.ConfigurationController
-import com.android.systemui.tracing.traceSection
 import com.android.systemui.util.animation.MeasurementOutput
 import com.android.systemui.util.animation.TransitionLayout
 import com.android.systemui.util.animation.TransitionLayoutController
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ActionIntentExecutor.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ActionIntentExecutor.kt
index 1416c10..a950539 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ActionIntentExecutor.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ActionIntentExecutor.kt
@@ -29,12 +29,12 @@
 import android.view.RemoteAnimationTarget
 import android.view.WindowManager
 import android.view.WindowManagerGlobal
+import com.android.app.tracing.TraceUtils.Companion.launch
 import com.android.internal.infra.ServiceConnector
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.dagger.qualifiers.Main
 import com.android.systemui.settings.DisplayTracker
-import com.android.systemui.tracing.TraceUtils.Companion.launch
 import javax.inject.Inject
 import kotlinx.coroutines.CompletableDeferred
 import kotlinx.coroutines.CoroutineDispatcher
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/RequestProcessor.kt b/packages/SystemUI/src/com/android/systemui/screenshot/RequestProcessor.kt
index 8b3548b..f56f416 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/RequestProcessor.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/RequestProcessor.kt
@@ -20,7 +20,7 @@
 import android.view.WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Application
-import com.android.systemui.tracing.TraceUtils.Companion.launch
+import com.android.app.tracing.TraceUtils.Companion.launch
 import kotlinx.coroutines.CoroutineScope
 import java.util.function.Consumer
 import javax.inject.Inject
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotProxyService.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotProxyService.kt
index c6b2cf5..713ede6 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotProxyService.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotProxyService.kt
@@ -25,7 +25,7 @@
 import com.android.systemui.shade.ShadeExpansionStateManager
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineDispatcher
-import com.android.systemui.tracing.TraceUtils.Companion.launch
+import com.android.app.tracing.TraceUtils.Companion.launch
 import kotlinx.coroutines.withContext
 
 /** Provides state from the main SystemUI process on behalf of the Screenshot process. */
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotSoundController.kt b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotSoundController.kt
index 385c813..38d00f7 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotSoundController.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotSoundController.kt
@@ -18,9 +18,9 @@
 
 import android.media.MediaPlayer
 import android.util.Log
+import com.android.app.tracing.TraceUtils.Companion.async
 import com.android.systemui.dagger.qualifiers.Application
 import com.android.systemui.dagger.qualifiers.Background
-import com.android.systemui.tracing.TraceUtils.Companion.async
 import com.google.errorprone.annotations.CanIgnoreReturnValue
 import javax.inject.Inject
 import kotlin.time.Duration.Companion.seconds
diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotExecutor.kt b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotExecutor.kt
index ccac533..f6c25e0 100644
--- a/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotExecutor.kt
+++ b/packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotExecutor.kt
@@ -5,6 +5,7 @@
 import android.util.Log
 import android.view.Display
 import android.view.WindowManager.TAKE_SCREENSHOT_PROVIDED_IMAGE
+import com.android.app.tracing.TraceUtils.Companion.launch
 import com.android.internal.logging.UiEventLogger
 import com.android.internal.util.ScreenshotRequest
 import com.android.systemui.dagger.SysUISingleton
@@ -13,7 +14,6 @@
 import com.android.systemui.res.R
 import com.android.systemui.screenshot.ScreenshotEvent.SCREENSHOT_CAPTURE_FAILED
 import com.android.systemui.screenshot.TakeScreenshotService.RequestCallback
-import com.android.systemui.tracing.TraceUtils.Companion.launch
 import java.util.function.Consumer
 import javax.inject.Inject
 import kotlinx.coroutines.CoroutineScope
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifLiveDataStoreImpl.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifLiveDataStoreImpl.kt
index b2bdb72..a1a2ba4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifLiveDataStoreImpl.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifLiveDataStoreImpl.kt
@@ -21,7 +21,7 @@
 import com.android.systemui.dagger.qualifiers.Main
 import com.android.systemui.util.Assert
 import com.android.systemui.util.ListenerSet
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 import java.util.Collections.unmodifiableList
 import java.util.concurrent.Executor
 import java.util.concurrent.atomic.AtomicReference
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/StackCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/StackCoordinator.kt
index 860697b..64970e4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/StackCoordinator.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/StackCoordinator.kt
@@ -26,7 +26,7 @@
 import com.android.systemui.statusbar.notification.shared.NotificationIconContainerRefactor
 import com.android.systemui.statusbar.notification.stack.BUCKET_SILENT
 import com.android.systemui.statusbar.phone.NotificationIconAreaController
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 import javax.inject.Inject
 
 /**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ViewConfigCoordinator.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ViewConfigCoordinator.kt
index e8afac5..3809ea0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ViewConfigCoordinator.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/coordinator/ViewConfigCoordinator.kt
@@ -28,7 +28,7 @@
 import com.android.systemui.statusbar.notification.row.NotificationGutsManager
 import com.android.systemui.statusbar.policy.ConfigurationController
 import com.android.systemui.util.Compile
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 import javax.inject.Inject
 
 /**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifEvent.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifEvent.kt
index 1f6f42d..1dd6242 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifEvent.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/notifcollection/NotifEvent.kt
@@ -23,7 +23,7 @@
 import com.android.systemui.statusbar.notification.collection.NotifCollection
 import com.android.systemui.statusbar.notification.collection.NotificationEntry
 import com.android.systemui.util.NamedListenerSet
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 
 /**
  * Set of classes that represent the various events that [NotifCollection] can dispatch to
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/NodeSpecBuilder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/NodeSpecBuilder.kt
index ca8e4fe..9fc4e40 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/NodeSpecBuilder.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/NodeSpecBuilder.kt
@@ -23,7 +23,7 @@
 import com.android.systemui.statusbar.notification.collection.listbuilder.NotifSection
 import com.android.systemui.statusbar.notification.collection.provider.SectionHeaderVisibilityProvider
 import com.android.systemui.util.Compile
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 
 /**
  * Converts a notif list (the output of the ShadeListBuilder) into a NodeSpec, an abstract
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/RenderStageManager.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/RenderStageManager.kt
index c2791a0..9b55210 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/RenderStageManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/RenderStageManager.kt
@@ -26,7 +26,7 @@
 import com.android.systemui.statusbar.notification.collection.listbuilder.OnAfterRenderEntryListener
 import com.android.systemui.statusbar.notification.collection.listbuilder.OnAfterRenderGroupListener
 import com.android.systemui.statusbar.notification.collection.listbuilder.OnAfterRenderListListener
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 import javax.inject.Inject
 
 /**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDiffer.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDiffer.kt
index c6d8500..61e6f65 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDiffer.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewDiffer.kt
@@ -18,7 +18,7 @@
 
 import android.annotation.MainThread
 import android.view.View
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 
 /**
  * Given a "spec" that describes a "tree" of views, adds and removes views from the
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewManager.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewManager.kt
index 2c59ee8..1935866 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/render/ShadeViewManager.kt
@@ -26,7 +26,7 @@
 import com.android.systemui.statusbar.notification.collection.PipelineDumper
 import com.android.systemui.statusbar.notification.collection.provider.SectionHeaderVisibilityProvider
 import com.android.systemui.statusbar.notification.stack.NotificationListContainer
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 import dagger.assisted.Assisted
 import dagger.assisted.AssistedFactory
 import dagger.assisted.AssistedInject
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/IconManager.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/IconManager.kt
index 05c88e0..9e8654a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/IconManager.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/IconManager.kt
@@ -34,7 +34,7 @@
 import com.android.systemui.statusbar.notification.collection.NotificationEntry
 import com.android.systemui.statusbar.notification.collection.notifcollection.CommonNotifCollection
 import com.android.systemui.statusbar.notification.collection.notifcollection.NotifCollectionListener
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 import javax.inject.Inject
 
 /**
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryLogger.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryLogger.kt
index c89f2fa..f096dd6 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/logging/NotificationMemoryLogger.kt
@@ -21,12 +21,12 @@
 import android.util.Log
 import android.util.StatsEvent
 import androidx.annotation.VisibleForTesting
+import com.android.app.tracing.traceSection
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Background
 import com.android.systemui.dagger.qualifiers.Main
 import com.android.systemui.shared.system.SysUiStatsLog
 import com.android.systemui.statusbar.notification.collection.NotifPipeline
-import com.android.systemui.tracing.traceSection
 import java.lang.Exception
 import java.util.concurrent.Executor
 import javax.inject.Inject
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt
index a98efba..af2ca26 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/ui/viewbinder/NotificationListViewBinder.kt
@@ -17,6 +17,7 @@
 package com.android.systemui.statusbar.notification.stack.ui.viewbinder
 
 import android.view.LayoutInflater
+import com.android.app.tracing.traceSection
 import com.android.systemui.common.ui.ConfigurationState
 import com.android.systemui.common.ui.reinflateAndBindLatest
 import com.android.systemui.lifecycle.repeatWhenAttached
@@ -31,7 +32,6 @@
 import com.android.systemui.statusbar.notification.stack.ui.viewmodel.NotificationListViewModel
 import com.android.systemui.statusbar.phone.NotificationIconAreaController
 import com.android.systemui.statusbar.policy.ConfigurationController
-import com.android.systemui.tracing.traceSection
 
 /** Binds a [NotificationStackScrollLayout] to its [view model][NotificationListViewModel]. */
 object NotificationListViewBinder {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt
index 894549d..cba72d0 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarContentInsetsProvider.kt
@@ -38,7 +38,7 @@
 import com.android.systemui.util.leak.RotationUtils.Rotation
 import com.android.systemui.util.leak.RotationUtils.getExactRotation
 import com.android.systemui.util.leak.RotationUtils.getResourcesForRotation
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 import java.io.PrintWriter
 import java.lang.Math.max
 import javax.inject.Inject
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt
index 1eea348..fb586ea 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/UnlockedScreenOffAnimationController.kt
@@ -31,7 +31,7 @@
 import com.android.systemui.statusbar.notification.stack.AnimationProperties
 import com.android.systemui.statusbar.notification.stack.StackStateAnimator
 import com.android.systemui.statusbar.policy.KeyguardStateController
-import com.android.systemui.tracing.TraceUtils
+import com.android.app.tracing.TraceUtils
 import com.android.systemui.util.settings.GlobalSettings
 import javax.inject.Inject
 import com.android.systemui.flags.FeatureFlags
diff --git a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt
index c3c0291..2afb435 100644
--- a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt
+++ b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt
@@ -48,7 +48,7 @@
 import com.android.systemui.unfold.updates.RotationChangeProvider
 import com.android.systemui.unfold.util.ScaleAwareTransitionProgressProvider.Companion.areAnimationsEnabled
 import com.android.systemui.util.concurrency.ThreadFactory
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 import com.android.wm.shell.displayareahelper.DisplayAreaHelper
 import java.util.Optional
 import java.util.concurrent.Executor
diff --git a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldTraceLogger.kt b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldTraceLogger.kt
index dfff7c4..12b8845 100644
--- a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldTraceLogger.kt
+++ b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldTraceLogger.kt
@@ -17,10 +17,10 @@
 
 import android.content.Context
 import android.os.Trace
+import com.android.app.tracing.TraceStateLogger
 import com.android.systemui.CoreStartable
 import com.android.systemui.dagger.SysUISingleton
 import com.android.systemui.dagger.qualifiers.Application
-import com.android.systemui.tracing.TraceStateLogger
 import com.android.systemui.unfold.system.DeviceStateRepository
 import com.android.systemui.unfold.updates.FoldStateRepository
 import javax.inject.Inject
diff --git a/packages/SystemUI/src/com/android/systemui/util/NamedListenerSet.kt b/packages/SystemUI/src/com/android/systemui/util/NamedListenerSet.kt
index 1e0f420..45d742f 100644
--- a/packages/SystemUI/src/com/android/systemui/util/NamedListenerSet.kt
+++ b/packages/SystemUI/src/com/android/systemui/util/NamedListenerSet.kt
@@ -16,7 +16,7 @@
 
 package com.android.systemui.util
 
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 import java.util.concurrent.CopyOnWriteArrayList
 import java.util.function.Consumer
 
diff --git a/packages/SystemUI/src/com/android/systemui/util/NoRemeasureMotionLayout.kt b/packages/SystemUI/src/com/android/systemui/util/NoRemeasureMotionLayout.kt
index cec9580..f49d616 100644
--- a/packages/SystemUI/src/com/android/systemui/util/NoRemeasureMotionLayout.kt
+++ b/packages/SystemUI/src/com/android/systemui/util/NoRemeasureMotionLayout.kt
@@ -20,7 +20,7 @@
 import android.util.AttributeSet
 import android.view.Choreographer
 import androidx.constraintlayout.motion.widget.MotionLayout
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 
 /**
  * [MotionLayout] that avoids remeasuring with the same inputs in the same frame.
diff --git a/packages/SystemUI/src/com/android/systemui/util/drawable/DrawableSize.kt b/packages/SystemUI/src/com/android/systemui/util/drawable/DrawableSize.kt
index afd2360..de92318 100644
--- a/packages/SystemUI/src/com/android/systemui/util/drawable/DrawableSize.kt
+++ b/packages/SystemUI/src/com/android/systemui/util/drawable/DrawableSize.kt
@@ -13,7 +13,7 @@
 import android.graphics.drawable.Drawable
 import android.util.Log
 import androidx.annotation.Px
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 
 class DrawableSize {
 
diff --git a/packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt b/packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt
index 5396bca..81737c7 100644
--- a/packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt
+++ b/packages/SystemUI/src/com/android/systemui/util/kotlin/CoroutinesModule.kt
@@ -7,8 +7,8 @@
 import com.android.systemui.dagger.qualifiers.Tracing
 import com.android.systemui.flags.FeatureFlagsClassic
 import com.android.systemui.flags.Flags
-import com.android.systemui.tracing.TraceUtils.Companion.coroutineTracingIsEnabled
-import com.android.systemui.tracing.TraceContextElement
+import com.android.app.tracing.TraceUtils.Companion.coroutineTracingIsEnabled
+import com.android.app.tracing.TraceContextElement
 import dagger.Module
 import dagger.Provides
 import kotlinx.coroutines.CoroutineDispatcher
diff --git a/packages/SystemUI/src/com/android/systemui/util/wrapper/LottieViewWrapper.kt b/packages/SystemUI/src/com/android/systemui/util/wrapper/LottieViewWrapper.kt
index 2e355bd..eefd849 100644
--- a/packages/SystemUI/src/com/android/systemui/util/wrapper/LottieViewWrapper.kt
+++ b/packages/SystemUI/src/com/android/systemui/util/wrapper/LottieViewWrapper.kt
@@ -18,7 +18,7 @@
 import android.content.Context
 import android.util.AttributeSet
 import com.airbnb.lottie.LottieAnimationView
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 
 /** LottieAnimationView that traces each call to invalidate. */
 open class LottieViewWrapper : LottieAnimationView {
diff --git a/packages/SystemUI/src/com/android/systemui/util/wrapper/RotationPolicyWrapper.kt b/packages/SystemUI/src/com/android/systemui/util/wrapper/RotationPolicyWrapper.kt
index 8f320a3..059ff56 100644
--- a/packages/SystemUI/src/com/android/systemui/util/wrapper/RotationPolicyWrapper.kt
+++ b/packages/SystemUI/src/com/android/systemui/util/wrapper/RotationPolicyWrapper.kt
@@ -21,7 +21,7 @@
 import com.android.internal.view.RotationPolicy
 import com.android.internal.view.RotationPolicy.RotationPolicyListener
 import com.android.systemui.util.settings.SecureSettings
-import com.android.systemui.tracing.traceSection
+import com.android.app.tracing.traceSection
 import javax.inject.Inject
 
 /**
diff --git a/packages/SystemUI/tests/src/com/android/systemui/tracing/TraceUtilsTest.kt b/packages/SystemUI/tests/src/com/android/systemui/tracing/TraceUtilsTest.kt
index 8fb5ff8..ba34ce6 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/tracing/TraceUtilsTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/tracing/TraceUtilsTest.kt
@@ -12,7 +12,7 @@
  * permissions and limitations under the License.
  */
 
-package com.android.systemui.tracing
+package com.android.app.tracing
 
 import android.os.Handler
 import android.os.Looper
@@ -76,7 +76,7 @@
     @Test
     fun testLongTraceSection_doesNotThrow_whenUsingHelper() {
         traceSection(SECTION_NAME_THATS_TOO_LONG) {
-            Log.v(TAG, "com.android.systemui.tracing.traceSection() block.")
+            Log.v(TAG, "com.android.app.tracing.traceSection() block.")
         }
     }