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

Commit 4268db22 authored by Andreas Miko's avatar Andreas Miko
Browse files

Consolidate dozeAmountTransition into transitionValue(AOD)

This change gets rid of dozeAmountTransition because the function is
essentially the same as transitionValue with the exception that whole
steps are emitted instead of just the value.

Test: None
Bug: b/330311871
Flag: com.android.systemui.scene_container
Change-Id: I9fda746f0d68caec306e92a507c7fef6362d7670
parent 07ce7a6b
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -235,6 +235,7 @@ class UdfpsKeyguardViewLegacyControllerWithCoroutinesTest :

            job.cancel()
        }

    @Test
    fun fadeFromDialogSuggestedAlpha() =
        testScope.runTest {
@@ -511,9 +512,10 @@ class UdfpsKeyguardViewLegacyControllerWithCoroutinesTest :
        testScope.runTest {
            // GIVEN view is attached
            mController.onViewAttached()
            val job = mController.listenForLockscreenAodTransitions(this)
            runCurrent()
            Mockito.reset(mView)

            val job = mController.listenForLockscreenAodTransitions(this)
            // WHEN aod to lockscreen transition is cancelled
            transitionRepository.sendTransitionStep(
                TransitionStep(
@@ -537,7 +539,7 @@ class UdfpsKeyguardViewLegacyControllerWithCoroutinesTest :

            // THEN doze amount is updated to zero
            verify(mView)
                .onDozeAmountChanged(eq(0f), eq(0f), eq(UdfpsKeyguardViewLegacy.ANIMATION_NONE))
                .onDozeAmountChanged(eq(0f), eq(0f), eq(ANIMATION_BETWEEN_AOD_AND_LOCKSCREEN))
            job.cancel()
        }

@@ -546,9 +548,10 @@ class UdfpsKeyguardViewLegacyControllerWithCoroutinesTest :
        testScope.runTest {
            // GIVEN view is attached
            mController.onViewAttached()
            val job = mController.listenForLockscreenAodTransitions(this)
            runCurrent()
            Mockito.reset(mView)

            val job = mController.listenForLockscreenAodTransitions(this)
            // WHEN lockscreen to aod transition is cancelled
            transitionRepository.sendTransitionStep(
                TransitionStep(
+0 −62
Original line number Diff line number Diff line
@@ -124,68 +124,6 @@ class KeyguardTransitionInteractorTest : SysuiTestCase() {
            assertThat(lockscreenToAodSteps).isEqualTo(steps.subList(5, 8))
        }

    @Test
    fun dozeAmountTransitionTest_AodToFromLockscreen() =
        testScope.runTest {
            val dozeAmountSteps by collectValues(underTest.dozeAmountTransition)

            val steps = mutableListOf<TransitionStep>()

            steps.add(TransitionStep(AOD, LOCKSCREEN, 0f, STARTED))
            steps.add(TransitionStep(AOD, LOCKSCREEN, 0.5f, RUNNING))
            steps.add(TransitionStep(AOD, LOCKSCREEN, 1f, FINISHED))
            steps.add(TransitionStep(LOCKSCREEN, AOD, 0f, STARTED))
            steps.add(TransitionStep(LOCKSCREEN, AOD, 0.8f, RUNNING))
            steps.add(TransitionStep(LOCKSCREEN, AOD, 0.9f, RUNNING))
            steps.add(TransitionStep(LOCKSCREEN, AOD, 1f, FINISHED))

            steps.forEach {
                repository.sendTransitionStep(it)
                runCurrent()
            }

            assertThat(dozeAmountSteps.subList(0, 3))
                .isEqualTo(
                    listOf(
                        steps[0].copy(value = 1f - steps[0].value),
                        steps[1].copy(value = 1f - steps[1].value),
                        steps[2].copy(value = 1f - steps[2].value),
                    )
                )
            assertThat(dozeAmountSteps.subList(3, 7)).isEqualTo(steps.subList(3, 7))
        }

    @Test
    fun dozeAmountTransitionTest_AodToFromGone() =
        testScope.runTest {
            val dozeAmountSteps by collectValues(underTest.dozeAmountTransition)

            val steps = mutableListOf<TransitionStep>()

            steps.add(TransitionStep(AOD, GONE, 0f, STARTED))
            steps.add(TransitionStep(AOD, GONE, 0.3f, RUNNING))
            steps.add(TransitionStep(AOD, GONE, 1f, FINISHED))
            steps.add(TransitionStep(GONE, AOD, 0f, STARTED))
            steps.add(TransitionStep(GONE, AOD, 0.1f, RUNNING))
            steps.add(TransitionStep(GONE, AOD, 0.3f, RUNNING))
            steps.add(TransitionStep(GONE, AOD, 1f, FINISHED))

            steps.forEach {
                repository.sendTransitionStep(it)
                runCurrent()
            }

            assertThat(dozeAmountSteps.subList(0, 3))
                .isEqualTo(
                    listOf(
                        steps[0].copy(value = 1f - steps[0].value),
                        steps[1].copy(value = 1f - steps[1].value),
                        steps[2].copy(value = 1f - steps[2].value),
                    )
                )
            assertThat(dozeAmountSteps.subList(3, 7)).isEqualTo(steps.subList(3, 7))
        }

    @Test
    fun finishedKeyguardStateTests() =
        testScope.runTest {
+5 −5
Original line number Diff line number Diff line
@@ -70,7 +70,7 @@ import com.android.systemui.keyguard.KeyguardBottomAreaRefactor;
import com.android.systemui.keyguard.MigrateClocksToBlueprint;
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor;
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor;
import com.android.systemui.keyguard.shared.model.TransitionStep;
import com.android.systemui.keyguard.shared.model.KeyguardState;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.res.R;
@@ -167,9 +167,9 @@ public class LegacyLockIconViewController implements Dumpable, LockIconViewContr
    private LockIconView mView;

    @VisibleForTesting
    final Consumer<TransitionStep> mDozeTransitionCallback = (TransitionStep step) -> {
        mInterpolatedDarkAmount = step.getValue();
        mView.setDozeAmount(step.getValue());
    final Consumer<Float> mDozeTransitionCallback = (Float value) -> {
        mInterpolatedDarkAmount = value;
        mView.setDozeAmount(value);
        updateBurnInOffsets();
    };

@@ -265,7 +265,7 @@ public class LegacyLockIconViewController implements Dumpable, LockIconViewContr
        mView.setAccessibilityDelegate(mAccessibilityDelegate);

        if (mFeatureFlags.isEnabled(DOZING_MIGRATION_1)) {
            collectFlow(mView, mTransitionInteractor.getDozeAmountTransition(),
            collectFlow(mView, mTransitionInteractor.transitionValue(KeyguardState.AOD),
                    mDozeTransitionCallback);
            collectFlow(mView, mKeyguardInteractor.isDozing(), mIsDozingCallback);
        }
+6 −23
Original line number Diff line number Diff line
@@ -39,7 +39,6 @@ import com.android.systemui.keyguard.shared.model.KeyguardState.DREAMING
import com.android.systemui.keyguard.shared.model.KeyguardState.GONE
import com.android.systemui.keyguard.shared.model.KeyguardState.OCCLUDED
import com.android.systemui.keyguard.shared.model.KeyguardState.PRIMARY_BOUNCER
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.lifecycle.repeatWhenAttached
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.res.R
@@ -59,7 +58,6 @@ import java.io.PrintWriter
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch

/** Class that coordinates non-HBM animations during keyguard authentication. */
@@ -307,30 +305,15 @@ open class UdfpsKeyguardViewControllerLegacy(
    @VisibleForTesting
    suspend fun listenForLockscreenAodTransitions(scope: CoroutineScope): Job {
        return scope.launch {
            transitionInteractor.dozeAmountTransition.collect { transitionStep ->
                if (
                    transitionStep.from == AOD &&
                        transitionStep.transitionState == TransitionState.CANCELED
                ) {
                    if (transitionInteractor.startedKeyguardTransitionStep.first().to != AOD) {
                        // If the next started transition isn't transitioning back to AOD, force
                        // doze amount to be 0f (as if the transition to the lockscreen completed).
                        view.onDozeAmountChanged(
                            0f,
                            0f,
                            UdfpsKeyguardViewLegacy.ANIMATION_NONE,
                        )
                    }
                } else {
            transitionInteractor.transitionValue(AOD).collect {
                view.onDozeAmountChanged(
                        transitionStep.value,
                        transitionStep.value,
                    it,
                    it,
                    UdfpsKeyguardViewLegacy.ANIMATION_BETWEEN_AOD_AND_LOCKSCREEN,
                )
            }
        }
    }
    }

    @VisibleForTesting
    suspend fun listenForBouncerExpansion(scope: CoroutineScope): Job {
+0 −17
Original line number Diff line number Diff line
@@ -250,23 +250,6 @@ constructor(
        return getTransitionValueFlow(state)
    }

    /**
     * AOD<->* transition information, mapped to dozeAmount range of AOD (1f) <->
     * * (0f).
     */
    @SuppressLint("SharedFlowCreation")
    val dozeAmountTransition: Flow<TransitionStep> =
        repository.transitions
            .filter { step -> step.from == AOD || step.to == AOD }
            .map { step ->
                if (step.from == AOD) {
                    step.copy(value = 1 - step.value)
                } else {
                    step
                }
            }
            .shareIn(scope, SharingStarted.Eagerly, replay = 1)

    /** The last [TransitionStep] with a [TransitionState] of STARTED */
    val startedKeyguardTransitionStep: Flow<TransitionStep> =
        repository.transitions.filter { step -> step.transitionState == TransitionState.STARTED }
Loading