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

Commit 206f2e78 authored by Josh Tsuji's avatar Josh Tsuji
Browse files

Migrate LightRevealScrim and all dependencies to flows.

Bug: 195430376
Test: atest LightRevealScrimRepositoryTest
Test: atest LightRevealScrimInteractorTest
Change-Id: I5ddede5301b4f3cf92d678e9276785823ae29d25
parent 6aeb8d9a
Loading
Loading
Loading
Loading
+25 −1
Original line number Diff line number Diff line
@@ -598,6 +598,10 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
                    getFingerprintSensorLocationInNaturalOrientation(),
                    mCachedDisplayInfo);
        }

        for (final Callback cb : mCallbacks) {
            cb.onFingerprintLocationChanged();
        }
    }

    /**
@@ -619,6 +623,10 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
                    mCachedDisplayInfo
            );
        }

        for (final Callback cb : mCallbacks) {
            cb.onFaceSensorLocationChanged();
        }
    }

    /**
@@ -1265,8 +1273,24 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
        default void onBiometricPromptDismissed() {}

        /**
         * The location in pixels can change due to resolution changes.
         * Called when the location of the fingerprint sensor changes. The location in pixels can
         * change due to resolution changes.
         */
        default void onFingerprintLocationChanged() {}

        /**
         * Called when the location of the under display fingerprint sensor changes. The location in
         * pixels can change due to resolution changes.
         *
         * On devices with UDFPS, this is always called alongside
         * {@link #onFingerprintLocationChanged}.
         */
        default void onUdfpsLocationChanged() {}

        /**
         * Called when the location of the face unlock sensor (typically the front facing camera)
         * changes. The location in pixels can change due to resolution changes.
         */
        default void onFaceSensorLocationChanged() {}
    }
}
+19 −7
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.settingslib.Utils
import com.android.systemui.R
import com.android.systemui.animation.Interpolators
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.CircleReveal
@@ -71,6 +73,7 @@ class AuthRippleController @Inject constructor(
    private val biometricUnlockController: BiometricUnlockController,
    private val udfpsControllerProvider: Provider<UdfpsController>,
    private val statusBarStateController: StatusBarStateController,
    private val featureFlags: FeatureFlags,
        rippleView: AuthRippleView?
) : ViewController<AuthRippleView>(rippleView), KeyguardStateController.Callback,
    WakefulnessLifecycle.Observer {
@@ -159,6 +162,10 @@ class AuthRippleController @Inject constructor(

    private fun showUnlockedRipple() {
        notificationShadeWindowController.setForcePluginOpen(true, this)

        // This code path is not used if the KeyguardTransitionRepository is managing the light
        // reveal scrim.
        if (!featureFlags.isEnabled(Flags.LIGHT_REVEAL_MIGRATION)) {
            val lightRevealScrim = centralSurfaces.lightRevealScrim
            if (statusBarStateController.isDozing || biometricUnlockController.isWakeAndUnlock) {
                circleReveal?.let {
@@ -167,6 +174,7 @@ class AuthRippleController @Inject constructor(
                    startLightRevealScrimOnKeyguardFadingAway = true
                }
            }
        }

        mView.startUnlockedRipple(
            /* end runnable */
@@ -177,6 +185,10 @@ class AuthRippleController @Inject constructor(
    }

    override fun onKeyguardFadingAwayChanged() {
        if (featureFlags.isEnabled(Flags.LIGHT_REVEAL_MIGRATION)) {
            return
        }

        if (keyguardStateController.isKeyguardFadingAway) {
            val lightRevealScrim = centralSurfaces.lightRevealScrim
            if (startLightRevealScrimOnKeyguardFadingAway && lightRevealScrim != null) {
+7 −0
Original line number Diff line number Diff line
@@ -164,6 +164,13 @@ object Flags {
    // TODO(b/256513609): Tracking Bug
    @JvmField val ACTIVE_UNLOCK_CHIPBAR = releasedFlag(217, "active_unlock_chipbar")

    /**
     * Migrates control of the LightRevealScrim's reveal effect and amount from legacy code to the
     * new KeyguardTransitionRepository.
     */
    @JvmField
    val LIGHT_REVEAL_MIGRATION = unreleasedFlag(218, "light_reveal_migration", teamfood = true)

    // 300 - power menu
    // TODO(b/254512600): Tracking Bug
    @JvmField val POWER_MENU_LITE = releasedFlag(300, "power_menu_lite")
+127 −43
Original line number Diff line number Diff line
@@ -16,8 +16,11 @@

package com.android.systemui.keyguard.data.repository

import android.graphics.Point
import android.hardware.biometrics.BiometricSourceType
import com.android.keyguard.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.biometrics.AuthController
import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLogging
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.common.shared.model.Position
@@ -27,8 +30,8 @@ import com.android.systemui.doze.DozeMachine
import com.android.systemui.doze.DozeTransitionCallback
import com.android.systemui.doze.DozeTransitionListener
import com.android.systemui.keyguard.WakefulnessLifecycle
import com.android.systemui.keyguard.WakefulnessLifecycle.Wakefulness
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.StatusBarState
@@ -88,8 +91,8 @@ interface KeyguardRepository {
     * enter to conserve battery when the device is locked and inactive.
     *
     * Note that it is possible for the system to be transitioning into doze while this flow still
     * returns `false`. In order to account for that, observers should also use the [dozeAmount]
     * flow to check if it's greater than `0`
     * returns `false`. In order to account for that, observers should also use the
     * [linearDozeAmount] flow to check if it's greater than `0`
     */
    val isDozing: Flow<Boolean>

@@ -111,7 +114,7 @@ interface KeyguardRepository {
     * happens during an animation/transition into doze mode. An observer would be wise to account
     * for both flows if needed.
     */
    val dozeAmount: Flow<Float>
    val linearDozeAmount: Flow<Float>

    /** Doze state information, as it transitions */
    val dozeTransitionModel: Flow<DozeTransitionModel>
@@ -120,11 +123,20 @@ interface KeyguardRepository {
    val statusBarState: Flow<StatusBarState>

    /** Observable for device wake/sleep state */
    val wakefulnessState: Flow<WakefulnessModel>
    val wakefulness: Flow<WakefulnessModel>

    /** Observable for biometric unlock modes */
    val biometricUnlockState: Flow<BiometricUnlockModel>

    /** Approximate location on the screen of the fingerprint sensor. */
    val fingerprintSensorLocation: Flow<Point?>

    /** Approximate location on the screen of the face unlock sensor/front facing camera. */
    val faceSensorLocation: Flow<Point?>

    /** Source of the most recent biometric unlock, such as fingerprint or face. */
    val biometricUnlockSource: Flow<BiometricUnlockSource?>

    /**
     * Returns `true` if the keyguard is showing; `false` otherwise.
     *
@@ -163,6 +175,7 @@ constructor(
    private val keyguardStateController: KeyguardStateController,
    private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
    private val dozeTransitionListener: DozeTransitionListener,
    private val authController: AuthController,
) : KeyguardRepository {
    private val _animateBottomAreaDozingTransitions = MutableStateFlow(false)
    override val animateBottomAreaDozingTransitions =
@@ -281,11 +294,11 @@ constructor(
            }
            .distinctUntilChanged()

    override val dozeAmount: Flow<Float> = conflatedCallbackFlow {
    override val linearDozeAmount: Flow<Float> = conflatedCallbackFlow {
        val callback =
            object : StatusBarStateController.StateListener {
                override fun onDozeAmountChanged(linear: Float, eased: Float) {
                    trySendWithFailureLogging(eased, TAG, "updated dozeAmount")
                    trySendWithFailureLogging(linear, TAG, "updated dozeAmount")
                }
            }

@@ -348,56 +361,137 @@ constructor(
        awaitClose { statusBarStateController.removeCallback(callback) }
    }

    override val wakefulnessState: Flow<WakefulnessModel> = conflatedCallbackFlow {
        val callback =
            object : WakefulnessLifecycle.Observer {
                override fun onStartedWakingUp() {
    override val biometricUnlockState: Flow<BiometricUnlockModel> = conflatedCallbackFlow {
        fun dispatchUpdate() {
            trySendWithFailureLogging(
                        WakefulnessModel.STARTING_TO_WAKE,
                biometricModeIntToObject(biometricUnlockController.mode),
                TAG,
                        "Wakefulness: starting to wake"
                "biometric mode"
            )
        }

        val callback =
            object : BiometricUnlockController.BiometricModeListener {
                override fun onModeChanged(@WakeAndUnlockMode mode: Int) {
                    dispatchUpdate()
                }

                override fun onResetMode() {
                    dispatchUpdate()
                }
            }

        biometricUnlockController.addBiometricModeListener(callback)
        dispatchUpdate()

        awaitClose { biometricUnlockController.removeBiometricModeListener(callback) }
    }

    override val wakefulness: Flow<WakefulnessModel> = conflatedCallbackFlow {
        val observer =
            object : WakefulnessLifecycle.Observer {
                override fun onStartedWakingUp() {
                    dispatchNewState()
                }

                override fun onFinishedWakingUp() {
                    trySendWithFailureLogging(WakefulnessModel.AWAKE, TAG, "Wakefulness: awake")
                    dispatchNewState()
                }

                override fun onPostFinishedWakingUp() {
                    dispatchNewState()
                }

                override fun onStartedGoingToSleep() {
                    dispatchNewState()
                }

                override fun onFinishedGoingToSleep() {
                    dispatchNewState()
                }

                private fun dispatchNewState() {
                    trySendWithFailureLogging(
                        WakefulnessModel.STARTING_TO_SLEEP,
                        WakefulnessModel.fromWakefulnessLifecycle(wakefulnessLifecycle),
                        TAG,
                        "Wakefulness: starting to sleep"
                        "updated wakefulness state"
                    )
                }
                override fun onFinishedGoingToSleep() {
                    trySendWithFailureLogging(WakefulnessModel.ASLEEP, TAG, "Wakefulness: asleep")
                }
            }
        wakefulnessLifecycle.addObserver(callback)

        wakefulnessLifecycle.addObserver(observer)
        trySendWithFailureLogging(
            wakefulnessIntToObject(wakefulnessLifecycle.getWakefulness()),
            WakefulnessModel.fromWakefulnessLifecycle(wakefulnessLifecycle),
            TAG,
            "initial wakefulness state"
        )

        awaitClose { wakefulnessLifecycle.removeObserver(callback) }
        awaitClose { wakefulnessLifecycle.removeObserver(observer) }
    }

    override val fingerprintSensorLocation: Flow<Point?> = conflatedCallbackFlow {
        fun sendFpLocation() {
            trySendWithFailureLogging(
                authController.fingerprintSensorLocation,
                TAG,
                "AuthController.Callback#onFingerprintLocationChanged"
            )
        }

    override val biometricUnlockState: Flow<BiometricUnlockModel> = conflatedCallbackFlow {
        val callback =
            object : BiometricUnlockController.BiometricModeListener {
                override fun onModeChanged(@WakeAndUnlockMode mode: Int) {
                    trySendWithFailureLogging(biometricModeIntToObject(mode), TAG, "biometric mode")
            object : AuthController.Callback {
                override fun onFingerprintLocationChanged() {
                    sendFpLocation()
                }
            }

        biometricUnlockController.addBiometricModeListener(callback)
        authController.addCallback(callback)
        sendFpLocation()

        awaitClose { authController.removeCallback(callback) }
    }

    override val faceSensorLocation: Flow<Point?> = conflatedCallbackFlow {
        fun sendSensorLocation() {
            trySendWithFailureLogging(
            biometricModeIntToObject(biometricUnlockController.getMode()),
                authController.faceSensorLocation,
                TAG,
            "initial biometric mode"
                "AuthController.Callback#onFingerprintLocationChanged"
            )
        }

        awaitClose { biometricUnlockController.removeBiometricModeListener(callback) }
        val callback =
            object : AuthController.Callback {
                override fun onFaceSensorLocationChanged() {
                    sendSensorLocation()
                }
            }

        authController.addCallback(callback)
        sendSensorLocation()

        awaitClose { authController.removeCallback(callback) }
    }

    override val biometricUnlockSource: Flow<BiometricUnlockSource?> = conflatedCallbackFlow {
        val callback =
            object : KeyguardUpdateMonitorCallback() {
                override fun onBiometricAuthenticated(
                    userId: Int,
                    biometricSourceType: BiometricSourceType?,
                    isStrongBiometric: Boolean
                ) {
                    trySendWithFailureLogging(
                        BiometricUnlockSource.fromBiometricSourceType(biometricSourceType),
                        TAG,
                        "onBiometricAuthenticated"
                    )
                }
            }

        keyguardUpdateMonitor.registerCallback(callback)
        trySendWithFailureLogging(null, TAG, "initial value")
        awaitClose { keyguardUpdateMonitor.removeCallback(callback) }
    }

    override fun setAnimateDozingTransitions(animate: Boolean) {
@@ -423,16 +517,6 @@ constructor(
        }
    }

    private fun wakefulnessIntToObject(@Wakefulness value: Int): WakefulnessModel {
        return when (value) {
            0 -> WakefulnessModel.ASLEEP
            1 -> WakefulnessModel.STARTING_TO_WAKE
            2 -> WakefulnessModel.AWAKE
            3 -> WakefulnessModel.STARTING_TO_SLEEP
            else -> throw IllegalArgumentException("Invalid Wakefulness value: $value")
        }
    }

    private fun biometricModeIntToObject(@WakeAndUnlockMode value: Int): BiometricUnlockModel {
        return when (value) {
            0 -> BiometricUnlockModel.NONE
+3 −0
Original line number Diff line number Diff line
@@ -27,4 +27,7 @@ interface KeyguardRepositoryModule {
    fun keyguardTransitionRepository(
        impl: KeyguardTransitionRepositoryImpl
    ): KeyguardTransitionRepository

    @Binds
    fun lightRevealScrimRepository(impl: LightRevealScrimRepositoryImpl): LightRevealScrimRepository
}
Loading