Add screen state, dozeTimeTick to keyguard repository
... to support upcoming migration of keyguard status view, logic will first need to move out of NPVC and CentralSurfacesImpl. Bug: 288242803 Test: atest KeyguardRepositoryImplTest Change-Id: I1dca48a4f4a91f1be6bc082ba0e8c2c06cbc6366
This commit is contained in:
@@ -31,11 +31,13 @@ import com.android.systemui.doze.DozeMachine
|
||||
import com.android.systemui.doze.DozeTransitionCallback
|
||||
import com.android.systemui.doze.DozeTransitionListener
|
||||
import com.android.systemui.dreams.DreamOverlayCallbackController
|
||||
import com.android.systemui.keyguard.ScreenLifecycle
|
||||
import com.android.systemui.keyguard.WakefulnessLifecycle
|
||||
import com.android.systemui.keyguard.shared.model.BiometricUnlockModel
|
||||
import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
|
||||
import com.android.systemui.keyguard.shared.model.DozeStateModel
|
||||
import com.android.systemui.keyguard.shared.model.DozeTransitionModel
|
||||
import com.android.systemui.keyguard.shared.model.ScreenModel
|
||||
import com.android.systemui.keyguard.shared.model.StatusBarState
|
||||
import com.android.systemui.keyguard.shared.model.WakefulnessModel
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController
|
||||
@@ -48,9 +50,11 @@ import kotlinx.coroutines.CoroutineDispatcher
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.channels.awaitClose
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.SharingStarted
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asSharedFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
@@ -147,6 +151,9 @@ interface KeyguardRepository {
|
||||
/** Observable for device wake/sleep state */
|
||||
val wakefulness: StateFlow<WakefulnessModel>
|
||||
|
||||
/** Observable for device screen state */
|
||||
val screenModel: StateFlow<ScreenModel>
|
||||
|
||||
/** Observable for biometric unlock modes */
|
||||
val biometricUnlockState: Flow<BiometricUnlockModel>
|
||||
|
||||
@@ -162,6 +169,9 @@ interface KeyguardRepository {
|
||||
/** Whether quick settings or quick-quick settings is visible. */
|
||||
val isQuickSettingsVisible: Flow<Boolean>
|
||||
|
||||
/** Receive an event for doze time tick */
|
||||
val dozeTimeTick: Flow<Unit>
|
||||
|
||||
/**
|
||||
* Returns `true` if the keyguard is showing; `false` otherwise.
|
||||
*
|
||||
@@ -195,6 +205,8 @@ interface KeyguardRepository {
|
||||
fun setIsDozing(isDozing: Boolean)
|
||||
|
||||
fun setIsActiveDreamLockscreenHosted(isLockscreenHosted: Boolean)
|
||||
|
||||
fun dozeTimeTick()
|
||||
}
|
||||
|
||||
/** Encapsulates application state for the keyguard. */
|
||||
@@ -204,6 +216,7 @@ class KeyguardRepositoryImpl
|
||||
constructor(
|
||||
statusBarStateController: StatusBarStateController,
|
||||
wakefulnessLifecycle: WakefulnessLifecycle,
|
||||
screenLifecycle: ScreenLifecycle,
|
||||
biometricUnlockController: BiometricUnlockController,
|
||||
private val keyguardStateController: KeyguardStateController,
|
||||
private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
|
||||
@@ -366,6 +379,13 @@ constructor(
|
||||
_isDozing.value = isDozing
|
||||
}
|
||||
|
||||
private val _dozeTimeTick = MutableSharedFlow<Unit>()
|
||||
override val dozeTimeTick = _dozeTimeTick.asSharedFlow()
|
||||
|
||||
override fun dozeTimeTick() {
|
||||
_dozeTimeTick.tryEmit(Unit)
|
||||
}
|
||||
|
||||
private val _lastDozeTapToWakePosition = MutableStateFlow<Point?>(null)
|
||||
override val lastDozeTapToWakePosition = _lastDozeTapToWakePosition.asStateFlow()
|
||||
|
||||
@@ -551,6 +571,42 @@ constructor(
|
||||
initialValue = WakefulnessModel.fromWakefulnessLifecycle(wakefulnessLifecycle),
|
||||
)
|
||||
|
||||
override val screenModel: StateFlow<ScreenModel> =
|
||||
conflatedCallbackFlow {
|
||||
val observer =
|
||||
object : ScreenLifecycle.Observer {
|
||||
override fun onScreenTurningOn() {
|
||||
dispatchNewState()
|
||||
}
|
||||
override fun onScreenTurnedOn() {
|
||||
dispatchNewState()
|
||||
}
|
||||
override fun onScreenTurningOff() {
|
||||
dispatchNewState()
|
||||
}
|
||||
override fun onScreenTurnedOff() {
|
||||
dispatchNewState()
|
||||
}
|
||||
|
||||
private fun dispatchNewState() {
|
||||
trySendWithFailureLogging(
|
||||
ScreenModel.fromScreenLifecycle(screenLifecycle),
|
||||
TAG,
|
||||
"updated screen state",
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
screenLifecycle.addObserver(observer)
|
||||
awaitClose { screenLifecycle.removeObserver(observer) }
|
||||
}
|
||||
.stateIn(
|
||||
scope,
|
||||
// Use Eagerly so that we're always listening and never miss an event.
|
||||
SharingStarted.Eagerly,
|
||||
initialValue = ScreenModel.fromScreenLifecycle(screenLifecycle),
|
||||
)
|
||||
|
||||
override val fingerprintSensorLocation: Flow<Point?> = conflatedCallbackFlow {
|
||||
fun sendFpLocation() {
|
||||
trySendWithFailureLogging(
|
||||
|
||||
@@ -35,4 +35,8 @@ constructor(
|
||||
fun setLastTapToWakePosition(position: Point) {
|
||||
keyguardRepository.setLastDozeTapToWakePosition(position)
|
||||
}
|
||||
|
||||
fun dozeTimeTick() {
|
||||
keyguardRepository.dozeTimeTick()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,8 @@ constructor(
|
||||
val dozeAmount: Flow<Float> = repository.linearDozeAmount
|
||||
/** Whether the system is in doze mode. */
|
||||
val isDozing: Flow<Boolean> = repository.isDozing
|
||||
/** Receive an event for doze time tick */
|
||||
val dozeTimeTick: Flow<Unit> = repository.dozeTimeTick
|
||||
/** Whether Always-on Display mode is available. */
|
||||
val isAodAvailable: Flow<Boolean> = repository.isAodAvailable
|
||||
/** Doze transition information. */
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (C) 2023 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License
|
||||
*/
|
||||
package com.android.systemui.keyguard.shared.model
|
||||
|
||||
import com.android.systemui.keyguard.ScreenLifecycle
|
||||
|
||||
/** Model device screen lifecycle states. */
|
||||
data class ScreenModel(
|
||||
val state: ScreenState,
|
||||
) {
|
||||
companion object {
|
||||
fun fromScreenLifecycle(screenLifecycle: ScreenLifecycle): ScreenModel {
|
||||
return ScreenModel(ScreenState.fromScreenLifecycleInt(screenLifecycle.getScreenState()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.systemui.keyguard.shared.model
|
||||
|
||||
import com.android.systemui.keyguard.ScreenLifecycle
|
||||
|
||||
enum class ScreenState {
|
||||
/** Screen is fully off. */
|
||||
SCREEN_OFF,
|
||||
/** Signal that the screen is turning on. */
|
||||
SCREEN_TURNING_ON,
|
||||
/** Screen is fully on. */
|
||||
SCREEN_ON,
|
||||
/** Signal that the screen is turning off. */
|
||||
SCREEN_TURNING_OFF;
|
||||
|
||||
companion object {
|
||||
fun fromScreenLifecycleInt(value: Int): ScreenState {
|
||||
return when (value) {
|
||||
ScreenLifecycle.SCREEN_OFF -> SCREEN_OFF
|
||||
ScreenLifecycle.SCREEN_TURNING_ON -> SCREEN_TURNING_ON
|
||||
ScreenLifecycle.SCREEN_ON -> SCREEN_ON
|
||||
ScreenLifecycle.SCREEN_TURNING_OFF -> SCREEN_TURNING_OFF
|
||||
else -> throw IllegalArgumentException("Invalid screen value: $value")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -311,6 +311,7 @@ public final class DozeServiceHost implements DozeHost {
|
||||
|
||||
@Override
|
||||
public void dozeTimeTick() {
|
||||
mDozeInteractor.dozeTimeTick();
|
||||
mNotificationPanel.dozeTimeTick();
|
||||
mAuthController.dozeTimeTick();
|
||||
if (mAmbientIndicationContainer instanceof DozeReceiver) {
|
||||
|
||||
@@ -31,11 +31,14 @@ import com.android.systemui.doze.DozeMachine
|
||||
import com.android.systemui.doze.DozeTransitionCallback
|
||||
import com.android.systemui.doze.DozeTransitionListener
|
||||
import com.android.systemui.dreams.DreamOverlayCallbackController
|
||||
import com.android.systemui.keyguard.ScreenLifecycle
|
||||
import com.android.systemui.keyguard.WakefulnessLifecycle
|
||||
import com.android.systemui.keyguard.shared.model.BiometricUnlockModel
|
||||
import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
|
||||
import com.android.systemui.keyguard.shared.model.DozeStateModel
|
||||
import com.android.systemui.keyguard.shared.model.DozeTransitionModel
|
||||
import com.android.systemui.keyguard.shared.model.ScreenModel
|
||||
import com.android.systemui.keyguard.shared.model.ScreenState
|
||||
import com.android.systemui.keyguard.shared.model.WakefulnessModel
|
||||
import com.android.systemui.keyguard.shared.model.WakefulnessState
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController
|
||||
@@ -70,6 +73,7 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
|
||||
@Mock private lateinit var statusBarStateController: StatusBarStateController
|
||||
@Mock private lateinit var keyguardStateController: KeyguardStateController
|
||||
@Mock private lateinit var wakefulnessLifecycle: WakefulnessLifecycle
|
||||
@Mock private lateinit var screenLifecycle: ScreenLifecycle
|
||||
@Mock private lateinit var biometricUnlockController: BiometricUnlockController
|
||||
@Mock private lateinit var dozeTransitionListener: DozeTransitionListener
|
||||
@Mock private lateinit var authController: AuthController
|
||||
@@ -90,6 +94,7 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
|
||||
KeyguardRepositoryImpl(
|
||||
statusBarStateController,
|
||||
wakefulnessLifecycle,
|
||||
screenLifecycle,
|
||||
biometricUnlockController,
|
||||
keyguardStateController,
|
||||
keyguardUpdateMonitor,
|
||||
@@ -156,6 +161,16 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
|
||||
assertThat(underTest.clockPosition.value).isEqualTo(Position(3, 1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun dozeTimeTick() =
|
||||
testScope.runTest {
|
||||
var dozeTimeTickValue = collectLastValue(underTest.dozeTimeTick)
|
||||
underTest.dozeTimeTick()
|
||||
runCurrent()
|
||||
|
||||
assertThat(dozeTimeTickValue()).isNull()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isKeyguardShowing() =
|
||||
testScope.runTest {
|
||||
@@ -353,6 +368,48 @@ class KeyguardRepositoryImplTest : SysuiTestCase() {
|
||||
job.cancel()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun screenModel() =
|
||||
testScope.runTest {
|
||||
val values = mutableListOf<ScreenModel>()
|
||||
val job = underTest.screenModel.onEach(values::add).launchIn(this)
|
||||
|
||||
runCurrent()
|
||||
val captor = argumentCaptor<ScreenLifecycle.Observer>()
|
||||
verify(screenLifecycle).addObserver(captor.capture())
|
||||
|
||||
whenever(screenLifecycle.getScreenState()).thenReturn(ScreenLifecycle.SCREEN_TURNING_ON)
|
||||
captor.value.onScreenTurningOn()
|
||||
runCurrent()
|
||||
|
||||
whenever(screenLifecycle.getScreenState()).thenReturn(ScreenLifecycle.SCREEN_ON)
|
||||
captor.value.onScreenTurnedOn()
|
||||
runCurrent()
|
||||
|
||||
whenever(screenLifecycle.getScreenState())
|
||||
.thenReturn(ScreenLifecycle.SCREEN_TURNING_OFF)
|
||||
captor.value.onScreenTurningOff()
|
||||
runCurrent()
|
||||
|
||||
whenever(screenLifecycle.getScreenState()).thenReturn(ScreenLifecycle.SCREEN_OFF)
|
||||
captor.value.onScreenTurnedOff()
|
||||
runCurrent()
|
||||
|
||||
assertThat(values.map { it.state })
|
||||
.isEqualTo(
|
||||
listOf(
|
||||
// Initial value will be OFF
|
||||
ScreenState.SCREEN_OFF,
|
||||
ScreenState.SCREEN_TURNING_ON,
|
||||
ScreenState.SCREEN_ON,
|
||||
ScreenState.SCREEN_TURNING_OFF,
|
||||
ScreenState.SCREEN_OFF,
|
||||
)
|
||||
)
|
||||
|
||||
job.cancel()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun isUdfpsSupported() =
|
||||
testScope.runTest {
|
||||
|
||||
@@ -22,11 +22,14 @@ import com.android.systemui.common.shared.model.Position
|
||||
import com.android.systemui.keyguard.shared.model.BiometricUnlockModel
|
||||
import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
|
||||
import com.android.systemui.keyguard.shared.model.DozeTransitionModel
|
||||
import com.android.systemui.keyguard.shared.model.ScreenModel
|
||||
import com.android.systemui.keyguard.shared.model.ScreenState
|
||||
import com.android.systemui.keyguard.shared.model.StatusBarState
|
||||
import com.android.systemui.keyguard.shared.model.WakeSleepReason
|
||||
import com.android.systemui.keyguard.shared.model.WakefulnessModel
|
||||
import com.android.systemui.keyguard.shared.model.WakefulnessState
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
import kotlinx.coroutines.flow.asStateFlow
|
||||
@@ -56,6 +59,9 @@ class FakeKeyguardRepository : KeyguardRepository {
|
||||
private val _isDozing = MutableStateFlow(false)
|
||||
override val isDozing: StateFlow<Boolean> = _isDozing
|
||||
|
||||
private val _dozeTimeTick = MutableSharedFlow<Unit>()
|
||||
override val dozeTimeTick = _dozeTimeTick
|
||||
|
||||
private val _lastDozeTapToWakePosition = MutableStateFlow<Point?>(null)
|
||||
override val lastDozeTapToWakePosition = _lastDozeTapToWakePosition.asStateFlow()
|
||||
|
||||
@@ -86,6 +92,9 @@ class FakeKeyguardRepository : KeyguardRepository {
|
||||
)
|
||||
override val wakefulness = _wakefulnessModel
|
||||
|
||||
private val _screenModel = MutableStateFlow(ScreenModel(ScreenState.SCREEN_OFF))
|
||||
override val screenModel = _screenModel
|
||||
|
||||
private val _isUdfpsSupported = MutableStateFlow(false)
|
||||
|
||||
private val _isKeyguardGoingAway = MutableStateFlow(false)
|
||||
@@ -142,6 +151,10 @@ class FakeKeyguardRepository : KeyguardRepository {
|
||||
_isDozing.value = isDozing
|
||||
}
|
||||
|
||||
override fun dozeTimeTick() {
|
||||
_dozeTimeTick.tryEmit(Unit)
|
||||
}
|
||||
|
||||
override fun setLastDozeTapToWakePosition(position: Point) {
|
||||
_lastDozeTapToWakePosition.value = position
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user