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

Commit 6d5739a7 authored by Matt Pietal's avatar Matt Pietal
Browse files

Move view updates to immediate dispatcher

To make sure alpha/view updates are animation frame aligned.

Bug: 370803736
Test: perfetto
Flag: EXEMPT bugfix
Change-Id: I5f8cbb121b556c9e109fa6e3586b27c1aae04c15
parent f618ab4c
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import com.android.compose.animation.scene.ElementKey
import com.android.systemui.biometrics.AuthController
import com.android.systemui.customization.R as customR
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.flags.FeatureFlagsClassic
import com.android.systemui.flags.Flags
import com.android.systemui.keyguard.ui.binder.DeviceEntryIconViewBinder
@@ -49,12 +50,14 @@ import com.android.systemui.res.R
import com.android.systemui.statusbar.VibratorHelper
import dagger.Lazy
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope

class LockSection
@Inject
constructor(
    @Application private val applicationScope: CoroutineScope,
    @Main private val mainDispatcher: CoroutineDispatcher,
    private val windowManager: WindowManager,
    private val authController: AuthController,
    private val featureFlags: FeatureFlagsClassic,
@@ -80,6 +83,7 @@ constructor(
                        id = R.id.device_entry_icon_view
                        DeviceEntryIconViewBinder.bind(
                            applicationScope,
                            mainDispatcher,
                            this,
                            deviceEntryIconViewModel.get(),
                            deviceEntryForegroundViewModel.get(),
+29 −21
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import com.android.systemui.plugins.FalsingManager
import com.android.systemui.res.R
import com.android.systemui.statusbar.VibratorHelper
import com.android.systemui.util.kotlin.DisposableHandles
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DisposableHandle

@@ -56,6 +57,7 @@ object DeviceEntryIconViewBinder {
    @JvmStatic
    fun bind(
        applicationScope: CoroutineScope,
        mainImmediateDispatcher: CoroutineDispatcher,
        view: DeviceEntryIconView,
        viewModel: DeviceEntryIconViewModel,
        fgViewModel: DeviceEntryForegroundViewModel,
@@ -95,6 +97,32 @@ object DeviceEntryIconViewBinder {
                }
            }

        disposables +=
            view.repeatWhenAttached(mainImmediateDispatcher) {
                repeatOnLifecycle(Lifecycle.State.CREATED) {
                    launch("$TAG#viewModel.useBackgroundProtection") {
                        viewModel.useBackgroundProtection.collect { useBackgroundProtection ->
                            if (useBackgroundProtection) {
                                bgView.visibility = View.VISIBLE
                            } else {
                                bgView.visibility = View.GONE
                            }
                        }
                    }
                    launch("$TAG#viewModel.burnInOffsets") {
                        viewModel.burnInOffsets.collect { burnInOffsets ->
                            view.translationX = burnInOffsets.x.toFloat()
                            view.translationY = burnInOffsets.y.toFloat()
                            view.aodFpDrawable.progress = burnInOffsets.progress
                        }
                    }

                    launch("$TAG#viewModel.deviceEntryViewAlpha") {
                        viewModel.deviceEntryViewAlpha.collect { alpha -> view.alpha = alpha }
                    }
                }
            }

        disposables +=
            view.repeatWhenAttached {
                // Repeat on CREATED so that the view will always observe the entire
@@ -152,26 +180,6 @@ object DeviceEntryIconViewBinder {
                            }
                        }
                    }
                    launch("$TAG#viewModel.useBackgroundProtection") {
                        viewModel.useBackgroundProtection.collect { useBackgroundProtection ->
                            if (useBackgroundProtection) {
                                bgView.visibility = View.VISIBLE
                            } else {
                                bgView.visibility = View.GONE
                            }
                        }
                    }
                    launch("$TAG#viewModel.burnInOffsets") {
                        viewModel.burnInOffsets.collect { burnInOffsets ->
                            view.translationX = burnInOffsets.x.toFloat()
                            view.translationY = burnInOffsets.y.toFloat()
                            view.aodFpDrawable.progress = burnInOffsets.progress
                        }
                    }

                    launch("$TAG#viewModel.deviceEntryViewAlpha") {
                        viewModel.deviceEntryViewAlpha.collect { alpha -> view.alpha = alpha }
                    }
                }
            }

@@ -212,7 +220,7 @@ object DeviceEntryIconViewBinder {
            }

        disposables +=
            bgView.repeatWhenAttached {
            bgView.repeatWhenAttached(mainImmediateDispatcher) {
                repeatOnLifecycle(Lifecycle.State.CREATED) {
                    launch("$TAG#bgViewModel.alpha") {
                        bgViewModel.alpha.collect { alpha -> bgView.alpha = alpha }
+4 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import androidx.constraintlayout.widget.ConstraintSet
import com.android.systemui.biometrics.AuthController
import com.android.systemui.customization.R as customR
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.keyguard.shared.model.KeyguardSection
@@ -48,6 +49,7 @@ import com.android.systemui.shade.ShadeDisplayAware
import com.android.systemui.statusbar.VibratorHelper
import dagger.Lazy
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.DisposableHandle

@@ -56,6 +58,7 @@ class DefaultDeviceEntrySection
@Inject
constructor(
    @Application private val applicationScope: CoroutineScope,
    @Main private val mainDispatcher: CoroutineDispatcher,
    private val authController: AuthController,
    private val windowManager: WindowManager,
    @ShadeDisplayAware private val context: Context,
@@ -91,6 +94,7 @@ constructor(
            disposableHandle =
                DeviceEntryIconViewBinder.bind(
                    applicationScope,
                    mainDispatcher,
                    it,
                    deviceEntryIconViewModel.get(),
                    deviceEntryForegroundViewModel.get(),
+3 −0
Original line number Diff line number Diff line
@@ -31,11 +31,13 @@ import com.android.systemui.flags.Flags
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryBackgroundViewModel
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryForegroundViewModel
import com.android.systemui.keyguard.ui.viewmodel.DeviceEntryIconViewModel
import com.android.systemui.kosmos.testDispatcher
import com.android.systemui.log.logcatLogBuffer
import com.android.systemui.plugins.FalsingManager
import com.android.systemui.res.R
import com.android.systemui.shade.NotificationPanelView
import com.android.systemui.statusbar.VibratorHelper
import com.android.systemui.testKosmos
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.MutableStateFlow
@@ -68,6 +70,7 @@ class DefaultDeviceEntrySectionTest : SysuiTestCase() {
        underTest =
            DefaultDeviceEntrySection(
                TestScope().backgroundScope,
                testKosmos().testDispatcher,
                authController,
                windowManager,
                context,