Loading packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/CustomShortcutCategoriesRepositoryTest.kt +32 −3 Original line number Diff line number Diff line Loading @@ -36,14 +36,14 @@ import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyboard.shared.model.ShortcutCustomizationRequestResult import com.android.systemui.keyboard.shortcut.customShortcutCategoriesRepository import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.ALL_SUPPORTED_MODIFIERS import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutAddRequest import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsInputGestureData import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allCustomizableInputGesturesWithSimpleShortcutCombinations import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutAddRequest import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutCategory import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutDeleteRequest import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allCustomizableInputGesturesWithSimpleShortcutCombinations import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.customizableInputGestureWithUnknownKeyGestureType import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.expectedShortcutCategoriesWithSimpleShortcutCombination import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.goHomeInputGestureData import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutDeleteRequest import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.standardKeyCombination import com.android.systemui.keyboard.shortcut.shared.model.KeyCombination import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCustomizationRequestInfo Loading Loading @@ -323,4 +323,33 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() { } } } @Test @EnableFlags(FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES, FLAG_USE_KEY_GESTURE_EVENT_HANDLER) fun categories_isUpdatedAfterCustomShortcutsAreReset() { testScope.runTest { // TODO(b/380445594) refactor tests and move these stubbings to ShortcutHelperTestHelper var customInputGestures = listOf(allAppsInputGestureData) whenever(inputManager.getCustomInputGestures(anyOrNull())).then { return@then customInputGestures } whenever( inputManager.removeAllCustomInputGestures( /* filter = */ InputGestureData.Filter.KEY ) ) .then { customInputGestures = emptyList() return@then CUSTOM_INPUT_GESTURE_RESULT_SUCCESS } val categories by collectLastValue(repo.categories) helper.toggle(deviceId = 123) repo.onCustomizationRequested(ShortcutCustomizationRequestInfo.Reset) assertThat(categories).containsExactly(allAppsShortcutCategory) repo.resetAllCustomShortcuts() assertThat(categories).isEmpty() } } } packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt +0 −12 Original line number Diff line number Diff line Loading @@ -49,7 +49,6 @@ import com.android.systemui.keyboard.shortcut.shared.model.ShortcutKey import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory import com.android.systemui.keyboard.shortcut.shared.model.shortcut import com.android.systemui.keyboard.shortcut.shared.model.shortcutCategory import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState import com.android.systemui.res.R object TestShortcuts { Loading Loading @@ -626,9 +625,6 @@ object TestShortcuts { } } val expectedStandardDeleteShortcutUiState = ShortcutCustomizationUiState.DeleteShortcutDialog(isDialogShowing = false) val keyDownEventWithoutActionKeyPressed = androidx.compose.ui.input.key.KeyEvent( android.view.KeyEvent( Loading Loading @@ -671,12 +667,4 @@ object TestShortcuts { categoryType = ShortcutCategoryType.System, subCategoryLabel = "Standard subcategory", ) val expectedStandardAddShortcutUiState = ShortcutCustomizationUiState.AddShortcutDialog( shortcutLabel = "Standard shortcut", defaultCustomShortcutModifierKey = ShortcutKey.Icon.ResIdIcon(R.drawable.ic_ksh_key_meta), isDialogShowing = false, ) } packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt +67 −20 Original line number Diff line number Diff line Loading @@ -28,25 +28,26 @@ import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase 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.expectedStandardAddShortcutUiState import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.expectedStandardDeleteShortcutUiState 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 import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutAddRequest import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.standardAddShortcutRequest import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutDeleteRequest import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCustomizationRequestInfo import com.android.systemui.keyboard.shortcut.shared.model.ShortcutKey import com.android.systemui.keyboard.shortcut.shortcutCustomizationViewModelFactory import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.testCase import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState.AddShortcutDialog 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.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.test.runTest import org.junit.Before Loading @@ -62,8 +63,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { private val mockUserContext: Context = mock() private val kosmos = Kosmos().also { it.testCase = this testKosmos().also { it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { mockUserContext }) } private val testScope = kosmos.testScope Loading Loading @@ -92,7 +92,23 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest) val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) assertThat(uiState).isEqualTo(expectedStandardAddShortcutUiState) assertThat(uiState).isEqualTo( AddShortcutDialog( shortcutLabel = "Standard shortcut", defaultCustomShortcutModifierKey = ShortcutKey.Icon.ResIdIcon(R.drawable.ic_ksh_key_meta), ) ) } } @Test fun uiState_correctlyUpdatedWhenResetShortcutCustomizationIsRequested() { testScope.runTest { viewModel.onShortcutCustomizationRequested(ShortcutCustomizationRequestInfo.Reset) val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) assertThat(uiState).isEqualTo(ResetShortcutDialog()) } } Loading @@ -102,7 +118,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onShortcutCustomizationRequested(allAppsShortcutDeleteRequest) val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) assertThat(uiState).isEqualTo(expectedStandardDeleteShortcutUiState) assertThat(uiState).isEqualTo(DeleteShortcutDialog()) } } Loading @@ -113,7 +129,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest) viewModel.onDialogShown() assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).isDialogShowing) assertThat((uiState as AddShortcutDialog).isDialogShowing) .isTrue() } } Loading @@ -126,12 +142,24 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onDialogShown() assertThat( (uiState as ShortcutCustomizationUiState.DeleteShortcutDialog).isDialogShowing (uiState as DeleteShortcutDialog).isDialogShowing ) .isTrue() } } @Test fun uiState_consumedOnResetDialogShown() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) viewModel.onShortcutCustomizationRequested(ShortcutCustomizationRequestInfo.Reset) viewModel.onDialogShown() assertThat((uiState as ResetShortcutDialog).isDialogShowing) .isTrue() } } @Test fun uiState_inactiveAfterDialogIsDismissed() { testScope.runTest { Loading @@ -148,7 +176,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest) assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).pressedKeys) assertThat((uiState as AddShortcutDialog).pressedKeys) .isEmpty() } } Loading @@ -173,7 +201,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onShortcutCustomizationRequested(allAppsShortcutAddRequest) viewModel.onDialogShown() assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).errorMessage) assertThat((uiState as AddShortcutDialog).errorMessage) .isEmpty() } } Loading @@ -187,7 +215,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { openAddShortcutDialogAndSetShortcut() assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).errorMessage) assertThat((uiState as AddShortcutDialog).errorMessage) .isEqualTo( context.getString( R.string.shortcut_customizer_key_combination_in_use_error_message Loading @@ -205,7 +233,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { openAddShortcutDialogAndSetShortcut() assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).errorMessage) assertThat((uiState as AddShortcutDialog).errorMessage) .isEqualTo( context.getString( R.string.shortcut_customizer_key_combination_in_use_error_message Loading @@ -223,7 +251,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { openAddShortcutDialogAndSetShortcut() assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).errorMessage) assertThat((uiState as AddShortcutDialog).errorMessage) .isEqualTo(context.getString(R.string.shortcut_customizer_generic_error_message)) } } Loading @@ -243,6 +271,18 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { } } @Test fun uiState_becomesInactiveAfterSuccessfullyResettingShortcuts() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) whenever(inputManager.getCustomInputGestures(any())).thenReturn(emptyList()) openResetShortcutDialogAndResetAllCustomShortcuts() assertThat(uiState).isEqualTo(ShortcutCustomizationUiState.Inactive) } } @Test fun onKeyPressed_handlesKeyEvents_whereActionKeyIsAlsoPressed() { testScope.runTest { Loading Loading @@ -272,7 +312,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onKeyPressed(keyUpEventWithActionKeyPressed) // Note that Action Key is excluded as it's already displayed on the UI assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).pressedKeys) assertThat((uiState as AddShortcutDialog).pressedKeys) .containsExactly(ShortcutKey.Text("Ctrl"), ShortcutKey.Text("A")) } } Loading @@ -286,13 +326,13 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onKeyPressed(keyUpEventWithActionKeyPressed) // Note that Action Key is excluded as it's already displayed on the UI assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).pressedKeys) assertThat((uiState as AddShortcutDialog).pressedKeys) .containsExactly(ShortcutKey.Text("Ctrl"), ShortcutKey.Text("A")) // Close the dialog and show it again viewModel.onDialogDismissed() viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest) assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).pressedKeys) assertThat((uiState as AddShortcutDialog).pressedKeys) .isEmpty() } } Loading @@ -313,4 +353,11 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.deleteShortcutCurrentlyBeingCustomized() } private suspend fun openResetShortcutDialogAndResetAllCustomShortcuts() { viewModel.onShortcutCustomizationRequested(ShortcutCustomizationRequestInfo.Reset) viewModel.onDialogShown() viewModel.resetAllCustomShortcuts() } } packages/SystemUI/res/values/strings.xml +13 −0 Original line number Diff line number Diff line Loading @@ -3772,6 +3772,11 @@ The helper is a component that shows the user which keyboard shortcuts they can use. Also allows the user to add/remove custom shortcuts.[CHAR LIMIT=NONE] --> <string name="shortcut_customize_mode_remove_shortcut_dialog_title">Remove shortcut?</string> <!-- Title at the top of the keyboard shortcut helper reset shortcut dialog. This dialog allows the user to remove all custom shortcuts the user has set, resetting to default shortcuts only. Shortcut helper is a component that shows the user which keyboard shortcuts they can use. Also allows the user to add/remove custom shortcuts.[CHAR LIMIT=NONE] --> <string name="shortcut_customize_mode_reset_shortcut_dialog_title">Reset back to default?</string> <!-- Sub title at the top of the keyboard shortcut helper customization dialog. Explains to the user what action they need to take in the customization dialog to assign a new custom shortcut. The shortcut customize dialog allows users to add/remove custom shortcuts Loading @@ -3782,6 +3787,10 @@ users to add/remove custom shortcuts [CHAR LIMIT=NONE] --> <string name="shortcut_customize_mode_remove_shortcut_description">This will delete your custom shortcut permanently.</string> <!-- Sub title at the top of the reset custom shortcut dialog. Explains to the user that the action they're about to take will remove all custom shortcuts they have set, resetting to default shortcuts only. The shortcut customize dialog allows users to add/remove custom shortcuts [CHAR LIMIT=NONE] --> <string name="shortcut_customize_mode_reset_shortcut_description">This will delete all your custom shortcuts permanently.</string> <!-- Placeholder text shown in the search box of the keyboard shortcut helper, when the user hasn't typed in anything in the search box yet. The helper is a component that shows the user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] --> Loading Loading @@ -3849,6 +3858,10 @@ confirm and remove previously added custom shortcut. The helper is a component that shows the user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] --> <string name="shortcut_helper_customize_dialog_remove_button_label">Remove</string> <!-- Label on the reset shortcut button in keyboard shortcut helper customize dialog, that allows user to confirm and reset all added custom shortcut. The helper is a component that shows the user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] --> <string name="shortcut_helper_customize_dialog_reset_button_label">Yes, reset</string> <!-- Label on the cancel button in keyboard shortcut helper customize dialog, that allows user to cancel and exit shortcut customization dialog, returning to the main shortcut helper page. The helper is a component that shows the user which keyboard shortcuts they can use. Loading packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/CustomInputGesturesRepository.kt +21 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,11 @@ constructor(private val userTracker: UserTracker, _customInputGesture.onStart { refreshCustomInputGestures() } private fun refreshCustomInputGestures() { _customInputGesture.value = retrieveCustomInputGestures() setCustomInputGestures(inputGestures = retrieveCustomInputGestures()) } private fun setCustomInputGestures(inputGestures: List<InputGestureData>) { _customInputGesture.value = inputGestures } fun retrieveCustomInputGestures(): List<InputGestureData> { Loading Loading @@ -112,6 +116,22 @@ constructor(private val userTracker: UserTracker, } } suspend fun resetAllCustomInputGestures(): ShortcutCustomizationRequestResult { return withContext(bgCoroutineContext) { try { inputManager.removeAllCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY) setCustomInputGestures(emptyList()) SUCCESS } catch (e: Exception) { Log.w( TAG, "Attempted to remove all custom shortcut but ran into a remote error: $e", ) ERROR_OTHER } } } private companion object { private const val TAG = "CustomInputGesturesRepository" } Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/repository/CustomShortcutCategoriesRepositoryTest.kt +32 −3 Original line number Diff line number Diff line Loading @@ -36,14 +36,14 @@ import com.android.systemui.coroutines.collectLastValue import com.android.systemui.keyboard.shared.model.ShortcutCustomizationRequestResult import com.android.systemui.keyboard.shortcut.customShortcutCategoriesRepository import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.ALL_SUPPORTED_MODIFIERS import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutAddRequest import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsInputGestureData import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allCustomizableInputGesturesWithSimpleShortcutCombinations import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutAddRequest import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutCategory import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutDeleteRequest import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allCustomizableInputGesturesWithSimpleShortcutCombinations import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.customizableInputGestureWithUnknownKeyGestureType import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.expectedShortcutCategoriesWithSimpleShortcutCombination import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.goHomeInputGestureData import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutDeleteRequest import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.standardKeyCombination import com.android.systemui.keyboard.shortcut.shared.model.KeyCombination import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCustomizationRequestInfo Loading Loading @@ -323,4 +323,33 @@ class CustomShortcutCategoriesRepositoryTest : SysuiTestCase() { } } } @Test @EnableFlags(FLAG_ENABLE_CUSTOMIZABLE_INPUT_GESTURES, FLAG_USE_KEY_GESTURE_EVENT_HANDLER) fun categories_isUpdatedAfterCustomShortcutsAreReset() { testScope.runTest { // TODO(b/380445594) refactor tests and move these stubbings to ShortcutHelperTestHelper var customInputGestures = listOf(allAppsInputGestureData) whenever(inputManager.getCustomInputGestures(anyOrNull())).then { return@then customInputGestures } whenever( inputManager.removeAllCustomInputGestures( /* filter = */ InputGestureData.Filter.KEY ) ) .then { customInputGestures = emptyList() return@then CUSTOM_INPUT_GESTURE_RESULT_SUCCESS } val categories by collectLastValue(repo.categories) helper.toggle(deviceId = 123) repo.onCustomizationRequested(ShortcutCustomizationRequestInfo.Reset) assertThat(categories).containsExactly(allAppsShortcutCategory) repo.resetAllCustomShortcuts() assertThat(categories).isEmpty() } } }
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt +0 −12 Original line number Diff line number Diff line Loading @@ -49,7 +49,6 @@ import com.android.systemui.keyboard.shortcut.shared.model.ShortcutKey import com.android.systemui.keyboard.shortcut.shared.model.ShortcutSubCategory import com.android.systemui.keyboard.shortcut.shared.model.shortcut import com.android.systemui.keyboard.shortcut.shared.model.shortcutCategory import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState import com.android.systemui.res.R object TestShortcuts { Loading Loading @@ -626,9 +625,6 @@ object TestShortcuts { } } val expectedStandardDeleteShortcutUiState = ShortcutCustomizationUiState.DeleteShortcutDialog(isDialogShowing = false) val keyDownEventWithoutActionKeyPressed = androidx.compose.ui.input.key.KeyEvent( android.view.KeyEvent( Loading Loading @@ -671,12 +667,4 @@ object TestShortcuts { categoryType = ShortcutCategoryType.System, subCategoryLabel = "Standard subcategory", ) val expectedStandardAddShortcutUiState = ShortcutCustomizationUiState.AddShortcutDialog( shortcutLabel = "Standard shortcut", defaultCustomShortcutModifierKey = ShortcutKey.Icon.ResIdIcon(R.drawable.ic_ksh_key_meta), isDialogShowing = false, ) }
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt +67 −20 Original line number Diff line number Diff line Loading @@ -28,25 +28,26 @@ import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase 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.expectedStandardAddShortcutUiState import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.expectedStandardDeleteShortcutUiState 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 import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutAddRequest import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.standardAddShortcutRequest import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsShortcutDeleteRequest import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCustomizationRequestInfo import com.android.systemui.keyboard.shortcut.shared.model.ShortcutKey import com.android.systemui.keyboard.shortcut.shortcutCustomizationViewModelFactory import com.android.systemui.keyboard.shortcut.shortcutHelperTestHelper import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState import com.android.systemui.kosmos.Kosmos import com.android.systemui.kosmos.testCase import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCustomizationUiState.AddShortcutDialog 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.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.test.runTest import org.junit.Before Loading @@ -62,8 +63,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { private val mockUserContext: Context = mock() private val kosmos = Kosmos().also { it.testCase = this testKosmos().also { it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { mockUserContext }) } private val testScope = kosmos.testScope Loading Loading @@ -92,7 +92,23 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest) val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) assertThat(uiState).isEqualTo(expectedStandardAddShortcutUiState) assertThat(uiState).isEqualTo( AddShortcutDialog( shortcutLabel = "Standard shortcut", defaultCustomShortcutModifierKey = ShortcutKey.Icon.ResIdIcon(R.drawable.ic_ksh_key_meta), ) ) } } @Test fun uiState_correctlyUpdatedWhenResetShortcutCustomizationIsRequested() { testScope.runTest { viewModel.onShortcutCustomizationRequested(ShortcutCustomizationRequestInfo.Reset) val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) assertThat(uiState).isEqualTo(ResetShortcutDialog()) } } Loading @@ -102,7 +118,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onShortcutCustomizationRequested(allAppsShortcutDeleteRequest) val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) assertThat(uiState).isEqualTo(expectedStandardDeleteShortcutUiState) assertThat(uiState).isEqualTo(DeleteShortcutDialog()) } } Loading @@ -113,7 +129,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest) viewModel.onDialogShown() assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).isDialogShowing) assertThat((uiState as AddShortcutDialog).isDialogShowing) .isTrue() } } Loading @@ -126,12 +142,24 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onDialogShown() assertThat( (uiState as ShortcutCustomizationUiState.DeleteShortcutDialog).isDialogShowing (uiState as DeleteShortcutDialog).isDialogShowing ) .isTrue() } } @Test fun uiState_consumedOnResetDialogShown() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) viewModel.onShortcutCustomizationRequested(ShortcutCustomizationRequestInfo.Reset) viewModel.onDialogShown() assertThat((uiState as ResetShortcutDialog).isDialogShowing) .isTrue() } } @Test fun uiState_inactiveAfterDialogIsDismissed() { testScope.runTest { Loading @@ -148,7 +176,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest) assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).pressedKeys) assertThat((uiState as AddShortcutDialog).pressedKeys) .isEmpty() } } Loading @@ -173,7 +201,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onShortcutCustomizationRequested(allAppsShortcutAddRequest) viewModel.onDialogShown() assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).errorMessage) assertThat((uiState as AddShortcutDialog).errorMessage) .isEmpty() } } Loading @@ -187,7 +215,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { openAddShortcutDialogAndSetShortcut() assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).errorMessage) assertThat((uiState as AddShortcutDialog).errorMessage) .isEqualTo( context.getString( R.string.shortcut_customizer_key_combination_in_use_error_message Loading @@ -205,7 +233,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { openAddShortcutDialogAndSetShortcut() assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).errorMessage) assertThat((uiState as AddShortcutDialog).errorMessage) .isEqualTo( context.getString( R.string.shortcut_customizer_key_combination_in_use_error_message Loading @@ -223,7 +251,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { openAddShortcutDialogAndSetShortcut() assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).errorMessage) assertThat((uiState as AddShortcutDialog).errorMessage) .isEqualTo(context.getString(R.string.shortcut_customizer_generic_error_message)) } } Loading @@ -243,6 +271,18 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { } } @Test fun uiState_becomesInactiveAfterSuccessfullyResettingShortcuts() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) whenever(inputManager.getCustomInputGestures(any())).thenReturn(emptyList()) openResetShortcutDialogAndResetAllCustomShortcuts() assertThat(uiState).isEqualTo(ShortcutCustomizationUiState.Inactive) } } @Test fun onKeyPressed_handlesKeyEvents_whereActionKeyIsAlsoPressed() { testScope.runTest { Loading Loading @@ -272,7 +312,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onKeyPressed(keyUpEventWithActionKeyPressed) // Note that Action Key is excluded as it's already displayed on the UI assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).pressedKeys) assertThat((uiState as AddShortcutDialog).pressedKeys) .containsExactly(ShortcutKey.Text("Ctrl"), ShortcutKey.Text("A")) } } Loading @@ -286,13 +326,13 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onKeyPressed(keyUpEventWithActionKeyPressed) // Note that Action Key is excluded as it's already displayed on the UI assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).pressedKeys) assertThat((uiState as AddShortcutDialog).pressedKeys) .containsExactly(ShortcutKey.Text("Ctrl"), ShortcutKey.Text("A")) // Close the dialog and show it again viewModel.onDialogDismissed() viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest) assertThat((uiState as ShortcutCustomizationUiState.AddShortcutDialog).pressedKeys) assertThat((uiState as AddShortcutDialog).pressedKeys) .isEmpty() } } Loading @@ -313,4 +353,11 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.deleteShortcutCurrentlyBeingCustomized() } private suspend fun openResetShortcutDialogAndResetAllCustomShortcuts() { viewModel.onShortcutCustomizationRequested(ShortcutCustomizationRequestInfo.Reset) viewModel.onDialogShown() viewModel.resetAllCustomShortcuts() } }
packages/SystemUI/res/values/strings.xml +13 −0 Original line number Diff line number Diff line Loading @@ -3772,6 +3772,11 @@ The helper is a component that shows the user which keyboard shortcuts they can use. Also allows the user to add/remove custom shortcuts.[CHAR LIMIT=NONE] --> <string name="shortcut_customize_mode_remove_shortcut_dialog_title">Remove shortcut?</string> <!-- Title at the top of the keyboard shortcut helper reset shortcut dialog. This dialog allows the user to remove all custom shortcuts the user has set, resetting to default shortcuts only. Shortcut helper is a component that shows the user which keyboard shortcuts they can use. Also allows the user to add/remove custom shortcuts.[CHAR LIMIT=NONE] --> <string name="shortcut_customize_mode_reset_shortcut_dialog_title">Reset back to default?</string> <!-- Sub title at the top of the keyboard shortcut helper customization dialog. Explains to the user what action they need to take in the customization dialog to assign a new custom shortcut. The shortcut customize dialog allows users to add/remove custom shortcuts Loading @@ -3782,6 +3787,10 @@ users to add/remove custom shortcuts [CHAR LIMIT=NONE] --> <string name="shortcut_customize_mode_remove_shortcut_description">This will delete your custom shortcut permanently.</string> <!-- Sub title at the top of the reset custom shortcut dialog. Explains to the user that the action they're about to take will remove all custom shortcuts they have set, resetting to default shortcuts only. The shortcut customize dialog allows users to add/remove custom shortcuts [CHAR LIMIT=NONE] --> <string name="shortcut_customize_mode_reset_shortcut_description">This will delete all your custom shortcuts permanently.</string> <!-- Placeholder text shown in the search box of the keyboard shortcut helper, when the user hasn't typed in anything in the search box yet. The helper is a component that shows the user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] --> Loading Loading @@ -3849,6 +3858,10 @@ confirm and remove previously added custom shortcut. The helper is a component that shows the user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] --> <string name="shortcut_helper_customize_dialog_remove_button_label">Remove</string> <!-- Label on the reset shortcut button in keyboard shortcut helper customize dialog, that allows user to confirm and reset all added custom shortcut. The helper is a component that shows the user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] --> <string name="shortcut_helper_customize_dialog_reset_button_label">Yes, reset</string> <!-- Label on the cancel button in keyboard shortcut helper customize dialog, that allows user to cancel and exit shortcut customization dialog, returning to the main shortcut helper page. The helper is a component that shows the user which keyboard shortcuts they can use. Loading
packages/SystemUI/src/com/android/systemui/keyboard/shortcut/data/repository/CustomInputGesturesRepository.kt +21 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,11 @@ constructor(private val userTracker: UserTracker, _customInputGesture.onStart { refreshCustomInputGestures() } private fun refreshCustomInputGestures() { _customInputGesture.value = retrieveCustomInputGestures() setCustomInputGestures(inputGestures = retrieveCustomInputGestures()) } private fun setCustomInputGestures(inputGestures: List<InputGestureData>) { _customInputGesture.value = inputGestures } fun retrieveCustomInputGestures(): List<InputGestureData> { Loading Loading @@ -112,6 +116,22 @@ constructor(private val userTracker: UserTracker, } } suspend fun resetAllCustomInputGestures(): ShortcutCustomizationRequestResult { return withContext(bgCoroutineContext) { try { inputManager.removeAllCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY) setCustomInputGestures(emptyList()) SUCCESS } catch (e: Exception) { Log.w( TAG, "Attempted to remove all custom shortcut but ran into a remote error: $e", ) ERROR_OTHER } } } private companion object { private const val TAG = "CustomInputGesturesRepository" } Loading