1 /*
<lambda>null2  * Copyright (C) 2023 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.statusbar.notification.shelf.domain.interactor
18 
19 import android.os.PowerManager
20 import com.android.systemui.dagger.SysUISingleton
21 import com.android.systemui.deviceentry.data.repository.DeviceEntryFaceAuthRepository
22 import com.android.systemui.keyguard.data.repository.KeyguardRepository
23 import com.android.systemui.power.domain.interactor.PowerInteractor
24 import com.android.systemui.statusbar.LockscreenShadeTransitionController
25 import com.android.systemui.statusbar.NotificationShelf
26 import javax.inject.Inject
27 import kotlinx.coroutines.flow.Flow
28 import kotlinx.coroutines.flow.combine
29 
30 /** Interactor for the [NotificationShelf] */
31 @SysUISingleton
32 class NotificationShelfInteractor
33 @Inject
34 constructor(
35     private val keyguardRepository: KeyguardRepository,
36     private val deviceEntryFaceAuthRepository: DeviceEntryFaceAuthRepository,
37     private val powerInteractor: PowerInteractor,
38     private val keyguardTransitionController: LockscreenShadeTransitionController,
39 ) {
40     /** Is the shelf showing on the keyguard? */
41     val isShowingOnKeyguard: Flow<Boolean>
42         get() = keyguardRepository.isKeyguardShowing
43 
44     /** Is the system in a state where the shelf is just a static display of notification icons? */
45     val isShelfStatic: Flow<Boolean>
46         get() =
47             combine(
48                 keyguardRepository.isKeyguardShowing,
49                 deviceEntryFaceAuthRepository.isBypassEnabled,
50             ) { isKeyguardShowing, isBypassEnabled ->
51                 isKeyguardShowing && isBypassEnabled
52             }
53 
54     /** Transition keyguard to the locked shade, triggered by the shelf. */
55     fun goToLockedShadeFromShelf() {
56         powerInteractor.wakeUpIfDozing("SHADE_CLICK", PowerManager.WAKE_REASON_GESTURE)
57         keyguardTransitionController.goToLockedShade(null)
58     }
59 }
60