From 3b251021c6324881c1622ebc582638f337bf5362 Mon Sep 17 00:00:00 2001 From: Alejandro Nijamkin Date: Tue, 4 Oct 2022 16:06:31 -0700 Subject: [PATCH] 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 --- .../data/repository/KeyguardRepository.kt | 6 +++++- .../repository/KeyguardRepositoryImplTest.kt | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt index 840a4b20a3f02..89c8281c75474 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt @@ -148,7 +148,11 @@ constructor( } } dozeHost.addCallback(callback) - trySendWithFailureLogging(false, TAG, "initial isDozing: false") + trySendWithFailureLogging( + statusBarStateController.isDozing, + TAG, + "initial isDozing", + ) awaitClose { dozeHost.removeCallback(callback) } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt index ba1e168bc3169..a4dd7176d0027 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt @@ -23,6 +23,7 @@ import com.android.systemui.doze.DozeHost import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.statusbar.policy.KeyguardStateController import com.android.systemui.util.mockito.argumentCaptor +import com.android.systemui.util.mockito.whenever import com.google.common.truth.Truth.assertThat import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -33,7 +34,6 @@ import org.junit.runner.RunWith import org.junit.runners.JUnit4 import org.mockito.Mock import org.mockito.Mockito.verify -import org.mockito.Mockito.`when` as whenever import org.mockito.MockitoAnnotations @SmallTest @@ -149,6 +149,21 @@ class KeyguardRepositoryImplTest : SysuiTestCase() { 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 fun dozeAmount() = runBlockingTest { val values = mutableListOf()