Loading packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/DefaultShortcutCategoriesRepositoryTest.kt +28 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,9 @@ 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.CYCLE_BACK_THROUGH_RECENT_APPS_SHORTCUT_LABEL import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.CYCLE_FORWARD_THROUGH_RECENT_APPS_SHORTCUT_LABEL import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.recentAppsGroup import com.android.systemui.keyboard.shortcut.defaultShortcutCategoriesRepository import com.android.systemui.keyboard.shortcut.shared.model.Shortcut import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory Loading Loading @@ -270,6 +273,31 @@ class DefaultShortcutCategoriesRepositoryTest : SysuiTestCase() { assertThat(systemCategory).isEqualTo(expectedCategory) } @Test fun categories_recentAppsSwitchShortcutsIsMarkedNonCustomizable() { testScope.runTest { helper.setImeShortcuts(emptyList()) fakeSystemSource.setGroups(emptyList()) fakeMultiTaskingSource.setGroups(recentAppsGroup) helper.showFromActivity() val categories by collectLastValue(repo.categories) val cycleForwardThroughRecentAppsShortcut = categories?.first { it.type == ShortcutCategoryType.MultiTasking } ?.subCategories?.first { it.label == recentAppsGroup.label } ?.shortcuts?.first { it.label == CYCLE_FORWARD_THROUGH_RECENT_APPS_SHORTCUT_LABEL } val cycleBackThroughRecentAppsShortcut = categories?.first { it.type == ShortcutCategoryType.MultiTasking } ?.subCategories?.first { it.label == recentAppsGroup.label } ?.shortcuts?.first { it.label == CYCLE_BACK_THROUGH_RECENT_APPS_SHORTCUT_LABEL } assertThat(cycleForwardThroughRecentAppsShortcut?.isCustomizable).isFalse() assertThat(cycleBackThroughRecentAppsShortcut?.isCustomizable).isFalse() } } private fun simpleSubCategory(vararg shortcuts: Shortcut) = ShortcutSubCategory(simpleGroupLabel, shortcuts.asList()) Loading packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt +58 −6 Original line number Diff line number Diff line Loading @@ -57,14 +57,14 @@ object TestShortcuts { KeyboardShortcutInfo( /* label = */ "Shortcut with repeated label", /* keycode = */ KeyEvent.KEYCODE_H, /* modifiers = */ KeyEvent.META_META_ON, /* modifiers = */ META_META_ON, ) private val shortcutInfoWithRepeatedLabelAlternate = KeyboardShortcutInfo( /* label = */ shortcutInfoWithRepeatedLabel.label, /* keycode = */ KeyEvent.KEYCODE_L, /* modifiers = */ KeyEvent.META_META_ON, /* modifiers = */ META_META_ON, ) private val shortcutInfoWithRepeatedLabelSecondAlternate = Loading Loading @@ -126,9 +126,44 @@ object TestShortcuts { KeyboardShortcutInfo( /* label = */ "Standard shortcut 1", /* keycode = */ KeyEvent.KEYCODE_N, /* modifiers = */ KeyEvent.META_META_ON, /* modifiers = */ META_META_ON, ) const val CYCLE_FORWARD_THROUGH_RECENT_APPS_SHORTCUT_LABEL = "Cycle forward through recent apps" const val CYCLE_BACK_THROUGH_RECENT_APPS_SHORTCUT_LABEL = "Cycle backward through recent apps" private val recentAppsCycleForwardShortcutInfo = KeyboardShortcutInfo( /* label = */ CYCLE_FORWARD_THROUGH_RECENT_APPS_SHORTCUT_LABEL, /* keycode = */ KeyEvent.KEYCODE_N, /* modifiers = */ META_META_ON, ) private val recentAppsCycleBackShortcutInfo = KeyboardShortcutInfo( /* label = */ CYCLE_BACK_THROUGH_RECENT_APPS_SHORTCUT_LABEL, /* keycode = */ KeyEvent.KEYCODE_N, /* modifiers = */ META_META_ON, ) private val recentAppsCycleForwardShortcut = shortcut(recentAppsCycleForwardShortcutInfo.label!!.toString()) { command { key(R.drawable.ic_ksh_key_meta) key("N") } isCustomizable = false } private val recentAppsCycleBackShortcut = shortcut(recentAppsCycleBackShortcutInfo.label!!.toString()) { command { key(R.drawable.ic_ksh_key_meta) key("N") } isCustomizable = false } private val standardShortcut1 = shortcut(standardShortcutInfo1.label!!.toString()) { command { Loading Loading @@ -186,7 +221,7 @@ object TestShortcuts { KeyboardShortcutInfo( /* label = */ "Shortcut with unsupported modifiers", /* keycode = */ KeyEvent.KEYCODE_A, /* modifiers = */ KeyEvent.META_META_ON or KeyEvent.KEYCODE_SPACE, /* modifiers = */ META_META_ON or KeyEvent.KEYCODE_SPACE, ) private val groupWithRepeatedShortcutLabels = Loading Loading @@ -262,6 +297,12 @@ object TestShortcuts { listOf(standardShortcut3), ) val recentAppsGroup = KeyboardShortcutGroup( "Recent apps", listOf(recentAppsCycleForwardShortcutInfo, recentAppsCycleBackShortcutInfo), ) private val standardGroup1 = KeyboardShortcutGroup( "Standard group 1", Loading @@ -280,6 +321,12 @@ object TestShortcuts { private val standardSystemAppSubcategoryWithCustomHomeShortcut = ShortcutSubCategory("System controls", listOf(customGoHomeShortcut)) private val recentAppsSubCategory = ShortcutSubCategory( recentAppsGroup.label!!.toString(), listOf(recentAppsCycleForwardShortcut, recentAppsCycleBackShortcut), ) private val standardSubCategory1 = ShortcutSubCategory( standardGroup1.label!!.toString(), Loading Loading @@ -375,6 +422,9 @@ object TestShortcuts { ), ) val multitaskingCategoryWithRecentAppsGroup = ShortcutCategory(type = MultiTasking, subCategories = listOf(recentAppsSubCategory)) val multitaskingGroups = listOf(standardGroup2, standardGroup1) val multitaskingCategory = ShortcutCategory( Loading Loading @@ -439,6 +489,7 @@ object TestShortcuts { category: ShortcutCategoryType, subcategoryLabel: String, shortcutLabel: String, includeInCustomization: Boolean = true, ): ShortcutCategory { return ShortcutCategory( type = category, Loading @@ -446,13 +497,13 @@ object TestShortcuts { listOf( ShortcutSubCategory( label = subcategoryLabel, shortcuts = listOf(simpleShortcut(shortcutLabel)), shortcuts = listOf(simpleShortcut(shortcutLabel, includeInCustomization)), ) ), ) } private fun simpleShortcut(label: String) = private fun simpleShortcut(label: String, includeInCustomization: Boolean = true) = Shortcut( label = label, commands = Loading @@ -467,6 +518,7 @@ object TestShortcuts { ), ) ), isCustomizable = includeInCustomization, ) val customizableInputGestureWithUnknownKeyGestureType = Loading packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutCategoriesUtils.kt +4 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ 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.ShortcutCommand import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperExclusions 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 Loading @@ -46,6 +47,7 @@ constructor( private val context: Context, @Background private val backgroundCoroutineContext: CoroutineContext, private val inputManager: InputManager, private val shortcutHelperExclusions: ShortcutHelperExclusions, ) { fun removeUnsupportedModifiers(modifierMask: Int): Int { Loading Loading @@ -135,6 +137,8 @@ constructor( label = shortcutInfo.label, icon = toShortcutIcon(keepIcon, shortcutInfo), commands = listOf(shortcutCommand), isCustomizable = shortcutHelperExclusions.isShortcutCustomizable(shortcutInfo.label), ) } Loading packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt +1 −3 Original line number Diff line number Diff line Loading @@ -92,9 +92,7 @@ constructor( .groupBy { it.label } .entries .map { (commonLabel, groupedShortcuts) -> Shortcut( label = commonLabel, icon = groupedShortcuts.firstOrNull()?.icon, groupedShortcuts[0].copy( commands = groupedShortcuts.flatMap { it.commands }.sortedBy { it.keys.size }, contentDescription = toContentDescription(commonLabel, groupedShortcuts.flatMap { it.commands }), Loading packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/Shortcut.kt +9 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ data class Shortcut( val commands: List<ShortcutCommand>, val icon: ShortcutIcon? = null, val contentDescription: String = "", val isCustomizable: Boolean = true, ) { val containsCustomShortcutCommands: Boolean = commands.any { it.isCustom } } Loading @@ -28,6 +29,7 @@ data class Shortcut( class ShortcutBuilder(private val label: String) { val commands = mutableListOf<ShortcutCommand>() var contentDescription = "" var isCustomizable = true fun command(builder: ShortcutCommandBuilder.() -> Unit) { commands += ShortcutCommandBuilder().apply(builder).build() Loading @@ -37,7 +39,13 @@ class ShortcutBuilder(private val label: String) { contentDescription = string.invoke() } fun build() = Shortcut(label, commands, contentDescription = contentDescription) fun build() = Shortcut( label, commands, contentDescription = contentDescription, isCustomizable = isCustomizable, ) } fun shortcut(label: String, block: ShortcutBuilder.() -> Unit): Shortcut = Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/DefaultShortcutCategoriesRepositoryTest.kt +28 −0 Original line number Diff line number Diff line Loading @@ -40,6 +40,9 @@ 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.CYCLE_BACK_THROUGH_RECENT_APPS_SHORTCUT_LABEL import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.CYCLE_FORWARD_THROUGH_RECENT_APPS_SHORTCUT_LABEL import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.recentAppsGroup import com.android.systemui.keyboard.shortcut.defaultShortcutCategoriesRepository import com.android.systemui.keyboard.shortcut.shared.model.Shortcut import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory Loading Loading @@ -270,6 +273,31 @@ class DefaultShortcutCategoriesRepositoryTest : SysuiTestCase() { assertThat(systemCategory).isEqualTo(expectedCategory) } @Test fun categories_recentAppsSwitchShortcutsIsMarkedNonCustomizable() { testScope.runTest { helper.setImeShortcuts(emptyList()) fakeSystemSource.setGroups(emptyList()) fakeMultiTaskingSource.setGroups(recentAppsGroup) helper.showFromActivity() val categories by collectLastValue(repo.categories) val cycleForwardThroughRecentAppsShortcut = categories?.first { it.type == ShortcutCategoryType.MultiTasking } ?.subCategories?.first { it.label == recentAppsGroup.label } ?.shortcuts?.first { it.label == CYCLE_FORWARD_THROUGH_RECENT_APPS_SHORTCUT_LABEL } val cycleBackThroughRecentAppsShortcut = categories?.first { it.type == ShortcutCategoryType.MultiTasking } ?.subCategories?.first { it.label == recentAppsGroup.label } ?.shortcuts?.first { it.label == CYCLE_BACK_THROUGH_RECENT_APPS_SHORTCUT_LABEL } assertThat(cycleForwardThroughRecentAppsShortcut?.isCustomizable).isFalse() assertThat(cycleBackThroughRecentAppsShortcut?.isCustomizable).isFalse() } } private fun simpleSubCategory(vararg shortcuts: Shortcut) = ShortcutSubCategory(simpleGroupLabel, shortcuts.asList()) Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt +58 −6 Original line number Diff line number Diff line Loading @@ -57,14 +57,14 @@ object TestShortcuts { KeyboardShortcutInfo( /* label = */ "Shortcut with repeated label", /* keycode = */ KeyEvent.KEYCODE_H, /* modifiers = */ KeyEvent.META_META_ON, /* modifiers = */ META_META_ON, ) private val shortcutInfoWithRepeatedLabelAlternate = KeyboardShortcutInfo( /* label = */ shortcutInfoWithRepeatedLabel.label, /* keycode = */ KeyEvent.KEYCODE_L, /* modifiers = */ KeyEvent.META_META_ON, /* modifiers = */ META_META_ON, ) private val shortcutInfoWithRepeatedLabelSecondAlternate = Loading Loading @@ -126,9 +126,44 @@ object TestShortcuts { KeyboardShortcutInfo( /* label = */ "Standard shortcut 1", /* keycode = */ KeyEvent.KEYCODE_N, /* modifiers = */ KeyEvent.META_META_ON, /* modifiers = */ META_META_ON, ) const val CYCLE_FORWARD_THROUGH_RECENT_APPS_SHORTCUT_LABEL = "Cycle forward through recent apps" const val CYCLE_BACK_THROUGH_RECENT_APPS_SHORTCUT_LABEL = "Cycle backward through recent apps" private val recentAppsCycleForwardShortcutInfo = KeyboardShortcutInfo( /* label = */ CYCLE_FORWARD_THROUGH_RECENT_APPS_SHORTCUT_LABEL, /* keycode = */ KeyEvent.KEYCODE_N, /* modifiers = */ META_META_ON, ) private val recentAppsCycleBackShortcutInfo = KeyboardShortcutInfo( /* label = */ CYCLE_BACK_THROUGH_RECENT_APPS_SHORTCUT_LABEL, /* keycode = */ KeyEvent.KEYCODE_N, /* modifiers = */ META_META_ON, ) private val recentAppsCycleForwardShortcut = shortcut(recentAppsCycleForwardShortcutInfo.label!!.toString()) { command { key(R.drawable.ic_ksh_key_meta) key("N") } isCustomizable = false } private val recentAppsCycleBackShortcut = shortcut(recentAppsCycleBackShortcutInfo.label!!.toString()) { command { key(R.drawable.ic_ksh_key_meta) key("N") } isCustomizable = false } private val standardShortcut1 = shortcut(standardShortcutInfo1.label!!.toString()) { command { Loading Loading @@ -186,7 +221,7 @@ object TestShortcuts { KeyboardShortcutInfo( /* label = */ "Shortcut with unsupported modifiers", /* keycode = */ KeyEvent.KEYCODE_A, /* modifiers = */ KeyEvent.META_META_ON or KeyEvent.KEYCODE_SPACE, /* modifiers = */ META_META_ON or KeyEvent.KEYCODE_SPACE, ) private val groupWithRepeatedShortcutLabels = Loading Loading @@ -262,6 +297,12 @@ object TestShortcuts { listOf(standardShortcut3), ) val recentAppsGroup = KeyboardShortcutGroup( "Recent apps", listOf(recentAppsCycleForwardShortcutInfo, recentAppsCycleBackShortcutInfo), ) private val standardGroup1 = KeyboardShortcutGroup( "Standard group 1", Loading @@ -280,6 +321,12 @@ object TestShortcuts { private val standardSystemAppSubcategoryWithCustomHomeShortcut = ShortcutSubCategory("System controls", listOf(customGoHomeShortcut)) private val recentAppsSubCategory = ShortcutSubCategory( recentAppsGroup.label!!.toString(), listOf(recentAppsCycleForwardShortcut, recentAppsCycleBackShortcut), ) private val standardSubCategory1 = ShortcutSubCategory( standardGroup1.label!!.toString(), Loading Loading @@ -375,6 +422,9 @@ object TestShortcuts { ), ) val multitaskingCategoryWithRecentAppsGroup = ShortcutCategory(type = MultiTasking, subCategories = listOf(recentAppsSubCategory)) val multitaskingGroups = listOf(standardGroup2, standardGroup1) val multitaskingCategory = ShortcutCategory( Loading Loading @@ -439,6 +489,7 @@ object TestShortcuts { category: ShortcutCategoryType, subcategoryLabel: String, shortcutLabel: String, includeInCustomization: Boolean = true, ): ShortcutCategory { return ShortcutCategory( type = category, Loading @@ -446,13 +497,13 @@ object TestShortcuts { listOf( ShortcutSubCategory( label = subcategoryLabel, shortcuts = listOf(simpleShortcut(shortcutLabel)), shortcuts = listOf(simpleShortcut(shortcutLabel, includeInCustomization)), ) ), ) } private fun simpleShortcut(label: String) = private fun simpleShortcut(label: String, includeInCustomization: Boolean = true) = Shortcut( label = label, commands = Loading @@ -467,6 +518,7 @@ object TestShortcuts { ), ) ), isCustomizable = includeInCustomization, ) val customizableInputGestureWithUnknownKeyGestureType = Loading
packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/ShortcutCategoriesUtils.kt +4 −0 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ 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.ShortcutCommand import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperExclusions 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 Loading @@ -46,6 +47,7 @@ constructor( private val context: Context, @Background private val backgroundCoroutineContext: CoroutineContext, private val inputManager: InputManager, private val shortcutHelperExclusions: ShortcutHelperExclusions, ) { fun removeUnsupportedModifiers(modifierMask: Int): Int { Loading Loading @@ -135,6 +137,8 @@ constructor( label = shortcutInfo.label, icon = toShortcutIcon(keepIcon, shortcutInfo), commands = listOf(shortcutCommand), isCustomizable = shortcutHelperExclusions.isShortcutCustomizable(shortcutInfo.label), ) } Loading
packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperCategoriesInteractor.kt +1 −3 Original line number Diff line number Diff line Loading @@ -92,9 +92,7 @@ constructor( .groupBy { it.label } .entries .map { (commonLabel, groupedShortcuts) -> Shortcut( label = commonLabel, icon = groupedShortcuts.firstOrNull()?.icon, groupedShortcuts[0].copy( commands = groupedShortcuts.flatMap { it.commands }.sortedBy { it.keys.size }, contentDescription = toContentDescription(commonLabel, groupedShortcuts.flatMap { it.commands }), Loading
packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/Shortcut.kt +9 −1 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ data class Shortcut( val commands: List<ShortcutCommand>, val icon: ShortcutIcon? = null, val contentDescription: String = "", val isCustomizable: Boolean = true, ) { val containsCustomShortcutCommands: Boolean = commands.any { it.isCustom } } Loading @@ -28,6 +29,7 @@ data class Shortcut( class ShortcutBuilder(private val label: String) { val commands = mutableListOf<ShortcutCommand>() var contentDescription = "" var isCustomizable = true fun command(builder: ShortcutCommandBuilder.() -> Unit) { commands += ShortcutCommandBuilder().apply(builder).build() Loading @@ -37,7 +39,13 @@ class ShortcutBuilder(private val label: String) { contentDescription = string.invoke() } fun build() = Shortcut(label, commands, contentDescription = contentDescription) fun build() = Shortcut( label, commands, contentDescription = contentDescription, isCustomizable = isCustomizable, ) } fun shortcut(label: String, block: ShortcutBuilder.() -> Unit): Shortcut = Loading