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

Commit 35de5a74 authored by Lucas Silva's avatar Lucas Silva
Browse files

Ensure config callback is always removed in dream overlay

Currently, when repeatOnLifecycle is cancelled, it will throw a
CancellationException which will cause the cleanup of the callback to be
skipped. This change wraps the cleanup in a finally block so that it
always runs.

Fixes: 297320149
Test: verified callback is now removed when dream exits using log statements
Flag: NA
Change-Id: Ic6c32df3969c7fddbc544e369551a7a52f4cdae1
parent 997be753
Loading
Loading
Loading
Loading
+34 −31
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ import androidx.lifecycle.Lifecycle
import androidx.lifecycle.repeatOnLifecycle
import com.android.app.animation.Interpolators
import com.android.dream.lowlight.util.TruncatedInterpolator
import com.android.systemui.res.R
import com.android.systemui.complication.ComplicationHostViewController
import com.android.systemui.complication.ComplicationLayoutParams
import com.android.systemui.complication.ComplicationLayoutParams.POSITION_BOTTOM
@@ -39,6 +38,7 @@ import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.Logger
import com.android.systemui.log.dagger.DreamLog
import com.android.systemui.res.R
import com.android.systemui.statusbar.BlurUtils
import com.android.systemui.statusbar.CrossFadeHelper
import com.android.systemui.statusbar.policy.ConfigurationController
@@ -101,6 +101,7 @@ constructor(

            configController.addCallback(configCallback)

            try {
                repeatOnLifecycle(Lifecycle.State.CREATED) {
                    /* Translation animations, when moving from DREAMING->LOCKSCREEN state */
                    launch {
@@ -140,10 +141,12 @@ constructor(
                        }
                    }
                }

            } finally {
                // Ensure the callback is removed when cancellation happens
                configController.removeCallback(configCallback)
            }
        }
    }

    /**
     * Starts the dream content and dream overlay entry animations.