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

Commit c56d4ecf authored by Chris Göllner's avatar Chris Göllner Committed by Android (Google) Code Review
Browse files

Merge "Shortcut Helper - Set shortcut helper visibility state in SysUiState" into main

parents f59f32eb 2907308a
Loading
Loading
Loading
Loading
+26 −2
Original line number Diff line number Diff line
@@ -17,19 +17,43 @@
package com.android.systemui.keyboard.shortcut.domain.interactor

import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.keyboard.shortcut.data.repository.ShortcutHelperRepository
import com.android.systemui.keyboard.shortcut.shared.model.ShortcutHelperState
import com.android.systemui.model.SysUiState
import com.android.systemui.settings.DisplayTracker
import com.android.systemui.shared.system.QuickStepContract
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.launch

@SysUISingleton
class ShortcutHelperInteractor
@Inject
constructor(private val repository: ShortcutHelperRepository) {
constructor(
    private val displayTracker: DisplayTracker,
    @Background private val backgroundScope: CoroutineScope,
    private val sysUiState: SysUiState,
    private val repository: ShortcutHelperRepository
) {

    val state: Flow<ShortcutHelperState> = repository.state

    fun onUserLeave() {
    fun onViewClosed() {
        repository.hide()
        setSysUiStateFlagEnabled(false)
    }

    fun onViewOpened() {
        setSysUiStateFlagEnabled(true)
    }

    private fun setSysUiStateFlagEnabled(enabled: Boolean) {
        backgroundScope.launch {
            sysUiState
                .setFlag(QuickStepContract.SYSUI_STATE_SHORTCUT_HELPER_SHOWING, enabled)
                .commitUpdate(displayTracker.defaultDisplayId)
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -63,12 +63,13 @@ constructor(
        setUpSheetDismissListener()
        setUpDismissOnTouchOutside()
        observeFinishRequired()
        viewModel.onViewOpened()
    }

    override fun onDestroy() {
        super.onDestroy()
        if (isFinishing) {
            viewModel.onUserLeave()
            viewModel.onViewClosed()
        }
    }

+6 −2
Original line number Diff line number Diff line
@@ -38,7 +38,11 @@ constructor(
            .distinctUntilChanged()
            .flowOn(backgroundDispatcher)

    fun onUserLeave() {
        interactor.onUserLeave()
    fun onViewClosed() {
        interactor.onViewClosed()
    }

    fun onViewOpened() {
        interactor.onViewOpened()
    }
}
+4 −0
Original line number Diff line number Diff line
@@ -73,6 +73,10 @@ public class SysUiState implements Dumpable {
        return mFlags;
    }

    public boolean isFlagEnabled(@SystemUiStateFlags long flag) {
        return (mFlags & flag) != 0;
    }

    /** Methods to this call can be chained together before calling {@link #commitUpdate(int)}. */
    public SysUiState setFlag(@SystemUiStateFlags long flag, boolean enabled) {
        final Boolean overrideOrNull = mSceneContainerPlugin.flagValueOverride(flag);
+29 −4
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@ 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.model.sysUiState
import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_SHORTCUT_HELPER_SHOWING
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
@@ -47,7 +49,7 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {

    private val testScope = kosmos.testScope
    private val testHelper = kosmos.shortcutHelperTestHelper

    private val sysUiState = kosmos.sysUiState
    private val viewModel = kosmos.shortcutHelperViewModel

    @Test
@@ -90,12 +92,12 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {
        }

    @Test
    fun shouldShow_falseAfterViewDestroyed() =
    fun shouldShow_falseAfterViewClosed() =
        testScope.runTest {
            val shouldShow by collectLastValue(viewModel.shouldShow)

            testHelper.toggle(deviceId = 567)
            viewModel.onUserLeave()
            viewModel.onViewClosed()

            assertThat(shouldShow).isFalse()
        }
@@ -108,7 +110,7 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {
            testHelper.hideForSystem()
            testHelper.toggle(deviceId = 987)
            testHelper.showFromActivity()
            viewModel.onUserLeave()
            viewModel.onViewClosed()
            testHelper.hideFromActivity()
            testHelper.hideForSystem()
            testHelper.toggle(deviceId = 456)
@@ -127,4 +129,27 @@ class ShortcutHelperViewModelTest : SysuiTestCase() {
            val shouldShowNew by collectLastValue(viewModel.shouldShow)
            assertThat(shouldShowNew).isEqualTo(shouldShow)
        }

    @Test
    fun sysUiStateFlag_disabledByDefault() =
        testScope.runTest {
            assertThat(sysUiState.isFlagEnabled(SYSUI_STATE_SHORTCUT_HELPER_SHOWING)).isFalse()
        }

    @Test
    fun sysUiStateFlag_trueAfterViewOpened() =
        testScope.runTest {
            viewModel.onViewOpened()

            assertThat(sysUiState.isFlagEnabled(SYSUI_STATE_SHORTCUT_HELPER_SHOWING)).isTrue()
        }

    @Test
    fun sysUiStateFlag_falseAfterViewClosed() =
        testScope.runTest {
            viewModel.onViewOpened()
            viewModel.onViewClosed()

            assertThat(sysUiState.isFlagEnabled(SYSUI_STATE_SHORTCUT_HELPER_SHOWING)).isFalse()
        }
}
Loading