1 /* <lambda>null2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.systemui.keyguard.domain.interactor 18 19 import android.animation.ValueAnimator 20 import com.android.app.animation.Interpolators 21 import com.android.systemui.dagger.SysUISingleton 22 import com.android.systemui.dagger.qualifiers.Application 23 import com.android.systemui.keyguard.data.repository.KeyguardTransitionRepository 24 import com.android.systemui.keyguard.shared.model.BiometricUnlockModel.Companion.isWakeAndUnlock 25 import com.android.systemui.keyguard.shared.model.DozeStateModel 26 import com.android.systemui.keyguard.shared.model.KeyguardState 27 import com.android.systemui.util.kotlin.Utils.Companion.toTriple 28 import com.android.systemui.util.kotlin.sample 29 import javax.inject.Inject 30 import kotlinx.coroutines.CoroutineScope 31 import kotlinx.coroutines.flow.combine 32 import kotlinx.coroutines.launch 33 34 @SysUISingleton 35 class FromAodTransitionInteractor 36 @Inject 37 constructor( 38 override val transitionRepository: KeyguardTransitionRepository, 39 override val transitionInteractor: KeyguardTransitionInteractor, 40 @Application private val scope: CoroutineScope, 41 private val keyguardInteractor: KeyguardInteractor, 42 ) : 43 TransitionInteractor( 44 fromState = KeyguardState.AOD, 45 ) { 46 47 override fun start() { 48 listenForAodToLockscreenOrOccluded() 49 listenForAodToGone() 50 } 51 52 private fun listenForAodToLockscreenOrOccluded() { 53 scope.launch { 54 keyguardInteractor 55 .dozeTransitionTo(DozeStateModel.FINISH) 56 .sample( 57 combine( 58 transitionInteractor.startedKeyguardTransitionStep, 59 keyguardInteractor.isKeyguardOccluded, 60 ::Pair 61 ), 62 ::toTriple 63 ) 64 .collect { (_, lastStartedStep, occluded) -> 65 if (lastStartedStep.to == KeyguardState.AOD) { 66 startTransitionTo( 67 if (occluded) KeyguardState.OCCLUDED else KeyguardState.LOCKSCREEN 68 ) 69 } 70 } 71 } 72 } 73 74 private fun listenForAodToGone() { 75 scope.launch { 76 keyguardInteractor.biometricUnlockState 77 .sample(transitionInteractor.finishedKeyguardState, ::Pair) 78 .collect { pair -> 79 val (biometricUnlockState, keyguardState) = pair 80 if ( 81 keyguardState == KeyguardState.AOD && isWakeAndUnlock(biometricUnlockState) 82 ) { 83 startTransitionTo(KeyguardState.GONE) 84 } 85 } 86 } 87 } 88 89 override fun getDefaultAnimatorForTransitionsToState(toState: KeyguardState): ValueAnimator { 90 return ValueAnimator().apply { 91 interpolator = Interpolators.LINEAR 92 duration = TRANSITION_DURATION_MS 93 } 94 } 95 96 companion object { 97 private const val TRANSITION_DURATION_MS = 500L 98 } 99 } 100