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

Commit aa345799 authored by Josh's avatar Josh
Browse files

Added Reset button for customization mode in shortcut helper

Test: manual - open shortcut helper, enter customization. Ensure reset
button appears
Flag: com.android.systemui.keyboard_shortcut_helper_shortcut_customizer
Fix: 380866710

Change-Id: I6088490f102418795ca0623517b2bb1a0896f13e
parent b83c0f52
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -662,7 +662,7 @@ object TestShortcuts {
    val standardAddShortcutRequest =
        ShortcutCustomizationRequestInfo.Add(
            label = "Standard shortcut",
            categoryType = ShortcutCategoryType.System,
            categoryType = System,
            subCategoryLabel = "Standard subcategory",
        )
}
+2 −45
Original line number Diff line number Diff line
@@ -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)
        }
    }

@@ -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)
        }
    }

@@ -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)
        }
@@ -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()
@@ -339,7 +299,6 @@ class ShortcutCustomizationViewModelTest : SysuiTestCase() {

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

        viewModel.onKeyPressed(keyDownEventWithActionKeyPressed)
        viewModel.onKeyPressed(keyUpEventWithActionKeyPressed)
@@ -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()
    }
+63 −17
Original line number Diff line number Diff line
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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 {
@@ -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
@@ -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
@@ -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,
+3 −0
Original line number Diff line number Diff line
@@ -3812,6 +3812,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] -->
+3 −1
Original line number Diff line number Diff line
@@ -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