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

Commit 7f43efda authored by Joshua Mokut's avatar Joshua Mokut Committed by Android (Google) Code Review
Browse files

Merge "Updated Logic for Build AppLaunchData for shortcut customization" into main

parents 9c5107a2 9cccf61c
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,
                    )
                )
            },