• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2024 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 com.android.systemui.bouncer.domain.interactor.AlternateBouncerInteractor
20 import com.android.systemui.dagger.SysUISingleton
21 import com.android.systemui.dump.DumpManager
22 import com.android.systemui.keyguard.data.repository.KeyguardBypassRepository
23 import com.android.systemui.scene.domain.interactor.SceneInteractor
24 import com.android.systemui.scene.shared.model.Overlays
25 import com.android.systemui.scene.shared.model.Scenes
26 import com.android.systemui.shade.domain.interactor.ShadeInteractor
27 import com.android.systemui.util.kotlin.FlowDumperImpl
28 import com.android.systemui.util.kotlin.combine
29 import javax.inject.Inject
30 import kotlinx.coroutines.flow.Flow
31 import kotlinx.coroutines.flow.flatMapLatest
32 import kotlinx.coroutines.flow.flowOf
33 import kotlinx.coroutines.flow.map
34 
35 @SysUISingleton
36 class KeyguardBypassInteractor
37 @Inject
38 constructor(
39     keyguardBypassRepository: KeyguardBypassRepository,
40     alternateBouncerInteractor: AlternateBouncerInteractor,
41     keyguardQuickAffordanceInteractor: KeyguardQuickAffordanceInteractor,
42     pulseExpansionInteractor: PulseExpansionInteractor,
43     sceneInteractor: SceneInteractor,
44     shadeInteractor: ShadeInteractor,
45     dumpManager: DumpManager,
46 ) : FlowDumperImpl(dumpManager) {
47 
48     /**
49      * Whether bypassing the keyguard is enabled by the user in user settings (skipping the
50      * lockscreen when authenticating using secondary authentication types like face unlock).
51      */
52     val isBypassAvailable: Flow<Boolean> =
53         keyguardBypassRepository.isBypassAvailable.dumpWhileCollecting("isBypassAvailable")
54 
55     /**
56      * Models whether bypass is unavailable (no secondary authentication types enrolled), or if the
57      * keyguard can be bypassed as a combination of the settings toggle value set by the user and
58      * other factors related to device state.
59      */
60     val canBypass: Flow<Boolean> =
61         isBypassAvailable
62             .flatMapLatest { isBypassAvailable ->
63                 if (isBypassAvailable) {
64                     combine(
65                         sceneInteractor.currentOverlays.map { overlays ->
66                             Overlays.Bouncer in overlays
67                         },
68                         alternateBouncerInteractor.isVisible,
69                         sceneInteractor.currentScene.map { scene -> scene == Scenes.Lockscreen },
70                         keyguardQuickAffordanceInteractor.launchingAffordance,
71                         pulseExpansionInteractor.isPulseExpanding,
72                         shadeInteractor.isQsExpanded,
73                     ) {
74                         isBouncerShowing,
75                         isAlternateBouncerShowing,
76                         isOnLockscreenScene,
77                         isLaunchingAffordance,
78                         isPulseExpanding,
79                         isQsExpanded ->
80                         when {
81                             isBouncerShowing -> true
82                             isAlternateBouncerShowing -> true
83                             !isOnLockscreenScene -> false
84                             isLaunchingAffordance -> false
85                             isPulseExpanding -> false
86                             isQsExpanded -> false
87                             else -> true
88                         }
89                     }
90                 } else {
91                     flowOf(false)
92                 }
93             }
94             .dumpWhileCollecting("canBypass")
95 
96     companion object {
97         private const val TAG: String = "KeyguardBypassInteractor"
98     }
99 }
100