diff options
| author | 2024-11-18 10:15:18 +0000 | |
|---|---|---|
| committer | 2024-11-18 10:15:18 +0000 | |
| commit | ed40bf45a9d4bdb0dfadfa662778c17ba0df4b1c (patch) | |
| tree | 6643e23478bc42f50f24c5278cf5d723cad0c79f | |
| parent | ab2b24d6970b2b60b29e102bf490fd01678f223c (diff) | |
| parent | 00f1127e7006f675702605bc49320b1228cd54be (diff) | |
Merge "Connected data layer and UI layer for custom shortcuts retrieval" into main
12 files changed, 487 insertions, 245 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/CustomShortcutCategoriesRepositoryTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/CustomShortcutCategoriesRepositoryTest.kt index cc4c7c419a11..af8341b8e0b9 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/CustomShortcutCategoriesRepositoryTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/CustomShortcutCategoriesRepositoryTest.kt @@ -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 @@ -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 @@ -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) @@ -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) @@ -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 - ), - ) } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt index c9c39b3ebf66..a1e7ef4ac5a3 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt @@ -16,11 +16,20 @@ package com.android.systemui.keyboard.shortcut.data.source +import android.hardware.input.InputGestureData +import android.hardware.input.InputGestureData.createKeyTrigger +import android.hardware.input.KeyGestureEvent import android.view.KeyEvent import android.view.KeyboardShortcutGroup import android.view.KeyboardShortcutInfo +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.shared.model.shortcut import com.android.systemui.res.R @@ -64,6 +73,13 @@ object TestShortcuts { } } + private val goHomeShortcutInfo = + KeyboardShortcutInfo( + /* label = */ "Go to home screen", + /* keycode = */ KeyEvent.KEYCODE_B, + /* modifiers = */ KeyEvent.META_CTRL_ON or KeyEvent.META_ALT_ON, + ) + private val standardShortcutInfo1 = KeyboardShortcutInfo( /* label = */ "Standard shortcut 1", @@ -79,6 +95,16 @@ object TestShortcuts { } } + private val customGoHomeShortcut = + shortcut("Go to home screen") { + command { + key("Ctrl") + key("Alt") + key("A") + isCustom(true) + } + } + private val standardShortcutInfo2 = KeyboardShortcutInfo( /* label = */ "Standard shortcut 2", @@ -123,35 +149,38 @@ object TestShortcuts { listOf( shortcutInfoWithRepeatedLabel, shortcutInfoWithRepeatedLabelAlternate, - shortcutInfoWithRepeatedLabelSecondAlternate - ) + shortcutInfoWithRepeatedLabelSecondAlternate, + ), ) private val subCategoryWithGroupedRepeatedShortcutLabels = ShortcutSubCategory( label = groupWithRepeatedShortcutLabels.label!!.toString(), - shortcuts = listOf(shortcutWithGroupedRepeatedLabel) + shortcuts = listOf(shortcutWithGroupedRepeatedLabel), ) private val groupWithStandardShortcutInfo = KeyboardShortcutGroup("Standard group", listOf(standardShortcutInfo1)) + val groupWithGoHomeShortcutInfo = + KeyboardShortcutGroup("System controls", listOf(goHomeShortcutInfo)) + private val subCategoryWithStandardShortcut = ShortcutSubCategory( label = groupWithStandardShortcutInfo.label!!.toString(), - shortcuts = listOf(standardShortcut1) + shortcuts = listOf(standardShortcut1), ) private val groupWithOnlyUnsupportedModifierShortcut = KeyboardShortcutGroup( "Group with unsupported modifiers", - listOf(shortcutInfoWithUnsupportedModifiers) + listOf(shortcutInfoWithUnsupportedModifiers), ) private val groupWithSupportedAndUnsupportedModifierShortcut = KeyboardShortcutGroup( "Group with mix of supported and not supported modifiers", - listOf(standardShortcutInfo3, shortcutInfoWithUnsupportedModifiers) + listOf(standardShortcutInfo3, shortcutInfoWithUnsupportedModifiers), ) private val switchToNextLanguageShortcut = @@ -174,19 +203,19 @@ object TestShortcuts { private val subCategoryForInputLanguageSwitchShortcuts = ShortcutSubCategory( "Input", - listOf(switchToNextLanguageShortcut, switchToPreviousLanguageShortcut) + listOf(switchToNextLanguageShortcut, switchToPreviousLanguageShortcut), ) private val subCategoryWithUnsupportedShortcutsRemoved = ShortcutSubCategory( groupWithSupportedAndUnsupportedModifierShortcut.label!!.toString(), - listOf(standardShortcut3) + listOf(standardShortcut3), ) private val standardGroup1 = KeyboardShortcutGroup( "Standard group 1", - listOf(standardShortcutInfo1, standardShortcutInfo2, standardShortcutInfo3) + listOf(standardShortcutInfo1, standardShortcutInfo2, standardShortcutInfo3), ) private val standardPackageName1 = "standard.app.group1" @@ -194,38 +223,63 @@ object TestShortcuts { private val standardAppGroup1 = KeyboardShortcutGroup( "Standard app group 1", - listOf(standardShortcutInfo1, standardShortcutInfo2, standardShortcutInfo3) + listOf(standardShortcutInfo1, standardShortcutInfo2, standardShortcutInfo3), ) .apply { packageName = standardPackageName1 } + private val standardSystemAppSubcategoryWithCustomHomeShortcut = + ShortcutSubCategory("System controls", listOf(customGoHomeShortcut)) + private val standardSubCategory1 = ShortcutSubCategory( standardGroup1.label!!.toString(), - listOf(standardShortcut1, standardShortcut2, standardShortcut3) + listOf(standardShortcut1, standardShortcut2, standardShortcut3), ) private val standardGroup2 = KeyboardShortcutGroup( "Standard group 2", - listOf(standardShortcutInfo3, standardShortcutInfo2, standardShortcutInfo1) + listOf(standardShortcutInfo3, standardShortcutInfo2, standardShortcutInfo1), ) private val standardSubCategory2 = ShortcutSubCategory( standardGroup2.label!!.toString(), - listOf(standardShortcut3, standardShortcut2, standardShortcut1) + listOf(standardShortcut3, standardShortcut2, standardShortcut1), ) private val standardGroup3 = KeyboardShortcutGroup( "Standard group 3", - listOf(standardShortcutInfo2, standardShortcutInfo1) + listOf(standardShortcutInfo2, standardShortcutInfo1), ) private val standardSubCategory3 = ShortcutSubCategory( standardGroup3.label!!.toString(), - listOf(standardShortcut2, standardShortcut1) + listOf(standardShortcut2, standardShortcut1), + ) + + private val systemSubCategoryWithGoHomeShortcuts = + ShortcutSubCategory( + label = "System controls", + shortcuts = + listOf( + shortcut("Go to home screen") { + command { + key("Ctrl") + key("Alt") + key("B") + } + command { + key("Ctrl") + key("Alt") + key("A") + isCustom(true) + } + } + ), ) + val imeGroups = listOf(standardGroup1, standardGroup2, standardGroup3) val imeCategory = ShortcutCategory( @@ -235,8 +289,8 @@ object TestShortcuts { subCategoryForInputLanguageSwitchShortcuts, standardSubCategory1, standardSubCategory2, - standardSubCategory3 - ) + standardSubCategory3, + ), ) val currentAppGroups = listOf(standardAppGroup1) @@ -245,15 +299,33 @@ object TestShortcuts { val systemGroups = listOf(standardGroup3, standardGroup2, standardGroup1) val systemCategory = ShortcutCategory( - type = ShortcutCategoryType.System, - subCategories = listOf(standardSubCategory3, standardSubCategory2, standardSubCategory1) + type = System, + subCategories = listOf(standardSubCategory3, standardSubCategory2, standardSubCategory1), + ) + + val systemCategoryWithMergedGoHomeShortcut = + ShortcutCategory( + type = System, + subCategories = listOf(systemSubCategoryWithGoHomeShortcuts), + ) + + val systemCategoryWithCustomHomeShortcut = + ShortcutCategory( + type = System, + subCategories = + listOf( + standardSubCategory3, + standardSubCategory2, + standardSubCategory1, + standardSystemAppSubcategoryWithCustomHomeShortcut, + ), ) val multitaskingGroups = listOf(standardGroup2, standardGroup1) val multitaskingCategory = ShortcutCategory( - type = ShortcutCategoryType.MultiTasking, - subCategories = listOf(standardSubCategory2, standardSubCategory1) + type = MultiTasking, + subCategories = listOf(standardSubCategory2, standardSubCategory1), ) val groupsWithDuplicateShortcutLabels = @@ -266,14 +338,14 @@ object TestShortcuts { listOf( subCategoryForInputLanguageSwitchShortcuts, subCategoryWithGroupedRepeatedShortcutLabels, - subCategoryWithStandardShortcut + subCategoryWithStandardShortcut, ) val groupsWithUnsupportedModifier = listOf( groupWithStandardShortcutInfo, groupWithOnlyUnsupportedModifierShortcut, - groupWithSupportedAndUnsupportedModifierShortcut + groupWithSupportedAndUnsupportedModifierShortcut, ) val subCategoriesWithUnsupportedModifiersRemoved = @@ -283,8 +355,174 @@ object TestShortcuts { listOf( subCategoryForInputLanguageSwitchShortcuts, subCategoryWithStandardShortcut, - subCategoryWithUnsupportedShortcutsRemoved + subCategoryWithUnsupportedShortcutsRemoved, ) val groupsWithOnlyUnsupportedModifiers = listOf(groupWithOnlyUnsupportedModifierShortcut) + + 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"), + ), + ) + ), + ) + + 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), + ) + + 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"), + ) + val customInputGestureTypeHome = + simpleInputGestureData(keyGestureType = KeyGestureEvent.KEY_GESTURE_TYPE_HOME) + + val allCustomizableInputGesturesWithSimpleShortcutCombinations = + 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 + ), + ) } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt index 57c8b444b922..f7c77017e239 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractorTest.kt @@ -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 @@ -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 @@ -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 { @@ -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 @@ -120,7 +145,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { ShortcutCategory( type = InputMethodEditor, subCategories = - TestShortcuts.imeSubCategoriesWithGroupedDuplicatedShortcutLabels + TestShortcuts.imeSubCategoriesWithGroupedDuplicatedShortcutLabels, ), ) .inOrder() @@ -140,7 +165,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { ShortcutCategory( type = System, subCategories = - TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels + TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels, ), TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, @@ -163,7 +188,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { ShortcutCategory( type = MultiTasking, subCategories = - TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels + TestShortcuts.subCategoriesWithGroupedDuplicatedShortcutLabels, ), TestShortcuts.imeCategory, ) @@ -185,7 +210,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { ShortcutCategory( type = InputMethodEditor, subCategories = - TestShortcuts.imeSubCategoriesWithUnsupportedModifiersRemoved + TestShortcuts.imeSubCategoriesWithUnsupportedModifiersRemoved, ), ) .inOrder() @@ -203,7 +228,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { .containsExactly( ShortcutCategory( type = System, - subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved + subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved, ), TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory, @@ -224,7 +249,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { TestShortcuts.systemCategory, ShortcutCategory( type = MultiTasking, - subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved + subCategories = TestShortcuts.subCategoriesWithUnsupportedModifiersRemoved, ), TestShortcuts.imeCategory, ) @@ -240,10 +265,7 @@ class ShortcutHelperCategoriesInteractorTest : SysuiTestCase() { helper.showFromActivity() assertThat(categories) - .containsExactly( - TestShortcuts.multitaskingCategory, - TestShortcuts.imeCategory, - ) + .containsExactly(TestShortcuts.multitaskingCategory, TestShortcuts.imeCategory) .inOrder() } @@ -256,10 +278,63 @@ 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, + ) + } + } + + @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, ) - .inOrder() } + } + + private fun setCustomInputGestures(customInputGestures: List<InputGestureData>) { + whenever(fakeInputManager.inputManager.getCustomInputGestures(/* filter= */ anyOrNull())) + .thenReturn(customInputGestures) + } } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/ShortcutHelperDialogStarterTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/ShortcutHelperDialogStarterTest.kt index 1580ea5c1272..000024f9b814 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/ShortcutHelperDialogStarterTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/ShortcutHelperDialogStarterTest.kt @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt index 7b3380a6a608..1af7340ad7b4 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ShortcutHelperModule.kt @@ -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 @@ -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 @@ -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 diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutCategoriesUtils.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutCategoriesUtils.kt index 899fd15d6115..dd0db88c06d1 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutCategoriesUtils.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutCategoriesUtils.kt @@ -35,9 +35,9 @@ import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCommand import com.android.systemui.keyboard.shortcut.shared.model.ShortcutIcon import com.android.systemui.keyboard.shortcut.shared.model.ShortcutKey import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory +import kotlinx.coroutines.withContext import javax.inject.Inject import kotlin.coroutines.CoroutineContext -import kotlinx.coroutines.withContext class ShortcutCategoriesUtils @Inject @@ -92,7 +92,7 @@ constructor( } .filter { it.shortcuts.isNotEmpty() } return if (subCategories.isEmpty()) { - Log.wtf(TAG, "Empty sub categories after converting $shortcutGroups") + Log.w(TAG, "Empty sub categories after converting $shortcutGroups") null } else { ShortcutCategory(type, subCategories) diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt index 39fc27d35082..06aadb84f079 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt @@ -16,37 +16,66 @@ package com.android.systemui.keyboard.shortcut.domain.interactor +import com.android.systemui.Flags.keyboardShortcutHelperShortcutCustomizer import com.android.systemui.dagger.SysUISingleton -import com.android.systemui.keyboard.shortcut.data.repository.DefaultShortcutCategoriesRepository +import com.android.systemui.keyboard.shortcut.data.repository.ShortcutCategoriesRepository +import com.android.systemui.keyboard.shortcut.qualifiers.CustomShortcutCategories +import com.android.systemui.keyboard.shortcut.qualifiers.DefaultShortcutCategories 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.ShortcutSubCategory -import javax.inject.Inject +import dagger.Lazy import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.map +import kotlinx.coroutines.flow.combine +import kotlinx.coroutines.flow.flowOf +import javax.inject.Inject @SysUISingleton class ShortcutHelperCategoriesInteractor @Inject -constructor(categoriesRepository: DefaultShortcutCategoriesRepository) { - +constructor( + @DefaultShortcutCategories defaultCategoriesRepository: ShortcutCategoriesRepository, + @CustomShortcutCategories customCategoriesRepositoryLazy: Lazy<ShortcutCategoriesRepository>, +) { val shortcutCategories: Flow<List<ShortcutCategory>> = - categoriesRepository.categories.map { categories -> - categories.map { category -> groupSubCategoriesInCategory(category) } + defaultCategoriesRepository.categories.combine( + if (keyboardShortcutHelperShortcutCustomizer()) { + customCategoriesRepositoryLazy.get().categories + } else { + flowOf(emptyList()) + } + ) { defaultShortcutCategories, customShortcutCategories -> + groupCategories(defaultShortcutCategories + customShortcutCategories) } - private fun groupSubCategoriesInCategory(shortcutCategory: ShortcutCategory): ShortcutCategory { - val subCategoriesWithGroupedShortcuts = - shortcutCategory.subCategories.map { + private fun groupCategories( + shortcutCategories: List<ShortcutCategory> + ): List<ShortcutCategory> { + return shortcutCategories + .groupBy { it.type } + .entries + .map { (categoryType, groupedCategories) -> + ShortcutCategory( + type = categoryType, + subCategories = + groupSubCategories(groupedCategories.flatMap { it.subCategories }), + ) + } + } + + private fun groupSubCategories( + subCategories: List<ShortcutSubCategory> + ): List<ShortcutSubCategory> { + return subCategories + .groupBy { it.label } + .entries + .map { (label, groupedSubcategories) -> ShortcutSubCategory( - label = it.label, - shortcuts = groupShortcutsInSubcategory(it.shortcuts), + label = label, + shortcuts = + groupShortcutsInSubcategory(groupedSubcategories.flatMap { it.shortcuts }), ) } - return ShortcutCategory( - type = shortcutCategory.type, - subCategories = subCategoriesWithGroupedShortcuts, - ) } private fun groupShortcutsInSubcategory(shortcuts: List<Shortcut>) = diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/qualifiers/CustomShortcutCategories.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/qualifiers/CustomShortcutCategories.kt new file mode 100644 index 000000000000..8acb9eebbd4d --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/qualifiers/CustomShortcutCategories.kt @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.keyboard.shortcut.qualifiers + +import javax.inject.Qualifier + +@Qualifier annotation class CustomShortcutCategories diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/qualifiers/DefaultShortcutCategories.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/qualifiers/DefaultShortcutCategories.kt new file mode 100644 index 000000000000..f94e10d17964 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/qualifiers/DefaultShortcutCategories.kt @@ -0,0 +1,21 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.keyboard.shortcut.qualifiers + +import javax.inject.Qualifier + +@Qualifier annotation class DefaultShortcutCategories diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModel.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModel.kt index 912bfe99cea8..fa3edaf592c2 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModel.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModel.kt @@ -40,7 +40,6 @@ import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCategoryUi import com.android.systemui.keyboard.shortcut.ui.model.ShortcutsUiState import com.android.systemui.res.R import com.android.systemui.settings.UserTracker -import javax.inject.Inject import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.MutableStateFlow @@ -51,6 +50,7 @@ import kotlinx.coroutines.flow.flowOn import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.withContext +import javax.inject.Inject class ShortcutHelperViewModel @Inject @@ -123,7 +123,7 @@ constructor( userContext.packageManager.getApplicationIcon(type.packageName) IconSource(painter = DrawablePainter(drawable = iconDrawable)) } catch (e: NameNotFoundException) { - Log.wtf( + Log.w( "ShortcutHelperViewModel", "Package not found when retrieving icon for ${type.packageName}", ) @@ -153,7 +153,7 @@ constructor( packageManagerForUser.getApplicationInfo(type.packageName, /* flags= */ 0) return packageManagerForUser.getApplicationLabel(currentAppInfo).toString() } catch (e: NameNotFoundException) { - Log.wtf( + Log.w( "ShortcutHelperViewModel", "Package Not found when retrieving Label for ${type.packageName}", ) diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt index 7383faf2fd78..14cb9a8ce662 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt @@ -278,7 +278,7 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { testScope.runTest { fakeSystemSource.setGroups( groupWithShortcutLabels("first Foo shortcut1", "first bar shortcut1"), - groupWithShortcutLabels("second foO shortcut2", "second bar shortcut2"), + groupWithShortcutLabels("second foO shortcut2", "second bar shortcut2", groupLabel = SECOND_SIMPLE_GROUP_LABEL), ) fakeMultiTaskingSource.setGroups( groupWithShortcutLabels("third FoO shortcut1", "third bar shortcut1") @@ -298,7 +298,7 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { ShortcutCategory( System, subCategoryWithShortcutLabels("first Foo shortcut1"), - subCategoryWithShortcutLabels("second foO shortcut2"), + subCategoryWithShortcutLabels("second foO shortcut2", subCategoryLabel = SECOND_SIMPLE_GROUP_LABEL), ), ), ShortcutCategoryUi( @@ -380,16 +380,16 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { assertThat(activeUiState.defaultSelectedCategory).isInstanceOf(CurrentApp::class.java) } - private fun groupWithShortcutLabels(vararg shortcutLabels: String) = - KeyboardShortcutGroup(SIMPLE_GROUP_LABEL, shortcutLabels.map { simpleShortcutInfo(it) }) + private fun groupWithShortcutLabels(vararg shortcutLabels: String, groupLabel: String = FIRST_SIMPLE_GROUP_LABEL) = + KeyboardShortcutGroup(groupLabel, shortcutLabels.map { simpleShortcutInfo(it) }) .apply { packageName = "test.package.name" } private fun simpleShortcutInfo(label: String) = KeyboardShortcutInfo(label, KeyEvent.KEYCODE_A, KeyEvent.META_CTRL_ON) - private fun subCategoryWithShortcutLabels(vararg shortcutLabels: String) = + private fun subCategoryWithShortcutLabels(vararg shortcutLabels: String, subCategoryLabel: String = FIRST_SIMPLE_GROUP_LABEL) = ShortcutSubCategory( - label = SIMPLE_GROUP_LABEL, + label = subCategoryLabel, shortcuts = shortcutLabels.map { simpleShortcut(it) }, ) @@ -402,6 +402,7 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { } companion object { - private const val SIMPLE_GROUP_LABEL = "simple group" + private const val FIRST_SIMPLE_GROUP_LABEL = "simple group 1" + private const val SECOND_SIMPLE_GROUP_LABEL = "simple group 2" } } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt index 903bc8ebf42d..7c5f901eeff9 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyboard/shortcut/KeyboardShortcutHelperKosmos.kt @@ -136,7 +136,11 @@ val Kosmos.shortcutHelperStateInteractor by } val Kosmos.shortcutHelperCategoriesInteractor by - Kosmos.Fixture { ShortcutHelperCategoriesInteractor(defaultShortcutCategoriesRepository) } + Kosmos.Fixture { + ShortcutHelperCategoriesInteractor( + defaultShortcutCategoriesRepository, + ) { customShortcutCategoriesRepository } + } val Kosmos.shortcutHelperViewModel by Kosmos.Fixture { |