Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt +10 −8 Original line number Diff line number Diff line Loading @@ -790,14 +790,6 @@ class CommunalInteractorTest : SysuiTestCase() { verify(editWidgetsActivityStarter).startActivity() } @Test fun showWidgetEditor_withPreselectedKey_startsActivity() = testScope.runTest { val widgetKey = CommunalContentModel.KEY.widget(123) underTest.showWidgetEditor(preselectedKey = widgetKey) verify(editWidgetsActivityStarter).startActivity(widgetKey) } @Test fun showWidgetEditor_openWidgetPickerOnStart_startsActivity() = testScope.runTest { Loading Loading @@ -1082,6 +1074,16 @@ class CommunalInteractorTest : SysuiTestCase() { assertThat(disclaimerDismissed).isFalse() } @Test fun settingSelectedKey_flowUpdated() { testScope.runTest { val key = "test" val selectedKey by collectLastValue(underTest.selectedKey) underTest.setSelectedKey(key) assertThat(selectedKey).isEqualTo(key) } } private fun setKeyguardFeaturesDisabled(user: UserInfo, disabledFlags: Int) { whenever(kosmos.devicePolicyManager.getKeyguardDisabledFeatures(nullable(), eq(user.id))) .thenReturn(disabledFlags) Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt +36 −18 Original line number Diff line number Diff line Loading @@ -159,8 +159,11 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() { communalInteractor = spy(kosmos.communalInteractor) underTest = CommunalViewModel( underTest = createViewModel() } private fun createViewModel(): CommunalViewModel { return CommunalViewModel( kosmos.testDispatcher, testScope, kosmos.testScope.backgroundScope, Loading Loading @@ -784,6 +787,21 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() { assertThat(touchAvailable).isTrue() } @Test fun selectedKey_changeAffectsAllInstances() = testScope.runTest { val model1 = createViewModel() val selectedKey1 by collectLastValue(model1.selectedKey) val model2 = createViewModel() val selectedKey2 by collectLastValue(model2.selectedKey) val key = "test" model1.setSelectedKey(key) assertThat(selectedKey1).isEqualTo(key) assertThat(selectedKey2).isEqualTo(key) } private suspend fun setIsMainUser(isMainUser: Boolean) { val user = if (isMainUser) MAIN_USER_INFO else SECONDARY_USER_INFO with(userRepository) { Loading packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/EditWidgetsActivityStarterTest.kt +2 −11 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.content.Intent import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.communal.widgets.EditWidgetsActivity.Companion.EXTRA_PRESELECTED_KEY import com.android.systemui.kosmos.testScope import com.android.systemui.plugins.ActivityStarter import com.android.systemui.testKosmos Loading Loading @@ -62,7 +61,7 @@ class EditWidgetsActivityStarterTest : SysuiTestCase() { fun activityLaunch_intentIsWellFormed() { with(kosmos) { testScope.runTest { underTest.startActivity(TEST_PRESELECTED_KEY, shouldOpenWidgetPickerOnStart = true) underTest.startActivity(shouldOpenWidgetPickerOnStart = true) val captor = argumentCaptor<Intent>() verify(activityStarter) Loading @@ -71,8 +70,6 @@ class EditWidgetsActivityStarterTest : SysuiTestCase() { assertThat(captor.lastValue.flags and Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0) assertThat(captor.lastValue.flags and Intent.FLAG_ACTIVITY_CLEAR_TASK) .isNotEqualTo(0) assertThat(captor.lastValue.extras?.getString(EXTRA_PRESELECTED_KEY)) .isEqualTo(TEST_PRESELECTED_KEY) assertThat( captor.lastValue.extras?.getBoolean( EditWidgetsActivity.EXTRA_OPEN_WIDGET_PICKER_ON_START Loading @@ -80,7 +77,7 @@ class EditWidgetsActivityStarterTest : SysuiTestCase() { ) .isEqualTo(true) underTest.startActivity(TEST_PRESELECTED_KEY, shouldOpenWidgetPickerOnStart = false) underTest.startActivity(shouldOpenWidgetPickerOnStart = false) verify(activityStarter, times(2)) .startActivityDismissingKeyguard(captor.capture(), eq(true), eq(true), any()) Loading @@ -88,8 +85,6 @@ class EditWidgetsActivityStarterTest : SysuiTestCase() { assertThat(captor.lastValue.flags and Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0) assertThat(captor.lastValue.flags and Intent.FLAG_ACTIVITY_CLEAR_TASK) .isNotEqualTo(0) assertThat(captor.lastValue.extras?.getString(EXTRA_PRESELECTED_KEY)) .isEqualTo(TEST_PRESELECTED_KEY) assertThat( captor.lastValue.extras?.getBoolean( EditWidgetsActivity.EXTRA_OPEN_WIDGET_PICKER_ON_START Loading @@ -99,8 +94,4 @@ class EditWidgetsActivityStarterTest : SysuiTestCase() { } } } companion object { const val TEST_PRESELECTED_KEY = "test-key" } } packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt +9 −2 Original line number Diff line number Diff line Loading @@ -140,6 +140,10 @@ constructor( */ val editActivityShowing: StateFlow<Boolean> = _editActivityShowing.asStateFlow() private val _selectedKey: MutableStateFlow<String?> = MutableStateFlow(null) val selectedKey: StateFlow<String?> = _selectedKey.asStateFlow() /** Whether communal features are enabled. */ val isCommunalEnabled: StateFlow<Boolean> = communalSettingsInteractor.isCommunalEnabled Loading Loading @@ -179,6 +183,10 @@ constructor( } } fun setSelectedKey(key: String?) { _selectedKey.value = key } /** Whether to show communal when exiting the occluded state. */ val showCommunalFromOccluded: Flow<Boolean> = keyguardTransitionInteractor.startedKeyguardTransitionStep Loading Loading @@ -345,11 +353,10 @@ constructor( /** Show the widget editor Activity. */ fun showWidgetEditor( preselectedKey: String? = null, shouldOpenWidgetPickerOnStart: Boolean = false, ) { communalSceneInteractor.setEditModeState(EditModeState.STARTING) editWidgetsActivityStarter.startActivity(preselectedKey, shouldOpenWidgetPickerOnStart) editWidgetsActivityStarter.startActivity(shouldOpenWidgetPickerOnStart) } /** Loading packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt +2 −5 Original line number Diff line number Diff line Loading @@ -55,11 +55,8 @@ abstract class BaseCommunalViewModel( /** Whether widgets are currently being re-ordered. */ open val reorderingWidgets: StateFlow<Boolean> = MutableStateFlow(false) private val _selectedKey: MutableStateFlow<String?> = MutableStateFlow(null) /** The key of the currently selected item, or null if no item selected. */ val selectedKey: StateFlow<String?> get() = _selectedKey val selectedKey: StateFlow<String?> = communalInteractor.selectedKey private val _isTouchConsumed: MutableStateFlow<Boolean> = MutableStateFlow(false) Loading Loading @@ -226,7 +223,7 @@ abstract class BaseCommunalViewModel( /** Set the key of the currently selected item */ fun setSelectedKey(key: String?) { _selectedKey.value = key communalInteractor.setSelectedKey(key) } /** Invoked once touches inside the lazy grid are consumed */ Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/domain/interactor/CommunalInteractorTest.kt +10 −8 Original line number Diff line number Diff line Loading @@ -790,14 +790,6 @@ class CommunalInteractorTest : SysuiTestCase() { verify(editWidgetsActivityStarter).startActivity() } @Test fun showWidgetEditor_withPreselectedKey_startsActivity() = testScope.runTest { val widgetKey = CommunalContentModel.KEY.widget(123) underTest.showWidgetEditor(preselectedKey = widgetKey) verify(editWidgetsActivityStarter).startActivity(widgetKey) } @Test fun showWidgetEditor_openWidgetPickerOnStart_startsActivity() = testScope.runTest { Loading Loading @@ -1082,6 +1074,16 @@ class CommunalInteractorTest : SysuiTestCase() { assertThat(disclaimerDismissed).isFalse() } @Test fun settingSelectedKey_flowUpdated() { testScope.runTest { val key = "test" val selectedKey by collectLastValue(underTest.selectedKey) underTest.setSelectedKey(key) assertThat(selectedKey).isEqualTo(key) } } private fun setKeyguardFeaturesDisabled(user: UserInfo, disabledFlags: Int) { whenever(kosmos.devicePolicyManager.getKeyguardDisabledFeatures(nullable(), eq(user.id))) .thenReturn(disabledFlags) Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/view/viewmodel/CommunalViewModelTest.kt +36 −18 Original line number Diff line number Diff line Loading @@ -159,8 +159,11 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() { communalInteractor = spy(kosmos.communalInteractor) underTest = CommunalViewModel( underTest = createViewModel() } private fun createViewModel(): CommunalViewModel { return CommunalViewModel( kosmos.testDispatcher, testScope, kosmos.testScope.backgroundScope, Loading Loading @@ -784,6 +787,21 @@ class CommunalViewModelTest(flags: FlagsParameterization) : SysuiTestCase() { assertThat(touchAvailable).isTrue() } @Test fun selectedKey_changeAffectsAllInstances() = testScope.runTest { val model1 = createViewModel() val selectedKey1 by collectLastValue(model1.selectedKey) val model2 = createViewModel() val selectedKey2 by collectLastValue(model2.selectedKey) val key = "test" model1.setSelectedKey(key) assertThat(selectedKey1).isEqualTo(key) assertThat(selectedKey2).isEqualTo(key) } private suspend fun setIsMainUser(isMainUser: Boolean) { val user = if (isMainUser) MAIN_USER_INFO else SECONDARY_USER_INFO with(userRepository) { Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/communal/widgets/EditWidgetsActivityStarterTest.kt +2 −11 Original line number Diff line number Diff line Loading @@ -21,7 +21,6 @@ import android.content.Intent import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.communal.widgets.EditWidgetsActivity.Companion.EXTRA_PRESELECTED_KEY import com.android.systemui.kosmos.testScope import com.android.systemui.plugins.ActivityStarter import com.android.systemui.testKosmos Loading Loading @@ -62,7 +61,7 @@ class EditWidgetsActivityStarterTest : SysuiTestCase() { fun activityLaunch_intentIsWellFormed() { with(kosmos) { testScope.runTest { underTest.startActivity(TEST_PRESELECTED_KEY, shouldOpenWidgetPickerOnStart = true) underTest.startActivity(shouldOpenWidgetPickerOnStart = true) val captor = argumentCaptor<Intent>() verify(activityStarter) Loading @@ -71,8 +70,6 @@ class EditWidgetsActivityStarterTest : SysuiTestCase() { assertThat(captor.lastValue.flags and Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0) assertThat(captor.lastValue.flags and Intent.FLAG_ACTIVITY_CLEAR_TASK) .isNotEqualTo(0) assertThat(captor.lastValue.extras?.getString(EXTRA_PRESELECTED_KEY)) .isEqualTo(TEST_PRESELECTED_KEY) assertThat( captor.lastValue.extras?.getBoolean( EditWidgetsActivity.EXTRA_OPEN_WIDGET_PICKER_ON_START Loading @@ -80,7 +77,7 @@ class EditWidgetsActivityStarterTest : SysuiTestCase() { ) .isEqualTo(true) underTest.startActivity(TEST_PRESELECTED_KEY, shouldOpenWidgetPickerOnStart = false) underTest.startActivity(shouldOpenWidgetPickerOnStart = false) verify(activityStarter, times(2)) .startActivityDismissingKeyguard(captor.capture(), eq(true), eq(true), any()) Loading @@ -88,8 +85,6 @@ class EditWidgetsActivityStarterTest : SysuiTestCase() { assertThat(captor.lastValue.flags and Intent.FLAG_ACTIVITY_NEW_TASK).isNotEqualTo(0) assertThat(captor.lastValue.flags and Intent.FLAG_ACTIVITY_CLEAR_TASK) .isNotEqualTo(0) assertThat(captor.lastValue.extras?.getString(EXTRA_PRESELECTED_KEY)) .isEqualTo(TEST_PRESELECTED_KEY) assertThat( captor.lastValue.extras?.getBoolean( EditWidgetsActivity.EXTRA_OPEN_WIDGET_PICKER_ON_START Loading @@ -99,8 +94,4 @@ class EditWidgetsActivityStarterTest : SysuiTestCase() { } } } companion object { const val TEST_PRESELECTED_KEY = "test-key" } }
packages/SystemUI/src/com/android/systemui/communal/domain/interactor/CommunalInteractor.kt +9 −2 Original line number Diff line number Diff line Loading @@ -140,6 +140,10 @@ constructor( */ val editActivityShowing: StateFlow<Boolean> = _editActivityShowing.asStateFlow() private val _selectedKey: MutableStateFlow<String?> = MutableStateFlow(null) val selectedKey: StateFlow<String?> = _selectedKey.asStateFlow() /** Whether communal features are enabled. */ val isCommunalEnabled: StateFlow<Boolean> = communalSettingsInteractor.isCommunalEnabled Loading Loading @@ -179,6 +183,10 @@ constructor( } } fun setSelectedKey(key: String?) { _selectedKey.value = key } /** Whether to show communal when exiting the occluded state. */ val showCommunalFromOccluded: Flow<Boolean> = keyguardTransitionInteractor.startedKeyguardTransitionStep Loading Loading @@ -345,11 +353,10 @@ constructor( /** Show the widget editor Activity. */ fun showWidgetEditor( preselectedKey: String? = null, shouldOpenWidgetPickerOnStart: Boolean = false, ) { communalSceneInteractor.setEditModeState(EditModeState.STARTING) editWidgetsActivityStarter.startActivity(preselectedKey, shouldOpenWidgetPickerOnStart) editWidgetsActivityStarter.startActivity(shouldOpenWidgetPickerOnStart) } /** Loading
packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/BaseCommunalViewModel.kt +2 −5 Original line number Diff line number Diff line Loading @@ -55,11 +55,8 @@ abstract class BaseCommunalViewModel( /** Whether widgets are currently being re-ordered. */ open val reorderingWidgets: StateFlow<Boolean> = MutableStateFlow(false) private val _selectedKey: MutableStateFlow<String?> = MutableStateFlow(null) /** The key of the currently selected item, or null if no item selected. */ val selectedKey: StateFlow<String?> get() = _selectedKey val selectedKey: StateFlow<String?> = communalInteractor.selectedKey private val _isTouchConsumed: MutableStateFlow<Boolean> = MutableStateFlow(false) Loading Loading @@ -226,7 +223,7 @@ abstract class BaseCommunalViewModel( /** Set the key of the currently selected item */ fun setSelectedKey(key: String?) { _selectedKey.value = key communalInteractor.setSelectedKey(key) } /** Invoked once touches inside the lazy grid are consumed */ Loading