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

Commit 5df44e99 authored by Lucas Silva's avatar Lucas Silva
Browse files

Avoid dismissing shade when launching activities from communal hub

As the shade is closed when an activity is launched from the hub, trying
to dismiss the shade will cause it to flicker open. This change avoids
this by not dismissing the shade.

This change also ensures that the hub remains visible while a
showWhenLocked activity opens over the hub.

Bug: 331591373
Fixes: 342395651
Flag: com.android.systemui.glanceable_hub
Test: atest SystemUiRoboTests
Change-Id: I550b646a1a1572a062d9a4c8090cd16dd60650aa
parent 61aacad9
Loading
Loading
Loading
Loading
+24 −0
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.kosmos.testScope
import com.android.systemui.statusbar.notificationShadeWindowController
import com.android.systemui.statusbar.phone.centralSurfaces
import com.android.systemui.statusbar.phone.centralSurfacesOptional
import com.android.systemui.testKosmos
import com.android.systemui.util.settings.fakeSettings
import com.google.common.truth.Truth.assertThat
@@ -49,6 +51,7 @@ import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.whenever

@OptIn(ExperimentalCoroutinesApi::class)
@SmallTest
@@ -74,6 +77,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
                        applicationScope = applicationCoroutineScope,
                        bgScope = applicationCoroutineScope,
                        mainDispatcher = testDispatcher,
                        centralSurfacesOpt = centralSurfacesOptional,
                    )
                    .apply { start() }

@@ -127,6 +131,7 @@ class CommunalSceneStartableTest : SysuiTestCase() {
    fun occluded_forceBlankScene() =
        with(kosmos) {
            testScope.runTest {
                whenever(centralSurfaces.isLaunchingActivityOverLockscreen).thenReturn(false)
                val scene by collectLastValue(communalInteractor.desiredScene)
                communalInteractor.changeScene(CommunalScenes.Communal)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)
@@ -141,6 +146,25 @@ class CommunalSceneStartableTest : SysuiTestCase() {
            }
        }

    @Test
    fun occluded_doesNotForceBlankSceneIfLaunchingActivityOverLockscreen() =
        with(kosmos) {
            testScope.runTest {
                whenever(centralSurfaces.isLaunchingActivityOverLockscreen).thenReturn(true)
                val scene by collectLastValue(communalInteractor.desiredScene)
                communalInteractor.changeScene(CommunalScenes.Communal)
                assertThat(scene).isEqualTo(CommunalScenes.Communal)

                updateDocked(true)
                fakeKeyguardTransitionRepository.sendTransitionSteps(
                    from = KeyguardState.GLANCEABLE_HUB,
                    to = KeyguardState.OCCLUDED,
                    testScope = this
                )
                assertThat(scene).isEqualTo(CommunalScenes.Communal)
            }
        }

    @Test
    fun deviceDocked_doesNotForceCommunalIfTransitioningFromCommunal() =
        with(kosmos) {
+2 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ class WidgetInteractionHandlerTest : SysuiTestCase() {
        verify(activityStarter)
            .startPendingIntentMaybeDismissingKeyguard(
                eq(testIntent),
                eq(false),
                isNull(),
                notNull(),
                refEq(fillInIntent),
@@ -91,6 +92,7 @@ class WidgetInteractionHandlerTest : SysuiTestCase() {
        verify(activityStarter)
            .startPendingIntentMaybeDismissingKeyguard(
                eq(testIntent),
                eq(false),
                isNull(),
                isNull(),
                refEq(fillInIntent),
+6 −1
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.systemui.SysuiTestCase
import com.android.systemui.animation.ActivityTransitionAnimator
import com.android.systemui.animation.LaunchableView
import com.android.systemui.assist.AssistManager
import com.android.systemui.communal.domain.interactor.CommunalSceneInteractor
import com.android.systemui.keyguard.KeyguardViewMediator
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.plugins.ActivityStarter.OnDismissAction
@@ -94,6 +95,7 @@ class LegacyActivityStarterInternalImplTest : SysuiTestCase() {
    @Mock private lateinit var deviceProvisionedController: DeviceProvisionedController
    @Mock private lateinit var userTracker: UserTracker
    @Mock private lateinit var activityIntentHelper: ActivityIntentHelper
    @Mock private lateinit var communalSceneInteractor: CommunalSceneInteractor
    private lateinit var underTest: LegacyActivityStarterInternalImpl
    private val mainExecutor = FakeExecutor(FakeSystemClock())
    private val shadeAnimationInteractor =
@@ -127,6 +129,7 @@ class LegacyActivityStarterInternalImplTest : SysuiTestCase() {
                userTracker = userTracker,
                activityIntentHelper = activityIntentHelper,
                mainExecutor = mainExecutor,
                communalSceneInteractor = communalSceneInteractor,
            )
        whenever(userTracker.userHandle).thenReturn(UserHandle.OWNER)
    }
@@ -138,7 +141,7 @@ class LegacyActivityStarterInternalImplTest : SysuiTestCase() {
        whenever(keyguardStateController.isShowing).thenReturn(true)
        whenever(deviceProvisionedController.isDeviceProvisioned).thenReturn(true)

        underTest.startPendingIntentDismissingKeyguard(pendingIntent)
        underTest.startPendingIntentDismissingKeyguard(intent = pendingIntent, dismissShade = true)
        mainExecutor.runAllReady()

        verify(statusBarKeyguardViewManager)
@@ -232,6 +235,7 @@ class LegacyActivityStarterInternalImplTest : SysuiTestCase() {

        underTest.startPendingIntentDismissingKeyguard(
            intent = pendingIntent,
            dismissShade = true,
            intentSentUiThreadCallback = null,
            associatedView = associatedView,
        )
@@ -344,6 +348,7 @@ class LegacyActivityStarterInternalImplTest : SysuiTestCase() {
    ) {
        underTest.startPendingIntentDismissingKeyguard(
            intent = intent,
            dismissShade = true,
            intentSentUiThreadCallback = intentSentUiThreadCallback,
            animationController = animationController,
            showOverLockscreen = true,
+3 −1
Original line number Diff line number Diff line
@@ -70,9 +70,11 @@ public interface ActivityStarter {
    /**
     * Similar to {@link #startPendingIntentMaybeDismissingKeyguard(PendingIntent, Runnable,
     * ActivityTransitionAnimator.Controller)}, but also specifies a fill-in intent and extra
     * options that could be used to populate the pending intent and launch the activity.
     * option that could be used to populate the pending intent and launch the activity. This also
     * allows the caller to avoid dismissing the shade.
     */
    void startPendingIntentMaybeDismissingKeyguard(PendingIntent intent,
            boolean dismissShade,
            @Nullable Runnable intentSentUiThreadCallback,
            @Nullable ActivityTransitionAnimator.Controller animationController,
            @Nullable Intent fillInIntent,
+12 −2
Original line number Diff line number Diff line
@@ -32,10 +32,13 @@ import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInterac
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.statusbar.NotificationShadeWindowController
import com.android.systemui.statusbar.phone.CentralSurfaces
import com.android.systemui.util.kotlin.emitOnStart
import com.android.systemui.util.kotlin.getValue
import com.android.systemui.util.kotlin.sample
import com.android.systemui.util.settings.SettingsProxyExt.observerFlow
import com.android.systemui.util.settings.SystemSettings
import java.util.Optional
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds
@@ -67,6 +70,7 @@ constructor(
    private val keyguardTransitionInteractor: KeyguardTransitionInteractor,
    private val keyguardInteractor: KeyguardInteractor,
    private val systemSettings: SystemSettings,
    centralSurfacesOpt: Optional<CentralSurfaces>,
    private val notificationShadeWindowController: NotificationShadeWindowController,
    @Application private val applicationScope: CoroutineScope,
    @Background private val bgScope: CoroutineScope,
@@ -78,6 +82,8 @@ constructor(

    private var isDreaming: Boolean = false

    private val centralSurfaces: CentralSurfaces? by centralSurfacesOpt

    override fun start() {
        // Handle automatically switching based on keyguard state.
        keyguardTransitionInteractor.startedKeyguardTransitionStep
@@ -184,11 +190,15 @@ constructor(
        val to = lastStartedTransition.to
        val from = lastStartedTransition.from
        val docked = dockManager.isDocked
        val launchingActivityOverLockscreen =
            centralSurfaces?.isLaunchingActivityOverLockscreen ?: false

        return when {
            to == KeyguardState.OCCLUDED -> {
            to == KeyguardState.OCCLUDED && !launchingActivityOverLockscreen -> {
                // Hide communal when an activity is started on keyguard, to ensure the activity
                // underneath the hub is shown.
                // underneath the hub is shown. When launching activities over lockscreen, we only
                // change scenes once the activity launch animation is finished, so avoid
                // changing the scene here.
                CommunalScenes.Blank
            }
            to == KeyguardState.GLANCEABLE_HUB && from == KeyguardState.OCCLUDED -> {
Loading