Merge "Add dark scrim from a background thread during unfold" into tm-qpr-dev

This commit is contained in:
Nicolò Mazzucato
2022-12-05 12:54:12 +00:00
committed by Android (Google) Code Review

View File

@@ -22,6 +22,8 @@ import android.hardware.devicestate.DeviceStateManager
import android.hardware.devicestate.DeviceStateManager.FoldStateListener import android.hardware.devicestate.DeviceStateManager.FoldStateListener
import android.hardware.display.DisplayManager import android.hardware.display.DisplayManager
import android.hardware.input.InputManager import android.hardware.input.InputManager
import android.os.Handler
import android.os.Looper
import android.os.Trace import android.os.Trace
import android.view.Choreographer import android.view.Choreographer
import android.view.Display import android.view.Display
@@ -32,6 +34,7 @@ import android.view.SurfaceControlViewHost
import android.view.SurfaceSession import android.view.SurfaceSession
import android.view.WindowManager import android.view.WindowManager
import android.view.WindowlessWindowManager import android.view.WindowlessWindowManager
import com.android.systemui.dagger.qualifiers.Background
import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dagger.qualifiers.UiBackground import com.android.systemui.dagger.qualifiers.UiBackground
import com.android.systemui.statusbar.LightRevealEffect import com.android.systemui.statusbar.LightRevealEffect
@@ -40,6 +43,7 @@ import com.android.systemui.statusbar.LinearLightRevealEffect
import com.android.systemui.unfold.UnfoldTransitionProgressProvider.TransitionProgressListener import com.android.systemui.unfold.UnfoldTransitionProgressProvider.TransitionProgressListener
import com.android.systemui.unfold.updates.RotationChangeProvider import com.android.systemui.unfold.updates.RotationChangeProvider
import com.android.systemui.unfold.util.ScaleAwareTransitionProgressProvider.Companion.areAnimationsEnabled import com.android.systemui.unfold.util.ScaleAwareTransitionProgressProvider.Companion.areAnimationsEnabled
import com.android.systemui.util.Assert.isMainThread
import com.android.systemui.util.traceSection import com.android.systemui.util.traceSection
import com.android.wm.shell.displayareahelper.DisplayAreaHelper import com.android.wm.shell.displayareahelper.DisplayAreaHelper
import java.util.Optional import java.util.Optional
@@ -59,6 +63,7 @@ constructor(
private val displayAreaHelper: Optional<DisplayAreaHelper>, private val displayAreaHelper: Optional<DisplayAreaHelper>,
@Main private val executor: Executor, @Main private val executor: Executor,
@UiBackground private val backgroundExecutor: Executor, @UiBackground private val backgroundExecutor: Executor,
@Background private val bgHandler: Handler,
private val rotationChangeProvider: RotationChangeProvider, private val rotationChangeProvider: RotationChangeProvider,
) { ) {
@@ -120,11 +125,11 @@ constructor(
try { try {
// Add the view only if we are unfolding and this is the first screen on // Add the view only if we are unfolding and this is the first screen on
if (!isFolded && !isUnfoldHandled && contentResolver.areAnimationsEnabled()) { if (!isFolded && !isUnfoldHandled && contentResolver.areAnimationsEnabled()) {
addView(onOverlayReady) executeInBackground { addView(onOverlayReady) }
isUnfoldHandled = true isUnfoldHandled = true
} else { } else {
// No unfold transition, immediately report that overlay is ready // No unfold transition, immediately report that overlay is ready
ensureOverlayRemoved() executeInBackground { ensureOverlayRemoved() }
onOverlayReady.run() onOverlayReady.run()
} }
} finally { } finally {
@@ -139,6 +144,7 @@ constructor(
return return
} }
ensureInBackground()
ensureOverlayRemoved() ensureOverlayRemoved()
val newRoot = SurfaceControlViewHost(context, context.display!!, wwm) val newRoot = SurfaceControlViewHost(context, context.display!!, wwm)
@@ -152,7 +158,7 @@ constructor(
val params = getLayoutParams() val params = getLayoutParams()
newRoot.setView(newView, params) newRoot.setView(newView, params)
onOverlayReady?.let { callback -> if (onOverlayReady != null) {
Trace.beginAsyncSection("UnfoldLightRevealOverlayAnimation#relayout", 0) Trace.beginAsyncSection("UnfoldLightRevealOverlayAnimation#relayout", 0)
newRoot.relayout(params) { transaction -> newRoot.relayout(params) { transaction ->
@@ -170,7 +176,7 @@ constructor(
.setFrameTimelineVsync(vsyncId + 1) .setFrameTimelineVsync(vsyncId + 1)
.addTransactionCommittedListener(backgroundExecutor) { .addTransactionCommittedListener(backgroundExecutor) {
Trace.endAsyncSection("UnfoldLightRevealOverlayAnimation#relayout", 0) Trace.endAsyncSection("UnfoldLightRevealOverlayAnimation#relayout", 0)
callback.run() onOverlayReady.run()
} }
.apply() .apply()
} }
@@ -213,9 +219,12 @@ constructor(
} }
private fun ensureOverlayRemoved() { private fun ensureOverlayRemoved() {
root?.release() ensureInBackground()
root = null traceSection("ensureOverlayRemoved") {
scrimView = null root?.release()
root = null
scrimView = null
}
} }
private fun getUnfoldedDisplayInfo(): DisplayInfo = private fun getUnfoldedDisplayInfo(): DisplayInfo =
@@ -228,17 +237,17 @@ constructor(
private inner class TransitionListener : TransitionProgressListener { private inner class TransitionListener : TransitionProgressListener {
override fun onTransitionProgress(progress: Float) { override fun onTransitionProgress(progress: Float) {
scrimView?.revealAmount = progress executeInBackground { scrimView?.revealAmount = progress }
} }
override fun onTransitionFinished() { override fun onTransitionFinished() {
ensureOverlayRemoved() executeInBackground { ensureOverlayRemoved() }
} }
override fun onTransitionStarted() { override fun onTransitionStarted() {
// Add view for folding case (when unfolding the view is added earlier) // Add view for folding case (when unfolding the view is added earlier)
if (scrimView == null) { if (scrimView == null) {
addView() executeInBackground { addView() }
} }
// Disable input dispatching during transition. // Disable input dispatching during transition.
InputManager.getInstance().cancelCurrentTouch() InputManager.getInstance().cancelCurrentTouch()
@@ -250,19 +259,35 @@ constructor(
traceSection("UnfoldLightRevealOverlayAnimation#onRotationChanged") { traceSection("UnfoldLightRevealOverlayAnimation#onRotationChanged") {
if (currentRotation != newRotation) { if (currentRotation != newRotation) {
currentRotation = newRotation currentRotation = newRotation
scrimView?.revealEffect = createLightRevealEffect() executeInBackground {
root?.relayout(getLayoutParams()) scrimView?.revealEffect = createLightRevealEffect()
root?.relayout(getLayoutParams())
}
} }
} }
} }
} }
private fun executeInBackground(f: () -> Unit) {
ensureInMainThread()
// The UiBackground executor is not used as it doesn't have a prepared looper.
bgHandler.post(f)
}
private fun ensureInBackground() {
check(Looper.myLooper() == bgHandler.looper) { "Not being executed in the background!" }
}
private fun ensureInMainThread() {
isMainThread()
}
private inner class FoldListener : private inner class FoldListener :
FoldStateListener( FoldStateListener(
context, context,
Consumer { isFolded -> Consumer { isFolded ->
if (isFolded) { if (isFolded) {
ensureOverlayRemoved() executeInBackground { ensureOverlayRemoved() }
isUnfoldHandled = false isUnfoldHandled = false
} }
this.isFolded = isFolded this.isFolded = isFolded