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..4c4b588888d1a 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 @@ -85,6 +85,15 @@ interface KeyguardRepository { */ val dozeAmount: Flow + /** + * Returns `true` if the keyguard is showing; `false` otherwise. + * + * Note: this is also `true` when the lock-screen is occluded with an `Activity` "above" it in + * the z-order (which is not really above the system UI window, but rather - the lock-screen + * becomes invisible to reveal the "occluding activity"). + */ + fun isKeyguardShowing(): Boolean + /** Sets whether the bottom area UI should animate the transition out of doze state. */ fun setAnimateDozingTransitions(animate: Boolean) @@ -103,7 +112,7 @@ class KeyguardRepositoryImpl @Inject constructor( statusBarStateController: StatusBarStateController, - keyguardStateController: KeyguardStateController, + private val keyguardStateController: KeyguardStateController, dozeHost: DozeHost, ) : KeyguardRepository { private val _animateBottomAreaDozingTransitions = MutableStateFlow(false) @@ -168,6 +177,10 @@ constructor( awaitClose { statusBarStateController.removeCallback(callback) } } + override fun isKeyguardShowing(): Boolean { + return keyguardStateController.isShowing + } + override fun setAnimateDozingTransitions(animate: Boolean) { _animateBottomAreaDozingTransitions.value = animate } diff --git a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt index dccc94178ed5c..192919e32cf64 100644 --- a/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt @@ -29,7 +29,7 @@ import kotlinx.coroutines.flow.Flow class KeyguardInteractor @Inject constructor( - repository: KeyguardRepository, + private val repository: KeyguardRepository, ) { /** * The amount of doze the system is in, where `1.0` is fully dozing and `0.0` is not dozing at @@ -40,4 +40,8 @@ constructor( val isDozing: Flow = repository.isDozing /** Whether the keyguard is showing ot not. */ val isKeyguardShowing: Flow = repository.isKeyguardShowing + + fun isKeyguardShowing(): Boolean { + return repository.isKeyguardShowing() + } } 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..eea2e952c81f0 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 @@ -116,6 +116,7 @@ class KeyguardRepositoryImplTest : SysuiTestCase() { val job = underTest.isKeyguardShowing.onEach { latest = it }.launchIn(this) assertThat(latest).isFalse() + assertThat(underTest.isKeyguardShowing()).isFalse() val captor = argumentCaptor() verify(keyguardStateController).addCallback(captor.capture()) @@ -123,10 +124,12 @@ class KeyguardRepositoryImplTest : SysuiTestCase() { whenever(keyguardStateController.isShowing).thenReturn(true) captor.value.onKeyguardShowingChanged() assertThat(latest).isTrue() + assertThat(underTest.isKeyguardShowing()).isTrue() whenever(keyguardStateController.isShowing).thenReturn(false) captor.value.onKeyguardShowingChanged() assertThat(latest).isFalse() + assertThat(underTest.isKeyguardShowing()).isFalse() job.cancel() } diff --git a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt index 42b434a9deaf2..725b1f41372c9 100644 --- a/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt +++ b/packages/SystemUI/tests/utils/src/com/android/systemui/keyguard/data/repository/FakeKeyguardRepository.kt @@ -44,6 +44,10 @@ class FakeKeyguardRepository : KeyguardRepository { private val _dozeAmount = MutableStateFlow(0f) override val dozeAmount: Flow = _dozeAmount + override fun isKeyguardShowing(): Boolean { + return _isKeyguardShowing.value + } + override fun setAnimateDozingTransitions(animate: Boolean) { _animateBottomAreaDozingTransitions.tryEmit(animate) }