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

Commit d0209c8f authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge changes from topic "mpietal_off" into main

* changes:
  Support OCCLUDED<->ALTERNATE_BOUNCER with animations
  Add OFF->LOCKSCREEN transition
parents 60e1a214 a50eb586
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -109,7 +109,9 @@ class CommunalSceneTransitionInteractorTest : SysuiTestCase() {
        kosmos.fakeFeatureFlagsClassic.set(Flags.COMMUNAL_SERVICE_ENABLED, true)
        underTest.start()
        kosmos.communalSceneRepository.setTransitionState(sceneTransitions)
        testScope.launch { keyguardTransitionRepository.emitInitialStepsFromOff(LOCKSCREEN) }
        testScope.launch {
            keyguardTransitionRepository.emitInitialStepsFromOff(LOCKSCREEN, testSetup = true)
        }
    }

    /** Transition from blank to glanceable hub. This is the default case. */
+2 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.keyguard.domain.interactor.KeyguardBlueprintInteractor
import com.android.systemui.keyguard.domain.interactor.keyguardTransitionInteractor
import com.android.systemui.testKosmos
import org.junit.Before
import org.junit.Test
@@ -44,6 +45,7 @@ class KeyguardBlueprintViewModelTest : SysuiTestCase() {
            KeyguardBlueprintViewModel(
                handler = kosmos.fakeExecutorHandler,
                keyguardBlueprintInteractor = keyguardBlueprintInteractor,
                keyguardTransitionInteractor = kosmos.keyguardTransitionInteractor,
            )
    }

+35 −8
Original line number Diff line number Diff line
@@ -89,9 +89,12 @@ class LockscreenToOccludedTransitionViewModelTest(flags: FlagsParameterization)
    }

    @Test
    fun lockscreenFadeOut() =
    fun lockscreenFadeOut_shadeNotExpanded() =
        testScope.runTest {
            val values by collectValues(underTest.lockscreenAlpha)
            shadeExpanded(false)
            runCurrent()

            repository.sendTransitionSteps(
                steps =
                    listOf(
@@ -104,10 +107,34 @@ class LockscreenToOccludedTransitionViewModelTest(flags: FlagsParameterization)
                    ),
                testScope = testScope,
            )
            // Only 5 values should be present, since the dream overlay runs for a small fraction
            // of the overall animation time
            assertThat(values.size).isEqualTo(5)
            values.forEach { assertThat(it).isIn(Range.closed(0f, 1f)) }
            assertThat(values[0]).isEqualTo(1f)
            assertThat(values[1]).isEqualTo(1f)
            assertThat(values[2]).isIn(Range.open(0f, 1f))
            assertThat(values[3]).isIn(Range.open(0f, 1f))
            assertThat(values[4]).isEqualTo(0f)
        }

    @Test
    fun lockscreenFadeOut_shadeExpanded() =
        testScope.runTest {
            val values by collectValues(underTest.lockscreenAlpha)
            shadeExpanded(true)
            runCurrent()

            repository.sendTransitionSteps(
                steps =
                    listOf(
                        step(0f, TransitionState.STARTED), // Should start running here...
                        step(0f),
                        step(.1f),
                        step(.4f),
                        step(.7f), // ...up to here
                        step(1f),
                    ),
                testScope = testScope,
            )
            values.forEach { assertThat(it).isEqualTo(0f) }
        }

    @Test
@@ -115,7 +142,7 @@ class LockscreenToOccludedTransitionViewModelTest(flags: FlagsParameterization)
        testScope.runTest {
            configurationRepository.setDimensionPixelSize(
                R.dimen.lockscreen_to_occluded_transition_lockscreen_translation_y,
                100
                100,
            )
            val values by collectValues(underTest.lockscreenTranslationY)
            repository.sendTransitionSteps(
@@ -138,7 +165,7 @@ class LockscreenToOccludedTransitionViewModelTest(flags: FlagsParameterization)
        testScope.runTest {
            configurationRepository.setDimensionPixelSize(
                R.dimen.lockscreen_to_occluded_transition_lockscreen_translation_y,
                100
                100,
            )
            val values by collectValues(underTest.lockscreenTranslationY)
            repository.sendTransitionSteps(
@@ -171,7 +198,7 @@ class LockscreenToOccludedTransitionViewModelTest(flags: FlagsParameterization)
                    listOf(
                        step(0f, TransitionState.STARTED),
                        step(.5f),
                        step(1f, TransitionState.FINISHED)
                        step(1f, TransitionState.FINISHED),
                    ),
                testScope = testScope,
            )
@@ -228,7 +255,7 @@ class LockscreenToOccludedTransitionViewModelTest(flags: FlagsParameterization)
            to = KeyguardState.OCCLUDED,
            value = value,
            transitionState = state,
            ownerName = "LockscreenToOccludedTransitionViewModelTest"
            ownerName = "LockscreenToOccludedTransitionViewModelTest",
        )
    }

+94 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.keyguard.ui.viewmodel

import android.platform.test.flag.junit.FlagsParameterization
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.andSceneContainer
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
import com.android.systemui.kosmos.testScope
import com.android.systemui.testKosmos
import com.google.common.collect.Range
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import platform.test.runner.parameterized.ParameterizedAndroidJunit4
import platform.test.runner.parameterized.Parameters

@ExperimentalCoroutinesApi
@SmallTest
@RunWith(ParameterizedAndroidJunit4::class)
class OffToLockscreenTransitionViewModelTest(flags: FlagsParameterization) : SysuiTestCase() {
    val kosmos = testKosmos()
    val testScope = kosmos.testScope
    val repository = kosmos.fakeKeyguardTransitionRepository
    lateinit var underTest: OffToLockscreenTransitionViewModel

    companion object {
        @JvmStatic
        @Parameters(name = "{0}")
        fun getParams(): List<FlagsParameterization> {
            return FlagsParameterization.allCombinationsOf().andSceneContainer()
        }
    }

    init {
        mSetFlagsRule.setFlagsParameterization(flags)
    }

    @Before
    fun setup() {
        underTest = kosmos.offToLockscreenTransitionViewModel
    }

    @Test
    fun lockscreenAlpha() =
        testScope.runTest {
            val alpha by collectLastValue(underTest.lockscreenAlpha)

            repository.sendTransitionStep(step(0f, TransitionState.STARTED))
            repository.sendTransitionStep(step(0f))
            assertThat(alpha).isEqualTo(0f)

            repository.sendTransitionStep(step(0.66f))
            assertThat(alpha).isIn(Range.open(.1f, .9f))

            repository.sendTransitionStep(step(1f))
            assertThat(alpha).isEqualTo(1f)
        }

    private fun step(
        value: Float,
        state: TransitionState = TransitionState.RUNNING,
    ): TransitionStep {
        return TransitionStep(
            from = KeyguardState.OFF,
            to = KeyguardState.LOCKSCREEN,
            value = value,
            transitionState = state,
            ownerName = "OffToLockscreenTransitionViewModelTest",
        )
    }
}
+15 −0
Original line number Diff line number Diff line
@@ -147,6 +147,7 @@ import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.flags.SystemPropertiesHelper;
import com.android.systemui.keyguard.dagger.KeyguardModule;
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor;
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionBootInteractor;
import com.android.systemui.keyguard.shared.model.TransitionStep;
import com.android.systemui.log.SessionTracker;
import com.android.systemui.navigationbar.NavigationModeController;
@@ -265,6 +266,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
    private static final int NOTIFY_STARTED_GOING_TO_SLEEP = 17;
    private static final int SYSTEM_READY = 18;
    private static final int CANCEL_KEYGUARD_EXIT_ANIM = 19;
    private static final int BOOT_INTERACTOR = 20;

    /** Enum for reasons behind updating wakeAndUnlock state. */
    @Retention(RetentionPolicy.SOURCE)
@@ -1390,6 +1392,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
    private final DozeParameters mDozeParameters;
    private final SelectedUserInteractor mSelectedUserInteractor;
    private final KeyguardInteractor mKeyguardInteractor;
    private final KeyguardTransitionBootInteractor mTransitionBootInteractor;
    @VisibleForTesting
    protected FoldGracePeriodProvider mFoldGracePeriodProvider =
            new FoldGracePeriodProvider();
@@ -1484,6 +1487,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            Lazy<WindowManagerLockscreenVisibilityManager> wmLockscreenVisibilityManager,
            SelectedUserInteractor selectedUserInteractor,
            KeyguardInteractor keyguardInteractor,
            KeyguardTransitionBootInteractor transitionBootInteractor,
            WindowManagerOcclusionManager wmOcclusionManager) {
        mContext = context;
        mUserTracker = userTracker;
@@ -1524,6 +1528,7 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
        mDozeParameters = dozeParameters;
        mSelectedUserInteractor = selectedUserInteractor;
        mKeyguardInteractor = keyguardInteractor;
        mTransitionBootInteractor = transitionBootInteractor;

        mStatusBarStateController = statusBarStateController;
        statusBarStateController.addCallback(this);
@@ -1678,6 +1683,8 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
            adjustStatusBarLocked();
            mDreamOverlayStateController.addCallback(mDreamOverlayStateCallback);

            mHandler.obtainMessage(BOOT_INTERACTOR).sendToTarget();

            final DreamViewModel dreamViewModel = mDreamViewModel.get();
            final CommunalTransitionViewModel communalViewModel =
                    mCommunalTransitionViewModel.get();
@@ -2705,11 +2712,19 @@ public class KeyguardViewMediator implements CoreStartable, Dumpable,
                    message = "SYSTEM_READY";
                    handleSystemReady();
                    break;
                case BOOT_INTERACTOR:
                    message = "BOOT_INTERACTOR";
                    handleBootInteractor();
                    break;
            }
            Log.d(TAG, "KeyguardViewMediator queue processing message: " + message);
        }
    };

    private void handleBootInteractor() {
        mTransitionBootInteractor.start();
    }

    private void tryKeyguardDone() {
        if (DEBUG) {
            Log.d(TAG, "tryKeyguardDone: pending - " + mKeyguardDonePending + ", animRan - "
Loading