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

Commit c6cb2fc5 authored by Ale Nijamkin's avatar Ale Nijamkin Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] Add scene/overlay change rejection logging." into main

parents 798ac005 8c9d8591
Loading
Loading
Loading
Loading
+67 −4
Original line number Diff line number Diff line
@@ -244,6 +244,7 @@ constructor(
    ) {
        val currentSceneKey = currentScene.value
        val resolvedScene = sceneFamilyResolvers.get()[toScene]?.resolvedScene?.value ?: toScene

        if (
            !validateSceneChange(
                from = currentSceneKey,
@@ -523,14 +524,32 @@ constructor(
        }

        if (from == to) {
            logger.logSceneChangeRejection(
                from = from,
                to = to,
                originalChangeReason = loggingReason,
                rejectionReason = "${from.debugName} is the same as ${to.debugName}",
            )
            return false
        }

        if (to !in repository.allContentKeys) {
            logger.logSceneChangeRejection(
                from = from,
                to = to,
                originalChangeReason = loggingReason,
                rejectionReason = "${to.debugName} isn't present in allContentKeys",
            )
            return false
        }

        if (disabledContentInteractor.isDisabled(to)) {
            logger.logSceneChangeRejection(
                from = from,
                to = to,
                originalChangeReason = loggingReason,
                rejectionReason = "${to.debugName} is currently disabled",
            )
            return false
        }

@@ -580,14 +599,58 @@ constructor(
        }

        if (to != null && disabledContentInteractor.isDisabled(to)) {
            logger.logSceneChangeRejection(
                from = from,
                to = to,
                originalChangeReason = loggingReason,
                rejectionReason = "${to.debugName} is currently disabled",
            )
            return false
        }

        val isFromValid = (from == null) || (from in currentOverlays.value)
        val isToValid =
            (to == null) || (to !in currentOverlays.value && to in repository.allContentKeys)
        return when {
            to != null && from != null && to == from -> {
                logger.logSceneChangeRejection(
                    from = from,
                    to = to,
                    originalChangeReason = loggingReason,
                    rejectionReason = "${from.debugName} is the same as ${to.debugName}",
                )
                false
            }

        return isFromValid && isToValid && from != to
            to != null && to !in repository.allContentKeys -> {
                logger.logSceneChangeRejection(
                    from = from,
                    to = to,
                    originalChangeReason = loggingReason,
                    rejectionReason = "${to.debugName} is not in allContentKeys",
                )
                false
            }

            from != null && from !in currentOverlays.value -> {
                logger.logSceneChangeRejection(
                    from = from,
                    to = to,
                    originalChangeReason = loggingReason,
                    rejectionReason = "${from.debugName} is not a current overlay",
                )
                false
            }

            to != null && to in currentOverlays.value -> {
                logger.logSceneChangeRejection(
                    from = from,
                    to = to,
                    originalChangeReason = loggingReason,
                    rejectionReason = "${to.debugName} is already a current overlay",
                )
                false
            }

            else -> true
        }
    }

    /** Returns a flow indicating if the currently visible scene can be resolved from [family]. */
+33 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.scene.shared.logger

import com.android.compose.animation.scene.ContentKey
import com.android.compose.animation.scene.ObservableTransitionState
import com.android.compose.animation.scene.OverlayKey
import com.android.compose.animation.scene.SceneKey
@@ -74,6 +75,38 @@ class SceneLogger @Inject constructor(@SceneFrameworkLog private val logBuffer:
        )
    }

    fun logSceneChangeRejection(
        from: ContentKey?,
        to: ContentKey?,
        originalChangeReason: String,
        rejectionReason: String,
    ) {
        logBuffer.log(
            tag = TAG,
            level = LogLevel.INFO,
            messageInitializer = {
                str1 = "${from?.debugName ?: "<none>"} → ${to?.debugName ?: "<none>"}"
                str2 = rejectionReason
                str3 = originalChangeReason
                bool1 = to is OverlayKey
            },
            messagePrinter = {
                buildString {
                    append("REJECTED ")
                    append(
                        if (bool1) {
                            "overlay "
                        } else {
                            "scene "
                        }
                    )
                    append("change because \"$str2\" ")
                    append("(original change reason: \"$str3\")")
                }
            },
        )
    }

    fun logSceneTransition(transitionState: ObservableTransitionState) {
        when (transitionState) {
            is ObservableTransitionState.Transition -> {