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

Commit 58fe6982 authored by Matt Pietal's avatar Matt Pietal
Browse files

Simplify dreaming flows

Don't use KeyguardUpdateMonitor for this information. Instead
rely directly on KeyguardService to ensure timely delivery
of the isDreaming signal.

Fixes: 345373593
Test: atest KeyguardRepositoryImplTest
Flag: EXEMPT
Change-Id: I687ff739263320f251e884f33377ec6bb061c6e4
parent b01d46eb
Loading
Loading
Loading
Loading
+8 −19
Original line number Diff line number Diff line
@@ -333,27 +333,16 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
        }

    @Test
    fun isDreamingFromKeyguardUpdateMonitor() =
        TestScope(mainDispatcher).runTest {
            whenever(keyguardUpdateMonitor.isDreaming()).thenReturn(false)
            var latest: Boolean? = null
            val job = underTest.isDreaming.onEach { latest = it }.launchIn(this)

            runCurrent()
            assertThat(latest).isFalse()

            val captor = argumentCaptor<KeyguardUpdateMonitorCallback>()
            verify(keyguardUpdateMonitor).registerCallback(captor.capture())

            captor.value.onDreamingStateChanged(true)
            runCurrent()
            assertThat(latest).isTrue()
    fun isDreaming() =
        testScope.runTest {
            val isDreaming by collectLastValue(underTest.isDreaming)
            assertThat(isDreaming).isFalse()

            captor.value.onDreamingStateChanged(false)
            runCurrent()
            assertThat(latest).isFalse()
            underTest.setDreaming(true)
            assertThat(isDreaming).isTrue()

            job.cancel()
            underTest.setDreaming(false)
            assertThat(isDreaming).isFalse()
        }

    @Test
+6 −0
Original line number Diff line number Diff line
@@ -80,6 +80,7 @@ import com.android.systemui.dagger.qualifiers.Application;
import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.keyguard.domain.interactor.KeyguardEnabledInteractor;
import com.android.systemui.keyguard.domain.interactor.KeyguardInteractor;
import com.android.systemui.keyguard.ui.binder.KeyguardSurfaceBehindParamsApplier;
import com.android.systemui.keyguard.ui.binder.KeyguardSurfaceBehindViewBinder;
import com.android.systemui.keyguard.ui.binder.WindowManagerLockscreenVisibilityViewBinder;
@@ -118,6 +119,7 @@ public class KeyguardService extends Service {
    private final ShellTransitions mShellTransitions;
    private final DisplayTracker mDisplayTracker;
    private final PowerInteractor mPowerInteractor;
    private final KeyguardInteractor mKeyguardInteractor;
    private final Lazy<SceneInteractor> mSceneInteractorLazy;
    private final Executor mMainExecutor;

@@ -338,6 +340,7 @@ public class KeyguardService extends Service {
            WindowManagerOcclusionManager windowManagerOcclusionManager,
            Lazy<SceneInteractor> sceneInteractorLazy,
            @Main Executor mainExecutor,
            KeyguardInteractor keyguardInteractor,
            KeyguardEnabledInteractor keyguardEnabledInteractor) {
        super();
        mKeyguardViewMediator = keyguardViewMediator;
@@ -347,6 +350,7 @@ public class KeyguardService extends Service {
        mDisplayTracker = displayTracker;
        mFlags = featureFlags;
        mPowerInteractor = powerInteractor;
        mKeyguardInteractor = keyguardInteractor;
        mSceneInteractorLazy = sceneInteractorLazy;
        mMainExecutor = mainExecutor;

@@ -474,6 +478,7 @@ public class KeyguardService extends Service {
        public void onDreamingStarted() {
            trace("onDreamingStarted");
            checkPermission();
            mKeyguardInteractor.setDreaming(true);
            mKeyguardViewMediator.onDreamingStarted();
        }

@@ -481,6 +486,7 @@ public class KeyguardService extends Service {
        public void onDreamingStopped() {
            trace("onDreamingStopped");
            checkPermission();
            mKeyguardInteractor.setDreaming(false);
            mKeyguardViewMediator.onDreamingStopped();
        }

+9 −20
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ interface KeyguardRepository {
     * Dozing/AOD is a specific type of dream, but it is also possible for other non-systemui dreams
     * to be active, such as screensavers.
     */
    val isDreaming: Flow<Boolean>
    val isDreaming: MutableStateFlow<Boolean>

    /** Observable for whether the device is dreaming with an overlay, see [DreamOverlayService] */
    val isDreamingWithOverlay: Flow<Boolean>
@@ -250,6 +250,9 @@ interface KeyguardRepository {
    /** Sets the current amount of alpha that should be used for rendering the keyguard. */
    fun setKeyguardAlpha(alpha: Float)

    /** Whether the device is actively dreaming */
    fun setDreaming(isDreaming: Boolean)

    /**
     * Returns whether the keyguard bottom area should be constrained to the top of the lock icon
     */
@@ -509,25 +512,7 @@ constructor(
            }
            .distinctUntilChanged()

    override val isDreaming: Flow<Boolean> =
        conflatedCallbackFlow {
                val callback =
                    object : KeyguardUpdateMonitorCallback() {
                        override fun onDreamingStateChanged(isDreaming: Boolean) {
                            trySendWithFailureLogging(isDreaming, TAG, "updated isDreaming")
                        }
                    }
                keyguardUpdateMonitor.registerCallback(callback)
                trySendWithFailureLogging(
                    keyguardUpdateMonitor.isDreaming,
                    TAG,
                    "initial isDreaming",
                )

                awaitClose { keyguardUpdateMonitor.removeCallback(callback) }
            }
            .flowOn(mainDispatcher)
            .distinctUntilChanged()
    override val isDreaming: MutableStateFlow<Boolean> = MutableStateFlow(false)

    override val linearDozeAmount: Flow<Float> = conflatedCallbackFlow {
        val callback =
@@ -674,6 +659,10 @@ constructor(
        _keyguardAlpha.value = alpha
    }

    override fun setDreaming(isDreaming: Boolean) {
        this.isDreaming.value = isDreaming
    }

    override fun isUdfpsSupported(): Boolean = keyguardUpdateMonitor.isUdfpsSupported

    override fun setQuickSettingsVisible(isVisible: Boolean) {
+4 −0
Original line number Diff line number Diff line
@@ -482,6 +482,10 @@ constructor(
        repository.topClippingBounds.value = top
    }

    fun setDreaming(isDreaming: Boolean) {
        repository.setDreaming(isDreaming)
    }

    /** Temporary shim, until [KeyguardWmStateRefactor] is enabled */
    fun showKeyguard() {
        fromGoneTransitionInteractor.get().showKeyguard()
+2 −2
Original line number Diff line number Diff line
@@ -80,7 +80,7 @@ class FakeKeyguardRepository @Inject constructor() : KeyguardRepository {
    override val isAodAvailable: StateFlow<Boolean> = _isAodAvailable

    private val _isDreaming = MutableStateFlow(false)
    override val isDreaming: Flow<Boolean> = _isDreaming
    override val isDreaming: MutableStateFlow<Boolean> = _isDreaming

    private val _isDreamingWithOverlay = MutableStateFlow(false)
    override val isDreamingWithOverlay: Flow<Boolean> = _isDreamingWithOverlay
@@ -204,7 +204,7 @@ class FakeKeyguardRepository @Inject constructor() : KeyguardRepository {
        _isAodAvailable.value = value
    }

    fun setDreaming(isDreaming: Boolean) {
    override fun setDreaming(isDreaming: Boolean) {
        _isDreaming.value = isDreaming
    }