Loading packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/CustomShortcutCategoriesRepositoryTest.kt +5 −179 Original line number Diff line number Diff line Loading @@ -18,13 +18,9 @@ package com.android.systemui.keyboard.shortcut.data.repository import android.content.Context import android.content.Context.INPUT_SERVICE import android.hardware.input.InputGestureData import android.hardware.input.InputGestureData.createKeyTrigger import android.hardware.input.KeyGestureEvent import android.hardware.input.fakeInputManager import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import android.view.KeyEvent import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.hardware.input.Flags.FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES Loading @@ -32,15 +28,9 @@ import com.android.hardware.input.Flags.FLAG_USE_KEY_GESTURE_EVENT_HANDLER import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyboard.shortcut.customShortcutCategoriesRepository import com.android.systemui.keyboard.shortcut.shared.model.Shortcut import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.AppCategories import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.MultiTasking import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.System import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCommand import com.android.systemui.keyboard.shortcut.shared.model.ShortcutKey import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allCustomizableInputGesturesWithSimpleShortcutCombinations import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.customizableInputGestureWithUnknownKeyGestureType import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.expectedShortcutCategoriesWithSimpleShortcutCombination import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper import com.android.systemui.kosmos.testScope import com.android.systemui.settings.FakeUserTracker Loading Loading @@ -83,7 +73,7 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() { whenever( fakeInputManager.inputManager.getCustomInputGestures(/* filter= */ anyOrNull()) ) .thenReturn(customizableInputGesturesWithSimpleShortcutCombinations) .thenReturn(allCustomizableInputGesturesWithSimpleShortcutCombinations) helper.toggle(deviceId = 123) val categories by collectLastValue(repo.categories) Loading @@ -100,7 +90,7 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() { whenever( fakeInputManager.inputManager.getCustomInputGestures(/* filter= */ anyOrNull()) ) .thenReturn(customizableInputGesturesWithSimpleShortcutCombinations) .thenReturn(allCustomizableInputGesturesWithSimpleShortcutCombinations) helper.toggle(deviceId = 123) val categories by collectLastValue(repo.categories) Loading @@ -124,168 +114,4 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() { assertThat(categories).isEmpty() } } private fun simpleInputGestureData( keyCode: Int = KeyEvent.KEYCODE_A, modifiers: Int = KeyEvent.META_CTRL_ON or KeyEvent.META_ALT_ON, keyGestureType: Int, ): InputGestureData { val builder = InputGestureData.Builder() builder.setKeyGestureType(keyGestureType) builder.setTrigger(createKeyTrigger(keyCode, modifiers)) return builder.build() } private fun simpleShortcutCategory( category: ShortcutCategoryType, subcategoryLabel: String, shortcutLabel: String, ): ShortcutCategory { return ShortcutCategory( type = category, subCategories = listOf( ShortcutSubCategory( label = subcategoryLabel, shortcuts = listOf(simpleShortcut(shortcutLabel)), ) ), ) } private fun simpleShortcut(label: String) = Shortcut( label = label, commands = listOf( ShortcutCommand( isCustom = true, keys = listOf( ShortcutKey.Text("Ctrl"), ShortcutKey.Text("Alt"), ShortcutKey.Text("A"), ), ) ), ) private val customizableInputGestureWithUnknownKeyGestureType = // These key gesture events are currently not supported by shortcut helper customizer listOf( simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_GLOBAL_ACTIONS ), simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_MEDIA_KEY), ) private val expectedShortcutCategoriesWithSimpleShortcutCombination = listOf( simpleShortcutCategory(System, "System apps", "Open assistant"), simpleShortcutCategory(System, "System controls", "Go to home screen"), simpleShortcutCategory(System, "System apps", "Open settings"), simpleShortcutCategory(System, "System controls", "Lock screen"), simpleShortcutCategory(System, "System controls", "View notifications"), simpleShortcutCategory(System, "System apps", "Take a note"), simpleShortcutCategory(System, "System controls", "Take screenshot"), simpleShortcutCategory(System, "System controls", "Go back"), simpleShortcutCategory( MultiTasking, "Split screen", "Switch from split screen to full screen", ), simpleShortcutCategory( MultiTasking, "Split screen", "Use split screen with current app on the left", ), simpleShortcutCategory( MultiTasking, "Split screen", "Switch to app on left or above while using split screen", ), simpleShortcutCategory( MultiTasking, "Split screen", "Use split screen with current app on the right", ), simpleShortcutCategory( MultiTasking, "Split screen", "Switch to app on right or below while using split screen", ), simpleShortcutCategory(System, "System controls", "Show shortcuts"), simpleShortcutCategory(System, "System controls", "View recent apps"), simpleShortcutCategory(AppCategories, "Applications", "Calculator"), simpleShortcutCategory(AppCategories, "Applications", "Calendar"), simpleShortcutCategory(AppCategories, "Applications", "Browser"), simpleShortcutCategory(AppCategories, "Applications", "Contacts"), simpleShortcutCategory(AppCategories, "Applications", "Email"), simpleShortcutCategory(AppCategories, "Applications", "Maps"), simpleShortcutCategory(AppCategories, "Applications", "SMS"), simpleShortcutCategory(MultiTasking, "Recent apps", "Cycle forward through recent apps"), ) private val customizableInputGesturesWithSimpleShortcutCombinations = listOf( simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT ), simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_HOME), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS ), simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LOCK_SCREEN), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL ), simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_NOTES), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TAKE_SCREENSHOT ), simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_BACK), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_MULTI_WINDOW_NAVIGATION ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_LEFT ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_CHANGE_SPLITSCREEN_FOCUS_LEFT ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_RIGHT ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_CHANGE_SPLITSCREEN_FOCUS_RIGHT ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_SHORTCUT_HELPER ), simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_CALCULATOR ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_CALENDAR ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_BROWSER ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_CONTACTS ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_EMAIL ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_MAPS ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_MESSAGING ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER ), ) } packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt +262 −24 File changed.Preview size limit exceeded, changes collapsed. Show changes packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt +87 −12 Original line number Diff line number Diff line Loading @@ -16,12 +16,24 @@ package com.android.systemui.keyboard.shortcut.domain.interactor import android.content.Context import android.content.Context.INPUT_SERVICE import android.hardware.input.InputGestureData import android.hardware.input.fakeInputManager import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.Flags import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyboard.shortcut.data.source.FakeKeyboardShortcutGroupsSource import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allCustomizableInputGesturesWithSimpleShortcutCombinations import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.customInputGestureTypeHome import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.groupWithGoHomeShortcutInfo import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.systemCategoryWithCustomHomeShortcut import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.systemCategoryWithMergedGoHomeShortcut import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.InputMethodEditor import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.MultiTasking Loading @@ -34,6 +46,8 @@ import com.android.systemui.keyboard.shortcut.shortcutHelperSystemShortcutsSourc import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope import com.android.systemui.settings.FakeUserTracker import com.android.systemui.settings.userTracker import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi Loading @@ -42,13 +56,18 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @SmallTest @RunWith(AndroidJUnit4::class) class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { private val mockUserContext: Context = mock() private val systemShortcutsSource = FakeKeyboardShortcutGroupsSource() private val multitaskingShortcutsSource = FakeKeyboardShortcutGroupsSource() @OptIn(ExperimentalCoroutinesApi::class) private val kosmos = testKosmos().also { Loading @@ -57,17 +76,23 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { it.shortcutHelperMultiTaskingShortcutsSource = multitaskingShortcutsSource it.shortcutHelperAppCategoriesShortcutsSource = FakeKeyboardShortcutGroupsSource() it.shortcutHelperCurrentAppShortcutsSource = FakeKeyboardShortcutGroupsSource() it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { mockUserContext }) } private val fakeInputManager = kosmos.fakeInputManager private val testScope = kosmos.testScope private val interactor = kosmos.shortcutHelperCategoriesInteractor private lateinit var interactor: ShortcutHelperCategoriesInteractor private val helper = kosmos.shortcutHelperTestHelper private val inter by lazy { kosmos.shortcutHelperCategoriesInteractor } @Before fun setShortcuts() { interactor = kosmos.shortcutHelperCategoriesInteractor helper.setImeShortcuts(TestShortcuts.imeGroups) systemShortcutsSource.setGroups(TestShortcuts.systemGroups) multitaskingShortcutsSource.setGroups(TestShortcuts.multitaskingGroups) whenever(mockUserContext.getSystemService(INPUT_SERVICE)) .thenReturn(fakeInputManager.inputManager) } @Test Loading Loading @@ -120,7 +145,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { ShortcutCategory( type = InputMethodEditor, subCategories = TestShortcuts.imeSubCategoriesWithGroupedDuplicatedShortcutLabels TestShortcuts.imeSubCategoriesWithGroupedDuplicatedShortcutLabels, ), ) .inOrder() Loading @@ -140,7 +165,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { ShortcutCategory( type = System, subCategories = TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels, ), TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, Loading @@ -163,7 +188,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { ShortcutCategory( type = MultiTasking, subCategories = TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels, ), TestShortcuts.imeCategory, ) Loading @@ -185,7 +210,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { ShortcutCategory( type = InputMethodEditor, subCategories = TestShortcuts.imeSubCategoriesWithUnsupportedModifiersRemoved TestShortcuts.imeSubCategoriesWithUnsupportedModifiersRemoved, ), ) .inOrder() Loading @@ -203,7 +228,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { .containsExactly( ShortcutCategory( type = System, subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved, ), TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, Loading @@ -224,7 +249,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { TestShortcuts.systemCategory, ShortcutCategory( type = MultiTasking, subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved, ), TestShortcuts.imeCategory, ) Loading @@ -240,10 +265,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { helper.showFromActivity() assertThat(categories) .containsExactly( TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, ) .containsExactly(TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory) .inOrder() } Loading @@ -255,11 +277,64 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { helper.showFromActivity() assertThat(categories) .containsExactly(TestShortcuts.systemCategory, TestShortcuts.imeCategory) .inOrder() } @Test @DisableFlags(Flags.FLAG_KEYBOARD_SHORTCUT_HELPER_SHORTCUT_CUSTOMIZER) fun categories_excludesCustomShortcutsWhenFlagIsOff() { testScope.runTest { setCustomInputGestures(allCustomizableInputGesturesWithSimpleShortcutCombinations) helper.showFromActivity() val categories by collectLastValue(interactor.shortcutCategories) assertThat(categories) .containsExactly( TestShortcuts.systemCategory, TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, ) .inOrder() } } @Test @EnableFlags(Flags.FLAG_KEYBOARD_SHORTCUT_HELPER_SHORTCUT_CUSTOMIZER) fun categories_includesCustomShortcutsWhenFlagIsOn() { testScope.runTest { setCustomInputGestures(listOf(customInputGestureTypeHome)) helper.showFromActivity() val categories by collectLastValue(interactor.shortcutCategories) assertThat(categories) .containsExactly( systemCategoryWithCustomHomeShortcut, TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, ) } } @Test @EnableFlags(Flags.FLAG_KEYBOARD_SHORTCUT_HELPER_SHORTCUT_CUSTOMIZER) fun categories_correctlyMergesDefaultAndCustomShortcutsOfSameType() { testScope.runTest { setCustomInputGestures(listOf(customInputGestureTypeHome)) systemShortcutsSource.setGroups(groupWithGoHomeShortcutInfo) helper.showFromActivity() val categories by collectLastValue(interactor.shortcutCategories) assertThat(categories) .containsExactly( systemCategoryWithMergedGoHomeShortcut, TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, ) } } private fun setCustomInputGestures(customInputGestures: List<InputGestureData>) { whenever(fakeInputManager.inputManager.getCustomInputGestures(/* filter= */ anyOrNull())) .thenReturn(customInputGestures) } } packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/ShortcutHelperDialogStarterTest.kt +11 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package com.android.systemui.keyboard.shortcut.ui import android.content.Context import android.content.Context.INPUT_SERVICE import android.hardware.input.fakeInputManager import androidx.test.annotation.UiThreadTest import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest Loading @@ -36,6 +39,8 @@ import com.android.systemui.kosmos.testCase import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope import com.android.systemui.plugins.activityStarter import com.android.systemui.settings.FakeUserTracker import com.android.systemui.settings.userTracker import com.android.systemui.statusbar.phone.systemUIDialogFactory import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi Loading @@ -44,6 +49,8 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @OptIn(ExperimentalCoroutinesApi::class) @SmallTest Loading @@ -52,7 +59,7 @@ class ShortcutHelperDialogStarterTest : SysuiTestCase() { private val fakeSystemSource = FakeKeyboardShortcutGroupsSource() private val fakeMultiTaskingSource = FakeKeyboardShortcutGroupsSource() private val mockUserContext: Context = mock() private val kosmos = Kosmos().also { it.testCase = this Loading @@ -62,8 +69,10 @@ class ShortcutHelperDialogStarterTest : SysuiTestCase() { it.shortcutHelperAppCategoriesShortcutsSource = FakeKeyboardShortcutGroupsSource() it.shortcutHelperInputShortcutsSource = FakeKeyboardShortcutGroupsSource() it.shortcutHelperCurrentAppShortcutsSource = FakeKeyboardShortcutGroupsSource() it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { mockUserContext }) } private val inputManager = kosmos.fakeInputManager.inputManager private val testScope = kosmos.testScope private val testHelper = kosmos.shortcutHelperTestHelper private val dialogFactory = kosmos.systemUIDialogFactory Loading @@ -85,6 +94,7 @@ class ShortcutHelperDialogStarterTest : SysuiTestCase() { fun setUp() { fakeSystemSource.setGroups(TestShortcuts.systemGroups) fakeMultiTaskingSource.setGroups(TestShortcuts.multitaskingGroups) whenever(mockUserContext.getSystemService(INPUT_SERVICE)).thenReturn(inputManager) } @Test Loading packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt +17 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ package com.android.systemui.keyboard.shortcut import com.android.systemui.CoreStartable import com.android.systemui.Flags.keyboardShortcutHelperRewrite import com.android.systemui.keyboard.shortcut.data.repository.CustomShortcutCategoriesRepository import com.android.systemui.keyboard.shortcut.data.repository.DefaultShortcutCategoriesRepository import com.android.systemui.keyboard.shortcut.data.repository.ShortcutCategoriesRepository import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperStateRepository import com.android.systemui.keyboard.shortcut.data.source.AppCategoriesShortcutsSource import com.android.systemui.keyboard.shortcut.data.source.CurrentAppShortcutsSource Loading @@ -27,6 +30,8 @@ import com.android.systemui.keyboard.shortcut.data.source.MultitaskingShortcutsS import com.android.systemui.keyboard.shortcut.data.source.SystemShortcutsSource import com.android.systemui.keyboard.shortcut.qualifiers.AppCategoriesShortcuts import com.android.systemui.keyboard.shortcut.qualifiers.CurrentAppShortcuts import com.android.systemui.keyboard.shortcut.qualifiers.CustomShortcutCategories import com.android.systemui.keyboard.shortcut.qualifiers.DefaultShortcutCategories import com.android.systemui.keyboard.shortcut.qualifiers.InputShortcuts import com.android.systemui.keyboard.shortcut.qualifiers.MultitaskingShortcuts import com.android.systemui.keyboard.shortcut.qualifiers.SystemShortcuts Loading Loading @@ -63,6 +68,18 @@ interface ShortcutHelperModule { impl: AppCategoriesShortcutsSource ): KeyboardShortcutGroupsSource @Binds @DefaultShortcutCategories fun defaultShortcutCategoriesRepository( impl: DefaultShortcutCategoriesRepository ): ShortcutCategoriesRepository @Binds @CustomShortcutCategories fun customShortcutCategoriesRepository( impl: CustomShortcutCategoriesRepository ): ShortcutCategoriesRepository companion object { @Provides @IntoMap Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/CustomShortcutCategoriesRepositoryTest.kt +5 −179 Original line number Diff line number Diff line Loading @@ -18,13 +18,9 @@ package com.android.systemui.keyboard.shortcut.data.repository import android.content.Context import android.content.Context.INPUT_SERVICE import android.hardware.input.InputGestureData import android.hardware.input.InputGestureData.createKeyTrigger import android.hardware.input.KeyGestureEvent import android.hardware.input.fakeInputManager import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import android.view.KeyEvent import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.hardware.input.Flags.FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES Loading @@ -32,15 +28,9 @@ import com.android.hardware.input.Flags.FLAG_USE_KEY_GESTURE_EVENT_HANDLER import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyboard.shortcut.customShortcutCategoriesRepository import com.android.systemui.keyboard.shortcut.shared.model.Shortcut import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.AppCategories import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.MultiTasking import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.System import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCommand import com.android.systemui.keyboard.shortcut.shared.model.ShortcutKey import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allCustomizableInputGesturesWithSimpleShortcutCombinations import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.customizableInputGestureWithUnknownKeyGestureType import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.expectedShortcutCategoriesWithSimpleShortcutCombination import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper import com.android.systemui.kosmos.testScope import com.android.systemui.settings.FakeUserTracker Loading Loading @@ -83,7 +73,7 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() { whenever( fakeInputManager.inputManager.getCustomInputGestures(/* filter= */ anyOrNull()) ) .thenReturn(customizableInputGesturesWithSimpleShortcutCombinations) .thenReturn(allCustomizableInputGesturesWithSimpleShortcutCombinations) helper.toggle(deviceId = 123) val categories by collectLastValue(repo.categories) Loading @@ -100,7 +90,7 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() { whenever( fakeInputManager.inputManager.getCustomInputGestures(/* filter= */ anyOrNull()) ) .thenReturn(customizableInputGesturesWithSimpleShortcutCombinations) .thenReturn(allCustomizableInputGesturesWithSimpleShortcutCombinations) helper.toggle(deviceId = 123) val categories by collectLastValue(repo.categories) Loading @@ -124,168 +114,4 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() { assertThat(categories).isEmpty() } } private fun simpleInputGestureData( keyCode: Int = KeyEvent.KEYCODE_A, modifiers: Int = KeyEvent.META_CTRL_ON or KeyEvent.META_ALT_ON, keyGestureType: Int, ): InputGestureData { val builder = InputGestureData.Builder() builder.setKeyGestureType(keyGestureType) builder.setTrigger(createKeyTrigger(keyCode, modifiers)) return builder.build() } private fun simpleShortcutCategory( category: ShortcutCategoryType, subcategoryLabel: String, shortcutLabel: String, ): ShortcutCategory { return ShortcutCategory( type = category, subCategories = listOf( ShortcutSubCategory( label = subcategoryLabel, shortcuts = listOf(simpleShortcut(shortcutLabel)), ) ), ) } private fun simpleShortcut(label: String) = Shortcut( label = label, commands = listOf( ShortcutCommand( isCustom = true, keys = listOf( ShortcutKey.Text("Ctrl"), ShortcutKey.Text("Alt"), ShortcutKey.Text("A"), ), ) ), ) private val customizableInputGestureWithUnknownKeyGestureType = // These key gesture events are currently not supported by shortcut helper customizer listOf( simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_GLOBAL_ACTIONS ), simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_MEDIA_KEY), ) private val expectedShortcutCategoriesWithSimpleShortcutCombination = listOf( simpleShortcutCategory(System, "System apps", "Open assistant"), simpleShortcutCategory(System, "System controls", "Go to home screen"), simpleShortcutCategory(System, "System apps", "Open settings"), simpleShortcutCategory(System, "System controls", "Lock screen"), simpleShortcutCategory(System, "System controls", "View notifications"), simpleShortcutCategory(System, "System apps", "Take a note"), simpleShortcutCategory(System, "System controls", "Take screenshot"), simpleShortcutCategory(System, "System controls", "Go back"), simpleShortcutCategory( MultiTasking, "Split screen", "Switch from split screen to full screen", ), simpleShortcutCategory( MultiTasking, "Split screen", "Use split screen with current app on the left", ), simpleShortcutCategory( MultiTasking, "Split screen", "Switch to app on left or above while using split screen", ), simpleShortcutCategory( MultiTasking, "Split screen", "Use split screen with current app on the right", ), simpleShortcutCategory( MultiTasking, "Split screen", "Switch to app on right or below while using split screen", ), simpleShortcutCategory(System, "System controls", "Show shortcuts"), simpleShortcutCategory(System, "System controls", "View recent apps"), simpleShortcutCategory(AppCategories, "Applications", "Calculator"), simpleShortcutCategory(AppCategories, "Applications", "Calendar"), simpleShortcutCategory(AppCategories, "Applications", "Browser"), simpleShortcutCategory(AppCategories, "Applications", "Contacts"), simpleShortcutCategory(AppCategories, "Applications", "Email"), simpleShortcutCategory(AppCategories, "Applications", "Maps"), simpleShortcutCategory(AppCategories, "Applications", "SMS"), simpleShortcutCategory(MultiTasking, "Recent apps", "Cycle forward through recent apps"), ) private val customizableInputGesturesWithSimpleShortcutCombinations = listOf( simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT ), simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_HOME), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS ), simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LOCK_SCREEN), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL ), simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_NOTES), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_TAKE_SCREENSHOT ), simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_BACK), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_MULTI_WINDOW_NAVIGATION ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_LEFT ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_CHANGE_SPLITSCREEN_FOCUS_LEFT ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_RIGHT ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_CHANGE_SPLITSCREEN_FOCUS_RIGHT ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_SHORTCUT_HELPER ), simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_CALCULATOR ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_CALENDAR ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_BROWSER ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_CONTACTS ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_EMAIL ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_MAPS ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_DEFAULT_MESSAGING ), simpleInputGestureData( keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER ), ) }
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt +262 −24 File changed.Preview size limit exceeded, changes collapsed. Show changes
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt +87 −12 Original line number Diff line number Diff line Loading @@ -16,12 +16,24 @@ package com.android.systemui.keyboard.shortcut.domain.interactor import android.content.Context import android.content.Context.INPUT_SERVICE import android.hardware.input.InputGestureData import android.hardware.input.fakeInputManager import android.platform.test.annotations.DisableFlags import android.platform.test.annotations.EnableFlags import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.Flags import com.android.systemui.SysuiTestCase import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyboard.shortcut.data.source.FakeKeyboardShortcutGroupsSource import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allCustomizableInputGesturesWithSimpleShortcutCombinations import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.customInputGestureTypeHome import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.groupWithGoHomeShortcutInfo import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.systemCategoryWithCustomHomeShortcut import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.systemCategoryWithMergedGoHomeShortcut import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.InputMethodEditor import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.MultiTasking Loading @@ -34,6 +46,8 @@ import com.android.systemui.keyboard.shortcut.shortcutHelperSystemShortcutsSourc import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope import com.android.systemui.settings.FakeUserTracker import com.android.systemui.settings.userTracker import com.android.systemui.testKosmos import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi Loading @@ -42,13 +56,18 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.anyOrNull import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @SmallTest @RunWith(AndroidJUnit4::class) class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { private val mockUserContext: Context = mock() private val systemShortcutsSource = FakeKeyboardShortcutGroupsSource() private val multitaskingShortcutsSource = FakeKeyboardShortcutGroupsSource() @OptIn(ExperimentalCoroutinesApi::class) private val kosmos = testKosmos().also { Loading @@ -57,17 +76,23 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { it.shortcutHelperMultiTaskingShortcutsSource = multitaskingShortcutsSource it.shortcutHelperAppCategoriesShortcutsSource = FakeKeyboardShortcutGroupsSource() it.shortcutHelperCurrentAppShortcutsSource = FakeKeyboardShortcutGroupsSource() it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { mockUserContext }) } private val fakeInputManager = kosmos.fakeInputManager private val testScope = kosmos.testScope private val interactor = kosmos.shortcutHelperCategoriesInteractor private lateinit var interactor: ShortcutHelperCategoriesInteractor private val helper = kosmos.shortcutHelperTestHelper private val inter by lazy { kosmos.shortcutHelperCategoriesInteractor } @Before fun setShortcuts() { interactor = kosmos.shortcutHelperCategoriesInteractor helper.setImeShortcuts(TestShortcuts.imeGroups) systemShortcutsSource.setGroups(TestShortcuts.systemGroups) multitaskingShortcutsSource.setGroups(TestShortcuts.multitaskingGroups) whenever(mockUserContext.getSystemService(INPUT_SERVICE)) .thenReturn(fakeInputManager.inputManager) } @Test Loading Loading @@ -120,7 +145,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { ShortcutCategory( type = InputMethodEditor, subCategories = TestShortcuts.imeSubCategoriesWithGroupedDuplicatedShortcutLabels TestShortcuts.imeSubCategoriesWithGroupedDuplicatedShortcutLabels, ), ) .inOrder() Loading @@ -140,7 +165,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { ShortcutCategory( type = System, subCategories = TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels, ), TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, Loading @@ -163,7 +188,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { ShortcutCategory( type = MultiTasking, subCategories = TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels, ), TestShortcuts.imeCategory, ) Loading @@ -185,7 +210,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { ShortcutCategory( type = InputMethodEditor, subCategories = TestShortcuts.imeSubCategoriesWithUnsupportedModifiersRemoved TestShortcuts.imeSubCategoriesWithUnsupportedModifiersRemoved, ), ) .inOrder() Loading @@ -203,7 +228,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { .containsExactly( ShortcutCategory( type = System, subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved, ), TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, Loading @@ -224,7 +249,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { TestShortcuts.systemCategory, ShortcutCategory( type = MultiTasking, subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved, ), TestShortcuts.imeCategory, ) Loading @@ -240,10 +265,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { helper.showFromActivity() assertThat(categories) .containsExactly( TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, ) .containsExactly(TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory) .inOrder() } Loading @@ -255,11 +277,64 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { helper.showFromActivity() assertThat(categories) .containsExactly(TestShortcuts.systemCategory, TestShortcuts.imeCategory) .inOrder() } @Test @DisableFlags(Flags.FLAG_KEYBOARD_SHORTCUT_HELPER_SHORTCUT_CUSTOMIZER) fun categories_excludesCustomShortcutsWhenFlagIsOff() { testScope.runTest { setCustomInputGestures(allCustomizableInputGesturesWithSimpleShortcutCombinations) helper.showFromActivity() val categories by collectLastValue(interactor.shortcutCategories) assertThat(categories) .containsExactly( TestShortcuts.systemCategory, TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, ) .inOrder() } } @Test @EnableFlags(Flags.FLAG_KEYBOARD_SHORTCUT_HELPER_SHORTCUT_CUSTOMIZER) fun categories_includesCustomShortcutsWhenFlagIsOn() { testScope.runTest { setCustomInputGestures(listOf(customInputGestureTypeHome)) helper.showFromActivity() val categories by collectLastValue(interactor.shortcutCategories) assertThat(categories) .containsExactly( systemCategoryWithCustomHomeShortcut, TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, ) } } @Test @EnableFlags(Flags.FLAG_KEYBOARD_SHORTCUT_HELPER_SHORTCUT_CUSTOMIZER) fun categories_correctlyMergesDefaultAndCustomShortcutsOfSameType() { testScope.runTest { setCustomInputGestures(listOf(customInputGestureTypeHome)) systemShortcutsSource.setGroups(groupWithGoHomeShortcutInfo) helper.showFromActivity() val categories by collectLastValue(interactor.shortcutCategories) assertThat(categories) .containsExactly( systemCategoryWithMergedGoHomeShortcut, TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, ) } } private fun setCustomInputGestures(customInputGestures: List<InputGestureData>) { whenever(fakeInputManager.inputManager.getCustomInputGestures(/* filter= */ anyOrNull())) .thenReturn(customInputGestures) } }
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/ShortcutHelperDialogStarterTest.kt +11 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package com.android.systemui.keyboard.shortcut.ui import android.content.Context import android.content.Context.INPUT_SERVICE import android.hardware.input.fakeInputManager import androidx.test.annotation.UiThreadTest import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest Loading @@ -36,6 +39,8 @@ import com.android.systemui.kosmos.testCase import com.android.systemui.kosmos.testDispatcher import com.android.systemui.kosmos.testScope import com.android.systemui.plugins.activityStarter import com.android.systemui.settings.FakeUserTracker import com.android.systemui.settings.userTracker import com.android.systemui.statusbar.phone.systemUIDialogFactory import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi Loading @@ -44,6 +49,8 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @OptIn(ExperimentalCoroutinesApi::class) @SmallTest Loading @@ -52,7 +59,7 @@ class ShortcutHelperDialogStarterTest : SysuiTestCase() { private val fakeSystemSource = FakeKeyboardShortcutGroupsSource() private val fakeMultiTaskingSource = FakeKeyboardShortcutGroupsSource() private val mockUserContext: Context = mock() private val kosmos = Kosmos().also { it.testCase = this Loading @@ -62,8 +69,10 @@ class ShortcutHelperDialogStarterTest : SysuiTestCase() { it.shortcutHelperAppCategoriesShortcutsSource = FakeKeyboardShortcutGroupsSource() it.shortcutHelperInputShortcutsSource = FakeKeyboardShortcutGroupsSource() it.shortcutHelperCurrentAppShortcutsSource = FakeKeyboardShortcutGroupsSource() it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { mockUserContext }) } private val inputManager = kosmos.fakeInputManager.inputManager private val testScope = kosmos.testScope private val testHelper = kosmos.shortcutHelperTestHelper private val dialogFactory = kosmos.systemUIDialogFactory Loading @@ -85,6 +94,7 @@ class ShortcutHelperDialogStarterTest : SysuiTestCase() { fun setUp() { fakeSystemSource.setGroups(TestShortcuts.systemGroups) fakeMultiTaskingSource.setGroups(TestShortcuts.multitaskingGroups) whenever(mockUserContext.getSystemService(INPUT_SERVICE)).thenReturn(inputManager) } @Test Loading
packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt +17 −0 Original line number Diff line number Diff line Loading @@ -18,6 +18,9 @@ package com.android.systemui.keyboard.shortcut import com.android.systemui.CoreStartable import com.android.systemui.Flags.keyboardShortcutHelperRewrite import com.android.systemui.keyboard.shortcut.data.repository.CustomShortcutCategoriesRepository import com.android.systemui.keyboard.shortcut.data.repository.DefaultShortcutCategoriesRepository import com.android.systemui.keyboard.shortcut.data.repository.ShortcutCategoriesRepository import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperStateRepository import com.android.systemui.keyboard.shortcut.data.source.AppCategoriesShortcutsSource import com.android.systemui.keyboard.shortcut.data.source.CurrentAppShortcutsSource Loading @@ -27,6 +30,8 @@ import com.android.systemui.keyboard.shortcut.data.source.MultitaskingShortcutsS import com.android.systemui.keyboard.shortcut.data.source.SystemShortcutsSource import com.android.systemui.keyboard.shortcut.qualifiers.AppCategoriesShortcuts import com.android.systemui.keyboard.shortcut.qualifiers.CurrentAppShortcuts import com.android.systemui.keyboard.shortcut.qualifiers.CustomShortcutCategories import com.android.systemui.keyboard.shortcut.qualifiers.DefaultShortcutCategories import com.android.systemui.keyboard.shortcut.qualifiers.InputShortcuts import com.android.systemui.keyboard.shortcut.qualifiers.MultitaskingShortcuts import com.android.systemui.keyboard.shortcut.qualifiers.SystemShortcuts Loading Loading @@ -63,6 +68,18 @@ interface ShortcutHelperModule { impl: AppCategoriesShortcutsSource ): KeyboardShortcutGroupsSource @Binds @DefaultShortcutCategories fun defaultShortcutCategoriesRepository( impl: DefaultShortcutCategoriesRepository ): ShortcutCategoriesRepository @Binds @CustomShortcutCategories fun customShortcutCategoriesRepository( impl: CustomShortcutCategoriesRepository ): ShortcutCategoriesRepository companion object { @Provides @IntoMap Loading