diff options
| author | 2024-12-03 20:39:50 +0000 | |
|---|---|---|
| committer | 2024-12-03 20:39:50 +0000 | |
| commit | 1fd831869ee3d3fcd19ddc48a4eed7bea21ed1a5 (patch) | |
| tree | e644d01636192770f32f32c9ab68a87f978f0db6 | |
| parent | 0e6a8da3ae22b8ec45cfa8e508ad71c72524b27d (diff) | |
| parent | 945855ff4c8c635054ab91d44b65b3d8c1987bfe (diff) | |
Merge "Mark recent apps shortcuts as non-customizable" into main
8 files changed, 141 insertions, 15 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/DefaultShortcutCategoriesRepositoryTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/DefaultShortcutCategoriesRepositoryTest.kt index f90ab1fcc75b..3bf59f34db76 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/DefaultShortcutCategoriesRepositoryTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/DefaultShortcutCategoriesRepositoryTest.kt @@ -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 @@ -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()) 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 cc718c784c78..75190e973c1b 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 @@ -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 = @@ -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 { @@ -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 = @@ -262,6 +297,12 @@ object TestShortcuts { listOf(standardShortcut3), ) + val recentAppsGroup = + KeyboardShortcutGroup( + "Recent apps", + listOf(recentAppsCycleForwardShortcutInfo, recentAppsCycleBackShortcutInfo), + ) + private val standardGroup1 = KeyboardShortcutGroup( "Standard group 1", @@ -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(), @@ -375,6 +422,9 @@ object TestShortcuts { ), ) + val multitaskingCategoryWithRecentAppsGroup = + ShortcutCategory(type = MultiTasking, subCategories = listOf(recentAppsSubCategory)) + val multitaskingGroups = listOf(standardGroup2, standardGroup1) val multitaskingCategory = ShortcutCategory( @@ -439,6 +489,7 @@ object TestShortcuts { category: ShortcutCategoryType, subcategoryLabel: String, shortcutLabel: String, + includeInCustomization: Boolean = true, ): ShortcutCategory { return ShortcutCategory( type = category, @@ -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 = @@ -467,6 +518,7 @@ object TestShortcuts { ), ) ), + isCustomizable = includeInCustomization, ) val customizableInputGestureWithUnknownKeyGestureType = 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 27d1a30f4346..4a725ec8abad 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 @@ -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 @@ -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 { @@ -135,6 +137,8 @@ constructor( label = shortcutInfo.label, icon = toShortcutIcon(keepIcon, shortcutInfo), commands = listOf(shortcutCommand), + isCustomizable = + shortcutHelperExclusions.isShortcutCustomizable(shortcutInfo.label), ) } 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 d62584644743..61d11f4df5e0 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 @@ -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 }), diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/Shortcut.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/Shortcut.kt index 9cc15ce809e9..55cc8e0905b6 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/Shortcut.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/Shortcut.kt @@ -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 } } @@ -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() @@ -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 = diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutHelperExclusions.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutHelperExclusions.kt new file mode 100644 index 000000000000..20b74c86973f --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutHelperExclusions.kt @@ -0,0 +1,32 @@ +/* + * 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.shared.model + +import android.content.Context +import com.android.systemui.res.R +import javax.inject.Inject + +class ShortcutHelperExclusions @Inject constructor(private val context: Context) { + private val nonCustomizableShortcutsLabels: List<String> + get() = + listOf( + context.getString(R.string.group_system_cycle_forward), + context.getString(R.string.group_system_cycle_back), + ) + + fun isShortcutCustomizable(label: String) = !nonCustomizableShortcutsLabels.contains(label) +} diff --git a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt index 2fdcf8767ae5..7d9e010e31fa 100644 --- a/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt +++ b/packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/composable/ShortcutHelper.kt @@ -565,7 +565,7 @@ private fun SubCategoryContainerDualPane( modifier = Modifier.padding(vertical = 8.dp), searchQuery = searchQuery, shortcut = shortcut, - isCustomizing = isCustomizing, + isCustomizing = isCustomizing && shortcut.isCustomizable, onCustomizationRequested = { requestInfo -> when (requestInfo) { is ShortcutCustomizationRequestInfo.Add -> 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 1828da5c0790..552cd9488657 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 @@ -38,6 +38,7 @@ import com.android.systemui.keyboard.shortcut.data.source.SystemShortcutsSource import com.android.systemui.keyboard.shortcut.domain.interactor.ShortcutCustomizationInteractor import com.android.systemui.keyboard.shortcut.domain.interactor.ShortcutHelperCategoriesInteractor import com.android.systemui.keyboard.shortcut.domain.interactor.ShortcutHelperStateInteractor +import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperExclusions import com.android.systemui.keyboard.shortcut.ui.ShortcutCustomizationDialogStarter import com.android.systemui.keyboard.shortcut.ui.viewmodel.ShortcutCustomizationViewModel import com.android.systemui.keyboard.shortcut.ui.viewmodel.ShortcutHelperViewModel @@ -80,12 +81,16 @@ var Kosmos.shortcutHelperInputShortcutsSource: KeyboardShortcutGroupsSource by var Kosmos.shortcutHelperCurrentAppShortcutsSource: KeyboardShortcutGroupsSource by Kosmos.Fixture { CurrentAppShortcutsSource(windowManager) } +val Kosmos.shortcutHelperExclusions by + Kosmos.Fixture { ShortcutHelperExclusions(applicationContext) } + val Kosmos.shortcutCategoriesUtils by Kosmos.Fixture { ShortcutCategoriesUtils( applicationContext, backgroundCoroutineContext, fakeInputManager.inputManager, + shortcutHelperExclusions, ) } @@ -107,9 +112,8 @@ val Kosmos.defaultShortcutCategoriesRepository by val Kosmos.inputGestureMaps by Kosmos.Fixture { InputGestureMaps(applicationContext) } -val Kosmos.customInputGesturesRepository by Kosmos.Fixture { - CustomInputGesturesRepository(userTracker, testDispatcher) -} +val Kosmos.customInputGesturesRepository by + Kosmos.Fixture { CustomInputGesturesRepository(userTracker, testDispatcher) } val Kosmos.customShortcutCategoriesRepository by Kosmos.Fixture { @@ -121,7 +125,7 @@ val Kosmos.customShortcutCategoriesRepository by applicationContext, inputGestureMaps, customInputGesturesRepository, - fakeInputManager.inputManager + fakeInputManager.inputManager, ) } |