Loading packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperInteractor.kt +26 −2 Original line number Diff line number Diff line Loading @@ -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) } } } packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/view/ShortcutHelperActivity.kt +2 −1 Original line number Diff line number Diff line Loading @@ -63,12 +63,13 @@ constructor( setUpSheetDismissListener() setUpDismissOnTouchOutside() observeFinishRequired() viewModel.onViewOpened() } override fun onDestroy() { super.onDestroy() if (isFinishing) { viewModel.onUserLeave() viewModel.onViewClosed() } } Loading packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModel.kt +6 −2 Original line number Diff line number Diff line Loading @@ -38,7 +38,11 @@ constructor( .distinctUntilChanged() .flowOn(backgroundDispatcher) fun onUserLeave() { interactor.onUserLeave() fun onViewClosed() { interactor.onViewClosed() } fun onViewOpened() { interactor.onViewOpened() } } packages/SystemUI/src/com/android/systemui/model/SysUiState.java +4 −0 Original line number Diff line number Diff line Loading @@ -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); Loading packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt +29 −4 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading Loading @@ -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() } Loading @@ -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) Loading @@ -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
packages/SystemUI/src/com/android/systemui/keyboard/shortcut/domain/interactor/ShortcutHelperInteractor.kt +26 −2 Original line number Diff line number Diff line Loading @@ -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) } } }
packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/view/ShortcutHelperActivity.kt +2 −1 Original line number Diff line number Diff line Loading @@ -63,12 +63,13 @@ constructor( setUpSheetDismissListener() setUpDismissOnTouchOutside() observeFinishRequired() viewModel.onViewOpened() } override fun onDestroy() { super.onDestroy() if (isFinishing) { viewModel.onUserLeave() viewModel.onViewClosed() } } Loading
packages/SystemUI/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModel.kt +6 −2 Original line number Diff line number Diff line Loading @@ -38,7 +38,11 @@ constructor( .distinctUntilChanged() .flowOn(backgroundDispatcher) fun onUserLeave() { interactor.onUserLeave() fun onViewClosed() { interactor.onViewClosed() } fun onViewOpened() { interactor.onViewOpened() } }
packages/SystemUI/src/com/android/systemui/model/SysUiState.java +4 −0 Original line number Diff line number Diff line Loading @@ -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); Loading
packages/SystemUI/tests/src/com/android/systemui/keyboard/shortcut/ui/viewmodel/ShortcutHelperViewModelTest.kt +29 −4 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading Loading @@ -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() } Loading @@ -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) Loading @@ -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() } }