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

Commit f081ea2a authored by Matt Pietal's avatar Matt Pietal Committed by Android (Google) Code Review
Browse files

Merge "Add screen state, dozeTimeTick to keyguard repository" into udc-qpr-dev

parents 3c61576c 98ae8e1d
Loading
Loading
Loading
Loading
+56 −0
Original line number Diff line number Diff line
@@ -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
@@ -49,9 +51,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
@@ -148,6 +152,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>

@@ -163,6 +170,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.
     *
@@ -204,6 +214,8 @@ interface KeyguardRepository {
    fun setIsDozing(isDozing: Boolean)

    fun setIsActiveDreamLockscreenHosted(isLockscreenHosted: Boolean)

    fun dozeTimeTick()
}

/** Encapsulates application state for the keyguard. */
@@ -213,6 +225,7 @@ class KeyguardRepositoryImpl
constructor(
    statusBarStateController: StatusBarStateController,
    wakefulnessLifecycle: WakefulnessLifecycle,
    screenLifecycle: ScreenLifecycle,
    biometricUnlockController: BiometricUnlockController,
    private val keyguardStateController: KeyguardStateController,
    private val keyguardBypassController: KeyguardBypassController,
@@ -370,6 +383,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()

@@ -559,6 +579,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(
+4 −0
Original line number Diff line number Diff line
@@ -35,4 +35,8 @@ constructor(
    fun setLastTapToWakePosition(position: Point) {
        keyguardRepository.setLastDozeTapToWakePosition(position)
    }

    fun dozeTimeTick() {
        keyguardRepository.dozeTimeTick()
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -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. */
+29 −0
Original line number Diff line number Diff line
/*
 * 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()))
        }
    }
}
+42 −0
Original line number Diff line number Diff line
/*
 * 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")
            }
        }
    }
}
Loading