Loading packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperStateRepositoryTest.kt +23 −5 Original line number Diff line number Diff line Loading @@ -22,10 +22,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState.Active import com.android.systemui.keyboard.shortcut.shortcutHelperStateRepository import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testScope import com.android.systemui.shade.data.repository.fakeFocusedDisplayRepository import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.test.runTest Loading @@ -51,7 +54,7 @@ class ShortcutHelperStateRepositoryTest : SysuiTestCase() { helper.toggle(deviceId) assertThat(state).isEqualTo(ShortcutHelperState.Active(deviceId)) assertThat(state).isEqualTo(Active(deviceId)) } @Test Loading @@ -61,7 +64,7 @@ class ShortcutHelperStateRepositoryTest : SysuiTestCase() { helper.showFromActivity() assertThat(state).isEqualTo(ShortcutHelperState.Active(VIRTUAL_KEYBOARD)) assertThat(state).isEqualTo(Active(VIRTUAL_KEYBOARD)) } @Test Loading @@ -73,7 +76,7 @@ class ShortcutHelperStateRepositoryTest : SysuiTestCase() { fakeInputManager.addPhysicalKeyboard(deviceId) helper.showFromActivity() assertThat(state).isEqualTo(ShortcutHelperState.Active(deviceId)) assertThat(state).isEqualTo(Active(deviceId)) } @Test Loading @@ -86,6 +89,21 @@ class ShortcutHelperStateRepositoryTest : SysuiTestCase() { fakeInputManager.inputManager.disableInputDevice(deviceId) helper.showFromActivity() assertThat(state).isEqualTo(ShortcutHelperState.Active(VIRTUAL_KEYBOARD)) assertThat(state).isEqualTo(Active(VIRTUAL_KEYBOARD)) } @Test fun activeStateDisplayId_isFocusedDisplay() = kosmos.runTest { val state by collectLastValue(repo.state) fakeFocusedDisplayRepository.setDisplayId(DISPLAY_ID) helper.showFromActivity() assertThat((state as Active).displayId).isEqualTo(DISPLAY_ID) } private companion object { const val DISPLAY_ID = 5 } } packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/ShortcutHelperDialogStarterTest.kt +3 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.keyboard.shortcut.ui import android.content.Context import android.content.Context.INPUT_SERVICE import android.content.applicationContext import android.hardware.input.fakeInputManager import androidx.test.annotation.UiThreadTest import androidx.test.ext.junit.runners.AndroidJUnit4 Loading Loading @@ -83,10 +84,12 @@ class ShortcutHelperDialogStarterTest : SysuiTestCase() { with(kosmos) { ShortcutHelperDialogStarter( coroutineScope, applicationContext, viewModel, shortcutCustomizationDialogStarterFactory, dialogFactory, activityStarter, testDispatcher, ) } Loading packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt +45 −0 Original line number Diff line number Diff line Loading @@ -19,9 +19,11 @@ package com.android.systemui.keyboard.shortcut.ui.viewmodel import android.app.role.RoleManager import android.app.role.mockRoleManager import android.content.Context import android.content.applicationContext import android.content.pm.ApplicationInfo import android.content.pm.PackageManager import android.content.pm.PackageManager.NameNotFoundException import android.view.Display import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Tv import androidx.compose.material.icons.filled.VerticalSplit Loading @@ -42,18 +44,24 @@ import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType. import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.System import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory import com.android.systemui.keyboard.shortcut.shared.model.shortcut import com.android.systemui.keyboard.shortcut.shortcutHelperCategoriesInteractor import com.android.systemui.keyboard.shortcut.shortcutHelperCustomizationModeInteractor import com.android.systemui.keyboard.shortcut.shortcutHelperStateInteractor import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper import com.android.systemui.keyboard.shortcut.shortcutHelperViewModel import com.android.systemui.keyboard.shortcut.ui.model.IconSource import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCategoryUi import com.android.systemui.keyboard.shortcut.ui.model.ShortcutsUiState import com.android.systemui.keyboard.shortcut.ui.viewmodel.ShortcutHelperViewModel.Companion.EXTENDED_APPS_SHORTCUT_CUSTOMIZATION_LIMIT import com.android.systemui.kosmos.applicationCoroutineScope import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.model.sysUiState import com.android.systemui.settings.FakeUserTracker import com.android.systemui.settings.fakeUserTracker import com.android.systemui.settings.userTracker import com.android.systemui.shade.data.repository.fakeFocusedDisplayRepository import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SHORTCUT_HELPER_SHOWING import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat Loading Loading @@ -89,6 +97,20 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { private val fakeUserTracker = kosmos.fakeUserTracker private val mockRoleManager = kosmos.mockRoleManager private val underTest = kosmos.shortcutHelperViewModel private val secondaryDisplayViewModel = with(kosmos) { ShortcutHelperViewModel( applicationContext, mockRoleManager, userTracker, applicationCoroutineScope, testDispatcher, shortcutHelperStateInteractor, shortcutHelperCategoriesInteractor, shortcutHelperCustomizationModeInteractor, displayId = SECONDARY_DISPLAY, ) } private val fakeDefaultShortcutCategoriesRepository = kosmos.fakeDefaultShortcutCategoriesRepository private val fakeCustomShortcutCategoriesRepository = Loading Loading @@ -199,6 +221,28 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { assertThat(shouldShowNew).isEqualTo(shouldShow) } @Test fun shouldShow_falseWhenShortcutHelperTriggeredFromDifferentDisplay() = testScope.runTest { kosmos.fakeFocusedDisplayRepository.setDisplayId(Display.DEFAULT_DISPLAY) val shouldShow by collectLastValue(secondaryDisplayViewModel.shouldShow) testHelper.showFromActivity() assertThat(shouldShow).isFalse() } @Test fun shouldShow_TrueWhenShortcutHelperTriggeredFromSameDisplay() = testScope.runTest { kosmos.fakeFocusedDisplayRepository.setDisplayId(SECONDARY_DISPLAY) val shouldShow by collectLastValue(secondaryDisplayViewModel.shouldShow) testHelper.showFromActivity() assertThat(shouldShow).isTrue() } @Test fun sysUiStateFlag_disabledByDefault() = testScope.runTest { Loading Loading @@ -664,5 +708,6 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { const val FIRST_SIMPLE_GROUP_LABEL = "simple group 1" const val SECOND_SIMPLE_GROUP_LABEL = "simple group 2" const val TEST_PACKAGE = "test.package.name" const val SECONDARY_DISPLAY = 5 } } packages/SystemUI/src/com/android/systemui/display/dagger/PerDisplayReferenceSystemUIModule.kt +2 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.display.dagger import com.android.systemui.keyboard.shortcut.ShortcutHelperDisplayModule import com.android.systemui.statusbar.phone.dagger.PerDisplayStatusBarReferenceModule import dagger.Module Loading @@ -25,5 +26,5 @@ import dagger.Module * If the classes are common to all SysUI flavors, they should be added to * [PerDisplaySystemUIModule] instead. */ @Module(includes = [PerDisplayStatusBarReferenceModule::class]) @Module(includes = [PerDisplayStatusBarReferenceModule::class, ShortcutHelperDisplayModule::class]) interface PerDisplayReferenceSystemUIModule packages/SystemUI/src/com/android/systemui/display/dagger/SystemUIDisplaySubcomponent.kt +4 −0 Original line number Diff line number Diff line Loading @@ -110,5 +110,9 @@ interface SystemUIDisplaySubcomponent { * removed, and the component will be destroyed. */ fun stop() {} companion object { val NOP: LifecycleListener = object : LifecycleListener {} } } } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutHelperStateRepositoryTest.kt +23 −5 Original line number Diff line number Diff line Loading @@ -22,10 +22,13 @@ import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState.Active import com.android.systemui.keyboard.shortcut.shortcutHelperStateRepository import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper import com.android.systemui.kosmos.collectLastValue import com.android.systemui.kosmos.runTest import com.android.systemui.kosmos.testScope import com.android.systemui.shade.data.repository.fakeFocusedDisplayRepository import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.test.runTest Loading @@ -51,7 +54,7 @@ class ShortcutHelperStateRepositoryTest : SysuiTestCase() { helper.toggle(deviceId) assertThat(state).isEqualTo(ShortcutHelperState.Active(deviceId)) assertThat(state).isEqualTo(Active(deviceId)) } @Test Loading @@ -61,7 +64,7 @@ class ShortcutHelperStateRepositoryTest : SysuiTestCase() { helper.showFromActivity() assertThat(state).isEqualTo(ShortcutHelperState.Active(VIRTUAL_KEYBOARD)) assertThat(state).isEqualTo(Active(VIRTUAL_KEYBOARD)) } @Test Loading @@ -73,7 +76,7 @@ class ShortcutHelperStateRepositoryTest : SysuiTestCase() { fakeInputManager.addPhysicalKeyboard(deviceId) helper.showFromActivity() assertThat(state).isEqualTo(ShortcutHelperState.Active(deviceId)) assertThat(state).isEqualTo(Active(deviceId)) } @Test Loading @@ -86,6 +89,21 @@ class ShortcutHelperStateRepositoryTest : SysuiTestCase() { fakeInputManager.inputManager.disableInputDevice(deviceId) helper.showFromActivity() assertThat(state).isEqualTo(ShortcutHelperState.Active(VIRTUAL_KEYBOARD)) assertThat(state).isEqualTo(Active(VIRTUAL_KEYBOARD)) } @Test fun activeStateDisplayId_isFocusedDisplay() = kosmos.runTest { val state by collectLastValue(repo.state) fakeFocusedDisplayRepository.setDisplayId(DISPLAY_ID) helper.showFromActivity() assertThat((state as Active).displayId).isEqualTo(DISPLAY_ID) } private companion object { const val DISPLAY_ID = 5 } }
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/ShortcutHelperDialogStarterTest.kt +3 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.keyboard.shortcut.ui import android.content.Context import android.content.Context.INPUT_SERVICE import android.content.applicationContext import android.hardware.input.fakeInputManager import androidx.test.annotation.UiThreadTest import androidx.test.ext.junit.runners.AndroidJUnit4 Loading Loading @@ -83,10 +84,12 @@ class ShortcutHelperDialogStarterTest : SysuiTestCase() { with(kosmos) { ShortcutHelperDialogStarter( coroutineScope, applicationContext, viewModel, shortcutCustomizationDialogStarterFactory, dialogFactory, activityStarter, testDispatcher, ) } Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt +45 −0 Original line number Diff line number Diff line Loading @@ -19,9 +19,11 @@ package com.android.systemui.keyboard.shortcut.ui.viewmodel import android.app.role.RoleManager import android.app.role.mockRoleManager import android.content.Context import android.content.applicationContext import android.content.pm.ApplicationInfo import android.content.pm.PackageManager import android.content.pm.PackageManager.NameNotFoundException import android.view.Display import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Tv import androidx.compose.material.icons.filled.VerticalSplit Loading @@ -42,18 +44,24 @@ import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType. import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.System import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory import com.android.systemui.keyboard.shortcut.shared.model.shortcut import com.android.systemui.keyboard.shortcut.shortcutHelperCategoriesInteractor import com.android.systemui.keyboard.shortcut.shortcutHelperCustomizationModeInteractor import com.android.systemui.keyboard.shortcut.shortcutHelperStateInteractor import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper import com.android.systemui.keyboard.shortcut.shortcutHelperViewModel import com.android.systemui.keyboard.shortcut.ui.model.IconSource import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCategoryUi import com.android.systemui.keyboard.shortcut.ui.model.ShortcutsUiState import com.android.systemui.keyboard.shortcut.ui.viewmodel.ShortcutHelperViewModel.Companion.EXTENDED_APPS_SHORTCUT_CUSTOMIZATION_LIMIT import com.android.systemui.kosmos.applicationCoroutineScope import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope import com.android.systemui.kosmos.useUnconfinedTestDispatcher import com.android.systemui.model.sysUiState import com.android.systemui.settings.FakeUserTracker import com.android.systemui.settings.fakeUserTracker import com.android.systemui.settings.userTracker import com.android.systemui.shade.data.repository.fakeFocusedDisplayRepository import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SHORTCUT_HELPER_SHOWING import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat Loading Loading @@ -89,6 +97,20 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { private val fakeUserTracker = kosmos.fakeUserTracker private val mockRoleManager = kosmos.mockRoleManager private val underTest = kosmos.shortcutHelperViewModel private val secondaryDisplayViewModel = with(kosmos) { ShortcutHelperViewModel( applicationContext, mockRoleManager, userTracker, applicationCoroutineScope, testDispatcher, shortcutHelperStateInteractor, shortcutHelperCategoriesInteractor, shortcutHelperCustomizationModeInteractor, displayId = SECONDARY_DISPLAY, ) } private val fakeDefaultShortcutCategoriesRepository = kosmos.fakeDefaultShortcutCategoriesRepository private val fakeCustomShortcutCategoriesRepository = Loading Loading @@ -199,6 +221,28 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { assertThat(shouldShowNew).isEqualTo(shouldShow) } @Test fun shouldShow_falseWhenShortcutHelperTriggeredFromDifferentDisplay() = testScope.runTest { kosmos.fakeFocusedDisplayRepository.setDisplayId(Display.DEFAULT_DISPLAY) val shouldShow by collectLastValue(secondaryDisplayViewModel.shouldShow) testHelper.showFromActivity() assertThat(shouldShow).isFalse() } @Test fun shouldShow_TrueWhenShortcutHelperTriggeredFromSameDisplay() = testScope.runTest { kosmos.fakeFocusedDisplayRepository.setDisplayId(SECONDARY_DISPLAY) val shouldShow by collectLastValue(secondaryDisplayViewModel.shouldShow) testHelper.showFromActivity() assertThat(shouldShow).isTrue() } @Test fun sysUiStateFlag_disabledByDefault() = testScope.runTest { Loading Loading @@ -664,5 +708,6 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { const val FIRST_SIMPLE_GROUP_LABEL = "simple group 1" const val SECOND_SIMPLE_GROUP_LABEL = "simple group 2" const val TEST_PACKAGE = "test.package.name" const val SECONDARY_DISPLAY = 5 } }
packages/SystemUI/src/com/android/systemui/display/dagger/PerDisplayReferenceSystemUIModule.kt +2 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.systemui.display.dagger import com.android.systemui.keyboard.shortcut.ShortcutHelperDisplayModule import com.android.systemui.statusbar.phone.dagger.PerDisplayStatusBarReferenceModule import dagger.Module Loading @@ -25,5 +26,5 @@ import dagger.Module * If the classes are common to all SysUI flavors, they should be added to * [PerDisplaySystemUIModule] instead. */ @Module(includes = [PerDisplayStatusBarReferenceModule::class]) @Module(includes = [PerDisplayStatusBarReferenceModule::class, ShortcutHelperDisplayModule::class]) interface PerDisplayReferenceSystemUIModule
packages/SystemUI/src/com/android/systemui/display/dagger/SystemUIDisplaySubcomponent.kt +4 −0 Original line number Diff line number Diff line Loading @@ -110,5 +110,9 @@ interface SystemUIDisplaySubcomponent { * removed, and the component will be destroyed. */ fun stop() {} companion object { val NOP: LifecycleListener = object : LifecycleListener {} } } }