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

Commit 83e77635 authored by Caitlin Shkuratov's avatar Caitlin Shkuratov
Browse files

[SB Refactor] Add better logging for the mobile icon ID.

Previous logging had `iconId=1028` or `iconId=132096`, which is
difficult to parse.

Bug: 238425913
Test: Manual: Dumped DemoMobileConnectionLog [1] and verified output
Test: atest MobileIconViewModelTest
Change-Id: I8ddeafe4dfb579d9d05e5c23a62bf2e55e256998
parent a8cd6d35
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -93,8 +93,13 @@ object MobileIconBinder {

                // Set the icon for the triangle
                launch {
                    viewModel.iconId.distinctUntilChanged().collect { iconId ->
                        mobileDrawable.level = iconId
                    viewModel.icon.distinctUntilChanged().collect { icon ->
                        mobileDrawable.level =
                            SignalDrawable.getState(
                                icon.level,
                                icon.numberOfLevels,
                                icon.showExclamationMark,
                            )
                    }
                }

+56 −0
Original line number Diff line number Diff line
/*
 * 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.statusbar.pipeline.mobile.ui.model

import com.android.systemui.log.table.Diffable
import com.android.systemui.log.table.TableRowLogger

/** A model that will be consumed by [SignalDrawable] to show the mobile triangle icon. */
data class SignalIconModel(
    val level: Int,
    val numberOfLevels: Int,
    val showExclamationMark: Boolean,
) : Diffable<SignalIconModel> {
    // TODO(b/267767715): Can we implement [logDiffs] and [logFull] generically for data classes?
    override fun logDiffs(prevVal: SignalIconModel, row: TableRowLogger) {
        if (prevVal.level != level) {
            row.logChange(COL_LEVEL, level)
        }
        if (prevVal.numberOfLevels != numberOfLevels) {
            row.logChange(COL_NUM_LEVELS, numberOfLevels)
        }
        if (prevVal.showExclamationMark != showExclamationMark) {
            row.logChange(COL_SHOW_EXCLAMATION, showExclamationMark)
        }
    }

    override fun logFull(row: TableRowLogger) {
        row.logChange(COL_LEVEL, level)
        row.logChange(COL_NUM_LEVELS, numberOfLevels)
        row.logChange(COL_SHOW_EXCLAMATION, showExclamationMark)
    }

    companion object {
        /** Creates a [SignalIconModel] representing an empty and invalidated state. */
        fun createEmptyState(numberOfLevels: Int) =
            SignalIconModel(level = 0, numberOfLevels, showExclamationMark = true)

        private const val COL_LEVEL = "level"
        private const val COL_NUM_LEVELS = "numLevels"
        private const val COL_SHOW_EXCLAMATION = "showExclamation"
    }
}
+7 −10
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@ import com.android.systemui.common.shared.model.Icon
import com.android.systemui.log.table.logDiffsForTable
import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.MobileIconInteractor
import com.android.systemui.statusbar.pipeline.mobile.domain.interactor.MobileIconsInteractor
import com.android.systemui.statusbar.pipeline.mobile.ui.model.SignalIconModel
import com.android.systemui.statusbar.pipeline.shared.ConnectivityConstants
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
import com.android.systemui.statusbar.pipeline.shared.data.model.DataActivityModel
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -42,8 +42,7 @@ import kotlinx.coroutines.flow.stateIn
/** Common interface for all of the location-based mobile icon view models. */
interface MobileIconViewModelCommon {
    val subscriptionId: Int
    /** An int consumable by [SignalDrawable] for display */
    val iconId: Flow<Int>
    val icon: Flow<SignalIconModel>
    val contentDescription: Flow<ContentDescription>
    val roaming: Flow<Boolean>
    /** The RAT icon (LTE, 3G, 5G, etc) to be displayed. Null if we shouldn't show anything */
@@ -72,7 +71,6 @@ class MobileIconViewModel
constructor(
    override val subscriptionId: Int,
    iconInteractor: MobileIconInteractor,
    logger: ConnectivityPipelineLogger,
    constants: ConnectivityConstants,
    scope: CoroutineScope,
) : MobileIconViewModelCommon {
@@ -80,8 +78,8 @@ constructor(
    private val showExclamationMark: Flow<Boolean> =
        iconInteractor.isDefaultDataEnabled.mapLatest { !it }

    override val iconId: Flow<Int> = run {
        val initial = SignalDrawable.getEmptyState(iconInteractor.numberOfLevels.value)
    override val icon: Flow<SignalIconModel> = run {
        val initial = SignalIconModel.createEmptyState(iconInteractor.numberOfLevels.value)
        combine(
                iconInteractor.level,
                iconInteractor.numberOfLevels,
@@ -89,16 +87,15 @@ constructor(
                iconInteractor.isInService,
            ) { level, numberOfLevels, showExclamationMark, isInService ->
                if (!isInService) {
                    SignalDrawable.getEmptyState(numberOfLevels)
                    SignalIconModel.createEmptyState(numberOfLevels)
                } else {
                    SignalDrawable.getState(level, numberOfLevels, showExclamationMark)
                    SignalIconModel(level, numberOfLevels, showExclamationMark)
                }
            }
            .distinctUntilChanged()
            .logDiffsForTable(
                iconInteractor.tableLogBuffer,
                columnPrefix = "",
                columnName = "iconId",
                columnPrefix = "icon",
                initialValue = initial,
            )
            .stateIn(scope, SharingStarted.WhileSubscribed(), initial)
+0 −1
Original line number Diff line number Diff line
@@ -56,7 +56,6 @@ constructor(
                ?: MobileIconViewModel(
                        subId,
                        interactor.createMobileConnectionInteractorForSubId(subId),
                        logger,
                        constants,
                        scope,
                    )
+0 −3
Original line number Diff line number Diff line
@@ -34,7 +34,6 @@ import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.LocationBased
import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.MobileIconViewModel
import com.android.systemui.statusbar.pipeline.mobile.ui.viewmodel.QsMobileIconViewModel
import com.android.systemui.statusbar.pipeline.shared.ConnectivityConstants
import com.android.systemui.statusbar.pipeline.shared.ConnectivityPipelineLogger
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
@@ -58,7 +57,6 @@ class ModernStatusBarMobileViewTest : SysuiTestCase() {

    @Mock private lateinit var statusBarPipelineFlags: StatusBarPipelineFlags
    @Mock private lateinit var tableLogBuffer: TableLogBuffer
    @Mock private lateinit var logger: ConnectivityPipelineLogger
    @Mock private lateinit var constants: ConnectivityConstants

    private lateinit var viewModel: LocationBasedMobileViewModel
@@ -74,7 +72,6 @@ class ModernStatusBarMobileViewTest : SysuiTestCase() {
            MobileIconViewModel(
                subscriptionId = 1,
                interactor,
                logger,
                constants,
                testScope.backgroundScope,
            )
Loading