Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 191ff724 authored by Julia Tuttle's avatar Julia Tuttle
Browse files

Flexiglass: add SceneStack.toString

I'd like to print the back stack in a debug message in a future change,
but it didn't have a toString, so I'm implementing one.

Bug: 364076359
Test: builds
Flag: com.android.systemui.scene_container
Change-Id: I6d048a4fe8f79c3e11977a25dfa0b29074cf79cd
parent 8bff5c38
Loading
Loading
Loading
Loading
+11 −4
Original line number Diff line number Diff line
@@ -21,10 +21,6 @@ import com.android.compose.animation.scene.SceneKey
/** An immutable stack of [SceneKey]s backed by a singly-linked list. */
sealed interface SceneStack

private data object EmptyStack : SceneStack

private data class StackedNodes(val head: SceneKey, val tail: SceneStack) : SceneStack

/** Returns the scene at the head of the stack, or `null` if empty. O(1) */
fun SceneStack.peek(): SceneKey? =
    when (this) {
@@ -69,3 +65,14 @@ fun sceneStackOf(vararg scenes: SceneKey): SceneStack {
    }
    return result
}

private data object EmptyStack : SceneStack {
    override fun toString() = sceneStackToString()
}

private data class StackedNodes(val head: SceneKey, val tail: SceneStack) : SceneStack {
    override fun toString() = sceneStackToString()
}

private fun SceneStack.sceneStackToString(): String =
    asIterable().joinToString { it.testTag }.let { "SceneStack([$it])" }
+2 −3
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.scene.domain.interactor
import com.android.compose.animation.scene.SceneKey
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.scene.data.model.SceneStack
import com.android.systemui.scene.data.model.asIterable
import com.android.systemui.scene.data.model.peek
import com.android.systemui.scene.data.model.pop
import com.android.systemui.scene.data.model.push
@@ -68,13 +67,13 @@ constructor(
                    checkNotNull(stack.pop()) { "Cannot pop ${from.debugName} when stack is empty" }
            }
        }
        logger.logSceneBackStack(backStack.value.asIterable())
        logger.logSceneBackStack(backStack.value)
    }

    /** Applies the given [transform] to the back stack. */
    fun updateBackStack(transform: (SceneStack) -> SceneStack) {
        _backStack.update { stack -> transform(stack) }
        logger.logSceneBackStack(backStack.value.asIterable())
        logger.logSceneBackStack(backStack.value)
    }

    private fun stackOperation(from: SceneKey, to: SceneKey, stack: SceneStack): StackOperation? {
+7 −17
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.compose.animation.scene.SceneKey
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
import com.android.systemui.log.dagger.SceneFrameworkLog
import com.android.systemui.scene.data.model.SceneStack
import javax.inject.Inject

class SceneLogger @Inject constructor(@SceneFrameworkLog private val logBuffer: LogBuffer) {
@@ -40,16 +41,11 @@ class SceneLogger @Inject constructor(@SceneFrameworkLog private val logBuffer:
            },
            messagePrinter = {
                "Scene framework is ${asWord(bool1)}${if (str1 != null) " $str1" else ""}"
            }
            },
        )
    }

    fun logSceneChanged(
        from: SceneKey,
        to: SceneKey,
        reason: String,
        isInstant: Boolean,
    ) {
    fun logSceneChanged(from: SceneKey, to: SceneKey, reason: String, isInstant: Boolean) {
        logBuffer.log(
            tag = TAG,
            level = LogLevel.INFO,
@@ -123,11 +119,7 @@ class SceneLogger @Inject constructor(@SceneFrameworkLog private val logBuffer:
        )
    }

    fun logVisibilityChange(
        from: Boolean,
        to: Boolean,
        reason: String,
    ) {
    fun logVisibilityChange(from: Boolean, to: Boolean, reason: String) {
        fun asWord(isVisible: Boolean): String {
            return if (isVisible) "visible" else "invisible"
        }
@@ -144,9 +136,7 @@ class SceneLogger @Inject constructor(@SceneFrameworkLog private val logBuffer:
        )
    }

    fun logRemoteUserInputStarted(
        reason: String,
    ) {
    fun logRemoteUserInputStarted(reason: String) {
        logBuffer.log(
            tag = TAG,
            level = LogLevel.INFO,
@@ -164,11 +154,11 @@ class SceneLogger @Inject constructor(@SceneFrameworkLog private val logBuffer:
        )
    }

    fun logSceneBackStack(backStack: Iterable<SceneKey>) {
    fun logSceneBackStack(backStack: SceneStack) {
        logBuffer.log(
            tag = TAG,
            level = LogLevel.INFO,
            messageInitializer = { str1 = backStack.joinToString(", ") { it.debugName } },
            messageInitializer = { str1 = backStack.toString() },
            messagePrinter = { "back stack: $str1" },
        )
    }