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

Commit 7312c085 authored by helen cheuk's avatar helen cheuk
Browse files

[Action Corner] Align the behavior between keyboard shortcut and action

corner

There is already an existing method call in CommandQueue used by keyboard shortcut which would handle the different flagging of status bar, we should use the same method instead of implementing the logic all over again.
After this change, the change of status bar flagging would be transparent to action corner. Action corner will automatically pick up the flagging logic change.
Also, when new flags are off, it would expand the existing shade that have QS and notification in the same panel.

Bug: 422953284
Test: ActionCornerInteractorTest
Flag: com.android.systemui.shared.cursor_hot_corner
Change-Id: I7abab481a304a76855085c0a8885f0e7d96019a5
parent 6d6befce
Loading
Loading
Loading
Loading
+8 −55
Original line number Diff line number Diff line
@@ -35,7 +35,6 @@ import com.android.systemui.actioncorner.data.model.ActionCornerRegion.BOTTOM_RI
import com.android.systemui.actioncorner.data.model.ActionCornerState.ActiveActionCorner
import com.android.systemui.actioncorner.data.repository.ActionCornerSettingRepository
import com.android.systemui.actioncorner.data.repository.FakeActionCornerRepository
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos.Fixture
import com.android.systemui.kosmos.runTest
@@ -43,18 +42,12 @@ import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.kosmos.useUnconfinedTestDispatcher
import com.android.systemui.lifecycle.activateIn
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.scene.shared.model.Overlays
import com.android.systemui.shade.domain.interactor.enableDualShade
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.shade.domain.interactor.shadeModeInteractor
import com.android.systemui.shade.shadeTestUtil
import com.android.systemui.shared.system.actioncorner.ActionCornerConstants.HOME
import com.android.systemui.shared.system.actioncorner.ActionCornerConstants.OVERVIEW
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.statusbar.policy.data.repository.fakeUserSetupRepository
import com.android.systemui.testKosmos
import com.android.systemui.util.settings.data.repository.userAwareSecureSettingsRepository
import com.google.common.truth.Truth.assertThat
import kotlin.test.Test
import org.junit.Before
import org.junit.runner.RunWith
@@ -63,7 +56,6 @@ import org.mockito.kotlin.never
import org.mockito.kotlin.verify

@SmallTest
@EnableSceneContainer
@RunWith(AndroidJUnit4::class)
class ActionCornerInteractorTest : SysuiTestCase() {
    private val kosmos = testKosmos().useUnconfinedTestDispatcher()
@@ -75,21 +67,20 @@ class ActionCornerInteractorTest : SysuiTestCase() {
    }

    private val Kosmos.launcherProxyService by Fixture { mock<LauncherProxyService>() }
    private val Kosmos.commandQueue by Fixture { mock<CommandQueue>() }

    private val Kosmos.underTest by Fixture {
        ActionCornerInteractor(
            testScope.coroutineContext,
            actionCornerRepository,
            launcherProxyService,
            shadeModeInteractor,
            shadeInteractor,
            actionCornerSettingRepository,
            fakeUserSetupRepository,
            commandQueue,
        )
    }

    @Before
    fun setUp() {
        kosmos.enableDualShade()
        kosmos.fakeUserSetupRepository.setUserSetUp(true)
        kosmos.underTest.activateIn(kosmos.testScope)
    }
@@ -114,71 +105,33 @@ class ActionCornerInteractorTest : SysuiTestCase() {
        }

    @Test
    fun shadeCollapsed_topLeftCornerActivated_notificationsActionConfigured_expandNotificationShade() =
        kosmos.runTest {
            settingsRepository.setInt(
                ACTION_CORNER_TOP_LEFT_ACTION,
                ACTION_CORNER_ACTION_NOTIFICATIONS,
            )
            shadeTestUtil.setShadeExpansion(0f)

            actionCornerRepository.addState(
                ActiveActionCorner(ActionCornerRegion.TOP_LEFT, DEFAULT_DISPLAY)
            )

            assertThat(sceneInteractor.currentOverlays.value)
                .containsExactly(Overlays.NotificationsShade)
        }

    @Test
    fun shadeExpanded_topLeftCornerActivated_notificationsActionConfigured_collapseNotificationShade() =
    fun topLeftCornerActivated_notificationsActionConfigured_toggleNotificationShade() =
        kosmos.runTest {
            settingsRepository.setInt(
                ACTION_CORNER_TOP_LEFT_ACTION,
                ACTION_CORNER_ACTION_NOTIFICATIONS,
            )
            shadeTestUtil.setShadeExpansion(1f)

            actionCornerRepository.addState(
                ActiveActionCorner(ActionCornerRegion.TOP_LEFT, DEFAULT_DISPLAY)
            )

            assertThat(sceneInteractor.currentOverlays.value)
                .doesNotContain(Overlays.NotificationsShade)
        }

    @Test
    fun qsCollapsed_topRightCornerActivated_qsActionConfigured_expandQsPanel() =
        kosmos.runTest {
            settingsRepository.setInt(
                ACTION_CORNER_TOP_RIGHT_ACTION,
                ACTION_CORNER_ACTION_QUICK_SETTINGS,
            )
            shadeTestUtil.setQsExpansion(0f)

            actionCornerRepository.addState(
                ActiveActionCorner(ActionCornerRegion.TOP_RIGHT, DEFAULT_DISPLAY)
            )

            assertThat(sceneInteractor.currentOverlays.value)
                .containsExactly(Overlays.QuickSettingsShade)
            verify(commandQueue).toggleNotificationsPanel()
        }

    @Test
    fun qsExpanded_topRightCornerActivated_qsActionConfigured_collapseQsPanel() =
    fun topRightCornerActivated_qsActionConfigured_toggleQsPanel() =
        kosmos.runTest {
            settingsRepository.setInt(
                ACTION_CORNER_TOP_RIGHT_ACTION,
                ACTION_CORNER_ACTION_QUICK_SETTINGS,
            )
            shadeTestUtil.setQsExpansion(1f)

            actionCornerRepository.addState(
                ActiveActionCorner(ActionCornerRegion.TOP_RIGHT, DEFAULT_DISPLAY)
            )

            assertThat(sceneInteractor.currentOverlays.value)
                .doesNotContain(Overlays.QuickSettingsShade)
            verify(commandQueue).toggleQuickSettingsPanel()
        }

    @Test
+4 −40
Original line number Diff line number Diff line
@@ -32,33 +32,25 @@ import com.android.systemui.actioncorner.data.model.ActionType.QUICK_SETTINGS
import com.android.systemui.actioncorner.data.repository.ActionCornerRepository
import com.android.systemui.actioncorner.data.repository.ActionCornerSettingRepository
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.lifecycle.ExclusiveActivatable
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.shade.domain.interactor.ShadeModeInteractor
import com.android.systemui.shade.shared.model.ShadeMode.Dual
import com.android.systemui.shared.system.actioncorner.ActionCornerConstants
import com.android.systemui.statusbar.CommandQueue
import com.android.systemui.statusbar.policy.data.repository.UserSetupRepository
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.awaitCancellation
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.withContext

@SysUISingleton
class ActionCornerInteractor
@Inject
constructor(
    @Main private val mainThreadContext: CoroutineContext,
    private val repository: ActionCornerRepository,
    private val launcherProxyService: LauncherProxyService,
    private val shadeModeInteractor: ShadeModeInteractor,
    private val shadeInteractor: ShadeInteractor,
    private val actionCornerSettingRepository: ActionCornerSettingRepository,
    private val userSetupRepository: UserSetupRepository,
    private val commandQueue: CommandQueue,
) : ExclusiveActivatable() {

    override suspend fun onActivated(): Nothing {
@@ -83,28 +75,8 @@ constructor(
                            ActionCornerConstants.OVERVIEW,
                            it.displayId,
                        )
                    NOTIFICATIONS -> {
                        if (isDualShadeEnabled()) {
                            withContext(mainThreadContext) {
                                if (shadeInteractor.isShadeAnyExpanded.value) {
                                    shadeInteractor.collapseNotificationsShade(LOGGING_REASON)
                                } else {
                                    shadeInteractor.expandNotificationsShade(LOGGING_REASON)
                                }
                            }
                        }
                    }
                    QUICK_SETTINGS -> {
                        if (isDualShadeEnabled()) {
                            withContext(mainThreadContext) {
                                if (shadeInteractor.isQsExpanded.value) {
                                    shadeInteractor.collapseQuickSettingsShade(LOGGING_REASON)
                                } else {
                                    shadeInteractor.expandQuickSettingsShade(LOGGING_REASON)
                                }
                            }
                        }
                    }
                    NOTIFICATIONS -> commandQueue.toggleNotificationsPanel()
                    QUICK_SETTINGS -> commandQueue.toggleQuickSettingsPanel()
                    NONE -> {}
                }
            }
@@ -119,12 +91,4 @@ constructor(
            BOTTOM_RIGHT -> actionCornerSettingRepository.bottomRightCornerAction.value
        }
    }

    private fun isDualShadeEnabled(): Boolean {
        return SceneContainerFlag.isEnabled && shadeModeInteractor.shadeMode.value == Dual
    }

    companion object {
        private const val LOGGING_REASON = "Active action corner"
    }
}