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

Commit dd1d999b authored by Josh Tsuji's avatar Josh Tsuji Committed by Android (Google) Code Review
Browse files

Merge "Migrate LightRevealScrim and all dependencies to flows." into tm-qpr-dev

parents ed1949c9 206f2e78
Loading
Loading
Loading
Loading
+25 −1
Original line number Original line Diff line number Diff line
@@ -598,6 +598,10 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
                    getFingerprintSensorLocationInNaturalOrientation(),
                    getFingerprintSensorLocationInNaturalOrientation(),
                    mCachedDisplayInfo);
                    mCachedDisplayInfo);
        }
        }

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


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

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


    /**
    /**
@@ -1265,8 +1273,24 @@ public class AuthController implements CoreStartable, CommandQueue.Callbacks,
        default void onBiometricPromptDismissed() {}
        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() {}
        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 Original line Diff line number Diff line
@@ -29,6 +29,8 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.settingslib.Utils
import com.android.settingslib.Utils
import com.android.systemui.R
import com.android.systemui.R
import com.android.systemui.animation.Interpolators
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.keyguard.WakefulnessLifecycle
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.CircleReveal
import com.android.systemui.statusbar.CircleReveal
@@ -71,6 +73,7 @@ class AuthRippleController @Inject constructor(
    private val biometricUnlockController: BiometricUnlockController,
    private val biometricUnlockController: BiometricUnlockController,
    private val udfpsControllerProvider: Provider<UdfpsController>,
    private val udfpsControllerProvider: Provider<UdfpsController>,
    private val statusBarStateController: StatusBarStateController,
    private val statusBarStateController: StatusBarStateController,
    private val featureFlags: FeatureFlags,
        rippleView: AuthRippleView?
        rippleView: AuthRippleView?
) : ViewController<AuthRippleView>(rippleView), KeyguardStateController.Callback,
) : ViewController<AuthRippleView>(rippleView), KeyguardStateController.Callback,
    WakefulnessLifecycle.Observer {
    WakefulnessLifecycle.Observer {
@@ -159,6 +162,10 @@ class AuthRippleController @Inject constructor(


    private fun showUnlockedRipple() {
    private fun showUnlockedRipple() {
        notificationShadeWindowController.setForcePluginOpen(true, this)
        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
            val lightRevealScrim = centralSurfaces.lightRevealScrim
            if (statusBarStateController.isDozing || biometricUnlockController.isWakeAndUnlock) {
            if (statusBarStateController.isDozing || biometricUnlockController.isWakeAndUnlock) {
                circleReveal?.let {
                circleReveal?.let {
@@ -167,6 +174,7 @@ class AuthRippleController @Inject constructor(
                    startLightRevealScrimOnKeyguardFadingAway = true
                    startLightRevealScrimOnKeyguardFadingAway = true
                }
                }
            }
            }
        }


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


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

        if (keyguardStateController.isKeyguardFadingAway) {
        if (keyguardStateController.isKeyguardFadingAway) {
            val lightRevealScrim = centralSurfaces.lightRevealScrim
            val lightRevealScrim = centralSurfaces.lightRevealScrim
            if (startLightRevealScrimOnKeyguardFadingAway && lightRevealScrim != null) {
            if (startLightRevealScrimOnKeyguardFadingAway && lightRevealScrim != null) {
+7 −0
Original line number Original line Diff line number Diff line
@@ -164,6 +164,13 @@ object Flags {
    // TODO(b/256513609): Tracking Bug
    // TODO(b/256513609): Tracking Bug
    @JvmField val ACTIVE_UNLOCK_CHIPBAR = releasedFlag(217, "active_unlock_chipbar")
    @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
    // 300 - power menu
    // TODO(b/254512600): Tracking Bug
    // TODO(b/254512600): Tracking Bug
    @JvmField val POWER_MENU_LITE = releasedFlag(300, "power_menu_lite")
    @JvmField val POWER_MENU_LITE = releasedFlag(300, "power_menu_lite")
+127 −43
Original line number Original line Diff line number Diff line
@@ -16,8 +16,11 @@


package com.android.systemui.keyguard.data.repository
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.KeyguardUpdateMonitor
import com.android.keyguard.KeyguardUpdateMonitorCallback
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.ChannelExt.trySendWithFailureLogging
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.common.shared.model.Position
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.DozeTransitionCallback
import com.android.systemui.doze.DozeTransitionListener
import com.android.systemui.doze.DozeTransitionListener
import com.android.systemui.keyguard.WakefulnessLifecycle
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.BiometricUnlockModel
import com.android.systemui.keyguard.shared.model.BiometricUnlockSource
import com.android.systemui.keyguard.shared.model.DozeStateModel
import com.android.systemui.keyguard.shared.model.DozeStateModel
import com.android.systemui.keyguard.shared.model.DozeTransitionModel
import com.android.systemui.keyguard.shared.model.DozeTransitionModel
import com.android.systemui.keyguard.shared.model.StatusBarState
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.
     * 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
     * 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]
     * returns `false`. In order to account for that, observers should also use the
     * flow to check if it's greater than `0`
     * [linearDozeAmount] flow to check if it's greater than `0`
     */
     */
    val isDozing: Flow<Boolean>
    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
     * happens during an animation/transition into doze mode. An observer would be wise to account
     * for both flows if needed.
     * for both flows if needed.
     */
     */
    val dozeAmount: Flow<Float>
    val linearDozeAmount: Flow<Float>


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


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


    /** Observable for biometric unlock modes */
    /** Observable for biometric unlock modes */
    val biometricUnlockState: Flow<BiometricUnlockModel>
    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.
     * Returns `true` if the keyguard is showing; `false` otherwise.
     *
     *
@@ -163,6 +175,7 @@ constructor(
    private val keyguardStateController: KeyguardStateController,
    private val keyguardStateController: KeyguardStateController,
    private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
    private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
    private val dozeTransitionListener: DozeTransitionListener,
    private val dozeTransitionListener: DozeTransitionListener,
    private val authController: AuthController,
) : KeyguardRepository {
) : KeyguardRepository {
    private val _animateBottomAreaDozingTransitions = MutableStateFlow(false)
    private val _animateBottomAreaDozingTransitions = MutableStateFlow(false)
    override val animateBottomAreaDozingTransitions =
    override val animateBottomAreaDozingTransitions =
@@ -281,11 +294,11 @@ constructor(
            }
            }
            .distinctUntilChanged()
            .distinctUntilChanged()


    override val dozeAmount: Flow<Float> = conflatedCallbackFlow {
    override val linearDozeAmount: Flow<Float> = conflatedCallbackFlow {
        val callback =
        val callback =
            object : StatusBarStateController.StateListener {
            object : StatusBarStateController.StateListener {
                override fun onDozeAmountChanged(linear: Float, eased: Float) {
                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) }
        awaitClose { statusBarStateController.removeCallback(callback) }
    }
    }


    override val wakefulnessState: Flow<WakefulnessModel> = conflatedCallbackFlow {
    override val biometricUnlockState: Flow<BiometricUnlockModel> = conflatedCallbackFlow {
        val callback =
        fun dispatchUpdate() {
            object : WakefulnessLifecycle.Observer {
                override fun onStartedWakingUp() {
            trySendWithFailureLogging(
            trySendWithFailureLogging(
                        WakefulnessModel.STARTING_TO_WAKE,
                biometricModeIntToObject(biometricUnlockController.mode),
                TAG,
                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() {
                override fun onFinishedWakingUp() {
                    trySendWithFailureLogging(WakefulnessModel.AWAKE, TAG, "Wakefulness: awake")
                    dispatchNewState()
                }

                override fun onPostFinishedWakingUp() {
                    dispatchNewState()
                }
                }

                override fun onStartedGoingToSleep() {
                override fun onStartedGoingToSleep() {
                    dispatchNewState()
                }

                override fun onFinishedGoingToSleep() {
                    dispatchNewState()
                }

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

        wakefulnessLifecycle.addObserver(observer)
        trySendWithFailureLogging(
        trySendWithFailureLogging(
            wakefulnessIntToObject(wakefulnessLifecycle.getWakefulness()),
            WakefulnessModel.fromWakefulnessLifecycle(wakefulnessLifecycle),
            TAG,
            TAG,
            "initial wakefulness state"
            "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 =
        val callback =
            object : BiometricUnlockController.BiometricModeListener {
            object : AuthController.Callback {
                override fun onModeChanged(@WakeAndUnlockMode mode: Int) {
                override fun onFingerprintLocationChanged() {
                    trySendWithFailureLogging(biometricModeIntToObject(mode), TAG, "biometric mode")
                    sendFpLocation()
                }
                }
            }
            }


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

        awaitClose { authController.removeCallback(callback) }
    }

    override val faceSensorLocation: Flow<Point?> = conflatedCallbackFlow {
        fun sendSensorLocation() {
            trySendWithFailureLogging(
            trySendWithFailureLogging(
            biometricModeIntToObject(biometricUnlockController.getMode()),
                authController.faceSensorLocation,
                TAG,
                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) {
    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 {
    private fun biometricModeIntToObject(@WakeAndUnlockMode value: Int): BiometricUnlockModel {
        return when (value) {
        return when (value) {
            0 -> BiometricUnlockModel.NONE
            0 -> BiometricUnlockModel.NONE
+3 −0
Original line number Original line Diff line number Diff line
@@ -27,4 +27,7 @@ interface KeyguardRepositoryModule {
    fun keyguardTransitionRepository(
    fun keyguardTransitionRepository(
        impl: KeyguardTransitionRepositoryImpl
        impl: KeyguardTransitionRepositoryImpl
    ): KeyguardTransitionRepository
    ): KeyguardTransitionRepository

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