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

Commit 7653ff43 authored by Beverly Tai's avatar Beverly Tai Committed by Automerger Merge Worker
Browse files

Merge "Hookup active unlock running state to bouncer delay logic" into udc-dev am: cf707e42

parents 26914a95 cf707e42
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -4397,7 +4397,8 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener, Dumpab
                    mFingerprintListenBuffer.toList()
                    mFingerprintListenBuffer.toList()
            ).printTableData(pw);
            ).printTableData(pw);
        }
        }

        pw.println("ActiveUnlockRunning="
                + mTrustManager.isActiveUnlockRunning(KeyguardUpdateMonitor.getCurrentUser()));
        new DumpsysTableLogger(
        new DumpsysTableLogger(
                "KeyguardActiveUnlockTriggers",
                "KeyguardActiveUnlockTriggers",
                KeyguardActiveUnlockModel.TABLE_HEADERS,
                KeyguardActiveUnlockModel.TABLE_HEADERS,
+22 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.keyguard.logging
package com.android.keyguard.logging


import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.keyguard.shared.model.ActiveUnlockModel
import com.android.systemui.keyguard.shared.model.TrustManagedModel
import com.android.systemui.keyguard.shared.model.TrustManagedModel
import com.android.systemui.keyguard.shared.model.TrustModel
import com.android.systemui.keyguard.shared.model.TrustModel
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.LogBuffer
@@ -76,6 +77,18 @@ constructor(
        )
        )
    }
    }


    fun activeUnlockModelEmitted(value: ActiveUnlockModel) {
        logBuffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                int1 = value.userId
                bool1 = value.isRunning
            },
            { "activeUnlockModel emitted: userId: $int1 isRunning: $bool1" }
        )
    }

    fun isCurrentUserTrusted(isCurrentUserTrusted: Boolean) {
    fun isCurrentUserTrusted(isCurrentUserTrusted: Boolean) {
        logBuffer.log(
        logBuffer.log(
            TAG,
            TAG,
@@ -85,6 +98,15 @@ constructor(
        )
        )
    }
    }


    fun isCurrentUserActiveUnlockRunning(isCurrentUserActiveUnlockRunning: Boolean) {
        logBuffer.log(
            TAG,
            LogLevel.DEBUG,
            { bool1 = isCurrentUserActiveUnlockRunning },
            { "isCurrentUserActiveUnlockRunning emitted: $bool1" }
        )
    }

    fun isCurrentUserTrustManaged(isTrustManaged: Boolean) {
    fun isCurrentUserTrustManaged(isTrustManaged: Boolean) {
        logBuffer.log(TAG, DEBUG, { bool1 = isTrustManaged }, { "isTrustManaged emitted: $bool1" })
        logBuffer.log(TAG, DEBUG, { bool1 = isTrustManaged }, { "isTrustManaged emitted: $bool1" })
    }
    }
+30 −10
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import com.android.systemui.common.coroutine.ChannelExt.trySendWithFailureLoggin
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.common.coroutine.ConflatedCallbackFlow.conflatedCallbackFlow
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.keyguard.shared.model.ActiveUnlockModel
import com.android.systemui.keyguard.shared.model.TrustManagedModel
import com.android.systemui.keyguard.shared.model.TrustManagedModel
import com.android.systemui.keyguard.shared.model.TrustModel
import com.android.systemui.keyguard.shared.model.TrustModel
import com.android.systemui.user.data.repository.UserRepository
import com.android.systemui.user.data.repository.UserRepository
@@ -29,7 +30,6 @@ import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.combine
@@ -45,8 +45,8 @@ interface TrustRepository {
    /** Flow representing whether the current user is trusted. */
    /** Flow representing whether the current user is trusted. */
    val isCurrentUserTrusted: Flow<Boolean>
    val isCurrentUserTrusted: Flow<Boolean>


    /** Flow representing whether active unlock is available for the current user. */
    /** Flow representing whether active unlock is running for the current user. */
    val isCurrentUserActiveUnlockAvailable: StateFlow<Boolean>
    val isCurrentUserActiveUnlockRunning: Flow<Boolean>


    /** Reports that whether trust is managed has changed for the current user. */
    /** Reports that whether trust is managed has changed for the current user. */
    val isCurrentUserTrustManaged: StateFlow<Boolean>
    val isCurrentUserTrustManaged: StateFlow<Boolean>
@@ -62,6 +62,7 @@ constructor(
    private val logger: TrustRepositoryLogger,
    private val logger: TrustRepositoryLogger,
) : TrustRepository {
) : TrustRepository {
    private val latestTrustModelForUser = mutableMapOf<Int, TrustModel>()
    private val latestTrustModelForUser = mutableMapOf<Int, TrustModel>()
    private val activeUnlockRunningForUser = mutableMapOf<Int, ActiveUnlockModel>()
    private val trustManagedForUser = mutableMapOf<Int, TrustManagedModel>()
    private val trustManagedForUser = mutableMapOf<Int, TrustManagedModel>()


    private val trust =
    private val trust =
@@ -87,6 +88,17 @@ constructor(


                        override fun onEnabledTrustAgentsChanged(userId: Int) = Unit
                        override fun onEnabledTrustAgentsChanged(userId: Int) = Unit


                        override fun onIsActiveUnlockRunningChanged(
                            isRunning: Boolean,
                            userId: Int
                        ) {
                            trySendWithFailureLogging(
                                ActiveUnlockModel(isRunning, userId),
                                TrustRepositoryLogger.TAG,
                                "onActiveUnlockRunningChanged"
                            )
                        }

                        override fun onTrustManagedChanged(isTrustManaged: Boolean, userId: Int) {
                        override fun onTrustManagedChanged(isTrustManaged: Boolean, userId: Int) {
                            logger.onTrustManagedChanged(isTrustManaged, userId)
                            logger.onTrustManagedChanged(isTrustManaged, userId)
                            trySendWithFailureLogging(
                            trySendWithFailureLogging(
@@ -95,11 +107,6 @@ constructor(
                                "onTrustManagedChanged"
                                "onTrustManagedChanged"
                            )
                            )
                        }
                        }

                        override fun onIsActiveUnlockRunningChanged(
                            isRunning: Boolean,
                            userId: Int
                        ) = Unit
                    }
                    }
                trustManager.registerTrustListener(callback)
                trustManager.registerTrustListener(callback)
                logger.trustListenerRegistered()
                logger.trustListenerRegistered()
@@ -114,6 +121,10 @@ constructor(
                        latestTrustModelForUser[it.userId] = it
                        latestTrustModelForUser[it.userId] = it
                        logger.trustModelEmitted(it)
                        logger.trustModelEmitted(it)
                    }
                    }
                    is ActiveUnlockModel -> {
                        activeUnlockRunningForUser[it.userId] = it
                        logger.activeUnlockModelEmitted(it)
                    }
                    is TrustManagedModel -> {
                    is TrustManagedModel -> {
                        trustManagedForUser[it.userId] = it
                        trustManagedForUser[it.userId] = it
                        logger.trustManagedModelEmitted(it)
                        logger.trustManagedModelEmitted(it)
@@ -122,8 +133,17 @@ constructor(
            }
            }
            .shareIn(applicationScope, started = SharingStarted.Eagerly, replay = 1)
            .shareIn(applicationScope, started = SharingStarted.Eagerly, replay = 1)


    // TODO: Implement based on TrustManager callback b/267322286
    override val isCurrentUserActiveUnlockRunning: Flow<Boolean> =
    override val isCurrentUserActiveUnlockAvailable: StateFlow<Boolean> = MutableStateFlow(true)
        combine(trust, userRepository.selectedUserInfo, ::Pair)
            .map { activeUnlockRunningForUser[it.second.id]?.isRunning ?: false }
            .distinctUntilChanged()
            .onEach { logger.isCurrentUserActiveUnlockRunning(it) }
            .onStart {
                emit(
                    activeUnlockRunningForUser[userRepository.getSelectedUserInfo().id]?.isRunning
                        ?: false
                )
            }


    override val isCurrentUserTrustManaged: StateFlow<Boolean>
    override val isCurrentUserTrustManaged: StateFlow<Boolean>
        get() =
        get() =
+27 −13
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.systemui.DejankUtils
import com.android.systemui.R
import com.android.systemui.R
import com.android.systemui.classifier.FalsingCollector
import com.android.systemui.classifier.FalsingCollector
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.dagger.qualifiers.Main
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.FeatureFlags
import com.android.systemui.flags.Flags
import com.android.systemui.flags.Flags
@@ -43,11 +44,14 @@ import com.android.systemui.keyguard.shared.model.BouncerShowMessageModel
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.plugins.ActivityStarter
import com.android.systemui.shared.system.SysUiStatsLog
import com.android.systemui.shared.system.SysUiStatsLog
import com.android.systemui.statusbar.policy.KeyguardStateController
import com.android.systemui.statusbar.policy.KeyguardStateController
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.filterNotNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Inject


/**
/**
@@ -70,6 +74,7 @@ constructor(
    private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
    private val keyguardUpdateMonitor: KeyguardUpdateMonitor,
    private val trustRepository: TrustRepository,
    private val trustRepository: TrustRepository,
    private val featureFlags: FeatureFlags,
    private val featureFlags: FeatureFlags,
    @Application private val applicationScope: CoroutineScope,
) {
) {
    private val passiveAuthBouncerDelay = context.resources.getInteger(
    private val passiveAuthBouncerDelay = context.resources.getInteger(
            R.integer.primary_bouncer_passive_auth_delay).toLong()
            R.integer.primary_bouncer_passive_auth_delay).toLong()
@@ -104,6 +109,7 @@ constructor(
    /** Allow for interaction when just about fully visible */
    /** Allow for interaction when just about fully visible */
    val isInteractable: Flow<Boolean> = bouncerExpansion.map { it > 0.9 }
    val isInteractable: Flow<Boolean> = bouncerExpansion.map { it > 0.9 }
    val sideFpsShowing: Flow<Boolean> = repository.sideFpsShowing
    val sideFpsShowing: Flow<Boolean> = repository.sideFpsShowing
    private var currentUserActiveUnlockRunning = false


    /** This callback needs to be a class field so it does not get garbage collected. */
    /** This callback needs to be a class field so it does not get garbage collected. */
    val keyguardUpdateMonitorCallback =
    val keyguardUpdateMonitorCallback =
@@ -122,6 +128,13 @@ constructor(


    init {
    init {
        keyguardUpdateMonitor.registerCallback(keyguardUpdateMonitorCallback)
        keyguardUpdateMonitor.registerCallback(keyguardUpdateMonitorCallback)
        if (featureFlags.isEnabled(Flags.DELAY_BOUNCER)) {
            applicationScope.launch {
                trustRepository.isCurrentUserActiveUnlockRunning.collect {
                    currentUserActiveUnlockRunning = it
                }
            }
        }
    }
    }


    // TODO(b/243685699): Move isScrimmed logic to data layer.
    // TODO(b/243685699): Move isScrimmed logic to data layer.
@@ -377,8 +390,9 @@ constructor(
    private fun usePrimaryBouncerPassiveAuthDelay(): Boolean {
    private fun usePrimaryBouncerPassiveAuthDelay(): Boolean {
        val canRunFaceAuth = keyguardStateController.isFaceAuthEnabled &&
        val canRunFaceAuth = keyguardStateController.isFaceAuthEnabled &&
                keyguardUpdateMonitor.isUnlockingWithBiometricAllowed(BiometricSourceType.FACE)
                keyguardUpdateMonitor.isUnlockingWithBiometricAllowed(BiometricSourceType.FACE)
        val canRunActiveUnlock = trustRepository.isCurrentUserActiveUnlockAvailable.value &&
        val canRunActiveUnlock = currentUserActiveUnlockRunning &&
                keyguardUpdateMonitor.canTriggerActiveUnlockBasedOnDeviceState()
                keyguardUpdateMonitor.canTriggerActiveUnlockBasedOnDeviceState()

        return featureFlags.isEnabled(Flags.DELAY_BOUNCER) &&
        return featureFlags.isEnabled(Flags.DELAY_BOUNCER) &&
                !needsFullscreenBouncer() &&
                !needsFullscreenBouncer() &&
                (canRunFaceAuth || canRunActiveUnlock)
                (canRunFaceAuth || canRunActiveUnlock)
+25 −0
Original line number Original line 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

/** Represents the active unlock state */
data class ActiveUnlockModel(
    /** If true, the system believes active unlock is available and can be usd to unlock. */
    val isRunning: Boolean,
    /** The user, for which active unlock may be running. */
    val userId: Int,
)
Loading