Loading packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardStateCallbackInteractor.kt +62 −13 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading @@ -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>() Loading @@ -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() Loading @@ -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 } } packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractor.kt +14 −13 Original line number Diff line number Diff line Loading @@ -77,7 +77,7 @@ constructor( MutableSharedFlow<Float>( replay = 1, extraBufferCapacity = 2, onBufferOverflow = BufferOverflow.DROP_OLDEST onBufferOverflow = BufferOverflow.DROP_OLDEST, ) .also { it.tryEmit(0f) } } Loading @@ -97,8 +97,8 @@ constructor( SharingStarted.Eagerly, WithPrev( sceneInteractor.transitionState.value, sceneInteractor.transitionState.value ) sceneInteractor.transitionState.value, ), ) /** Loading Loading @@ -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.", ) } } Loading Loading @@ -202,7 +202,7 @@ constructor( transitionMap.getOrPut(mappedEdge) { MutableSharedFlow( extraBufferCapacity = 10, onBufferOverflow = BufferOverflow.DROP_OLDEST onBufferOverflow = BufferOverflow.DROP_OLDEST, ) } Loading Loading @@ -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) Loading @@ -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) Loading Loading @@ -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()) } Loading Loading @@ -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 } Loading Loading
packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardStateCallbackInteractor.kt +62 −13 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading @@ -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>() Loading @@ -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() Loading @@ -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 } }
packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardTransitionInteractor.kt +14 −13 Original line number Diff line number Diff line Loading @@ -77,7 +77,7 @@ constructor( MutableSharedFlow<Float>( replay = 1, extraBufferCapacity = 2, onBufferOverflow = BufferOverflow.DROP_OLDEST onBufferOverflow = BufferOverflow.DROP_OLDEST, ) .also { it.tryEmit(0f) } } Loading @@ -97,8 +97,8 @@ constructor( SharingStarted.Eagerly, WithPrev( sceneInteractor.transitionState.value, sceneInteractor.transitionState.value ) sceneInteractor.transitionState.value, ), ) /** Loading Loading @@ -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.", ) } } Loading Loading @@ -202,7 +202,7 @@ constructor( transitionMap.getOrPut(mappedEdge) { MutableSharedFlow( extraBufferCapacity = 10, onBufferOverflow = BufferOverflow.DROP_OLDEST onBufferOverflow = BufferOverflow.DROP_OLDEST, ) } Loading Loading @@ -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) Loading @@ -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) Loading Loading @@ -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()) } Loading Loading @@ -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 } Loading