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

Commit 9282e2c3 authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

Make some Keyguard changes to accomodate screenshot testing

Also changed ClockSize to a kotlin enum

Bug: 326375986
Bug: 333389512
Test: atest SimpleClockScreenshotTest
Flag: ACONFIG com.android.systemui.migrate_clocks_to_blueprint STAGING
Change-Id: I744dadc4d4ef7cf3a24e939f2c89728bc8075f2c
parent 057b5afc
Loading
Loading
Loading
Loading
+5 −8
Original line number Diff line number Diff line
@@ -60,6 +60,8 @@ constructor(
        modifier: Modifier = Modifier,
    ) {
        val currentClock by viewModel.currentClock.collectAsState()
        val smallTopMargin by
            viewModel.smallClockTopMargin.collectAsState(viewModel.getSmallClockTopMargin())
        if (currentClock?.smallClock?.view == null) {
            return
        }
@@ -75,7 +77,7 @@ constructor(
                modifier
                    .height(dimensionResource(R.dimen.small_clock_height))
                    .padding(horizontal = dimensionResource(R.dimen.clock_padding_start))
                    .padding(top = { viewModel.getSmallClockTopMargin(context) })
                    .padding(top = { smallTopMargin })
                    .onTopPlacementChanged(onTopChanged)
                    .burnInAware(
                        viewModel = aodBurnInViewModel,
@@ -107,13 +109,8 @@ constructor(
                    1f
                }

            val distance =
                if (transition.toScene == splitShadeLargeClockScene) {
                        -getClockCenteringDistance()
                    } else {
                        getClockCenteringDistance()
                    }
                    .toFloat()
            val dir = if (transition.toScene == splitShadeLargeClockScene) -1f else 1f
            val distance = dir * getClockCenteringDistance()
            val largeClock = checkNotNull(currentClock).largeClock
            largeClock.animations.onPositionUpdated(
                distance = distance,
+1 −1
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@ class DefaultCommunalBlueprintTest : SysuiTestCase() {
    @Test
    fun addView() {
        val constraintLayout = ConstraintLayout(context, null)
        blueprint.replaceViews(null, constraintLayout)
        blueprint.replaceViews(constraintLayout)
        verify(hubSection).addViews(constraintLayout)
    }

+16 −21
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.systemui.keyguard.domain.interactor

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.keyguard.KeyguardClockSwitch.LARGE
import com.android.keyguard.KeyguardClockSwitch.SMALL
import com.android.systemui.SysuiTestCase
import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.DisableSceneContainer
@@ -30,6 +28,7 @@ import com.android.systemui.keyguard.data.repository.fakeKeyguardClockRepository
import com.android.systemui.keyguard.data.repository.fakeKeyguardTransitionRepository
import com.android.systemui.keyguard.data.repository.keyguardClockRepository
import com.android.systemui.keyguard.data.repository.keyguardRepository
import com.android.systemui.keyguard.shared.model.ClockSize
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.keyguard.shared.model.TransitionState
import com.android.systemui.keyguard.shared.model.TransitionStep
@@ -69,11 +68,11 @@ class KeyguardClockInteractorTest : SysuiTestCase() {
    fun clockSize_sceneContainerFlagOff_basedOnRepository() =
        testScope.runTest {
            val value by collectLastValue(underTest.clockSize)
            kosmos.keyguardClockRepository.setClockSize(LARGE)
            assertThat(value).isEqualTo(LARGE)
            kosmos.keyguardClockRepository.setClockSize(ClockSize.LARGE)
            assertThat(value).isEqualTo(ClockSize.LARGE)

            kosmos.keyguardClockRepository.setClockSize(SMALL)
            assertThat(value).isEqualTo(SMALL)
            kosmos.keyguardClockRepository.setClockSize(ClockSize.SMALL)
            assertThat(value).isEqualTo(ClockSize.SMALL)
        }

    @Test
@@ -96,7 +95,7 @@ class KeyguardClockInteractorTest : SysuiTestCase() {
            kosmos.fakeKeyguardClockRepository.setShouldForceSmallClock(true)
            kosmos.fakeFeatureFlagsClassic.set(Flags.LOCKSCREEN_ENABLE_LANDSCAPE, true)
            transitionTo(KeyguardState.AOD, KeyguardState.LOCKSCREEN)
            assertThat(value).isEqualTo(SMALL)
            assertThat(value).isEqualTo(ClockSize.SMALL)
        }

    @Test
@@ -106,7 +105,7 @@ class KeyguardClockInteractorTest : SysuiTestCase() {
            val value by collectLastValue(underTest.clockSize)
            kosmos.shadeRepository.setShadeMode(ShadeMode.Single)
            kosmos.activeNotificationListRepository.setActiveNotifs(1)
            assertThat(value).isEqualTo(SMALL)
            assertThat(value).isEqualTo(ClockSize.SMALL)
        }

    @Test
@@ -117,7 +116,7 @@ class KeyguardClockInteractorTest : SysuiTestCase() {
            kosmos.shadeRepository.setShadeMode(ShadeMode.Single)
            val userMedia = MediaData().copy(active = true)
            kosmos.mediaFilterRepository.addSelectedUserMediaEntry(userMedia)
            assertThat(value).isEqualTo(SMALL)
            assertThat(value).isEqualTo(ClockSize.SMALL)
        }

    @Test
@@ -129,7 +128,7 @@ class KeyguardClockInteractorTest : SysuiTestCase() {
            kosmos.shadeRepository.setShadeMode(ShadeMode.Split)
            kosmos.mediaFilterRepository.addSelectedUserMediaEntry(userMedia)
            kosmos.keyguardRepository.setIsDozing(false)
            assertThat(value).isEqualTo(SMALL)
            assertThat(value).isEqualTo(ClockSize.SMALL)
        }

    @Test
@@ -139,7 +138,7 @@ class KeyguardClockInteractorTest : SysuiTestCase() {
            val value by collectLastValue(underTest.clockSize)
            kosmos.shadeRepository.setShadeMode(ShadeMode.Split)
            kosmos.keyguardRepository.setIsDozing(false)
            assertThat(value).isEqualTo(LARGE)
            assertThat(value).isEqualTo(ClockSize.LARGE)
        }

    @Test
@@ -151,7 +150,7 @@ class KeyguardClockInteractorTest : SysuiTestCase() {
            kosmos.shadeRepository.setShadeMode(ShadeMode.Split)
            kosmos.mediaFilterRepository.addSelectedUserMediaEntry(userMedia)
            kosmos.keyguardRepository.setIsDozing(true)
            assertThat(value).isEqualTo(LARGE)
            assertThat(value).isEqualTo(ClockSize.LARGE)
        }

    @Test
@@ -219,14 +218,10 @@ class KeyguardClockInteractorTest : SysuiTestCase() {
        }

    private suspend fun transitionTo(from: KeyguardState, to: KeyguardState) {
        kosmos.fakeKeyguardTransitionRepository.sendTransitionStep(
            TransitionStep(from, to, 0f, TransitionState.STARTED)
        )
        kosmos.fakeKeyguardTransitionRepository.sendTransitionStep(
            TransitionStep(from, to, 0.5f, TransitionState.RUNNING)
        )
        kosmos.fakeKeyguardTransitionRepository.sendTransitionStep(
            TransitionStep(from, to, 1f, TransitionState.FINISHED)
        )
        with(kosmos.fakeKeyguardTransitionRepository) {
            sendTransitionStep(TransitionStep(from, to, 0f, TransitionState.STARTED))
            sendTransitionStep(TransitionStep(from, to, 0.5f, TransitionState.RUNNING))
            sendTransitionStep(TransitionStep(from, to, 1f, TransitionState.FINISHED))
        }
    }
}
+27 −19
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.keyguard.ui.viewmodel

import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
import com.android.keyguard.KeyguardClockSwitch
import com.android.systemui.SysuiTestCase
import com.android.systemui.biometrics.authController
import com.android.systemui.common.ui.data.repository.fakeConfigurationRepository
@@ -26,6 +25,7 @@ import com.android.systemui.coroutines.collectLastValue
import com.android.systemui.flags.Flags
import com.android.systemui.flags.fakeFeatureFlagsClassic
import com.android.systemui.keyguard.data.repository.fakeKeyguardClockRepository
import com.android.systemui.keyguard.shared.model.ClockSize
import com.android.systemui.kosmos.Kosmos
import com.android.systemui.kosmos.testScope
import com.android.systemui.res.R
@@ -62,7 +62,7 @@ class LockscreenContentViewModelTest : SysuiTestCase() {
    fun isUdfpsVisible_withUdfps_true() =
        with(kosmos) {
            testScope.runTest {
                whenever(kosmos.authController.isUdfpsSupported).thenReturn(true)
                whenever(authController.isUdfpsSupported).thenReturn(true)
                assertThat(underTest.isUdfpsVisible).isTrue()
            }
        }
@@ -71,26 +71,28 @@ class LockscreenContentViewModelTest : SysuiTestCase() {
    fun isUdfpsVisible_withoutUdfps_false() =
        with(kosmos) {
            testScope.runTest {
                whenever(kosmos.authController.isUdfpsSupported).thenReturn(false)
                whenever(authController.isUdfpsSupported).thenReturn(false)
                assertThat(underTest.isUdfpsVisible).isFalse()
            }
        }

    @Test
    fun isLargeClockVisible_withLargeClock_true() =
    fun clockSize_withLargeClock_true() =
        with(kosmos) {
            testScope.runTest {
                kosmos.fakeKeyguardClockRepository.setClockSize(KeyguardClockSwitch.LARGE)
                assertThat(underTest.isLargeClockVisible).isTrue()
                val clockSize by collectLastValue(underTest.clockSize)
                fakeKeyguardClockRepository.setClockSize(ClockSize.LARGE)
                assertThat(clockSize).isEqualTo(ClockSize.LARGE)
            }
        }

    @Test
    fun isLargeClockVisible_withSmallClock_false() =
    fun clockSize_withSmallClock_false() =
        with(kosmos) {
            testScope.runTest {
                kosmos.fakeKeyguardClockRepository.setClockSize(KeyguardClockSwitch.SMALL)
                assertThat(underTest.isLargeClockVisible).isFalse()
                val clockSize by collectLastValue(underTest.clockSize)
                fakeKeyguardClockRepository.setClockSize(ClockSize.SMALL)
                assertThat(clockSize).isEqualTo(ClockSize.SMALL)
            }
        }

@@ -98,18 +100,21 @@ class LockscreenContentViewModelTest : SysuiTestCase() {
    fun areNotificationsVisible_splitShadeTrue_true() =
        with(kosmos) {
            testScope.runTest {
                val areNotificationsVisible by collectLastValue(underTest.areNotificationsVisible)
                shadeRepository.setShadeMode(ShadeMode.Split)
                kosmos.fakeKeyguardClockRepository.setClockSize(KeyguardClockSwitch.LARGE)
                fakeKeyguardClockRepository.setClockSize(ClockSize.LARGE)

                assertThat(collectLastValue(underTest.areNotificationsVisible).invoke()).isTrue()
                assertThat(areNotificationsVisible).isTrue()
            }
        }

    @Test
    fun areNotificationsVisible_withSmallClock_true() =
        with(kosmos) {
            testScope.runTest {
                kosmos.fakeKeyguardClockRepository.setClockSize(KeyguardClockSwitch.SMALL)
                assertThat(collectLastValue(underTest.areNotificationsVisible).invoke()).isTrue()
                val areNotificationsVisible by collectLastValue(underTest.areNotificationsVisible)
                fakeKeyguardClockRepository.setClockSize(ClockSize.SMALL)
                assertThat(areNotificationsVisible).isTrue()
            }
        }

@@ -117,8 +122,9 @@ class LockscreenContentViewModelTest : SysuiTestCase() {
    fun areNotificationsVisible_withLargeClock_false() =
        with(kosmos) {
            testScope.runTest {
                kosmos.fakeKeyguardClockRepository.setClockSize(KeyguardClockSwitch.LARGE)
                assertThat(collectLastValue(underTest.areNotificationsVisible).invoke()).isFalse()
                val areNotificationsVisible by collectLastValue(underTest.areNotificationsVisible)
                fakeKeyguardClockRepository.setClockSize(ClockSize.LARGE)
                assertThat(areNotificationsVisible).isFalse()
            }
        }

@@ -126,9 +132,10 @@ class LockscreenContentViewModelTest : SysuiTestCase() {
    fun shouldUseSplitNotificationShade_withConfigTrue_true() =
        with(kosmos) {
            testScope.runTest {
                val shouldUseSplitNotificationShade by
                    collectLastValue(underTest.shouldUseSplitNotificationShade)
                shadeRepository.setShadeMode(ShadeMode.Split)
                assertThat(collectLastValue(underTest.shouldUseSplitNotificationShade).invoke())
                    .isTrue()
                assertThat(shouldUseSplitNotificationShade).isTrue()
            }
        }

@@ -136,9 +143,10 @@ class LockscreenContentViewModelTest : SysuiTestCase() {
    fun shouldUseSplitNotificationShade_withConfigFalse_false() =
        with(kosmos) {
            testScope.runTest {
                val shouldUseSplitNotificationShade by
                    collectLastValue(underTest.shouldUseSplitNotificationShade)
                shadeRepository.setShadeMode(ShadeMode.Single)
                assertThat(collectLastValue(underTest.shouldUseSplitNotificationShade).invoke())
                    .isFalse()
                assertThat(shouldUseSplitNotificationShade).isFalse()
            }
        }

+3 −3
Original line number Diff line number Diff line
@@ -68,6 +68,8 @@ import com.android.systemui.util.ViewController;
import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.util.settings.SecureSettings;

import kotlinx.coroutines.DisposableHandle;

import java.io.PrintWriter;
import java.util.Locale;
import java.util.concurrent.Executor;
@@ -75,8 +77,6 @@ import java.util.function.Consumer;

import javax.inject.Inject;

import kotlinx.coroutines.DisposableHandle;

/**
 * Injectable controller for {@link KeyguardClockSwitch}.
 */
@@ -593,7 +593,7 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS

    boolean isClockTopAligned() {
        if (MigrateClocksToBlueprint.isEnabled()) {
            return mKeyguardClockInteractor.getClockSize().getValue() == LARGE;
            return mKeyguardClockInteractor.getClockSize().getValue().getLegacyValue() == LARGE;
        }
        return mLargeClockFrame.getVisibility() != View.VISIBLE;
    }
Loading