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

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

Merge "Added Bugfix Flag to guard App Shortcut Removal Fix." into main

parents 6119ac28 c92830fb
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -2169,3 +2169,13 @@ flag {
    description: "Enables global actions focus on TV."
    bug: "402759931"
}

flag {
    name: "app_shortcut_removal_fix"
    namespace: "systemui"
    description: "During custom app shortcut removal, use custom shortcut command as key to find the right InputGestureData to be deleted"
    bug: "405058325"
    metadata {
        purpose: PURPOSE_BUGFIX
    }
}
+10 −5
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.hardware.input.Flags.FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES
import com.android.hardware.input.Flags.FLAG_USE_KEY_GESTURE_EVENT_HANDLER
import com.android.systemui.Flags.FLAG_APP_SHORTCUT_REMOVAL_FIX
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyboard.shared.model.ShortcutCustomizationRequestResult
@@ -320,7 +321,11 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() {
    }

    @Test
    @EnableFlags(FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES, FLAG_USE_KEY_GESTURE_EVENT_HANDLER)
    @EnableFlags(
        FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES,
        FLAG_USE_KEY_GESTURE_EVENT_HANDLER,
        FLAG_APP_SHORTCUT_REMOVAL_FIX,
    )
    fun removeAppCategoryShortcut_successfullyRetrievesGestureDataAndDeletesTheCorrectShortcut() {
        testScope.runTest {
            // We are collecting this because the flow is a cold flow but we need its value as a
@@ -340,8 +345,8 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() {
            }
            helper.toggle(deviceId = 123)

            customizeShortcut(customizationRequest = ctrlAltAShortcutDeleteRequest)
            assertThat(customInputGestures).containsExactly(ctrlAltBShortcut)
            customizeShortcut(customizationRequest = ctrlAltBShortcutDeleteRequest)
            assertThat(customInputGestures).containsExactly(ctrlAltAShortcut)
        }
    }

@@ -493,7 +498,7 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() {

    private val ctrlAltAShortcut = simpleInputGestureDataForAppLaunchShortcut()
    private val ctrlAltBShortcut = simpleInputGestureDataForAppLaunchShortcut(keyCode = KEYCODE_B)
    private val ctrlAltAShortcutDeleteRequest =
    private val ctrlAltBShortcutDeleteRequest =
        SingleShortcutCustomization.Delete(
            categoryType = ShortcutCategoryType.AppCategories,
            subCategoryLabel = context.getString(R.string.keyboard_shortcut_group_applications),
@@ -501,7 +506,7 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() {
                shortcutCommand {
                    key("Ctrl")
                    key("Alt")
                    key("A")
                    key("B")
                },
        )

+33 −19
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.hardware.input.KeyGestureEvent.KeyGestureType
import android.hardware.input.KeyGlyphMap
import android.util.Log
import androidx.annotation.VisibleForTesting
import com.android.systemui.Flags.appShortcutRemovalFix
import com.android.systemui.Flags.shortcutHelperKeyGlyph
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
@@ -152,15 +153,21 @@ constructor(

    private fun retrieveInputGestureDataForShortcutBeingDeleted(): InputGestureData? {
        val keyGestureTypeForShortcutBeingDeleted = getKeyGestureTypeForShortcutBeingCustomized()
        if (appShortcutRemovalFix()) {
            val inputGesturesMatchingKeyGestureType =
                customInputGesturesRepository.retrieveCustomInputGestures().filter {
                    it.action.keyGestureType() == keyGestureTypeForShortcutBeingDeleted
                }

        return if (keyGestureTypeForShortcutBeingDeleted == KEY_GESTURE_TYPE_LAUNCH_APPLICATION) {
            return if (
                keyGestureTypeForShortcutBeingDeleted == KEY_GESTURE_TYPE_LAUNCH_APPLICATION
            ) {
                val shortcutBeingDeleted = getShortcutBeingCustomized() as Delete
                if (shortcutBeingDeleted.customShortcutCommand == null) {
                Log.w(TAG, "Requested to delete custom shortcut but customShortcutCommand was null")
                    Log.w(
                        TAG,
                        "Requested to delete custom shortcut but customShortcutCommand was null",
                    )
                    return null
                }

@@ -173,6 +180,11 @@ constructor(
            } else {
                inputGesturesMatchingKeyGestureType.firstOrNull()
            }
        } else {
            return customInputGesturesRepository.retrieveCustomInputGestures().firstOrNull {
                it.action.keyGestureType() == keyGestureTypeForShortcutBeingDeleted
            }
        }
    }

    suspend fun confirmAndSetShortcutCurrentlyBeingCustomized():
@@ -261,10 +273,12 @@ constructor(
            if (defaultShortcutCommand == null) {
                AppLaunchData.createLaunchDataForComponent(
                    /* packageName= */ shortcutBeingCustomized.packageName,
                    /* className= */ shortcutBeingCustomized.className
                    /* className= */ shortcutBeingCustomized.className,
                )
            } else {
                appLaunchDataRepository.getAppLaunchDataForShortcutWithCommand(defaultShortcutCommand)
                appLaunchDataRepository.getAppLaunchDataForShortcutWithCommand(
                    defaultShortcutCommand
                )
            }

        return if (appLaunchData == null) this else this.setAppLaunchData(appLaunchData)