Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 945855ff authored by Josh's avatar Josh
Browse files

Mark recent apps shortcuts as non-customizable

Marking the shortcuts "Cycle forward through recent apps" and "Cycle
backward through recent apps" as non-customizable.

Test: DefaultShortcutCategoriesRepositoryTest
Flag: com.android.systemui.keyboard_shortcut_helper_shortcut_customizer
Fix: 380439529
Change-Id: I36b904bc79636149f784125f8e81448d7bcf53cd
parent d8dacaf6
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -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())

+58 −6
Original line number Diff line number Diff line
@@ -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 =
+4 −0
Original line number Diff line number Diff line
@@ -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),
        )
    }

+1 −3
Original line number Diff line number Diff line
@@ -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 }),
+9 −1
Original line number Diff line number Diff line
@@ -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 =
Loading