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

Commit bb45bda7 authored by Josh's avatar Josh
Browse files

Fixed Peristent search in shortcut helper

Previously when a search query was typed in shortcut helper, this query
would persist even after shortcut helper was closed and reopened.

This fixes the issue, resetting the search query onViewClosed.

Test: ShortcutHelperViewModelTest
Flag: com.android.systemui.keyboard_shortcut_helper_rewrite
Fix: 381244038
Change-Id: Id5ff5381b40d40181a45e5717283687b757312c5
parent 7e7e2cc7
Loading
Loading
Loading
Loading
+25 −5
Original line number Diff line number Diff line
@@ -55,15 +55,15 @@ import com.android.systemui.keyboard.shortcut.shortcutHelperViewModel
import com.android.systemui.keyboard.shortcut.ui.model.IconSource
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutCategoryUi
import com.android.systemui.keyboard.shortcut.ui.model.ShortcutsUiState
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testCase
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.model.sysUiState
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.testKosmos
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
@@ -89,8 +89,7 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {
    private val mockApplicationInfo: ApplicationInfo = mock()

    private val kosmos =
        Kosmos().also {
            it.testCase = this
        testKosmos().useUnconfinedTestDispatcher().also {
            it.testDispatcher = UnconfinedTestDispatcher()
            it.shortcutHelperSystemShortcutsSource = fakeSystemSource
            it.shortcutHelperMultiTaskingShortcutsSource = fakeMultiTaskingSource
@@ -108,7 +107,6 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {
    private val inputManager = kosmos.fakeInputManager.inputManager
    private val viewModel = kosmos.shortcutHelperViewModel


    @Before
    fun setUp() {
        fakeSystemSource.setGroups(TestShortcuts.systemGroups)
@@ -433,6 +431,28 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {
            assertThat(activeUiState.shouldShowResetButton).isTrue()
        }

    @Test
    fun shortcutsUiState_searchQuery_isResetAfterHelperIsClosedAndReOpened() =
        testScope.runTest{
            val uiState by collectLastValue(viewModel.shortcutsUiState)

            openHelperAndSearchForFooString()
            assertThat((uiState as? ShortcutsUiState.Active)?.searchQuery).isEqualTo("foo")

            closeAndReopenShortcutHelper()
            assertThat((uiState as? ShortcutsUiState.Active)?.searchQuery).isEqualTo("")
        }

    private fun openHelperAndSearchForFooString(){
        testHelper.showFromActivity()
        viewModel.onSearchQueryChanged("foo")
    }

    private fun closeAndReopenShortcutHelper() {
        viewModel.onViewClosed()
        testHelper.showFromActivity()
    }

    private fun groupWithShortcutLabels(
        vararg shortcutLabels: String,
        groupLabel: String = FIRST_SIMPLE_GROUP_LABEL,
+6 −1
Original line number Diff line number Diff line
@@ -129,7 +129,7 @@ constructor(
                    val iconDrawable =
                        userContext.packageManager.getApplicationIcon(type.packageName)
                    IconSource(painter = DrawablePainter(drawable = iconDrawable))
                } catch (e: NameNotFoundException) {
                } catch (_: NameNotFoundException) {
                    Log.w(
                        "ShortcutHelperViewModel",
                        "Package not found when retrieving icon for ${type.packageName}",
@@ -234,6 +234,7 @@ constructor(

    fun onViewClosed() {
        stateInteractor.onViewClosed()
        resetSearchQuery()
    }

    fun onViewOpened() {
@@ -243,4 +244,8 @@ constructor(
    fun onSearchQueryChanged(query: String) {
        searchQuery.value = query
    }

    private fun resetSearchQuery(){
        searchQuery.value = ""
    }
}