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

Commit b3ab9ac7 authored by Chandru S's avatar Chandru S
Browse files

Reset internal state in DepthController whenever blur gets disabled by battery saver

Other changes: rename property to match its intended use.

Fixes: 402691460
Bug: 381263619
Test: pending unit tests, tracked in b/381263619
Flag: com.android.systemui.bouncer_ui_revamp
Change-Id: I303afaf3699f8e68ec98f6c83ecd4b2e32dc94e6
parent efaf9f20
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -73,7 +73,7 @@ class WindowRootViewModelTest : SysuiTestCase() {

            assertThat(blurRadius).isEqualTo(0f)

            kosmos.windowRootViewBlurRepository.blurRadius.value = 60
            kosmos.windowRootViewBlurRepository.blurRequestedByShade.value = 60
            runCurrent()

            assertThat(blurRadius).isEqualTo(0f)
+23 −4
Original line number Diff line number Diff line
@@ -360,7 +360,9 @@ constructor(
                        interpolator = Interpolators.FAST_OUT_SLOW_IN
                        addUpdateListener { animation: ValueAnimator ->
                            wakeAndUnlockBlurData =
                                WakeAndUnlockBlurData(blurUtils.blurRadiusOfRatio(animation.animatedValue as Float))
                                WakeAndUnlockBlurData(
                                    blurUtils.blurRadiusOfRatio(animation.animatedValue as Float)
                                )
                        }
                        addListener(
                            object : AnimatorListenerAdapter() {
@@ -443,8 +445,10 @@ constructor(
        applicationScope.launch {
            wallpaperInteractor.wallpaperSupportsAmbientMode.collect { supported ->
                wallpaperSupportsAmbientMode = supported
                if (getNewWakeBlurRadius(prevDozeAmount) == wakeAndUnlockBlurData.radius
                    && !wakeAndUnlockBlurData.useZoom) {
                if (
                    getNewWakeBlurRadius(prevDozeAmount) == wakeAndUnlockBlurData.radius &&
                        !wakeAndUnlockBlurData.useZoom
                ) {
                    // Update wake and unlock radius only if the previous value comes from wake-up.
                    updateWakeBlurRadius(prevDozeAmount)
                }
@@ -467,6 +471,21 @@ constructor(
                scheduleUpdate()
            }
        }

        applicationScope.launch {
            windowRootViewBlurInteractor.isBlurCurrentlySupported.collect { supported ->
                if (supported) {
                    // when battery saver changes, try scheduling an update.
                    scheduleUpdate()
                } else {
                    // when blur becomes unsupported, no more updates will be scheduled,
                    // reset updateScheduled state.
                    updateScheduled = false
                    // reset blur and internal state to 0
                    onBlurApplied(0, 0.0f)
                }
            }
        }
    }

    private fun updateResources() {
+1 −2
Original line number Diff line number Diff line
@@ -16,13 +16,12 @@

package com.android.systemui.window.data.repository

import com.android.systemui.window.data.repository.WindowRootViewBlurRepository
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

class NoopWindowRootViewBlurRepository @Inject constructor() : WindowRootViewBlurRepository {
    override val blurRadius: MutableStateFlow<Int> = MutableStateFlow(0)
    override val blurRequestedByShade: MutableStateFlow<Int> = MutableStateFlow(0)
    override val isBlurOpaque: MutableStateFlow<Boolean> = MutableStateFlow(true)
    override val isBlurSupported: StateFlow<Boolean> = MutableStateFlow(false)
    override var blurAppliedListener: BlurAppliedListener? = null
+2 −2
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ typealias BlurAppliedListener = Consumer<Int>

/** Repository that maintains state for the window blur effect. */
interface WindowRootViewBlurRepository {
    val blurRadius: MutableStateFlow<Int>
    val blurRequestedByShade: MutableStateFlow<Int>
    val isBlurOpaque: MutableStateFlow<Boolean>

    /** Is blur supported based on settings toggle and battery power saver mode. */
@@ -67,7 +67,7 @@ constructor(
    @Main private val executor: Executor,
    @Application private val scope: CoroutineScope,
) : WindowRootViewBlurRepository {
    override val blurRadius = MutableStateFlow(0)
    override val blurRequestedByShade = MutableStateFlow(0)

    override val isBlurOpaque = MutableStateFlow(false)

+2 −2
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ constructor(
    val isBlurCurrentlySupported: StateFlow<Boolean> = repository.isBlurSupported

    /** Radius of blur to be applied on the window root view. */
    val blurRadius: StateFlow<Int> = repository.blurRadius.asStateFlow()
    val blurRadiusRequestedByShade: StateFlow<Int> = repository.blurRequestedByShade.asStateFlow()

    /** Whether the blur applied is opaque or transparent. */
    val isBlurOpaque: Flow<Boolean> =
@@ -128,7 +128,7 @@ constructor(
            return false
        }
        Log.d(TAG, "requestingBlurForShade for $blurRadius $opaque")
        repository.blurRadius.value = blurRadius
        repository.blurRequestedByShade.value = blurRadius
        repository.isBlurOpaque.value = opaque
        return true
    }
Loading