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

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

Merge changes Iba9538f0,I6dedfcf0,Idcec42d9,Ic5af2c9b into main

* changes:
  Added Tests for Early custom shortcut verification
  Added early verification of selected key combination
  Backspace to clear selected shortcut key combination
  Redesigned Add Shortcut Dialog Edit Box
parents 9b71acee 7836525e
Loading
Loading
Loading
Loading
+40 −22
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.content.Intent
import android.hardware.input.FakeInputManager
import android.hardware.input.InputGestureData
import android.hardware.input.InputManager
import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_SUCCESS
@@ -57,13 +58,14 @@ class CustomInputGesturesRepositoryTest : SysuiTestCase() {
    private val secondaryUserContext: Context = mock()
    private var activeUserContext: Context = primaryUserContext

    private val kosmos = testKosmos().also {
    private val kosmos =
        testKosmos().also {
            it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { activeUserContext })
        }

    private val inputManager = kosmos.fakeInputManager.inputManager
    private val broadcastDispatcher = kosmos.broadcastDispatcher
    private val inputManagerForSecondaryUser: InputManager = mock()
    private val inputManagerForSecondaryUser: InputManager = FakeInputManager().inputManager
    private val testScope = kosmos.testScope
    private val testHelper = kosmos.shortcutHelperTestHelper
    private val customInputGesturesRepository = kosmos.customInputGesturesRepository
@@ -94,9 +96,10 @@ class CustomInputGesturesRepositoryTest : SysuiTestCase() {
    fun customInputGestures_initialValueReturnsDataFromAPI() {
        testScope.runTest {
            val customInputGestures = listOf(allAppsInputGestureData)
            whenever(
                inputManager.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY)
            ).then { return@then customInputGestures }
            whenever(inputManager.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY))
                .then {
                    return@then customInputGestures
                }

            val inputGestures by collectLastValue(customInputGesturesRepository.customInputGestures)

@@ -108,9 +111,10 @@ class CustomInputGesturesRepositoryTest : SysuiTestCase() {
    fun customInputGestures_isUpdatedToMostRecentDataAfterNewGestureIsAdded() {
        testScope.runTest {
            var customInputGestures = listOf<InputGestureData>()
            whenever(
                inputManager.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY)
            ).then { return@then customInputGestures }
            whenever(inputManager.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY))
                .then {
                    return@then customInputGestures
                }
            whenever(inputManager.addCustomInputGesture(any())).then { invocation ->
                val inputGesture = invocation.getArgument<InputGestureData>(0)
                customInputGestures = customInputGestures + inputGesture
@@ -129,10 +133,10 @@ class CustomInputGesturesRepositoryTest : SysuiTestCase() {
    fun retrieveCustomInputGestures_retrievesMostRecentData() {
        testScope.runTest {
            var customInputGestures = listOf<InputGestureData>()
            whenever(
                inputManager.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY)
            ).then { return@then customInputGestures }

            whenever(inputManager.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY))
                .then {
                    return@then customInputGestures
                }

            assertThat(customInputGesturesRepository.retrieveCustomInputGestures()).isEmpty()

@@ -143,24 +147,38 @@ class CustomInputGesturesRepositoryTest : SysuiTestCase() {
        }
    }

    @Test
    fun getInputGestureByTrigger_returnsInputGestureFromInputManager() =
        testScope.runTest {
            inputManager.addCustomInputGesture(allAppsInputGestureData)

            val inputGestureData =
                customInputGesturesRepository.getInputGestureByTrigger(
                    allAppsInputGestureData.trigger
                )

            assertThat(inputGestureData).isEqualTo(allAppsInputGestureData)
        }

    private fun setCustomInputGesturesForPrimaryUser(vararg inputGesture: InputGestureData) {
        whenever(
            inputManager.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY)
        ).thenReturn(inputGesture.toList())
        whenever(inputManager.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY))
            .thenReturn(inputGesture.toList())
    }

    private fun setCustomInputGesturesForSecondaryUser(vararg inputGesture: InputGestureData) {
        whenever(
            inputManagerForSecondaryUser.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY)
        ).thenReturn(inputGesture.toList())
                inputManagerForSecondaryUser.getCustomInputGestures(
                    /* filter= */ InputGestureData.Filter.KEY
                )
            )
            .thenReturn(inputGesture.toList())
    }

    private fun switchToSecondaryUser() {
        activeUserContext = secondaryUserContext
        broadcastDispatcher.sendIntentToMatchingReceiversOnly(
            context,
            Intent(Intent.ACTION_USER_SWITCHED)
            Intent(Intent.ACTION_USER_SWITCHED),
        )
    }

}
+57 −22
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.hardware.input.InputGestureData
import android.hardware.input.InputGestureData.createKeyTrigger
import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_ERROR_DOES_NOT_EXIST
import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_SUCCESS
import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_HOME
import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_APPLICATION
import android.hardware.input.fakeInputManager
import android.platform.test.annotations.DisableFlags
@@ -336,28 +337,6 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() {
        }
    }

    private suspend fun customizeShortcut(
        customizationRequest: ShortcutCustomizationRequestInfo,
        keyCombination: KeyCombination? = null,
    ): ShortcutCustomizationRequestResult {
        repo.onCustomizationRequested(customizationRequest)
        repo.updateUserKeyCombination(keyCombination)

        return when (customizationRequest) {
            is SingleShortcutCustomization.Add -> {
                repo.confirmAndSetShortcutCurrentlyBeingCustomized()
            }

            is SingleShortcutCustomization.Delete -> {
                repo.deleteShortcutCurrentlyBeingCustomized()
            }

            else -> {
                ShortcutCustomizationRequestResult.ERROR_OTHER
            }
        }
    }

    @Test
    @EnableFlags(FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES, FLAG_USE_KEY_GESTURE_EVENT_HANDLER)
    fun categories_isUpdatedAfterCustomShortcutsAreReset() {
@@ -387,10 +366,66 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() {
        }
    }

    @Test
    fun selectedKeyCombinationIsAvailable_whenTriggerIsNotRegisteredInInputManager() =
        testScope.runTest {
            helper.toggle(deviceId = 123)
            repo.onCustomizationRequested(allAppsShortcutAddRequest)
            repo.updateUserKeyCombination(standardKeyCombination)

            assertThat(repo.isSelectedKeyCombinationAvailable()).isTrue()
        }

    @Test
    fun selectedKeyCombinationIsNotAvailable_whenTriggerIsRegisteredInInputManager() =
        testScope.runTest {
            inputManager.addCustomInputGesture(buildInputGestureWithStandardKeyCombination())

            helper.toggle(deviceId = 123)
            repo.onCustomizationRequested(allAppsShortcutAddRequest)
            repo.updateUserKeyCombination(standardKeyCombination)

            assertThat(repo.isSelectedKeyCombinationAvailable()).isFalse()
        }

    private fun setApiAppLaunchBookmarks(appLaunchBookmarks: List<InputGestureData>) {
        whenever(inputManager.appLaunchBookmarks).thenReturn(appLaunchBookmarks)
    }

    private suspend fun customizeShortcut(
        customizationRequest: ShortcutCustomizationRequestInfo,
        keyCombination: KeyCombination? = null,
    ): ShortcutCustomizationRequestResult {
        repo.onCustomizationRequested(customizationRequest)
        repo.updateUserKeyCombination(keyCombination)

        return when (customizationRequest) {
            is SingleShortcutCustomization.Add -> {
                repo.confirmAndSetShortcutCurrentlyBeingCustomized()
            }

            is SingleShortcutCustomization.Delete -> {
                repo.deleteShortcutCurrentlyBeingCustomized()
            }

            else -> {
                ShortcutCustomizationRequestResult.ERROR_OTHER
            }
        }
    }

    private fun buildInputGestureWithStandardKeyCombination() =
        InputGestureData.Builder()
            .setKeyGestureType(KEY_GESTURE_TYPE_HOME)
            .setTrigger(
                createKeyTrigger(
                    /* keycode= */ standardKeyCombination.keyCode!!,
                    /* modifierState= */ standardKeyCombination.modifiers and
                        ALL_SUPPORTED_MODIFIERS,
                )
            )
            .build()

    private fun simpleInputGestureDataForAppLaunchShortcut(
        keyCode: Int = KEYCODE_A,
        modifiers: Int = META_CTRL_ON or META_ALT_ON,
+72 −26
Original line number Diff line number Diff line
@@ -18,11 +18,15 @@ package com.android.systemui.keyboard.shortcut.ui.viewmodel

import android.content.Context
import android.content.Context.INPUT_SERVICE
import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_ERROR_ALREADY_EXISTS
import android.hardware.input.InputGestureData
import android.hardware.input.InputGestureData.createKeyTrigger
import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_ERROR_OTHER
import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_ERROR_RESERVED_GESTURE
import android.hardware.input.InputManager.CUSTOM_INPUT_GESTURE_RESULT_SUCCESS
import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_HOME
import android.hardware.input.fakeInputManager
import android.view.KeyEvent.KEYCODE_A
import android.view.KeyEvent.META_CTRL_ON
import android.view.KeyEvent.META_META_ON
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
@@ -30,7 +34,6 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsInputGestureData
import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutAddRequest
import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutDeleteRequest
import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.goHomeInputGestureData
import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.keyDownEventWithActionKeyPressed
import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.keyDownEventWithoutActionKeyPressed
import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.keyUpEventWithActionKeyPressed
@@ -44,16 +47,17 @@ import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiSt
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState.DeleteShortcutDialog
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState.ResetShortcutDialog
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.res.R
import com.android.systemui.settings.FakeUserTracker
import com.android.systemui.settings.userTracker
import com.android.systemui.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.any
import org.mockito.kotlin.mock
import org.mockito.kotlin.whenever

@@ -63,7 +67,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {

    private val mockUserContext: Context = mock()
    private val kosmos =
        testKosmos().also {
        testKosmos().useUnconfinedTestDispatcher().also {
            it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { mockUserContext })
        }
    private val testScope = kosmos.testScope
@@ -75,6 +79,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
    fun setup() {
        helper.showFromActivity()
        whenever(mockUserContext.getSystemService(INPUT_SERVICE)).thenReturn(inputManager)
        testScope.backgroundScope.launch { viewModel.activate() }
    }

    @Test
@@ -146,8 +151,6 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
    fun uiState_becomeInactiveAfterSuccessfullySettingShortcut() {
        testScope.runTest {
            val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
            whenever(inputManager.addCustomInputGesture(any()))
                .thenReturn(CUSTOM_INPUT_GESTURE_RESULT_SUCCESS)

            openAddShortcutDialogAndSetShortcut()

@@ -166,11 +169,38 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
    }

    @Test
    fun uiState_errorMessage_isKeyCombinationInUse_whenKeyCombinationAlreadyExists() {
    fun uiState_errorMessage_onKeyPressed_isKeyCombinationInUse_whenKeyCombinationAlreadyExists() {
        testScope.runTest {
            inputManager.addCustomInputGesture(buildSimpleInputGestureWithMetaCtrlATrigger())
            val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)

            openAddShortcutDialogAndPressKeyCombination()

            assertThat((uiState as AddShortcutDialog).errorMessage)
                .isEqualTo(
                    context.getString(
                        R.string.shortcut_customizer_key_combination_in_use_error_message
                    )
                )
        }
    }

    @Test
    fun uiState_errorMessage_onKeyPressed_isEmpty_whenKeyCombinationIsAvailable() {
        testScope.runTest {
            val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)

            openAddShortcutDialogAndPressKeyCombination()

            assertThat((uiState as AddShortcutDialog).errorMessage).isEmpty()
        }
    }

    @Test
    fun uiState_errorMessage_onSetShortcut_isKeyCombinationInUse_whenKeyCombinationAlreadyExists() {
        testScope.runTest {
            inputManager.addCustomInputGesture(buildSimpleInputGestureWithMetaCtrlATrigger())
            val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
            whenever(inputManager.addCustomInputGesture(any()))
                .thenReturn(CUSTOM_INPUT_GESTURE_RESULT_ERROR_ALREADY_EXISTS)

            openAddShortcutDialogAndSetShortcut()

@@ -184,11 +214,12 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
    }

    @Test
    fun uiState_errorMessage_isKeyCombinationInUse_whenKeyCombinationIsReserved() {
    fun uiState_errorMessage_onSetShortcut_isKeyCombinationInUse_whenKeyCombinationIsReserved() {
        testScope.runTest {
            inputManager.addCustomInputGesture(buildSimpleInputGestureWithMetaCtrlATrigger())
            kosmos.fakeInputManager.addCustomInputGestureErrorCode =
                CUSTOM_INPUT_GESTURE_RESULT_ERROR_RESERVED_GESTURE
            val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
            whenever(inputManager.addCustomInputGesture(any()))
                .thenReturn(CUSTOM_INPUT_GESTURE_RESULT_ERROR_RESERVED_GESTURE)

            openAddShortcutDialogAndSetShortcut()

@@ -202,11 +233,12 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
    }

    @Test
    fun uiState_errorMessage_isGenericError_whenErrorIsUnknown() {
    fun uiState_errorMessage_onSetShortcut_isGenericError_whenErrorIsUnknown() {
        testScope.runTest {
            inputManager.addCustomInputGesture(buildSimpleInputGestureWithMetaCtrlATrigger())
            kosmos.fakeInputManager.addCustomInputGestureErrorCode =
                CUSTOM_INPUT_GESTURE_RESULT_ERROR_OTHER
            val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
            whenever(inputManager.addCustomInputGesture(any()))
                .thenReturn(CUSTOM_INPUT_GESTURE_RESULT_ERROR_OTHER)

            openAddShortcutDialogAndSetShortcut()

@@ -219,10 +251,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
    fun uiState_becomesInactiveAfterSuccessfullyDeletingShortcut() {
        testScope.runTest {
            val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
            whenever(inputManager.getCustomInputGestures(any()))
                .thenReturn(listOf(goHomeInputGestureData, allAppsInputGestureData))
            whenever(inputManager.removeCustomInputGesture(any()))
                .thenReturn(CUSTOM_INPUT_GESTURE_RESULT_SUCCESS)
            inputManager.addCustomInputGesture(allAppsInputGestureData)

            openDeleteShortcutDialogAndDeleteShortcut()

@@ -234,7 +263,6 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
    fun uiState_becomesInactiveAfterSuccessfullyResettingShortcuts() {
        testScope.runTest {
            val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
            whenever(inputManager.getCustomInputGestures(any())).thenReturn(emptyList())

            openResetShortcutDialogAndResetAllCustomShortcuts()

@@ -297,24 +325,42 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {
        }
    }

    private suspend fun openAddShortcutDialogAndSetShortcut() {
        viewModel.onShortcutCustomizationRequested(allAppsShortcutAddRequest)

    @Test
    fun uiState_pressedKeys_resetsToEmpty_onClearSelectedShortcutKeyCombination() {
        testScope.runTest {
            val uiState by collectLastValue(viewModel.shortcutCustomizationUiState)
            viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest)
            viewModel.onShortcutKeyCombinationSelected(keyDownEventWithActionKeyPressed)
            viewModel.onShortcutKeyCombinationSelected(keyUpEventWithActionKeyPressed)
            viewModel.clearSelectedKeyCombination()
            assertThat((uiState as AddShortcutDialog).pressedKeys).isEmpty()
        }
    }

    private suspend fun openAddShortcutDialogAndSetShortcut() {
        openAddShortcutDialogAndPressKeyCombination()
        viewModel.onSetShortcut()
    }

    private fun openAddShortcutDialogAndPressKeyCombination() {
        viewModel.onShortcutCustomizationRequested(allAppsShortcutAddRequest)
        viewModel.onShortcutKeyCombinationSelected(keyDownEventWithActionKeyPressed)
        viewModel.onShortcutKeyCombinationSelected(keyUpEventWithActionKeyPressed)
    }

    private suspend fun openDeleteShortcutDialogAndDeleteShortcut() {
        viewModel.onShortcutCustomizationRequested(allAppsShortcutDeleteRequest)

        viewModel.deleteShortcutCurrentlyBeingCustomized()
    }

    private suspend fun openResetShortcutDialogAndResetAllCustomShortcuts() {
        viewModel.onShortcutCustomizationRequested(ShortcutCustomizationRequestInfo.Reset)

        viewModel.resetAllCustomShortcuts()
    }

    private fun buildSimpleInputGestureWithMetaCtrlATrigger() =
        InputGestureData.Builder()
            .setKeyGestureType(KEY_GESTURE_TYPE_HOME)
            .setTrigger(createKeyTrigger(KEYCODE_A, META_CTRL_ON or META_META_ON))
            .build()
}
+23 −20
Original line number Diff line number Diff line
@@ -32,18 +32,19 @@ import com.android.systemui.keyboard.shared.model.ShortcutCustomizationRequestRe
import com.android.systemui.keyboard.shared.model.ShortcutCustomizationRequestResult.ERROR_RESERVED_COMBINATION
import com.android.systemui.keyboard.shared.model.ShortcutCustomizationRequestResult.SUCCESS
import com.android.systemui.settings.UserTracker
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.withContext
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext

@SysUISingleton
class CustomInputGesturesRepository
@Inject
constructor(private val userTracker: UserTracker,
    @Background private val bgCoroutineContext: CoroutineContext)
{
constructor(
    private val userTracker: UserTracker,
    @Background private val bgCoroutineContext: CoroutineContext,
) {

    private val userContext: Context
        get() = userTracker.createCurrentUserContext(userTracker.userContext)
@@ -55,8 +56,7 @@ constructor(private val userTracker: UserTracker,

    private val _customInputGesture = MutableStateFlow<List<InputGestureData>>(emptyList())

    val customInputGestures =
        _customInputGesture.onStart { refreshCustomInputGestures() }
    val customInputGestures = _customInputGesture.onStart { refreshCustomInputGestures() }

    fun refreshCustomInputGestures() {
        setCustomInputGestures(inputGestures = retrieveCustomInputGestures())
@@ -72,18 +72,18 @@ constructor(private val userTracker: UserTracker,
        } else emptyList()
    }

    suspend fun addCustomInputGesture(inputGesture: InputGestureData): ShortcutCustomizationRequestResult {
    suspend fun addCustomInputGesture(
        inputGesture: InputGestureData
    ): ShortcutCustomizationRequestResult {
        return withContext(bgCoroutineContext) {
            when (val result = inputManager.addCustomInputGesture(inputGesture)) {
                CUSTOM_INPUT_GESTURE_RESULT_SUCCESS -> {
                    refreshCustomInputGestures()
                    SUCCESS
                }
                CUSTOM_INPUT_GESTURE_RESULT_ERROR_ALREADY_EXISTS ->
                    ERROR_RESERVED_COMBINATION
                CUSTOM_INPUT_GESTURE_RESULT_ERROR_ALREADY_EXISTS -> ERROR_RESERVED_COMBINATION

                CUSTOM_INPUT_GESTURE_RESULT_ERROR_RESERVED_GESTURE ->
                    ERROR_RESERVED_COMBINATION
                CUSTOM_INPUT_GESTURE_RESULT_ERROR_RESERVED_GESTURE -> ERROR_RESERVED_COMBINATION

                else -> {
                    Log.w(
@@ -97,11 +97,11 @@ constructor(private val userTracker: UserTracker,
        }
    }

    suspend fun deleteCustomInputGesture(inputGesture: InputGestureData): ShortcutCustomizationRequestResult {
    suspend fun deleteCustomInputGesture(
        inputGesture: InputGestureData
    ): ShortcutCustomizationRequestResult {
        return withContext(bgCoroutineContext) {
            when (
                val result = inputManager.removeCustomInputGesture(inputGesture)
            ) {
            when (val result = inputManager.removeCustomInputGesture(inputGesture)) {
                CUSTOM_INPUT_GESTURE_RESULT_SUCCESS -> {
                    refreshCustomInputGestures()
                    SUCCESS
@@ -134,6 +134,9 @@ constructor(private val userTracker: UserTracker,
        }
    }

    suspend fun getInputGestureByTrigger(trigger: InputGestureData.Trigger): InputGestureData? =
        withContext(bgCoroutineContext) { inputManager.getInputGesture(trigger) }

    private companion object {
        private const val TAG = "CustomInputGesturesRepository"
    }
+16 −9
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.keyboard.shortcut.data.repository

import android.hardware.input.InputGestureData
import android.hardware.input.InputGestureData.Builder
import android.hardware.input.InputGestureData.Trigger
import android.hardware.input.InputGestureData.createKeyTrigger
import android.hardware.input.InputManager
import android.hardware.input.KeyGestureEvent.KeyGestureType
@@ -175,6 +176,11 @@ constructor(
        return customInputGesturesRepository.resetAllCustomInputGestures()
    }

    suspend fun isSelectedKeyCombinationAvailable(): Boolean {
        val trigger = buildTriggerFromSelectedKeyCombination() ?: return false
        return customInputGesturesRepository.getInputGestureByTrigger(trigger) == null
    }

    private fun Builder.addKeyGestureTypeForShortcutBeingCustomized(): Builder {
        val keyGestureType = getKeyGestureTypeForShortcutBeingCustomized()

@@ -222,7 +228,10 @@ constructor(
        )
    }

    private fun Builder.addTriggerFromSelectedKeyCombination(): Builder {
    private fun Builder.addTriggerFromSelectedKeyCombination(): Builder =
        setTrigger(buildTriggerFromSelectedKeyCombination())

    private fun buildTriggerFromSelectedKeyCombination(): Trigger? {
        val selectedKeyCombination = _selectedKeyCombination.value
        if (selectedKeyCombination?.keyCode == null) {
            Log.w(
@@ -230,17 +239,15 @@ constructor(
                "User requested to set shortcut but selected key combination is " +
                    "$selectedKeyCombination",
            )
            return this
            return null
        }

        return setTrigger(
            createKeyTrigger(
        return createKeyTrigger(
            /* keycode= */ selectedKeyCombination.keyCode,
            /* modifierState= */ shortcutCategoriesUtils.removeUnsupportedModifiers(
                selectedKeyCombination.modifiers
            ),
        )
        )
    }

    @VisibleForTesting
Loading