• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.systemui.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.keyguard.shared.model.TransitionInfo
28 import com.android.systemui.util.kotlin.sample
29 import javax.inject.Inject
30 import kotlinx.coroutines.CoroutineScope
31 import kotlinx.coroutines.launch
32 
33 @SysUISingleton
34 class FromAodTransitionInteractor
35 @Inject
36 constructor(
37     @Application private val scope: CoroutineScope,
38     private val keyguardInteractor: KeyguardInteractor,
39     private val keyguardTransitionRepository: KeyguardTransitionRepository,
40     private val keyguardTransitionInteractor: KeyguardTransitionInteractor,
41 ) : TransitionInteractor(FromAodTransitionInteractor::class.simpleName!!) {
42 
43     override fun start() {
44         listenForAodToLockscreen()
45         listenForAodToGone()
46     }
47 
48     private fun listenForAodToLockscreen() {
49         scope.launch {
50             keyguardInteractor
51                 .dozeTransitionTo(DozeStateModel.FINISH)
52                 .sample(keyguardTransitionInteractor.startedKeyguardTransitionStep, ::Pair)
53                 .collect { pair ->
54                     val (dozeToAod, lastStartedStep) = pair
55                     if (lastStartedStep.to == KeyguardState.AOD) {
56                         keyguardTransitionRepository.startTransition(
57                             TransitionInfo(
58                                 name,
59                                 KeyguardState.AOD,
60                                 KeyguardState.LOCKSCREEN,
61                                 getAnimator(),
62                             )
63                         )
64                     }
65                 }
66         }
67     }
68 
69     private fun listenForAodToGone() {
70         scope.launch {
71             keyguardInteractor.biometricUnlockState
72                 .sample(keyguardTransitionInteractor.finishedKeyguardState, ::Pair)
73                 .collect { pair ->
74                     val (biometricUnlockState, keyguardState) = pair
75                     if (
76                         keyguardState == KeyguardState.AOD && isWakeAndUnlock(biometricUnlockState)
77                     ) {
78                         keyguardTransitionRepository.startTransition(
79                             TransitionInfo(
80                                 name,
81                                 KeyguardState.AOD,
82                                 KeyguardState.GONE,
83                                 getAnimator(),
84                             )
85                         )
86                     }
87                 }
88         }
89     }
90 
91     private fun getAnimator(): ValueAnimator {
92         return ValueAnimator().apply {
93             setInterpolator(Interpolators.LINEAR)
94             setDuration(TRANSITION_DURATION_MS)
95         }
96     }
97 
98     companion object {
99         private const val TRANSITION_DURATION_MS = 500L
100     }
101 }
102