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

Commit 18ffb887 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "[flexiglass] Hydrate ScrimController screen state from ScrimStartable" into main

parents c9e9b20a 36308f7f
Loading
Loading
Loading
Loading
+85 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.scene.domain.startable

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.flags.EnableSceneContainer
import com.android.systemui.kosmos.runCurrent
import com.android.systemui.kosmos.runTest
import com.android.systemui.power.domain.interactor.PowerInteractor.Companion.setScreenPowerState
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.power.shared.model.ScreenPowerState
import com.android.systemui.statusbar.phone.scrimController
import com.android.systemui.testKosmos
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.clearInvocations
import org.mockito.kotlin.never
import org.mockito.kotlin.verify

@SmallTest
@RunWith(AndroidJUnit4::class)
@EnableSceneContainer
class ScrimStartablePowerTest : SysuiTestCase() {

    private val kosmos = testKosmos()
    val underTest = kosmos.scrimStartable

    @Before
    fun setUp() {
        underTest.start()
    }

    @Test
    fun onScreenTurnedOn_calledWhenScreenTurnsOn() =
        kosmos.runTest {
            kosmos.powerInteractor.setScreenPowerState(ScreenPowerState.SCREEN_OFF)
            runCurrent()
            clearInvocations(kosmos.scrimController)

            kosmos.powerInteractor.setScreenPowerState(ScreenPowerState.SCREEN_TURNING_ON)
            runCurrent()
            verify(kosmos.scrimController, never()).onScreenTurnedOn()
            verify(kosmos.scrimController, never()).onScreenTurnedOff()

            kosmos.powerInteractor.setScreenPowerState(ScreenPowerState.SCREEN_ON)
            runCurrent()
            verify(kosmos.scrimController).onScreenTurnedOn()
            verify(kosmos.scrimController, never()).onScreenTurnedOff()
        }

    @Test
    fun onScreenTurnedOff_calledWhenScreenTurnsOff() =
        kosmos.runTest {
            kosmos.powerInteractor.setScreenPowerState(ScreenPowerState.SCREEN_ON)
            runCurrent()
            clearInvocations(kosmos.scrimController)

            kosmos.powerInteractor.setScreenPowerState(ScreenPowerState.SCREEN_TURNING_OFF)
            runCurrent()
            verify(kosmos.scrimController, never()).onScreenTurnedOn()
            verify(kosmos.scrimController, never()).onScreenTurnedOff()

            kosmos.powerInteractor.setScreenPowerState(ScreenPowerState.SCREEN_OFF)
            runCurrent()
            verify(kosmos.scrimController, never()).onScreenTurnedOn()
            verify(kosmos.scrimController).onScreenTurnedOff()
        }
}
+13 −0
Original line number Diff line number Diff line
@@ -31,6 +31,8 @@ import com.android.systemui.keyguard.domain.interactor.BiometricUnlockInteractor
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.shared.model.BiometricUnlockMode
import com.android.systemui.keyguard.shared.model.BiometricUnlockModel
import com.android.systemui.power.domain.interactor.PowerInteractor
import com.android.systemui.power.shared.model.ScreenPowerState
import com.android.systemui.scene.domain.interactor.SceneContainerOcclusionInteractor
import com.android.systemui.scene.domain.interactor.SceneInteractor
import com.android.systemui.scene.shared.flag.SceneContainerFlag
@@ -66,6 +68,7 @@ constructor(
    private val alternateBouncerInteractor: AlternateBouncerInteractor,
    brightnessMirrorShowingInteractor: BrightnessMirrorShowingInteractorPassThrough,
    private val dozeServiceHost: DozeServiceHost,
    private val powerInteractor: PowerInteractor,
) : CoreStartable {

    @VisibleForTesting
@@ -207,6 +210,16 @@ constructor(
                scrimController.transitionTo(scrimState)
            }
        }

        applicationScope.launch {
            powerInteractor.screenPowerState.collect { powerState ->
                when (powerState) {
                    ScreenPowerState.SCREEN_ON -> scrimController.onScreenTurnedOn()
                    ScreenPowerState.SCREEN_OFF -> scrimController.onScreenTurnedOff()
                    else -> Unit
                }
            }
        }
    }

    private fun onKeyguardFadedAway(isKeyguardGoingAway: Boolean) {
+8 −1
Original line number Diff line number Diff line
@@ -2710,6 +2710,11 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {

        @Override
        public void onScreenTurnedOn() {
            if (SceneContainerFlag.isEnabled()) {
                // Already handled in ScrimStartable when the scene framework is enabled.
                return;
            }

            mScrimController.onScreenTurnedOn();
        }

@@ -2717,7 +2722,9 @@ public class CentralSurfacesImpl implements CoreStartable, CentralSurfaces {
        public void onScreenTurnedOff() {
            Trace.beginSection("CentralSurfaces#onScreenTurnedOff");
            mFalsingCollector.onScreenOff();
            if (!SceneContainerFlag.isEnabled()) {
                mScrimController.onScreenTurnedOff();
            }
            if (mCloseQsBeforeScreenOff) {
                mQsController.closeQs();
                mCloseQsBeforeScreenOff = false;
+14 −2
Original line number Diff line number Diff line
@@ -788,12 +788,14 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    public void testFingerprintNotification_UpdatesScrims() {
        mCentralSurfaces.notifyBiometricAuthModeChanged();
        verify(mScrimController).legacyTransitionTo(any(), any());
    }

    @Test
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    public void testFingerprintUnlock_UpdatesScrims() {
        // Simulate unlocking from AoD with fingerprint.
        when(mBiometricUnlockController.getMode())
@@ -803,6 +805,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    public void testTransitionLaunch_goesToUnlocked() {
        mCentralSurfaces.setBarStateForTest(StatusBarState.KEYGUARD);
        mCentralSurfaces.showKeyguardImpl();
@@ -814,6 +817,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    public void testSetExpansionAffectsAlpha_whenKeyguardShowingButGoingAwayForAnyReason() {
        mCentralSurfaces.updateScrimController();
        verify(mScrimController).setExpansionAffectsAlpha(eq(true));
@@ -838,6 +842,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    public void testTransitionLaunch_noPreview_doesntGoUnlocked() {
        mCentralSurfaces.setBarStateForTest(StatusBarState.KEYGUARD);
        when(mKeyguardStateController.isShowing()).thenReturn(true);
@@ -850,6 +855,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    public void testSetOccluded_propagatesToScrimController() {
        ArgumentCaptor<KeyguardStateController.Callback> callbackCaptor =
                ArgumentCaptor.forClass(KeyguardStateController.Callback.class);
@@ -866,6 +872,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    public void testPulseWhileDozing_updatesScrimController() {
        mCentralSurfaces.setBarStateForTest(StatusBarState.KEYGUARD);
        when(mKeyguardStateController.isShowing()).thenReturn(true);
@@ -883,6 +890,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    public void testSetDozingNotUnlocking_transitionToAOD_cancelKeyguardFadingAway() {
        setDozing(true);
        when(mKeyguardStateController.isShowing()).thenReturn(false);
@@ -895,6 +903,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    public void testNotOccluding_QSNotExpanded_flagOn_doesNotTransitionScrimState() {
        when(mAlternateBouncerInteractor.isVisibleState()).thenReturn(true);

@@ -910,6 +919,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    public void testNotOccluding_QSExpanded_flagOn_doesTransitionScrimStateToKeyguard() {
        when(mAlternateBouncerInteractor.isVisibleState()).thenReturn(true);

@@ -925,6 +935,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    public void testEnteringGlanceableHub_updatesScrim() {
        // Transition to the glanceable hub.
        mKosmos.getCommunalRepository()
@@ -946,6 +957,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    public void testEnteringGlanceableHub_whenDreaming_updatesScrim() {
        when(mKeyguardStateController.isShowing()).thenReturn(true);
        when(mKeyguardStateController.isOccluded()).thenReturn(true);
@@ -1163,7 +1175,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    @EnableFlags(QSComposeFragment.FLAG_NAME)
    public void brightnesShowingChanged_qsUiRefactorFlagEnabled_ScrimControllerNotified() {
        mBrightnessMirrorShowingRepository.setMirrorShowing(true);
@@ -1180,7 +1192,7 @@ public class CentralSurfacesImplTest extends SysuiTestCase {
    }

    @Test
    @DisableSceneContainer
    @DisableSceneContainer // ScrimStartable updates scrims when the scene framework is enabled.
    @DisableFlags(QSComposeFragment.FLAG_NAME)
    public void brightnesShowingChanged_flagsDisabled_ScrimControllerNotified() {
        mBrightnessMirrorShowingRepository.setMirrorShowing(true);
+2 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.Kosmos.Fixture
import com.android.systemui.kosmos.applicationCoroutineScope
import com.android.systemui.power.domain.interactor.powerInteractor
import com.android.systemui.scene.domain.interactor.sceneContainerOcclusionInteractor
import com.android.systemui.scene.domain.interactor.sceneInteractor
import com.android.systemui.settings.brightness.domain.interactor.brightnessMirrorShowingInteractor
@@ -43,5 +44,6 @@ val Kosmos.scrimStartable by Fixture {
        alternateBouncerInteractor = alternateBouncerInteractor,
        brightnessMirrorShowingInteractor = brightnessMirrorShowingInteractor,
        dozeServiceHost = dozeServiceHost,
        powerInteractor = powerInteractor,
    )
}