Loading packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +5 −0 Original line number Diff line number Diff line Loading @@ -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 Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/log/CommunalMetricsLoggerTest.kt +24 −0 Original line number Diff line number Diff line Loading @@ -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>() Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt +11 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -170,7 +173,8 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() { kosmos.communalTutorialInteractor, kosmos.shadeInteractor, mediaHost, logcatLogBuffer("CommunalViewModelTest") logcatLogBuffer("CommunalViewModelTest"), metricsLogger, ) } Loading Loading @@ -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) { Loading packages/SystemUI/src/com/android/systemui/communal/shared/log/CommunalMetricsLogger.kt +13 −0 Original line number Diff line number Diff line Loading @@ -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>, Loading packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt +6 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +5 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/log/CommunalMetricsLoggerTest.kt +24 −0 Original line number Diff line number Diff line Loading @@ -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>() Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt +11 −1 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading Loading @@ -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 Loading Loading @@ -170,7 +173,8 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() { kosmos.communalTutorialInteractor, kosmos.shadeInteractor, mediaHost, logcatLogBuffer("CommunalViewModelTest") logcatLogBuffer("CommunalViewModelTest"), metricsLogger, ) } Loading Loading @@ -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) { Loading
packages/SystemUI/src/com/android/systemui/communal/shared/log/CommunalMetricsLogger.kt +13 −0 Original line number Diff line number Diff line Loading @@ -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>, Loading
packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt +6 −0 Original line number Diff line number Diff line Loading @@ -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