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

Commit 3b251021 authored by Alejandro Nijamkin's avatar Alejandro Nijamkin
Browse files

Fixes bug where affordances are visible in AOD

The issue is that, when consumers are subscribed to the repository's
isDozing flow, they get an initial value of false and are not updated
until after the doze state is changed.

The reason this matters is because the subscribers in this case are the
quick affordance button views themsellves and they subscribe and
unsubscribe based on their visibility. Hence, they get resubscribed
often, seeing the false value.

The fix in this CL is to give the true initial value to the newly
subscribed instead of just false.

Fix: 249084394
Test: Manually verified the fix. The attached bug doesn't reproduce
after the fix. Also tested with "Control from Locked Device" being set
to true and verified no harm done. Unit test case added.

Change-Id: I93369cc559af4ce266bfaec9372c748c8a353466
parent df2bdd51
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -148,7 +148,11 @@ constructor(
                        }
                        }
                    }
                    }
                dozeHost.addCallback(callback)
                dozeHost.addCallback(callback)
                trySendWithFailureLogging(false, TAG, "initial isDozing: false")
                trySendWithFailureLogging(
                    statusBarStateController.isDozing,
                    TAG,
                    "initial isDozing",
                )


                awaitClose { dozeHost.removeCallback(callback) }
                awaitClose { dozeHost.removeCallback(callback) }
            }
            }
+16 −1
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import com.android.systemui.doze.DozeHost
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.util.mockito.argumentCaptor
import com.android.systemui.util.mockito.argumentCaptor
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat
import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onEach
@@ -33,7 +34,6 @@ import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.runners.JUnit4
import org.mockito.Mock
import org.mockito.Mock
import org.mockito.Mockito.verify
import org.mockito.Mockito.verify
import org.mockito.Mockito.`when` as whenever
import org.mockito.MockitoAnnotations
import org.mockito.MockitoAnnotations


@SmallTest
@SmallTest
@@ -149,6 +149,21 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
        verify(dozeHost).removeCallback(captor.value)
        verify(dozeHost).removeCallback(captor.value)
    }
    }


    @Test
    fun `isDozing - starts with correct initial value for isDozing`() = runBlockingTest {
        var latest: Boolean? = null

        whenever(statusBarStateController.isDozing).thenReturn(true)
        var job = underTest.isDozing.onEach { latest = it }.launchIn(this)
        assertThat(latest).isTrue()
        job.cancel()

        whenever(statusBarStateController.isDozing).thenReturn(false)
        job = underTest.isDozing.onEach { latest = it }.launchIn(this)
        assertThat(latest).isFalse()
        job.cancel()
    }

    @Test
    @Test
    fun dozeAmount() = runBlockingTest {
    fun dozeAmount() = runBlockingTest {
        val values = mutableListOf<Float>()
        val values = mutableListOf<Float>()