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

Commit 9cccf61c authored by Josh's avatar Josh
Browse files

Updated Logic for Build AppLaunchData for shortcut customization

Logic for build appLaunch data for shortcut customization has been
updated as default apps in apps shortcut category have their
appLaunchData computed and cached while user-added apps have their
appLaunchData built as componentData from packageName and className.

Test: CustomShortcutCategoriesRepositoryTest
Flag: com.android.systemui.extended_apps_shortcut_category
Bug: 403244725
Change-Id: Ie54684bd84302c7ee19ba2666dc0e8fbe7907ae1
parent 9308ef59
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.keyboard.shortcut.data.repository
import android.content.Context
import android.content.Context.INPUT_SERVICE
import android.hardware.input.AppLaunchData
import android.hardware.input.AppLaunchData.ComponentData
import android.hardware.input.AppLaunchData.RoleData
import android.hardware.input.InputGestureData
import android.hardware.input.InputGestureData.createKeyTrigger
@@ -280,6 +281,29 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() {
            assertThat(inputGestureData?.action?.appLaunchData()).isNotNull()
        }

    @Test
    fun buildInputGestureDataForAppLaunchShortcut_addsComponentDataForNonDefaultAppShortcuts() =
        testScope.runTest {
            helper.toggle(deviceId = 123)

            repo.onCustomizationRequested(
                SingleShortcutCustomization.Add(
                    categoryType = ShortcutCategoryType.AppCategories,
                    defaultShortcutCommand = null,
                    packageName = TEST_PACKAGE,
                    className = TEST_CLASS,
                )
            )
            repo.updateUserKeyCombination(standardKeyCombination)

            val inputGestureData = repo.buildInputGestureDataForShortcutBeingCustomized()

            assertThat(inputGestureData?.action?.appLaunchData())
                .isEqualTo(
                    ComponentData(/* packageName= */ TEST_PACKAGE, /* className= */ TEST_CLASS)
                )
        }

    @Test
    @EnableFlags(FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES, FLAG_USE_KEY_GESTURE_EVENT_HANDLER)
    fun deleteShortcut_successfullyRetrievesGestureDataAndDeletesShortcut() {
@@ -480,4 +504,9 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() {
                    key("A")
                },
        )

    private companion object {
        const val TEST_PACKAGE = "com.test.package"
        const val TEST_CLASS = "TestClass"
    }
}
+10 −2
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.keyboard.shortcut.data.repository

import android.hardware.input.AppLaunchData
import android.hardware.input.InputGestureData
import android.hardware.input.InputGestureData.Builder
import android.hardware.input.InputGestureData.KeyTrigger
@@ -255,9 +256,16 @@ constructor(
            return this
        }

        val defaultShortcutCommand = shortcutBeingCustomized.defaultShortcutCommand ?: return this
        val defaultShortcutCommand = shortcutBeingCustomized.defaultShortcutCommand
        val appLaunchData =
            if (defaultShortcutCommand == null) {
                AppLaunchData.createLaunchDataForComponent(
                    /* packageName= */ shortcutBeingCustomized.packageName,
                    /* className= */ shortcutBeingCustomized.className
                )
            } else{
                appLaunchDataRepository.getAppLaunchDataForShortcutWithCommand(defaultShortcutCommand)
            }

        return if (appLaunchData == null) this else this.setAppLaunchData(appLaunchData)
    }
+6 −0
Original line number Diff line number Diff line
@@ -23,12 +23,16 @@ sealed interface ShortcutCustomizationRequestInfo {
        val categoryType: ShortcutCategoryType
        val subCategoryLabel: String
        val defaultShortcutCommand: ShortcutCommand?
        val packageName: String
        val className: String

        data class Add(
            override val label: String = "",
            override val categoryType: ShortcutCategoryType = ShortcutCategoryType.System,
            override val subCategoryLabel: String = "",
            override val defaultShortcutCommand: ShortcutCommand? = null,
            override val packageName: String = "",
            override val className: String = "",
        ) : SingleShortcutCustomization

        data class Delete(
@@ -37,6 +41,8 @@ sealed interface ShortcutCustomizationRequestInfo {
            override val subCategoryLabel: String = "",
            override val defaultShortcutCommand: ShortcutCommand? = null,
            val customShortcutCommand: ShortcutCommand? = null,
            override val packageName: String = "",
            override val className: String = "",
        ) : SingleShortcutCustomization
    }

+4 −0
Original line number Diff line number Diff line
@@ -669,6 +669,8 @@ private fun Shortcut(
                    ShortcutCustomizationRequestInfo.SingleShortcutCustomization.Add(
                        label = shortcut.label,
                        defaultShortcutCommand = shortcut.commands.firstOrNull { !it.isCustom },
                        packageName = shortcut.pkgName,
                        className = shortcut.className
                    )
                )
            },
@@ -678,6 +680,8 @@ private fun Shortcut(
                        label = shortcut.label,
                        defaultShortcutCommand = shortcut.commands.firstOrNull { !it.isCustom },
                        customShortcutCommand = shortcut.commands.firstOrNull { it.isCustom },
                        packageName = shortcut.pkgName,
                        className = shortcut.className,
                    )
                )
            },