Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartableTest.kt +41 −1 Original line number Diff line number Diff line Loading @@ -16,12 +16,14 @@ package com.android.systemui.communal.widgets import android.appwidget.AppWidgetProviderInfo import android.content.pm.UserInfo import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.Flags.FLAG_COMMUNAL_HUB import com.android.systemui.SysuiTestCase import com.android.systemui.communal.data.repository.fakeCommunalWidgetRepository import com.android.systemui.communal.domain.interactor.CommunalInteractor import com.android.systemui.communal.domain.interactor.communalInteractor import com.android.systemui.communal.domain.interactor.communalSettingsInteractor import com.android.systemui.communal.domain.interactor.setCommunalEnabled Loading Loading @@ -49,6 +51,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.never import org.mockito.Mockito.spy import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations Loading @@ -65,6 +68,7 @@ class CommunalAppWidgetHostStartableTest : SysuiTestCase() { private lateinit var appWidgetIdToRemove: MutableSharedFlow<Int> private lateinit var communalInteractorSpy: CommunalInteractor private lateinit var underTest: CommunalAppWidgetHostStartable @Before Loading @@ -78,12 +82,13 @@ class CommunalAppWidgetHostStartableTest : SysuiTestCase() { helper = kosmos.fakeGlanceableHubMultiUserHelper appWidgetIdToRemove = MutableSharedFlow() whenever(appWidgetHost.appWidgetIdToRemove).thenReturn(appWidgetIdToRemove) communalInteractorSpy = spy(kosmos.communalInteractor) underTest = CommunalAppWidgetHostStartable( { appWidgetHost }, { communalWidgetHost }, { kosmos.communalInteractor }, { communalInteractorSpy }, { kosmos.communalSettingsInteractor }, { kosmos.keyguardInteractor }, { kosmos.fakeUserTracker }, Loading Loading @@ -258,6 +263,41 @@ class CommunalAppWidgetHostStartableTest : SysuiTestCase() { } } @Test fun removeNotLockscreenWidgets_whenCommunalIsAvailable() = with(kosmos) { testScope.runTest { // Communal is available setCommunalAvailable(true) kosmos.fakeUserTracker.set( userInfos = listOf(MAIN_USER_INFO), selectedUserIndex = 0, ) fakeCommunalWidgetRepository.addWidget( appWidgetId = 1, userId = MAIN_USER_INFO.id, category = AppWidgetProviderInfo.WIDGET_CATEGORY_NOT_KEYGUARD, ) fakeCommunalWidgetRepository.addWidget(appWidgetId = 2, userId = MAIN_USER_INFO.id) fakeCommunalWidgetRepository.addWidget( appWidgetId = 3, userId = MAIN_USER_INFO.id, category = AppWidgetProviderInfo.WIDGET_CATEGORY_NOT_KEYGUARD, ) underTest.start() runCurrent() val communalWidgets by collectLastValue(fakeCommunalWidgetRepository.communalWidgets) assertThat(communalWidgets).hasSize(1) assertThat(communalWidgets!![0].appWidgetId).isEqualTo(2) verify(communalInteractorSpy).deleteWidget(1) verify(communalInteractorSpy).deleteWidget(3) } } @Test fun onStartHeadlessSystemUser_registerWidgetManager_whenCommunalIsAvailable() = with(kosmos) { Loading packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartable.kt +15 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.communal.widgets import android.appwidget.AppWidgetProviderInfo import com.android.systemui.CoreStartable import com.android.systemui.communal.domain.interactor.CommunalInteractor import com.android.systemui.communal.domain.interactor.CommunalSettingsInteractor Loading Loading @@ -101,6 +102,7 @@ constructor( val (_, isActive) = withPrev // The validation is performed once the hub becomes active. if (isActive) { removeNotLockscreenWidgets(widgets) validateWidgetsAndDeleteOrphaned(widgets) } } Loading Loading @@ -144,6 +146,19 @@ constructor( } } private fun removeNotLockscreenWidgets(widgets: List<CommunalWidgetContentModel>) { widgets .filter { widget -> when (widget) { is CommunalWidgetContentModel.Available -> widget.providerInfo.widgetCategory and AppWidgetProviderInfo.WIDGET_CATEGORY_NOT_KEYGUARD != 0 else -> false } } .onEach { widget -> communalInteractor.deleteWidget(id = widget.appWidgetId) } } /** * Ensure the existence of all associated users for widgets, and remove widgets belonging to * users who have been deleted. Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartableTest.kt +41 −1 Original line number Diff line number Diff line Loading @@ -16,12 +16,14 @@ package com.android.systemui.communal.widgets import android.appwidget.AppWidgetProviderInfo import android.content.pm.UserInfo import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.Flags.FLAG_COMMUNAL_HUB import com.android.systemui.SysuiTestCase import com.android.systemui.communal.data.repository.fakeCommunalWidgetRepository import com.android.systemui.communal.domain.interactor.CommunalInteractor import com.android.systemui.communal.domain.interactor.communalInteractor import com.android.systemui.communal.domain.interactor.communalSettingsInteractor import com.android.systemui.communal.domain.interactor.setCommunalEnabled Loading Loading @@ -49,6 +51,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mock import org.mockito.Mockito.never import org.mockito.Mockito.spy import org.mockito.Mockito.verify import org.mockito.MockitoAnnotations Loading @@ -65,6 +68,7 @@ class CommunalAppWidgetHostStartableTest : SysuiTestCase() { private lateinit var appWidgetIdToRemove: MutableSharedFlow<Int> private lateinit var communalInteractorSpy: CommunalInteractor private lateinit var underTest: CommunalAppWidgetHostStartable @Before Loading @@ -78,12 +82,13 @@ class CommunalAppWidgetHostStartableTest : SysuiTestCase() { helper = kosmos.fakeGlanceableHubMultiUserHelper appWidgetIdToRemove = MutableSharedFlow() whenever(appWidgetHost.appWidgetIdToRemove).thenReturn(appWidgetIdToRemove) communalInteractorSpy = spy(kosmos.communalInteractor) underTest = CommunalAppWidgetHostStartable( { appWidgetHost }, { communalWidgetHost }, { kosmos.communalInteractor }, { communalInteractorSpy }, { kosmos.communalSettingsInteractor }, { kosmos.keyguardInteractor }, { kosmos.fakeUserTracker }, Loading Loading @@ -258,6 +263,41 @@ class CommunalAppWidgetHostStartableTest : SysuiTestCase() { } } @Test fun removeNotLockscreenWidgets_whenCommunalIsAvailable() = with(kosmos) { testScope.runTest { // Communal is available setCommunalAvailable(true) kosmos.fakeUserTracker.set( userInfos = listOf(MAIN_USER_INFO), selectedUserIndex = 0, ) fakeCommunalWidgetRepository.addWidget( appWidgetId = 1, userId = MAIN_USER_INFO.id, category = AppWidgetProviderInfo.WIDGET_CATEGORY_NOT_KEYGUARD, ) fakeCommunalWidgetRepository.addWidget(appWidgetId = 2, userId = MAIN_USER_INFO.id) fakeCommunalWidgetRepository.addWidget( appWidgetId = 3, userId = MAIN_USER_INFO.id, category = AppWidgetProviderInfo.WIDGET_CATEGORY_NOT_KEYGUARD, ) underTest.start() runCurrent() val communalWidgets by collectLastValue(fakeCommunalWidgetRepository.communalWidgets) assertThat(communalWidgets).hasSize(1) assertThat(communalWidgets!![0].appWidgetId).isEqualTo(2) verify(communalInteractorSpy).deleteWidget(1) verify(communalInteractorSpy).deleteWidget(3) } } @Test fun onStartHeadlessSystemUser_registerWidgetManager_whenCommunalIsAvailable() = with(kosmos) { Loading
packages/SystemUI/src/com/android/systemui/communal/widgets/CommunalAppWidgetHostStartable.kt +15 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.communal.widgets import android.appwidget.AppWidgetProviderInfo import com.android.systemui.CoreStartable import com.android.systemui.communal.domain.interactor.CommunalInteractor import com.android.systemui.communal.domain.interactor.CommunalSettingsInteractor Loading Loading @@ -101,6 +102,7 @@ constructor( val (_, isActive) = withPrev // The validation is performed once the hub becomes active. if (isActive) { removeNotLockscreenWidgets(widgets) validateWidgetsAndDeleteOrphaned(widgets) } } Loading Loading @@ -144,6 +146,19 @@ constructor( } } private fun removeNotLockscreenWidgets(widgets: List<CommunalWidgetContentModel>) { widgets .filter { widget -> when (widget) { is CommunalWidgetContentModel.Available -> widget.providerInfo.widgetCategory and AppWidgetProviderInfo.WIDGET_CATEGORY_NOT_KEYGUARD != 0 else -> false } } .onEach { widget -> communalInteractor.deleteWidget(id = widget.appWidgetId) } } /** * Ensure the existence of all associated users for widgets, and remove widgets belonging to * users who have been deleted. Loading