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

Commit 33498792 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add remaining KeyguardStateCallback calls + send initial values to new callbacks." into main

parents 923a70fc d9a1fd21
Loading
Loading
Loading
Loading
+62 −13
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.os.DeadObjectException
import android.os.RemoteException
import com.android.internal.policy.IKeyguardStateCallback
import com.android.systemui.CoreStartable
import com.android.systemui.bouncer.domain.interactor.SimBouncerInteractor
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
@@ -27,13 +28,13 @@ import com.android.systemui.keyguard.KeyguardWmStateRefactor
import com.android.systemui.keyguard.shared.model.KeyguardState
import com.android.systemui.scene.shared.flag.SceneContainerFlag
import com.android.systemui.user.domain.interactor.SelectedUserInteractor
import javax.inject.Inject
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import javax.inject.Inject

/**
 * Updates KeyguardStateCallbacks provided to KeyguardService with KeyguardTransitionInteractor
@@ -50,6 +51,8 @@ constructor(
    @Background private val backgroundDispatcher: CoroutineDispatcher,
    private val selectedUserInteractor: SelectedUserInteractor,
    private val keyguardTransitionInteractor: KeyguardTransitionInteractor,
    private val trustInteractor: TrustInteractor,
    private val simBouncerInteractor: SimBouncerInteractor,
) : CoreStartable {
    private val callbacks = mutableListOf<IKeyguardStateCallback>()

@@ -62,19 +65,53 @@ constructor(
            combine(
                    selectedUserInteractor.selectedUser,
                    keyguardTransitionInteractor.currentKeyguardState,
                ::Pair
            ).collectLatest { (selectedUser, currentState) ->
                    keyguardTransitionInteractor.startedKeyguardTransitionStep,
                    ::Triple,
                )
                .collectLatest { (selectedUser, _, _) ->
                    val iterator = callbacks.iterator()
                    withContext(backgroundDispatcher) {
                        while (iterator.hasNext()) {
                            val callback = iterator.next()
                            try {
                                 callback.onShowingStateChanged(
                                    currentState != KeyguardState.GONE,
                                    selectedUser
                                )
                                callback.onInputRestrictedStateChanged(
                                    currentState != KeyguardState.GONE)
                                callback.onShowingStateChanged(!isIdleInGone(), selectedUser)
                                callback.onInputRestrictedStateChanged(!isIdleInGone())
                            } catch (e: RemoteException) {
                                if (e is DeadObjectException) {
                                    iterator.remove()
                                }
                            }
                        }
                    }
                }
        }

        applicationScope.launch {
            trustInteractor.isTrusted.collectLatest { isTrusted ->
                val iterator = callbacks.iterator()
                withContext(backgroundDispatcher) {
                    while (iterator.hasNext()) {
                        val callback = iterator.next()
                        try {
                            callback.onTrustedChanged(isTrusted)
                        } catch (e: RemoteException) {
                            if (e is DeadObjectException) {
                                iterator.remove()
                            }
                        }
                    }
                }
            }
        }

        applicationScope.launch {
            simBouncerInteractor.isAnySimSecure.collectLatest { isSimSecured ->
                val iterator = callbacks.iterator()
                withContext(backgroundDispatcher) {
                    while (iterator.hasNext()) {
                        val callback = iterator.next()
                        try {
                            callback.onSimSecureStateChanged(isSimSecured)
                        } catch (e: RemoteException) {
                            if (e is DeadObjectException) {
                                iterator.remove()
@@ -89,5 +126,17 @@ constructor(
    fun addCallback(callback: IKeyguardStateCallback) {
        KeyguardWmStateRefactor.isUnexpectedlyInLegacyMode()
        callbacks.add(callback)

        // Send initial values to new callbacks.
        callback.onShowingStateChanged(!isIdleInGone(), selectedUserInteractor.getSelectedUserId())
        callback.onInputRestrictedStateChanged(!isIdleInGone())
        callback.onTrustedChanged(trustInteractor.isTrusted.value)
        callback.onSimSecureStateChanged(simBouncerInteractor.isAnySimSecure.value)
    }

    /** Whether we're in KeyguardState.GONE and haven't started a transition to another state. */
    private fun isIdleInGone(): Boolean {
        return keyguardTransitionInteractor.getCurrentState() == KeyguardState.GONE &&
            keyguardTransitionInteractor.getStartedState() == KeyguardState.GONE
    }
}
+14 −13
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ constructor(
            MutableSharedFlow<Float>(
                    replay = 1,
                    extraBufferCapacity = 2,
                    onBufferOverflow = BufferOverflow.DROP_OLDEST
                    onBufferOverflow = BufferOverflow.DROP_OLDEST,
                )
                .also { it.tryEmit(0f) }
        }
@@ -97,8 +97,8 @@ constructor(
                SharingStarted.Eagerly,
                WithPrev(
                    sceneInteractor.transitionState.value,
                    sceneInteractor.transitionState.value
                )
                    sceneInteractor.transitionState.value,
                ),
            )

    /**
@@ -156,7 +156,7 @@ constructor(
                    Log.e(
                        TAG,
                        "STARTED step ($startedStep) was preceded by a RUNNING step " +
                            "($prevStep), which should never happen. Things could go badly here."
                            "($prevStep), which should never happen. Things could go badly here.",
                    )
                }
            }
@@ -202,7 +202,7 @@ constructor(
            transitionMap.getOrPut(mappedEdge) {
                MutableSharedFlow(
                    extraBufferCapacity = 10,
                    onBufferOverflow = BufferOverflow.DROP_OLDEST
                    onBufferOverflow = BufferOverflow.DROP_OLDEST,
                )
            }

@@ -262,7 +262,7 @@ constructor(
            is Edge.StateToState ->
                Edge.create(
                    from = edge.from?.mapToSceneContainerState(),
                    to = edge.to?.mapToSceneContainerState()
                    to = edge.to?.mapToSceneContainerState(),
                )
            is Edge.SceneToState -> Edge.create(UNDEFINED, edge.to)
            is Edge.StateToScene -> Edge.create(edge.from, UNDEFINED)
@@ -286,9 +286,7 @@ constructor(
     * The value will be `0` (or close to `0`, due to float point arithmetic) if not in this step or
     * `1` when fully in the given state.
     */
    fun transitionValue(
        state: KeyguardState,
    ): Flow<Float> {
    fun transitionValue(state: KeyguardState): Flow<Float> {
        if (SceneContainerFlag.isEnabled && state != state.mapToSceneContainerState()) {
            Log.e(TAG, "SceneContainer is enabled but a deprecated state $state is used.")
            return transitionValue(state.mapToSceneContainerScene()!!, state)
@@ -369,10 +367,9 @@ constructor(
            .stateIn(scope, SharingStarted.Eagerly, OFF)

    val isInTransition =
        combine(
            isInTransitionWhere({ true }, { true }),
            sceneInteractor.transitionState,
        ) { isKeyguardTransitioning, sceneTransitionState ->
        combine(isInTransitionWhere({ true }, { true }), sceneInteractor.transitionState) {
            isKeyguardTransitioning,
            sceneTransitionState ->
            isKeyguardTransitioning ||
                (SceneContainerFlag.isEnabled && sceneTransitionState.isTransitioning())
        }
@@ -465,6 +462,10 @@ constructor(
        return currentKeyguardState.replayCache.last()
    }

    fun getStartedState(): KeyguardState {
        return startedKeyguardTransitionStep.value.to
    }

    private val finishedKeyguardState: StateFlow<KeyguardState> =
        repository.transitions
            .filter { it.transitionState == TransitionState.FINISHED }