diff options
author | 2024-11-12 20:52:58 +0000 | |
---|---|---|
committer | 2024-11-12 20:52:58 +0000 | |
commit | 913e30ed1d4adaee82dbb67dc30bb55628eb786a (patch) | |
tree | fd68be66956787d961e1a73cee7e7f630d842c9d | |
parent | 20fcda0359d7b1b0f1cf278a3795fe93838bb46b (diff) | |
parent | 397cc0fda01802b91a69da4a35395ff220864fe2 (diff) |
Merge "[Widget resizing] Add metrics logging for widget resizing" into main
8 files changed, 128 insertions, 52 deletions
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContent.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContent.kt index 9392b1afffa3..96e99b15363d 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContent.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalContent.kt @@ -66,13 +66,13 @@ constructor( interactionHandler = interactionHandler, dialogFactory = dialogFactory, widgetSection = widgetSection, - modifier = Modifier.element(Communal.Elements.Grid) + modifier = Modifier.element(Communal.Elements.Grid), ) } with(lockSection) { LockIcon( overrideColor = MaterialTheme.colorScheme.onPrimaryContainer, - modifier = Modifier.element(Communal.Elements.LockIcon) + modifier = Modifier.element(Communal.Elements.LockIcon), ) } with(bottomAreaSection) { @@ -80,17 +80,13 @@ constructor( Modifier.element(Communal.Elements.IndicationArea).fillMaxWidth() ) } - } + }, ) { measurables, constraints -> val communalGridMeasurable = measurables[0] val lockIconMeasurable = measurables[1] val bottomAreaMeasurable = measurables[2] - val noMinConstraints = - constraints.copy( - minWidth = 0, - minHeight = 0, - ) + val noMinConstraints = constraints.copy(minWidth = 0, minHeight = 0) val lockIconPlaceable = lockIconMeasurable.measure(noMinConstraints) val lockIconBounds = @@ -109,14 +105,8 @@ constructor( ) layout(constraints.maxWidth, constraints.maxHeight) { - communalGridPlaceable.place( - x = 0, - y = 0, - ) - lockIconPlaceable.place( - x = lockIconBounds.left, - y = lockIconBounds.top, - ) + communalGridPlaceable.place(x = 0, y = 0) + lockIconPlaceable.place(x = lockIconBounds.left, y = lockIconBounds.top) bottomAreaPlaceable.place( x = 0, y = constraints.maxHeight - bottomAreaPlaceable.height, diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt index 5e1ac1f30354..df1185cb1a6d 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/CommunalHub.kt @@ -807,7 +807,6 @@ private fun BoxScope.CommunalHubLazyGrid( ) { ResizeableItemFrameViewModel() } - if (viewModel.isEditMode && dragDropState != null) { val isItemDragging = dragDropState.draggingItemKey == item.key val outlineAlpha by diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/ContentListState.kt b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/ContentListState.kt index 6e30575a684d..16002bc709fd 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/ContentListState.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/communal/ui/compose/ContentListState.kt @@ -59,7 +59,14 @@ internal constructor( private val onAddWidget: (componentName: ComponentName, user: UserHandle, rank: Int) -> Unit, private val onDeleteWidget: (id: Int, componentName: ComponentName, rank: Int) -> Unit, private val onReorderWidgets: (widgetIdToRankMap: Map<Int, Int>) -> Unit, - private val onResizeWidget: (id: Int, spanY: Int, widgetIdToRankMap: Map<Int, Int>) -> Unit, + private val onResizeWidget: + ( + id: Int, + spanY: Int, + widgetIdToRankMap: Map<Int, Int>, + componentName: ComponentName, + rank: Int, + ) -> Unit, ) { var list = communalContent.toMutableStateList() private set @@ -105,7 +112,9 @@ internal constructor( } else { emptyMap() } - onResizeWidget(item.appWidgetId, newSpan, widgetIdToRankMap) + val componentName = item.componentName + val rank = item.rank + onResizeWidget(item.appWidgetId, newSpan, widgetIdToRankMap, componentName, rank) } /** diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/log/CommunalMetricsLoggerTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/log/CommunalMetricsLoggerTest.kt index 82918a569990..af2d7e45ee5f 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/log/CommunalMetricsLoggerTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/log/CommunalMetricsLoggerTest.kt @@ -47,20 +47,14 @@ class CommunalMetricsLoggerTest : SysuiTestCase() { @Test fun logAddWidget_componentNotLoggable_doNotLog() { - underTest.logAddWidget( - componentName = "com.green.package/my_test_widget", - rank = 1, - ) + underTest.logAddWidget(componentName = "com.green.package/my_test_widget", rank = 1) verify(statsLogProxy, never()) - .writeCommunalHubWidgetEventReported(anyInt(), any(), anyInt()) + .writeCommunalHubWidgetEventReported(anyInt(), any(), anyInt(), anyInt()) } @Test fun logAddWidget_componentLoggable_logAddEvent() { - underTest.logAddWidget( - componentName = "com.blue.package/my_test_widget", - rank = 1, - ) + underTest.logAddWidget(componentName = "com.blue.package/my_test_widget", rank = 1) verify(statsLogProxy) .writeCommunalHubWidgetEventReported( SysUiStatsLog.COMMUNAL_HUB_WIDGET_EVENT_REPORTED__ACTION__ADD, @@ -71,20 +65,14 @@ class CommunalMetricsLoggerTest : SysuiTestCase() { @Test fun logRemoveWidget_componentNotLoggable_doNotLog() { - underTest.logRemoveWidget( - componentName = "com.yellow.package/my_test_widget", - rank = 2, - ) + underTest.logRemoveWidget(componentName = "com.yellow.package/my_test_widget", rank = 2) verify(statsLogProxy, never()) - .writeCommunalHubWidgetEventReported(anyInt(), any(), anyInt()) + .writeCommunalHubWidgetEventReported(anyInt(), any(), anyInt(), anyInt()) } @Test fun logRemoveWidget_componentLoggable_logRemoveEvent() { - underTest.logRemoveWidget( - componentName = "com.red.package/my_test_widget", - rank = 2, - ) + underTest.logRemoveWidget(componentName = "com.red.package/my_test_widget", rank = 2) verify(statsLogProxy) .writeCommunalHubWidgetEventReported( SysUiStatsLog.COMMUNAL_HUB_WIDGET_EVENT_REPORTED__ACTION__REMOVE, @@ -95,20 +83,14 @@ class CommunalMetricsLoggerTest : SysuiTestCase() { @Test fun logTapWidget_componentNotLoggable_doNotLog() { - underTest.logTapWidget( - componentName = "com.yellow.package/my_test_widget", - rank = 2, - ) + underTest.logTapWidget(componentName = "com.yellow.package/my_test_widget", rank = 2) verify(statsLogProxy, never()) - .writeCommunalHubWidgetEventReported(anyInt(), any(), anyInt()) + .writeCommunalHubWidgetEventReported(anyInt(), any(), anyInt(), anyInt()) } @Test fun logTapWidget_componentLoggable_logRemoveEvent() { - underTest.logTapWidget( - componentName = "com.red.package/my_test_widget", - rank = 2, - ) + underTest.logTapWidget(componentName = "com.red.package/my_test_widget", rank = 2) verify(statsLogProxy) .writeCommunalHubWidgetEventReported( SysUiStatsLog.COMMUNAL_HUB_WIDGET_EVENT_REPORTED__ACTION__TAP, @@ -140,4 +122,43 @@ class CommunalMetricsLoggerTest : SysuiTestCase() { ) assertThat(statsEvents).hasSize(1) } + + @Test + fun logResizeWidget_componentNotLoggable_doNotLog() { + underTest.logResizeWidget( + componentName = "com.green.package/my_test_widget", + rank = 1, + spanY = 2, + ) + verify(statsLogProxy, never()) + .writeCommunalHubWidgetEventReported(anyInt(), any(), anyInt(), anyInt()) + } + + @Test + fun logResizeWidget_componentLoggable_logResizeEvent() { + underTest.logResizeWidget( + componentName = "com.blue.package/my_test_widget", + rank = 1, + spanY = 2, + ) + verify(statsLogProxy) + .writeCommunalHubWidgetEventReported( + SysUiStatsLog.COMMUNAL_HUB_WIDGET_EVENT_REPORTED__ACTION__RESIZE, + "com.blue.package/my_test_widget", + rank = 1, + spanY = 2, + ) + } + + @Test + fun logResizeWidget_defaultSpanY_usesDefaultValue() { + underTest.logResizeWidget(componentName = "com.blue.package/my_test_widget", rank = 1) + verify(statsLogProxy) + .writeCommunalHubWidgetEventReported( + SysUiStatsLog.COMMUNAL_HUB_WIDGET_EVENT_REPORTED__ACTION__RESIZE, + "com.blue.package/my_test_widget", + rank = 1, + spanY = 0, + ) + } } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt index cecc11e5ffd4..6b851cb017e1 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalEditModeViewModelTest.kt @@ -353,6 +353,32 @@ class CommunalEditModeViewModelTest : SysuiTestCase() { assertThat(event.contentDescription).isEqualTo("Test Clock widget added to lock screen") } + @Test + fun onResizeWidget_logsMetrics() = + testScope.runTest { + val appWidgetId = 123 + val spanY = 2 + val widgetIdToRankMap = mapOf(appWidgetId to 1) + val componentName = ComponentName("test.package", "TestWidget") + val rank = 1 + + underTest.onResizeWidget( + appWidgetId = appWidgetId, + spanY = spanY, + widgetIdToRankMap = widgetIdToRankMap, + componentName = componentName, + rank = rank, + ) + + verify(communalInteractor).resizeWidget(appWidgetId, spanY, widgetIdToRankMap) + verify(metricsLogger) + .logResizeWidget( + componentName = componentName.flattenToString(), + rank = rank, + spanY = spanY, + ) + } + private companion object { val MAIN_USER_INFO = UserInfo(0, "primary", UserInfo.FLAG_MAIN) const val WIDGET_PICKER_PACKAGE_NAME = "widget_picker_package_name" diff --git a/packages/SystemUI/src/com/android/systemui/communal/shared/log/CommunalMetricsLogger.kt b/packages/SystemUI/src/com/android/systemui/communal/shared/log/CommunalMetricsLogger.kt index 7cfad60b84cd..6423f8f7783b 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/shared/log/CommunalMetricsLogger.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/shared/log/CommunalMetricsLogger.kt @@ -30,6 +30,7 @@ constructor( @Named(LOGGABLE_PREFIXES) private val loggablePrefixes: List<String>, private val statsLogProxy: StatsLogProxy, ) { + /** Logs an add widget event for metrics. No-op if widget is not loggable. */ fun logAddWidget(componentName: String, rank: Int?) { if (!componentName.isLoggable()) { @@ -69,11 +70,21 @@ constructor( ) } + fun logResizeWidget(componentName: String, rank: Int, spanY: Int = 0) { + if (!componentName.isLoggable()) { + return + } + + statsLogProxy.writeCommunalHubWidgetEventReported( + SysUiStatsLog.COMMUNAL_HUB_WIDGET_EVENT_REPORTED__ACTION__RESIZE, + componentName, + rank = rank, + spanY = spanY, + ) + } + /** Logs loggable widgets and the total widget count as a [StatsEvent]. */ - fun logWidgetsSnapshot( - statsEvents: MutableList<StatsEvent>, - componentNames: List<String>, - ) { + fun logWidgetsSnapshot(statsEvents: MutableList<StatsEvent>, componentNames: List<String>) { val loggableComponentNames = componentNames.filter { it.isLoggable() }.toTypedArray() statsEvents.add( statsLogProxy.buildCommunalHubSnapshotStatsEvent( @@ -95,6 +106,7 @@ constructor( action: Int, componentName: String, rank: Int, + spanY: Int = 0, ) /** Builds a [SysUiStatsLog.COMMUNAL_HUB_SNAPSHOT] stats event. */ @@ -112,12 +124,14 @@ class CommunalStatsLogProxyImpl @Inject constructor() : CommunalMetricsLogger.St action: Int, componentName: String, rank: Int, + spanY: Int, ) { SysUiStatsLog.write( SysUiStatsLog.COMMUNAL_HUB_WIDGET_EVENT_REPORTED, action, componentName, rank, + spanY, ) } diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt index e25ea4cbfb25..4e0e11226faa 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt @@ -178,7 +178,13 @@ abstract class BaseCommunalViewModel( * alongside the resize, in case resizing also requires re-ordering. This ensures the * re-ordering is done in the same database transaction as the resize. */ - open fun onResizeWidget(appWidgetId: Int, spanY: Int, widgetIdToRankMap: Map<Int, Int>) {} + open fun onResizeWidget( + appWidgetId: Int, + spanY: Int, + widgetIdToRankMap: Map<Int, Int>, + componentName: ComponentName, + rank: Int, + ) {} /** Called as the UI requests opening the widget editor with an optional preselected widget. */ open fun onOpenWidgetEditor(shouldOpenWidgetPickerOnStart: Boolean = false) {} diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt index 6508e4b574a3..ccff23003aa0 100644 --- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalEditModeViewModel.kt @@ -141,8 +141,19 @@ constructor( override fun onReorderWidgets(widgetIdToRankMap: Map<Int, Int>) = communalInteractor.updateWidgetOrder(widgetIdToRankMap) - override fun onResizeWidget(appWidgetId: Int, spanY: Int, widgetIdToRankMap: Map<Int, Int>) { + override fun onResizeWidget( + appWidgetId: Int, + spanY: Int, + widgetIdToRankMap: Map<Int, Int>, + componentName: ComponentName, + rank: Int, + ) { communalInteractor.resizeWidget(appWidgetId, spanY, widgetIdToRankMap) + metricsLogger.logResizeWidget( + componentName = componentName.flattenToString(), + rank = rank, + spanY = spanY, + ) } override fun onReorderWidgetStart() { |