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

Commit feb3245d authored by Zekan Qian's avatar Zekan Qian Committed by Android (Google) Code Review
Browse files

Merge "Add arguments in Logger."

parents 0f8c32e2 dbeb8bc8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ private fun EntryStatusData.debugContent(): String {
}

fun SettingsPage.debugArguments(): String {
    val normArguments = parameter.normalize(arguments)
    val normArguments = parameter.normalize(arguments, eraseRuntimeValues = true)
    if (normArguments == null || normArguments.isEmpty) return "[No arguments]"
    return normArguments.toString().removeRange(0, 6)
}
+12 −8
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ interface EntryData {
        get() = null
    val isHighlighted: Boolean
        get() = false
    val arguments: Bundle?
        get() = null
}

val LocalEntryDataProvider =
@@ -121,11 +123,11 @@ data class SettingsEntry(
    }

    private fun fullArgument(runtimeArguments: Bundle? = null): Bundle {
        val arguments = Bundle()
        if (owner.arguments != null) arguments.putAll(owner.arguments)
        return Bundle().apply {
            if (owner.arguments != null) putAll(owner.arguments)
            // Put runtime args later, which can override page args.
        if (runtimeArguments != null) arguments.putAll(runtimeArguments)
        return arguments
            if (runtimeArguments != null) putAll(runtimeArguments)
        }
    }

    fun getStatusData(runtimeArguments: Bundle? = null): EntryStatusData? {
@@ -142,19 +144,21 @@ data class SettingsEntry(

    @Composable
    fun UiLayout(runtimeArguments: Bundle? = null) {
        CompositionLocalProvider(provideLocalEntryData()) {
            uiLayoutImpl(fullArgument(runtimeArguments))
        val arguments = remember { fullArgument(runtimeArguments) }
        CompositionLocalProvider(provideLocalEntryData(arguments)) {
            uiLayoutImpl(arguments)
        }
    }

    @Composable
    fun provideLocalEntryData(): ProvidedValue<EntryData> {
    fun provideLocalEntryData(arguments: Bundle): ProvidedValue<EntryData> {
        val controller = LocalNavController.current
        return LocalEntryDataProvider provides remember {
            object : EntryData {
                override val pageId = containerPage().id
                override val entryId = id
                override val isHighlighted = controller.highlightEntryId == id
                override val arguments = arguments
            }
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ data class SettingsPage(
            parameter: List<NamedNavArgument> = emptyList(),
            arguments: Bundle? = null
        ): String {
            val normArguments = parameter.normalize(arguments)
            val normArguments = parameter.normalize(arguments, eraseRuntimeValues = true)
            return "$name:${normArguments?.toString()}".toHashId()
        }
    }
+5 −2
Original line number Diff line number Diff line
@@ -28,9 +28,12 @@ import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
@Composable
fun logEntryEvent(): (event: LogEvent, extraData: Bundle) -> Unit {
    val entryId = LocalEntryDataProvider.current.entryId ?: return { _, _ -> }
    val arguments = LocalEntryDataProvider.current.arguments
    return { event, extraData ->
        SpaEnvironmentFactory.instance.logger.event(
            entryId, event, category = LogCategory.VIEW, extraData = extraData
            entryId, event, category = LogCategory.VIEW, extraData = extraData.apply {
                if (arguments != null) putAll(arguments)
            }
        )
    }
}
@@ -40,7 +43,7 @@ fun wrapOnClickWithLog(onClick: (() -> Unit)?): (() -> Unit)? {
    if (onClick == null) return null
    val logEvent = logEntryEvent()
    return {
        logEvent(LogEvent.ENTRY_CLICK, Bundle.EMPTY)
        logEvent(LogEvent.ENTRY_CLICK, bundleOf())
        onClick()
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -48,7 +48,10 @@ internal fun SettingsPageProvider.PageEvent(arguments: Bundle? = null) {
                    extraData = bundleOf(
                        LOG_DATA_DISPLAY_NAME to page.displayName,
                        LOG_DATA_SESSION_NAME to navController.sessionSourceName,
                    )
                    ).apply {
                        val normArguments = parameter.normalize(arguments)
                        if (normArguments != null) putAll(normArguments)
                    }
                )
            }
            if (event == Lifecycle.Event.ON_START) {
Loading