Loading packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt +1 −1 Original line number Diff line number Diff line Loading @@ -662,7 +662,7 @@ object TestShortcuts { val standardAddShortcutRequest = ShortcutCustomizationRequestInfo.Add( label = "Standard shortcut", categoryType = ShortcutCategoryType.System, categoryType = System, subCategoryLabel = "Standard subcategory", ) } packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt +2 −45 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onShortcutCustomizationRequested(ShortcutCustomizationRequestInfo.Reset) val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) assertThat(uiState).isEqualTo(ResetShortcutDialog()) assertThat(uiState).isEqualTo(ResetShortcutDialog) } } Loading @@ -118,45 +118,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onShortcutCustomizationRequested(allAppsShortcutDeleteRequest) val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) assertThat(uiState).isEqualTo(DeleteShortcutDialog()) } } @Test fun uiState_consumedOnAddDialogShown() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest) viewModel.onDialogShown() assertThat((uiState as AddShortcutDialog).isDialogShowing) .isTrue() } } @Test fun uiState_consumedOnDeleteDialogShown() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) viewModel.onShortcutCustomizationRequested(allAppsShortcutDeleteRequest) viewModel.onDialogShown() assertThat( (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() assertThat(uiState).isEqualTo(DeleteShortcutDialog) } } Loading @@ -165,7 +127,6 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest) viewModel.onDialogShown() viewModel.onDialogDismissed() assertThat(uiState).isEqualTo(ShortcutCustomizationUiState.Inactive) } Loading Loading @@ -199,7 +160,6 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) viewModel.onShortcutCustomizationRequested(allAppsShortcutAddRequest) viewModel.onDialogShown() assertThat((uiState as AddShortcutDialog).errorMessage) .isEmpty() Loading Loading @@ -339,7 +299,6 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { private suspend fun openAddShortcutDialogAndSetShortcut() { viewModel.onShortcutCustomizationRequested(allAppsShortcutAddRequest) viewModel.onDialogShown() viewModel.onKeyPressed(keyDownEventWithActionKeyPressed) viewModel.onKeyPressed(keyUpEventWithActionKeyPressed) Loading @@ -349,14 +308,12 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { private suspend fun openDeleteShortcutDialogAndDeleteShortcut() { viewModel.onShortcutCustomizationRequested(allAppsShortcutDeleteRequest) viewModel.onDialogShown() viewModel.deleteShortcutCurrentlyBeingCustomized() } private suspend fun openResetShortcutDialogAndResetAllCustomShortcuts() { viewModel.onShortcutCustomizationRequested(ShortcutCustomizationRequestInfo.Reset) viewModel.onDialogShown() viewModel.resetAllCustomShortcuts() } Loading packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt→packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt +63 −17 Original line number Diff line number Diff line Loading @@ -18,6 +18,13 @@ package com.android.systemui.keyboard.shortcut.ui.viewmodel import android.app.role.RoleManager import android.app.role.mockRoleManager import android.content.Context import android.content.Context.INPUT_SERVICE import android.content.pm.ApplicationInfo import android.content.pm.PackageManager import android.content.pm.PackageManager.NameNotFoundException import android.hardware.input.InputGestureData import android.hardware.input.fakeInputManager import android.view.KeyEvent import android.view.KeyboardShortcutGroup import android.view.KeyboardShortcutInfo Loading @@ -31,6 +38,7 @@ import com.android.systemui.coroutines.collectLastValue import com.android.systemui.coroutines.collectValues import com.android.systemui.keyboard.shortcut.data.source.FakeKeyboardShortcutGroupsSource import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsInputGestureData import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.CurrentApp import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.MultiTasking Loading @@ -56,7 +64,6 @@ import com.android.systemui.settings.FakeUserTracker import com.android.systemui.settings.fakeUserTracker import com.android.systemui.settings.userTracker import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SHORTCUT_HELPER_SHOWING import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.UnconfinedTestDispatcher Loading @@ -64,6 +71,10 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.anyString import org.mockito.kotlin.eq import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @OptIn(ExperimentalCoroutinesApi::class) @SmallTest Loading @@ -73,6 +84,9 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { private val fakeSystemSource = FakeKeyboardShortcutGroupsSource() private val fakeMultiTaskingSource = FakeKeyboardShortcutGroupsSource() private val fakeCurrentAppsSource = FakeKeyboardShortcutGroupsSource() private val mockPackageManager: PackageManager = mock() private val mockUserContext: Context = mock() private val mockApplicationInfo: ApplicationInfo = mock() private val kosmos = Kosmos().also { Loading @@ -83,7 +97,7 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { it.shortcutHelperAppCategoriesShortcutsSource = FakeKeyboardShortcutGroupsSource() it.shortcutHelperInputShortcutsSource = FakeKeyboardShortcutGroupsSource() it.shortcutHelperCurrentAppShortcutsSource = fakeCurrentAppsSource it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { context }) it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { mockUserContext }) } private val testScope = kosmos.testScope Loading @@ -91,13 +105,20 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { private val sysUiState = kosmos.sysUiState private val fakeUserTracker = kosmos.fakeUserTracker private val mockRoleManager = kosmos.mockRoleManager private val inputManager = kosmos.fakeInputManager.inputManager private val viewModel = kosmos.shortcutHelperViewModel @Before fun setUp() { fakeSystemSource.setGroups(TestShortcuts.systemGroups) fakeMultiTaskingSource.setGroups(TestShortcuts.multitaskingGroups) fakeCurrentAppsSource.setGroups(TestShortcuts.currentAppGroups) whenever(mockPackageManager.getApplicationInfo(anyString(), eq(0))).thenReturn(mockApplicationInfo) whenever(mockPackageManager.getApplicationLabel(mockApplicationInfo)).thenReturn("Current App") whenever(mockPackageManager.getApplicationIcon(anyString())).thenThrow(NameNotFoundException()) whenever(mockUserContext.packageManager).thenReturn(mockPackageManager) whenever(mockUserContext.getSystemService(INPUT_SERVICE)).thenReturn(inputManager) } @Test Loading Loading @@ -387,6 +408,31 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { assertThat(activeUiState.defaultSelectedCategory).isInstanceOf(CurrentApp::class.java) } @Test fun shortcutsUiState_shouldShowResetButton_isFalseWhenThereAreNoCustomShortcuts() = testScope.runTest { val uiState by collectLastValue(viewModel.shortcutsUiState) testHelper.showFromActivity() val activeUiState = uiState as ShortcutsUiState.Active assertThat(activeUiState.shouldShowResetButton).isFalse() } @Test fun shortcutsUiState_shouldShowResetButton_isTrueWhenThereAreCustomShortcuts() = testScope.runTest { whenever( inputManager.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY) ).thenReturn(listOf(allAppsInputGestureData)) val uiState by collectLastValue(viewModel.shortcutsUiState) testHelper.showFromActivity() val activeUiState = uiState as ShortcutsUiState.Active assertThat(activeUiState.shouldShowResetButton).isTrue() } private fun groupWithShortcutLabels( vararg shortcutLabels: String, groupLabel: String = FIRST_SIMPLE_GROUP_LABEL, Loading packages/SystemUI/res/values/strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -3814,6 +3814,9 @@ shortcut helper The helper is a component that shows the user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] --> <string name="shortcut_helper_customize_button_text">Customize</string> <!-- Description text of the button that allows user to resets all custom shortcuts in keyboard shortcut helper when in customization mode. [CHAR LIMIT=NONE] --> <string name="shortcut_helper_reset_button_text">Reset</string> <!-- Description text of the button that allows user to exit shortcut customization mode in keyboard shortcut helper The helper is a component that shows the user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] --> Loading packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutSubCategory.kt +3 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,9 @@ package com.android.systemui.keyboard.shortcut.shared.model data class ShortcutSubCategory(val label: String, val shortcuts: List<Shortcut>) data class ShortcutSubCategory(val label: String, val shortcuts: List<Shortcut>) { val containsCustomShortcuts: Boolean = shortcuts.any { it.containsCustomShortcutCommands } } class ShortcutSubCategoryBuilder(val label: String) { private val shortcuts = mutableListOf<Shortcut>() Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/data/source/TestShortcuts.kt +1 −1 Original line number Diff line number Diff line Loading @@ -662,7 +662,7 @@ object TestShortcuts { val standardAddShortcutRequest = ShortcutCustomizationRequestInfo.Add( label = "Standard shortcut", categoryType = ShortcutCategoryType.System, categoryType = System, subCategoryLabel = "Standard subcategory", ) }
packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutCustomizationViewModelTest.kt +2 −45 Original line number Diff line number Diff line Loading @@ -108,7 +108,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onShortcutCustomizationRequested(ShortcutCustomizationRequestInfo.Reset) val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) assertThat(uiState).isEqualTo(ResetShortcutDialog()) assertThat(uiState).isEqualTo(ResetShortcutDialog) } } Loading @@ -118,45 +118,7 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { viewModel.onShortcutCustomizationRequested(allAppsShortcutDeleteRequest) val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) assertThat(uiState).isEqualTo(DeleteShortcutDialog()) } } @Test fun uiState_consumedOnAddDialogShown() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest) viewModel.onDialogShown() assertThat((uiState as AddShortcutDialog).isDialogShowing) .isTrue() } } @Test fun uiState_consumedOnDeleteDialogShown() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) viewModel.onShortcutCustomizationRequested(allAppsShortcutDeleteRequest) viewModel.onDialogShown() assertThat( (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() assertThat(uiState).isEqualTo(DeleteShortcutDialog) } } Loading @@ -165,7 +127,6 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) viewModel.onShortcutCustomizationRequested(standardAddShortcutRequest) viewModel.onDialogShown() viewModel.onDialogDismissed() assertThat(uiState).isEqualTo(ShortcutCustomizationUiState.Inactive) } Loading Loading @@ -199,7 +160,6 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { testScope.runTest { val uiState by collectLastValue(viewModel.shortcutCustomizationUiState) viewModel.onShortcutCustomizationRequested(allAppsShortcutAddRequest) viewModel.onDialogShown() assertThat((uiState as AddShortcutDialog).errorMessage) .isEmpty() Loading Loading @@ -339,7 +299,6 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { private suspend fun openAddShortcutDialogAndSetShortcut() { viewModel.onShortcutCustomizationRequested(allAppsShortcutAddRequest) viewModel.onDialogShown() viewModel.onKeyPressed(keyDownEventWithActionKeyPressed) viewModel.onKeyPressed(keyUpEventWithActionKeyPressed) Loading @@ -349,14 +308,12 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() { private suspend fun openDeleteShortcutDialogAndDeleteShortcut() { viewModel.onShortcutCustomizationRequested(allAppsShortcutDeleteRequest) viewModel.onDialogShown() viewModel.deleteShortcutCurrentlyBeingCustomized() } private suspend fun openResetShortcutDialogAndResetAllCustomShortcuts() { viewModel.onShortcutCustomizationRequested(ShortcutCustomizationRequestInfo.Reset) viewModel.onDialogShown() viewModel.resetAllCustomShortcuts() } Loading
packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt→packages/SystemUI/multivalentTests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt +63 −17 Original line number Diff line number Diff line Loading @@ -18,6 +18,13 @@ package com.android.systemui.keyboard.shortcut.ui.viewmodel import android.app.role.RoleManager import android.app.role.mockRoleManager import android.content.Context import android.content.Context.INPUT_SERVICE import android.content.pm.ApplicationInfo import android.content.pm.PackageManager import android.content.pm.PackageManager.NameNotFoundException import android.hardware.input.InputGestureData import android.hardware.input.fakeInputManager import android.view.KeyEvent import android.view.KeyboardShortcutGroup import android.view.KeyboardShortcutInfo Loading @@ -31,6 +38,7 @@ import com.android.systemui.coroutines.collectLastValue import com.android.systemui.coroutines.collectValues import com.android.systemui.keyboard.shortcut.data.source.FakeKeyboardShortcutGroupsSource import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts import com.android.systemui.keyboard.shortcut.data.source.TestShortcuts.allAppsInputGestureData import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategory import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.CurrentApp import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.MultiTasking Loading @@ -56,7 +64,6 @@ import com.android.systemui.settings.FakeUserTracker import com.android.systemui.settings.fakeUserTracker import com.android.systemui.settings.userTracker import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SHORTCUT_HELPER_SHOWING import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.UnconfinedTestDispatcher Loading @@ -64,6 +71,10 @@ import kotlinx.coroutines.test.runTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.ArgumentMatchers.anyString import org.mockito.kotlin.eq import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @OptIn(ExperimentalCoroutinesApi::class) @SmallTest Loading @@ -73,6 +84,9 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { private val fakeSystemSource = FakeKeyboardShortcutGroupsSource() private val fakeMultiTaskingSource = FakeKeyboardShortcutGroupsSource() private val fakeCurrentAppsSource = FakeKeyboardShortcutGroupsSource() private val mockPackageManager: PackageManager = mock() private val mockUserContext: Context = mock() private val mockApplicationInfo: ApplicationInfo = mock() private val kosmos = Kosmos().also { Loading @@ -83,7 +97,7 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { it.shortcutHelperAppCategoriesShortcutsSource = FakeKeyboardShortcutGroupsSource() it.shortcutHelperInputShortcutsSource = FakeKeyboardShortcutGroupsSource() it.shortcutHelperCurrentAppShortcutsSource = fakeCurrentAppsSource it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { context }) it.userTracker = FakeUserTracker(onCreateCurrentUserContext = { mockUserContext }) } private val testScope = kosmos.testScope Loading @@ -91,13 +105,20 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { private val sysUiState = kosmos.sysUiState private val fakeUserTracker = kosmos.fakeUserTracker private val mockRoleManager = kosmos.mockRoleManager private val inputManager = kosmos.fakeInputManager.inputManager private val viewModel = kosmos.shortcutHelperViewModel @Before fun setUp() { fakeSystemSource.setGroups(TestShortcuts.systemGroups) fakeMultiTaskingSource.setGroups(TestShortcuts.multitaskingGroups) fakeCurrentAppsSource.setGroups(TestShortcuts.currentAppGroups) whenever(mockPackageManager.getApplicationInfo(anyString(), eq(0))).thenReturn(mockApplicationInfo) whenever(mockPackageManager.getApplicationLabel(mockApplicationInfo)).thenReturn("Current App") whenever(mockPackageManager.getApplicationIcon(anyString())).thenThrow(NameNotFoundException()) whenever(mockUserContext.packageManager).thenReturn(mockPackageManager) whenever(mockUserContext.getSystemService(INPUT_SERVICE)).thenReturn(inputManager) } @Test Loading Loading @@ -387,6 +408,31 @@ class ShortcutHelperViewModelTest : SysuiTestCase() { assertThat(activeUiState.defaultSelectedCategory).isInstanceOf(CurrentApp::class.java) } @Test fun shortcutsUiState_shouldShowResetButton_isFalseWhenThereAreNoCustomShortcuts() = testScope.runTest { val uiState by collectLastValue(viewModel.shortcutsUiState) testHelper.showFromActivity() val activeUiState = uiState as ShortcutsUiState.Active assertThat(activeUiState.shouldShowResetButton).isFalse() } @Test fun shortcutsUiState_shouldShowResetButton_isTrueWhenThereAreCustomShortcuts() = testScope.runTest { whenever( inputManager.getCustomInputGestures(/* filter= */ InputGestureData.Filter.KEY) ).thenReturn(listOf(allAppsInputGestureData)) val uiState by collectLastValue(viewModel.shortcutsUiState) testHelper.showFromActivity() val activeUiState = uiState as ShortcutsUiState.Active assertThat(activeUiState.shouldShowResetButton).isTrue() } private fun groupWithShortcutLabels( vararg shortcutLabels: String, groupLabel: String = FIRST_SIMPLE_GROUP_LABEL, Loading
packages/SystemUI/res/values/strings.xml +3 −0 Original line number Diff line number Diff line Loading @@ -3814,6 +3814,9 @@ shortcut helper The helper is a component that shows the user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] --> <string name="shortcut_helper_customize_button_text">Customize</string> <!-- Description text of the button that allows user to resets all custom shortcuts in keyboard shortcut helper when in customization mode. [CHAR LIMIT=NONE] --> <string name="shortcut_helper_reset_button_text">Reset</string> <!-- Description text of the button that allows user to exit shortcut customization mode in keyboard shortcut helper The helper is a component that shows the user which keyboard shortcuts they can use. [CHAR LIMIT=NONE] --> Loading
packages/SystemUI/src/com/android/systemui/keyboard/shortcut/shared/model/ShortcutSubCategory.kt +3 −1 Original line number Diff line number Diff line Loading @@ -16,7 +16,9 @@ package com.android.systemui.keyboard.shortcut.shared.model data class ShortcutSubCategory(val label: String, val shortcuts: List<Shortcut>) data class ShortcutSubCategory(val label: String, val shortcuts: List<Shortcut>) { val containsCustomShortcuts: Boolean = shortcuts.any { it.containsCustomShortcutCommands } } class ShortcutSubCategoryBuilder(val label: String) { private val shortcuts = mutableListOf<Shortcut>() Loading