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

Commit 4fb31dfa authored by Chandru S's avatar Chandru S Committed by Android (Google) Code Review
Browse files

Merge changes from topic "blur-early-wakeup" into main

* changes:
  Set early wakeup flag on surface flinger when lockscreen is visible or when shade dragging begins
  Add persistentEarlyWakeupRequired to BlurUtils to support early wake up flag being enabled for a longer period of time.
parents 55c43cbe d816cd77
Loading
Loading
Loading
Loading
+68 −17
Original line number Diff line number Diff line
@@ -16,12 +16,15 @@

package com.android.systemui.statusbar

import android.annotation.SuppressLint
import android.app.ActivityManager
import android.content.res.Resources
import android.os.Build
import android.os.SystemProperties
import android.os.Trace
import android.os.Trace.TRACE_TAG_APP
import android.util.IndentingPrintWriter
import android.util.Log
import android.util.MathUtils
import android.view.CrossWindowBlurListeners
import android.view.CrossWindowBlurListeners.CROSS_WINDOW_BLUR_SUPPORTED
@@ -45,7 +48,7 @@ open class BlurUtils @Inject constructor(
    private val crossWindowBlurListeners: CrossWindowBlurListeners,
    dumpManager: DumpManager
) : Dumpable {
    val minBlurRadius = resources.getDimensionPixelSize(R.dimen.min_window_blur_radius).toFloat();
    val minBlurRadius = resources.getDimensionPixelSize(R.dimen.min_window_blur_radius).toFloat()
    val maxBlurRadius = if (Flags.notificationShadeBlur()) {
        blurConfig.maxBlurRadiusPx
    } else {
@@ -55,6 +58,9 @@ open class BlurUtils @Inject constructor(
    private var lastAppliedBlur = 0
    private var earlyWakeupEnabled = false

    /** When this is true, early wakeup flag is not reset on surface flinger when blur drops to 0 */
    private var persistentEarlyWakeupRequired = false

    init {
        dumpManager.registerDumpable(this)
    }
@@ -91,11 +97,8 @@ open class BlurUtils @Inject constructor(
            return
        }
        if (lastAppliedBlur == 0 && radius != 0) {
            Trace.asyncTraceForTrackBegin(
                    TRACE_TAG_APP, TRACK_NAME, "eEarlyWakeup (prepareBlur)", 0)
            earlyWakeupEnabled = true
            createTransaction().use {
                it.setEarlyWakeupStart()
                earlyWakeupStart(it, "eEarlyWakeup (prepareBlur)")
                it.apply()
            }
        }
@@ -116,19 +119,15 @@ open class BlurUtils @Inject constructor(
            if (shouldBlur(radius)) {
                it.setBackgroundBlurRadius(viewRootImpl.surfaceControl, radius)
                if (!earlyWakeupEnabled && lastAppliedBlur == 0 && radius != 0) {
                    Trace.asyncTraceForTrackBegin(
                        TRACE_TAG_APP,
                        TRACK_NAME,
                        "eEarlyWakeup (applyBlur)",
                        0
                    )
                    it.setEarlyWakeupStart()
                    earlyWakeupEnabled = true
                    earlyWakeupStart(it, "eEarlyWakeup (applyBlur)")
                }
                if (earlyWakeupEnabled && lastAppliedBlur != 0 && radius == 0) {
                    it.setEarlyWakeupEnd()
                    Trace.asyncTraceForTrackEnd(TRACE_TAG_APP, TRACK_NAME, 0)
                    earlyWakeupEnabled = false
                if (
                    earlyWakeupEnabled &&
                        lastAppliedBlur != 0 &&
                        radius == 0 &&
                        !persistentEarlyWakeupRequired
                ) {
                    earlyWakeupEnd(it, "applyBlur")
                }
                lastAppliedBlur = radius
            }
@@ -137,6 +136,26 @@ open class BlurUtils @Inject constructor(
        }
    }

    private fun v(verboseLog: String) {
        if (isLoggable) Log.v(TAG, verboseLog)
    }

    @SuppressLint("MissingPermission")
    private fun earlyWakeupStart(transaction: SurfaceControl.Transaction, traceMethodName: String) {
        v("earlyWakeupStart from $traceMethodName")
        Trace.asyncTraceForTrackBegin(TRACE_TAG_APP, TRACK_NAME, traceMethodName, 0)
        transaction.setEarlyWakeupStart()
        earlyWakeupEnabled = true
    }

    @SuppressLint("MissingPermission")
    private fun earlyWakeupEnd(transaction: SurfaceControl.Transaction, loggingContext: String) {
        v("earlyWakeupEnd from $loggingContext")
        transaction.setEarlyWakeupEnd()
        Trace.asyncTraceForTrackEnd(TRACE_TAG_APP, TRACK_NAME, 0)
        earlyWakeupEnabled = false
    }

    @VisibleForTesting
    open fun createTransaction(): SurfaceControl.Transaction {
        return SurfaceControl.Transaction()
@@ -177,7 +196,39 @@ open class BlurUtils @Inject constructor(
        }
    }

    /**
     * Enables/disables the early wakeup flag on surface flinger. Keeps the early wakeup flag on
     * until it reset by passing false to this method.
     */
    fun setPersistentEarlyWakeup(persistentWakeup: Boolean, viewRootImpl: ViewRootImpl?) {
        persistentEarlyWakeupRequired = persistentWakeup
        if (viewRootImpl == null || !supportsBlursOnWindows()) return
        if (persistentEarlyWakeupRequired) {
            if (earlyWakeupEnabled) return
            createTransaction().use {
                earlyWakeupStart(it, "setEarlyWakeup")
                it.apply()
            }
        } else {
            if (!earlyWakeupEnabled) return
            if (lastAppliedBlur > 0) {
                Log.w(
                    TAG,
                    "resetEarlyWakeup invoked when lastAppliedBlur $lastAppliedBlur is " +
                        "non-zero, this means that the early wakeup signal was reset while blur" +
                        " was still active",
                )
            }
            createTransaction().use {
                earlyWakeupEnd(it, "resetEarlyWakeup")
                it.apply()
            }
        }
    }

    companion object {
        const val TRACK_NAME = "BlurUtils"
        private const val TAG = "BlurUtils"
        private val isLoggable = Log.isLoggable(TAG, Log.VERBOSE) || Build.isDebuggable()
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -59,6 +59,15 @@ object WindowRootViewBinder {
            ) { viewModel ->
                try {
                    Log.d(TAG, "Launching coroutines that update window root view state")
                    launchTraced("early-wakeup") {
                        viewModel.isPersistentEarlyWakeupRequired.collect { wakeupRequired ->
                            blurUtils.setPersistentEarlyWakeup(
                                wakeupRequired,
                                view.rootView?.viewRootImpl,
                            )
                        }
                    }

                    launchTraced("WindowBlur") {
                        var wasUpdateScheduledForThisFrame = false
                        var lastScheduledBlurRadius = 0
+23 −0
Original line number Diff line number Diff line
@@ -19,13 +19,16 @@ package com.android.systemui.window.ui.viewmodel
import android.os.Build
import android.util.Log
import com.android.systemui.Flags
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor
import com.android.systemui.keyguard.ui.transitions.GlanceableHubTransition
import com.android.systemui.keyguard.ui.transitions.PrimaryBouncerTransition
import com.android.systemui.shade.domain.interactor.ShadeInteractor
import com.android.systemui.window.domain.interactor.WindowRootViewBlurInteractor
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
@@ -41,6 +44,8 @@ constructor(
    primaryBouncerTransitions: Set<@JvmSuppressWildcards PrimaryBouncerTransition>,
    glanceableHubTransitions: Set<@JvmSuppressWildcards GlanceableHubTransition>,
    private val blurInteractor: WindowRootViewBlurInteractor,
    private val keyguardInteractor: KeyguardInteractor,
    private val shadeInteractor: ShadeInteractor,
) {

    private val bouncerBlurRadiusFlows =
@@ -70,6 +75,24 @@ constructor(
            }
        }

    val isPersistentEarlyWakeupRequired =
        blurInteractor.isBlurCurrentlySupported
            .flatMapLatest { blurSupported ->
                if (blurSupported) {
                    combine(
                        keyguardInteractor.isKeyguardShowing,
                        shadeInteractor.isUserInteracting,
                        shadeInteractor.isAnyExpanded,
                    ) { keyguardShowing, userDraggingShade, anyExpanded ->
                        keyguardShowing || userDraggingShade || anyExpanded
                    }
                } else {
                    flowOf(false)
                }
            }
            .distinctUntilChanged()
            .logIfPossible("isPersistentEarlyWakeupRequired")

    val isBlurOpaque =
        blurInteractor.isBlurCurrentlySupported.flatMapLatest { blurSupported ->
            if (blurSupported) {
+4 −0
Original line number Diff line number Diff line
@@ -16,9 +16,11 @@

package com.android.systemui.window.ui.viewmodel

import com.android.systemui.keyguard.domain.interactor.keyguardInteractor
import com.android.systemui.keyguard.ui.transitions.FakeBouncerTransition
import com.android.systemui.keyguard.ui.transitions.FakeGlanceableHubTransition
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.shade.domain.interactor.shadeInteractor
import com.android.systemui.window.domain.interactor.windowRootViewBlurInteractor
import org.mockito.internal.util.collections.Sets

@@ -38,5 +40,7 @@ val Kosmos.windowRootViewModel by
            fakeBouncerTransitions,
            fakeGlanceableHubTransitions,
            windowRootViewBlurInteractor,
            keyguardInteractor,
            shadeInteractor,
        )
    }