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

Commit 3a444aad authored by Fiona Campbell's avatar Fiona Campbell Committed by Android (Google) Code Review
Browse files

Merge "Check for Adj display groups to fallback to state=off" into main

parents dfd09020 29098c74
Loading
Loading
Loading
Loading
+25 −0
Original line number Original line Diff line number Diff line
@@ -18,12 +18,16 @@ package com.android.systemui.statusbar.phone


import android.os.Handler
import android.os.Handler
import android.os.PowerManager
import android.os.PowerManager
import android.platform.test.annotations.RequiresFlagsEnabled
import android.testing.TestableLooper.RunWithLooper
import android.testing.TestableLooper.RunWithLooper
import android.view.Display
import android.view.Display
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import androidx.test.filters.SmallTest
import com.android.internal.jank.InteractionJankMonitor
import com.android.internal.jank.InteractionJankMonitor
import com.android.server.display.feature.flags.Flags as displayManagerFlags
import com.android.server.power.feature.flags.Flags as powerManagerFlags
import com.android.systemui.SysuiTestCase
import com.android.systemui.SysuiTestCase
import com.android.systemui.display.domain.interactor.DisplayStateInteractor
import com.android.systemui.keyguard.KeyguardViewMediator
import com.android.systemui.keyguard.KeyguardViewMediator
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.shade.ShadeViewController
import com.android.systemui.shade.ShadeViewController
@@ -36,6 +40,7 @@ import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.settings.GlobalSettings
import com.android.systemui.util.settings.GlobalSettings
import junit.framework.Assert.assertFalse
import junit.framework.Assert.assertFalse
import kotlinx.coroutines.flow.MutableStateFlow
import org.junit.After
import org.junit.After
import org.junit.Before
import org.junit.Before
import org.junit.Test
import org.junit.Test
@@ -68,6 +73,7 @@ class UnlockedScreenOffAnimationControllerTest : SysuiTestCase() {
    @Mock private lateinit var statusBarStateController: StatusBarStateControllerImpl
    @Mock private lateinit var statusBarStateController: StatusBarStateControllerImpl
    @Mock private lateinit var interactionJankMonitor: InteractionJankMonitor
    @Mock private lateinit var interactionJankMonitor: InteractionJankMonitor
    @Mock private lateinit var powerManager: PowerManager
    @Mock private lateinit var powerManager: PowerManager
    @Mock private lateinit var displayStateInteractor: DisplayStateInteractor
    @Mock private lateinit var handler: Handler
    @Mock private lateinit var handler: Handler


    val kosmos = testKosmos()
    val kosmos = testKosmos()
@@ -88,6 +94,7 @@ class UnlockedScreenOffAnimationControllerTest : SysuiTestCase() {
                powerManager,
                powerManager,
                { shadeLockscreenInteractor },
                { shadeLockscreenInteractor },
                { panelExpansionInteractor },
                { panelExpansionInteractor },
                { displayStateInteractor },
                handler,
                handler,
            )
            )
        controller.initialize(centralSurfaces, shadeViewController, lightRevealScrim)
        controller.initialize(centralSurfaces, shadeViewController, lightRevealScrim)
@@ -112,6 +119,7 @@ class UnlockedScreenOffAnimationControllerTest : SysuiTestCase() {
    fun testAodUiShownIfNotInteractive() {
    fun testAodUiShownIfNotInteractive() {
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
        `when`(powerManager.isInteractive).thenReturn(false)
        `when`(powerManager.isInteractive).thenReturn(false)
        `when`(displayStateInteractor.isDefaultDisplayOff).thenReturn(MutableStateFlow(false))


        val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
        val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
        controller.startAnimation()
        controller.startAnimation()
@@ -127,6 +135,7 @@ class UnlockedScreenOffAnimationControllerTest : SysuiTestCase() {
    fun testAodUiShowNotInvokedIfWakingUp() {
    fun testAodUiShowNotInvokedIfWakingUp() {
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
        `when`(powerManager.isInteractive).thenReturn(false)
        `when`(powerManager.isInteractive).thenReturn(false)
        `when`(displayStateInteractor.isDefaultDisplayOff).thenReturn(MutableStateFlow(false))


        val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
        val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
        controller.startAnimation()
        controller.startAnimation()
@@ -151,6 +160,7 @@ class UnlockedScreenOffAnimationControllerTest : SysuiTestCase() {
    fun testAodUiNotShownIfInteractive() {
    fun testAodUiNotShownIfInteractive() {
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
        `when`(powerManager.isInteractive(eq(Display.DEFAULT_DISPLAY))).thenReturn(true)
        `when`(powerManager.isInteractive(eq(Display.DEFAULT_DISPLAY))).thenReturn(true)
        `when`(displayStateInteractor.isDefaultDisplayOff).thenReturn(MutableStateFlow(false))


        val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
        val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
        controller.startAnimation()
        controller.startAnimation()
@@ -166,6 +176,7 @@ class UnlockedScreenOffAnimationControllerTest : SysuiTestCase() {
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)
        `when`(powerManager.isInteractive()).thenReturn(false)
        `when`(powerManager.isInteractive()).thenReturn(false)
        `when`(powerManager.isInteractive(eq(Display.DEFAULT_DISPLAY))).thenReturn(false)
        `when`(powerManager.isInteractive(eq(Display.DEFAULT_DISPLAY))).thenReturn(false)
        `when`(displayStateInteractor.isDefaultDisplayOff).thenReturn(MutableStateFlow(false))


        val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
        val callbackCaptor = ArgumentCaptor.forClass(Runnable::class.java)
        controller.startAnimation()
        controller.startAnimation()
@@ -184,4 +195,18 @@ class UnlockedScreenOffAnimationControllerTest : SysuiTestCase() {
        controller.startAnimation()
        controller.startAnimation()
        assertFalse(controller.isAnimationPlaying())
        assertFalse(controller.isAnimationPlaying())
    }
    }

    @RequiresFlagsEnabled(
        displayManagerFlags.FLAG_SEPARATE_TIMEOUTS,
        powerManagerFlags.FLAG_SEPARATE_TIMEOUTS_FLICKER,
    )
    @Test
    fun testNoAnimationPlaying_whenDefaultDisplayIsOff() {
        `when`(displayStateInteractor.isDefaultDisplayOff).thenReturn(MutableStateFlow(true))
        `when`(dozeParameters.canControlUnlockedScreenOff()).thenReturn(true)

        assertFalse(controller.shouldPlayUnlockedScreenOffAnimation())
        controller.startAnimation()
        assertFalse(controller.isAnimationPlaying())
    }
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -39,7 +39,7 @@ import kotlinx.coroutines.flow.stateIn
/** Aggregates display state information. */
/** Aggregates display state information. */
interface DisplayStateInteractor {
interface DisplayStateInteractor {
    /** Whether the default display is currently off. */
    /** Whether the default display is currently off. */
    val isDefaultDisplayOff: Flow<Boolean>
    val isDefaultDisplayOff: StateFlow<Boolean>


    /** Whether the device is currently in rear display mode. */
    /** Whether the device is currently in rear display mode. */
    val isInRearDisplayMode: StateFlow<Boolean>
    val isInRearDisplayMode: StateFlow<Boolean>
+11 −0
Original line number Original line Diff line number Diff line
@@ -16,9 +16,11 @@ import com.android.app.tracing.namedRunnable
import com.android.internal.jank.InteractionJankMonitor
import com.android.internal.jank.InteractionJankMonitor
import com.android.internal.jank.InteractionJankMonitor.CUJ_SCREEN_OFF
import com.android.internal.jank.InteractionJankMonitor.CUJ_SCREEN_OFF
import com.android.internal.jank.InteractionJankMonitor.CUJ_SCREEN_OFF_SHOW_AOD
import com.android.internal.jank.InteractionJankMonitor.CUJ_SCREEN_OFF_SHOW_AOD
import com.android.server.power.feature.flags.Flags as powerManagerFlags
import com.android.systemui.DejankUtils
import com.android.systemui.DejankUtils
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.display.domain.interactor.DisplayStateInteractor
import com.android.systemui.keyguard.KeyguardViewMediator
import com.android.systemui.keyguard.KeyguardViewMediator
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.shade.ShadeViewController
import com.android.systemui.shade.ShadeViewController
@@ -69,6 +71,7 @@ constructor(
    private val powerManager: PowerManager,
    private val powerManager: PowerManager,
    private val shadeLockscreenInteractorLazy: Lazy<ShadeLockscreenInteractor>,
    private val shadeLockscreenInteractorLazy: Lazy<ShadeLockscreenInteractor>,
    private val panelExpansionInteractorLazy: Lazy<PanelExpansionInteractor>,
    private val panelExpansionInteractorLazy: Lazy<PanelExpansionInteractor>,
    private val displayStateInteractorLazy: Lazy<DisplayStateInteractor>,
    @Main private val handler: Handler,
    @Main private val handler: Handler,
) : WakefulnessLifecycle.Observer, ScreenOffAnimation {
) : WakefulnessLifecycle.Observer, ScreenOffAnimation {
    private lateinit var centralSurfaces: CentralSurfaces
    private lateinit var centralSurfaces: CentralSurfaces
@@ -368,6 +371,14 @@ constructor(
            return false
            return false
        }
        }


        // If this display is off, skip animation to reduce flickers.
        if (
            powerManagerFlags.separateTimeoutsFlicker() &&
                displayStateInteractorLazy.get().isDefaultDisplayOff.value
        ) {
            return false
        }

        // Otherwise, good to go.
        // Otherwise, good to go.
        return true
        return true
    }
    }
+2 −5
Original line number Original line Diff line number Diff line
@@ -26,7 +26,6 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.runBlocking
import org.mockito.kotlin.mock
import org.mockito.kotlin.mock


@@ -126,9 +125,7 @@ class FakeDisplayRepository @Inject constructor() : DisplayRepository {
    override val pendingDisplay: Flow<PendingDisplay?>
    override val pendingDisplay: Flow<PendingDisplay?>
        get() = pendingDisplayFlow
        get() = pendingDisplayFlow


    private val _defaultDisplayOff: MutableStateFlow<Boolean> = MutableStateFlow(false)
    override val defaultDisplayOff = MutableStateFlow(false)
    override val defaultDisplayOff: Flow<Boolean>
        get() = _defaultDisplayOff.asStateFlow()


    override fun getDisplay(displayId: Int): Display? {
    override fun getDisplay(displayId: Int): Display? {
        return displays.value.find { it.displayId == displayId }
        return displays.value.find { it.displayId == displayId }
@@ -148,7 +145,7 @@ class FakeDisplayRepository @Inject constructor() : DisplayRepository {
    suspend fun emitDisplayChangeEvent(displayId: Int) = _displayChangeEvent.emit(displayId)
    suspend fun emitDisplayChangeEvent(displayId: Int) = _displayChangeEvent.emit(displayId)


    fun setDefaultDisplayOff(defaultDisplayOff: Boolean) {
    fun setDefaultDisplayOff(defaultDisplayOff: Boolean) {
        _defaultDisplayOff.value = defaultDisplayOff
        this.defaultDisplayOff.value = defaultDisplayOff
    }
    }
}
}


+10 −4
Original line number Original line Diff line number Diff line
@@ -530,7 +530,7 @@ public class PowerGroup {
    // interactivity state
    // interactivity state
    private void updateScreenPolicyLocked(boolean quiescent, boolean dozeAfterScreenOff,
    private void updateScreenPolicyLocked(boolean quiescent, boolean dozeAfterScreenOff,
            boolean bootCompleted, boolean screenBrightnessBoostInProgress,
            boolean bootCompleted, boolean screenBrightnessBoostInProgress,
            boolean brightWhenDozing) {
            boolean brightWhenDozing, boolean allAdjacentGroupsAreNonInteractive) {
        final int wakefulness = getWakefulnessLocked();
        final int wakefulness = getWakefulnessLocked();
        final int wakeLockSummary = getWakeLockSummaryLocked();
        final int wakeLockSummary = getWakeLockSummaryLocked();
        int policyReason = Display.STATE_REASON_DEFAULT_POLICY;
        int policyReason = Display.STATE_REASON_DEFAULT_POLICY;
@@ -543,7 +543,12 @@ public class PowerGroup {
        } else if (wakefulness == WAKEFULNESS_DOZING) {
        } else if (wakefulness == WAKEFULNESS_DOZING) {
            if ((wakeLockSummary & WAKE_LOCK_DOZE) != 0) {
            if ((wakeLockSummary & WAKE_LOCK_DOZE) != 0) {
                policy = DisplayPowerRequest.POLICY_DOZE;
                policy = DisplayPowerRequest.POLICY_DOZE;
            } else if (dozeAfterScreenOff) {
            } else if (dozeAfterScreenOff || (mFeatureFlags.isSeparateTimeoutsFlickerEnabled()
                    && allAdjacentGroupsAreNonInteractive
                    && mGroupId == Display.DEFAULT_DISPLAY_GROUP)) {
                // If we force dozeAfterScreenOff or
                // if we have adjacent groups, but they are all non-interactive now,
                // then set policy to OFF instead to reduce flickers.
                policy = DisplayPowerRequest.POLICY_OFF;
                policy = DisplayPowerRequest.POLICY_OFF;
            } else if (brightWhenDozing) {
            } else if (brightWhenDozing) {
                policy = DisplayPowerRequest.POLICY_BRIGHT;
                policy = DisplayPowerRequest.POLICY_BRIGHT;
@@ -585,9 +590,10 @@ public class PowerGroup {
            PowerSaveState powerSaverState, boolean quiescent,
            PowerSaveState powerSaverState, boolean quiescent,
            boolean dozeAfterScreenOff, boolean bootCompleted,
            boolean dozeAfterScreenOff, boolean bootCompleted,
            boolean screenBrightnessBoostInProgress, boolean waitForNegativeProximity,
            boolean screenBrightnessBoostInProgress, boolean waitForNegativeProximity,
            boolean brightWhenDozing) {
            boolean brightWhenDozing, boolean allAdjacentGroupsAreNonInteractive) {
        updateScreenPolicyLocked(quiescent, dozeAfterScreenOff,
        updateScreenPolicyLocked(quiescent, dozeAfterScreenOff,
                bootCompleted, screenBrightnessBoostInProgress, brightWhenDozing);
                bootCompleted, screenBrightnessBoostInProgress, brightWhenDozing,
                allAdjacentGroupsAreNonInteractive);
        mDisplayPowerRequest.screenBrightnessOverride = screenBrightnessOverride;
        mDisplayPowerRequest.screenBrightnessOverride = screenBrightnessOverride;
        mDisplayPowerRequest.screenBrightnessOverrideTag = overrideTag;
        mDisplayPowerRequest.screenBrightnessOverrideTag = overrideTag;
        mDisplayPowerRequest.useProximitySensor = useProximitySensor;
        mDisplayPowerRequest.useProximitySensor = useProximitySensor;
Loading