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

Commit 8cc95186 authored by Darrell Shi's avatar Darrell Shi
Browse files

Log widget taps

This change detects single tap events on widgets in the hub when it is
not in edit mode, and logs to statsd.

Test: atest CommunalMetricsLoggerTest
Test: atest CommunalViewModelTest
Test: statsd_testdrive 908
Bug: 317798449
Flag: com.android.systemui.communal_hub
Change-Id: Ie106a473f915b790bb7631b0f938404d9c24720b
parent 0fc4b90b
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -993,6 +993,11 @@ private fun WidgetContent(
        modifier =
            modifier
                .then(selectableModifier)
                .thenIf(!viewModel.isEditMode && !model.inQuietMode) {
                    Modifier.pointerInput(Unit) {
                        observeTaps { viewModel.onTapWidget(model.componentName, model.priority) }
                    }
                }
                .thenIf(!viewModel.isEditMode && model.inQuietMode) {
                    Modifier.pointerInput(Unit) {
                        // consume tap to prevent the child view from triggering interactions with
+24 −0
Original line number Diff line number Diff line
@@ -93,6 +93,30 @@ class CommunalMetricsLoggerTest : SysuiTestCase() {
            )
    }

    @Test
    fun logTapWidget_componentNotLoggable_doNotLog() {
        underTest.logTapWidget(
            componentName = "com.yellow.package/my_test_widget",
            rank = 2,
        )
        verify(statsLogProxy, never())
            .writeCommunalHubWidgetEventReported(anyInt(), any(), anyInt())
    }

    @Test
    fun logTapWidget_componentLoggable_logRemoveEvent() {
        underTest.logTapWidget(
            componentName = "com.red.package/my_test_widget",
            rank = 2,
        )
        verify(statsLogProxy)
            .writeCommunalHubWidgetEventReported(
                SysUiStatsLog.COMMUNAL_HUB_WIDGET_EVENT_REPORTED__ACTION__TAP,
                "com.red.package/my_test_widget",
                2,
            )
    }

    @Test
    fun logWidgetsSnapshot_logOnlyLoggableComponents() {
        val statsEvents = mutableListOf<StatsEvent>()
+11 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.communal.view.viewmodel

import android.content.ComponentName
import android.content.pm.UserInfo
import android.platform.test.flag.junit.FlagsParameterization
import android.provider.Settings
@@ -41,6 +42,7 @@ import com.android.systemui.communal.domain.interactor.communalSceneInteractor
import com.android.systemui.communal.domain.interactor.communalSettingsInteractor
import com.android.systemui.communal.domain.interactor.communalTutorialInteractor
import com.android.systemui.communal.domain.model.CommunalContentModel
import com.android.systemui.communal.shared.log.CommunalMetricsLogger
import com.android.systemui.communal.shared.model.CommunalScenes
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel
import com.android.systemui.communal.ui.viewmodel.CommunalViewModel.Companion.POPUP_AUTO_HIDE_TIMEOUT_MS
@@ -107,6 +109,7 @@ import platform.test.runner.parameterized.Parameters
@RunWith(ParameterizedAndroidJunit4::class)
class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
    @Mock private lateinit var mediaHost: MediaHost
    @Mock private lateinit var metricsLogger: CommunalMetricsLogger

    private val kosmos = testKosmos()
    private val testScope = kosmos.testScope
@@ -170,7 +173,8 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
                kosmos.communalTutorialInteractor,
                kosmos.shadeInteractor,
                mediaHost,
                logcatLogBuffer("CommunalViewModelTest")
                logcatLogBuffer("CommunalViewModelTest"),
                metricsLogger,
            )
    }

@@ -746,6 +750,12 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
        verify(communalInteractor).setScrollPosition(eq(index), eq(offset))
    }

    @Test
    fun onTapWidget_logEvent() {
        underTest.onTapWidget(ComponentName("test_pkg", "test_cls"), priority = 10)
        verify(metricsLogger).logTapWidget("test_pkg/test_cls", rank = 10)
    }

    private suspend fun setIsMainUser(isMainUser: Boolean) {
        val user = if (isMainUser) MAIN_USER_INFO else SECONDARY_USER_INFO
        with(userRepository) {
+13 −0
Original line number Diff line number Diff line
@@ -56,6 +56,19 @@ constructor(
        )
    }

    /** Logs a tap widget event for metrics. No-op if widget is not loggable. */
    fun logTapWidget(componentName: String, rank: Int) {
        if (!componentName.isLoggable()) {
            return
        }

        statsLogProxy.writeCommunalHubWidgetEventReported(
            SysUiStatsLog.COMMUNAL_HUB_WIDGET_EVENT_REPORTED__ACTION__TAP,
            componentName,
            rank,
        )
    }

    /** Logs loggable widgets and the total widget count as a [StatsEvent]. */
    fun logWidgetsSnapshot(
        statsEvents: MutableList<StatsEvent>,
+6 −0
Original line number Diff line number Diff line
@@ -139,6 +139,12 @@ abstract class BaseCommunalViewModel(
        priority: Int,
    ) {}

    /** Called as the UI detects a tap event on the widget. */
    open fun onTapWidget(
        componentName: ComponentName,
        priority: Int,
    ) {}

    /**
     * Called as the UI requests reordering widgets.
     *
Loading