Loading packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt +44 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,12 @@ interface KeyguardRepository { /** Is an activity showing over the keyguard? */ val isKeyguardOccluded: Flow<Boolean> /** * Whether the device is locked or unlocked right now. This is true when keyguard has been * dismissed or can be dismissed by a swipe */ val isKeyguardUnlocked: StateFlow<Boolean> /** * Observable for the signal that keyguard is about to go away. * Loading Loading @@ -332,6 +338,44 @@ constructor( } .distinctUntilChanged() override val isKeyguardUnlocked: StateFlow<Boolean> = conflatedCallbackFlow { val callback = object : KeyguardStateController.Callback { override fun onUnlockedChanged() { trySendWithFailureLogging( keyguardStateController.isUnlocked, TAG, "updated isKeyguardUnlocked due to onUnlockedChanged" ) } override fun onKeyguardShowingChanged() { trySendWithFailureLogging( keyguardStateController.isUnlocked, TAG, "updated isKeyguardUnlocked due to onKeyguardShowingChanged" ) } } keyguardStateController.addCallback(callback) // Adding the callback does not send an initial update. trySendWithFailureLogging( keyguardStateController.isUnlocked, TAG, "initial isKeyguardUnlocked" ) awaitClose { keyguardStateController.removeCallback(callback) } } .distinctUntilChanged() .stateIn( scope, SharingStarted.Eagerly, initialValue = false, ) override val isKeyguardGoingAway: Flow<Boolean> = conflatedCallbackFlow { val callback = object : KeyguardStateController.Callback { Loading packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt +1 −3 Original line number Diff line number Diff line Loading @@ -30,7 +30,6 @@ import com.android.systemui.common.shared.model.Position import com.android.systemui.common.shared.model.SharedNotificationContainerPosition import com.android.systemui.common.ui.data.repository.ConfigurationRepository import com.android.systemui.dagger.SysUISingleton import com.android.systemui.deviceentry.data.repository.DeviceEntryRepository import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.keyguard.data.repository.KeyguardRepository Loading Loading @@ -78,7 +77,6 @@ constructor( private val powerInteractor: PowerInteractor, featureFlags: FeatureFlags, sceneContainerFlags: SceneContainerFlags, deviceEntryRepository: DeviceEntryRepository, bouncerRepository: KeyguardBouncerRepository, configurationRepository: ConfigurationRepository, shadeRepository: ShadeRepository, Loading Loading @@ -160,7 +158,7 @@ constructor( val isKeyguardShowing: Flow<Boolean> = repository.isKeyguardShowing /** Whether the keyguard is unlocked or not. */ val isKeyguardUnlocked: Flow<Boolean> = deviceEntryRepository.isUnlocked val isKeyguardUnlocked: Flow<Boolean> = repository.isKeyguardUnlocked /** Whether the keyguard is occluded (covered by an activity). */ val isKeyguardOccluded: Flow<Boolean> = repository.isKeyguardOccluded Loading packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt +23 −0 Original line number Diff line number Diff line Loading @@ -215,6 +215,29 @@ class KeyguardRepositoryImplTest : SysuiTestCase() { job.cancel() } @Test fun isKeyguardUnlocked() = testScope.runTest { whenever(keyguardStateController.isUnlocked).thenReturn(false) val isKeyguardUnlocked by collectLastValue(underTest.isKeyguardUnlocked) runCurrent() assertThat(isKeyguardUnlocked).isFalse() val captor = argumentCaptor<KeyguardStateController.Callback>() verify(keyguardStateController, atLeastOnce()).addCallback(captor.capture()) whenever(keyguardStateController.isUnlocked).thenReturn(true) captor.value.onUnlockedChanged() runCurrent() assertThat(isKeyguardUnlocked).isTrue() whenever(keyguardStateController.isUnlocked).thenReturn(false) captor.value.onKeyguardShowingChanged() runCurrent() assertThat(isKeyguardUnlocked).isFalse() } @Test fun isDozing() = testScope.runTest { Loading packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorTest.kt +0 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,6 @@ class KeyguardInteractorTest : SysuiTestCase() { powerInteractor = PowerInteractorFactory.create().powerInteractor, featureFlags = featureFlags, sceneContainerFlags = testUtils.sceneContainerFlags, deviceEntryRepository = testUtils.deviceEntryRepository, bouncerRepository = bouncerRepository, configurationRepository = configurationRepository, shadeRepository = shadeRepository, Loading packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowControllerImplTest.java +0 −2 Original line number Diff line number Diff line Loading @@ -54,7 +54,6 @@ import com.android.systemui.bouncer.data.repository.FakeKeyguardBouncerRepositor import com.android.systemui.classifier.FalsingCollectorFake; import com.android.systemui.colorextraction.SysuiColorExtractor; import com.android.systemui.common.ui.data.repository.FakeConfigurationRepository; import com.android.systemui.deviceentry.data.repository.FakeDeviceEntryRepository; import com.android.systemui.dump.DumpManager; import com.android.systemui.flags.FakeFeatureFlagsClassic; import com.android.systemui.keyguard.KeyguardViewMediator; Loading Loading @@ -185,7 +184,6 @@ public class NotificationShadeWindowControllerImplTest extends SysuiTestCase { powerInteractor, featureFlags, sceneContainerFlags, new FakeDeviceEntryRepository(), new FakeKeyguardBouncerRepository(), configurationRepository, shadeRepository, Loading Loading
packages/SystemUI/src/com/android/systemui/keyguard/data/repository/KeyguardRepository.kt +44 −0 Original line number Diff line number Diff line Loading @@ -92,6 +92,12 @@ interface KeyguardRepository { /** Is an activity showing over the keyguard? */ val isKeyguardOccluded: Flow<Boolean> /** * Whether the device is locked or unlocked right now. This is true when keyguard has been * dismissed or can be dismissed by a swipe */ val isKeyguardUnlocked: StateFlow<Boolean> /** * Observable for the signal that keyguard is about to go away. * Loading Loading @@ -332,6 +338,44 @@ constructor( } .distinctUntilChanged() override val isKeyguardUnlocked: StateFlow<Boolean> = conflatedCallbackFlow { val callback = object : KeyguardStateController.Callback { override fun onUnlockedChanged() { trySendWithFailureLogging( keyguardStateController.isUnlocked, TAG, "updated isKeyguardUnlocked due to onUnlockedChanged" ) } override fun onKeyguardShowingChanged() { trySendWithFailureLogging( keyguardStateController.isUnlocked, TAG, "updated isKeyguardUnlocked due to onKeyguardShowingChanged" ) } } keyguardStateController.addCallback(callback) // Adding the callback does not send an initial update. trySendWithFailureLogging( keyguardStateController.isUnlocked, TAG, "initial isKeyguardUnlocked" ) awaitClose { keyguardStateController.removeCallback(callback) } } .distinctUntilChanged() .stateIn( scope, SharingStarted.Eagerly, initialValue = false, ) override val isKeyguardGoingAway: Flow<Boolean> = conflatedCallbackFlow { val callback = object : KeyguardStateController.Callback { Loading
packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractor.kt +1 −3 Original line number Diff line number Diff line Loading @@ -30,7 +30,6 @@ import com.android.systemui.common.shared.model.Position import com.android.systemui.common.shared.model.SharedNotificationContainerPosition import com.android.systemui.common.ui.data.repository.ConfigurationRepository import com.android.systemui.dagger.SysUISingleton import com.android.systemui.deviceentry.data.repository.DeviceEntryRepository import com.android.systemui.flags.FeatureFlags import com.android.systemui.flags.Flags import com.android.systemui.keyguard.data.repository.KeyguardRepository Loading Loading @@ -78,7 +77,6 @@ constructor( private val powerInteractor: PowerInteractor, featureFlags: FeatureFlags, sceneContainerFlags: SceneContainerFlags, deviceEntryRepository: DeviceEntryRepository, bouncerRepository: KeyguardBouncerRepository, configurationRepository: ConfigurationRepository, shadeRepository: ShadeRepository, Loading Loading @@ -160,7 +158,7 @@ constructor( val isKeyguardShowing: Flow<Boolean> = repository.isKeyguardShowing /** Whether the keyguard is unlocked or not. */ val isKeyguardUnlocked: Flow<Boolean> = deviceEntryRepository.isUnlocked val isKeyguardUnlocked: Flow<Boolean> = repository.isKeyguardUnlocked /** Whether the keyguard is occluded (covered by an activity). */ val isKeyguardOccluded: Flow<Boolean> = repository.isKeyguardOccluded Loading
packages/SystemUI/tests/src/com/android/systemui/keyguard/data/repository/KeyguardRepositoryImplTest.kt +23 −0 Original line number Diff line number Diff line Loading @@ -215,6 +215,29 @@ class KeyguardRepositoryImplTest : SysuiTestCase() { job.cancel() } @Test fun isKeyguardUnlocked() = testScope.runTest { whenever(keyguardStateController.isUnlocked).thenReturn(false) val isKeyguardUnlocked by collectLastValue(underTest.isKeyguardUnlocked) runCurrent() assertThat(isKeyguardUnlocked).isFalse() val captor = argumentCaptor<KeyguardStateController.Callback>() verify(keyguardStateController, atLeastOnce()).addCallback(captor.capture()) whenever(keyguardStateController.isUnlocked).thenReturn(true) captor.value.onUnlockedChanged() runCurrent() assertThat(isKeyguardUnlocked).isTrue() whenever(keyguardStateController.isUnlocked).thenReturn(false) captor.value.onKeyguardShowingChanged() runCurrent() assertThat(isKeyguardUnlocked).isFalse() } @Test fun isDozing() = testScope.runTest { Loading
packages/SystemUI/tests/src/com/android/systemui/keyguard/domain/interactor/KeyguardInteractorTest.kt +0 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,6 @@ class KeyguardInteractorTest : SysuiTestCase() { powerInteractor = PowerInteractorFactory.create().powerInteractor, featureFlags = featureFlags, sceneContainerFlags = testUtils.sceneContainerFlags, deviceEntryRepository = testUtils.deviceEntryRepository, bouncerRepository = bouncerRepository, configurationRepository = configurationRepository, shadeRepository = shadeRepository, Loading
packages/SystemUI/tests/src/com/android/systemui/shade/NotificationShadeWindowControllerImplTest.java +0 −2 Original line number Diff line number Diff line Loading @@ -54,7 +54,6 @@ import com.android.systemui.bouncer.data.repository.FakeKeyguardBouncerRepositor import com.android.systemui.classifier.FalsingCollectorFake; import com.android.systemui.colorextraction.SysuiColorExtractor; import com.android.systemui.common.ui.data.repository.FakeConfigurationRepository; import com.android.systemui.deviceentry.data.repository.FakeDeviceEntryRepository; import com.android.systemui.dump.DumpManager; import com.android.systemui.flags.FakeFeatureFlagsClassic; import com.android.systemui.keyguard.KeyguardViewMediator; Loading Loading @@ -185,7 +184,6 @@ public class NotificationShadeWindowControllerImplTest extends SysuiTestCase { powerInteractor, featureFlags, sceneContainerFlags, new FakeDeviceEntryRepository(), new FakeKeyguardBouncerRepository(), configurationRepository, shadeRepository, Loading