• 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.model
18 
19 import com.android.compose.animation.scene.ObservableTransitionState
20 import com.android.compose.animation.scene.SceneKey
21 import com.android.systemui.dagger.SysUISingleton
22 import com.android.systemui.scene.domain.interactor.SceneContainerOcclusionInteractor
23 import com.android.systemui.scene.domain.interactor.SceneInteractor
24 import com.android.systemui.scene.shared.flag.SceneContainerFlag
25 import com.android.systemui.scene.shared.model.Scenes
26 import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_BOUNCER_SHOWING
27 import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED
28 import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE
29 import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_QUICK_SETTINGS_EXPANDED
30 import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING
31 import com.android.systemui.shared.system.QuickStepContract.SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED
32 import com.android.systemui.shared.system.QuickStepContract.SystemUiStateFlags
33 import dagger.Lazy
34 import javax.inject.Inject
35 
36 /**
37  * A plugin for [SysUiState] that provides overrides for certain state flags that must be pulled
38  * from the scene framework when that framework is enabled.
39  */
40 @SysUISingleton
41 class SceneContainerPlugin
42 @Inject
43 constructor(
44     private val sceneInteractor: Lazy<SceneInteractor>,
45     private val occlusionInteractor: Lazy<SceneContainerOcclusionInteractor>,
46 ) {
47 
48     /**
49      * Returns an override value for the given [flag] or `null` if the scene framework isn't enabled
50      * or if the flag value doesn't need to be overridden.
51      */
52     fun flagValueOverride(@SystemUiStateFlags flag: Long): Boolean? {
53         if (!SceneContainerFlag.isEnabled) {
54             return null
55         }
56 
57         val transitionState = sceneInteractor.get().transitionState.value
58         val idleTransitionStateOrNull = transitionState as? ObservableTransitionState.Idle
59         val currentSceneOrNull = idleTransitionStateOrNull?.currentScene
60         val invisibleDueToOcclusion = occlusionInteractor.get().invisibleDueToOcclusion.value
61         return currentSceneOrNull?.let { sceneKey ->
62             EvaluatorByFlag[flag]?.invoke(
63                 SceneContainerPluginState(
64                     scene = sceneKey,
65                     invisibleDueToOcclusion = invisibleDueToOcclusion,
66                 )
67             )
68         }
69     }
70 
71     companion object {
72 
73         /**
74          * Value evaluator function by state flag ID.
75          *
76          * The value evaluator function can be invoked, passing in the current [SceneKey] to know
77          * the override value of the flag ID.
78          *
79          * If the map doesn't contain an entry for a certain flag ID, it means that it doesn't need
80          * to be overridden by the scene framework.
81          */
82         val EvaluatorByFlag =
83             mapOf<Long, (SceneContainerPluginState) -> Boolean>(
84                 SYSUI_STATE_NOTIFICATION_PANEL_VISIBLE to { it.scene != Scenes.Gone },
85                 SYSUI_STATE_NOTIFICATION_PANEL_EXPANDED to
86                     {
87                         it.scene == Scenes.Lockscreen ||
88                             it.scene == Scenes.NotificationsShade ||
89                             it.scene == Scenes.Shade
90                     },
91                 SYSUI_STATE_QUICK_SETTINGS_EXPANDED to
92                     {
93                         it.scene == Scenes.QuickSettingsShade || it.scene == Scenes.QuickSettings
94                     },
95                 SYSUI_STATE_BOUNCER_SHOWING to { it.scene == Scenes.Bouncer },
96                 SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING to
97                     {
98                         it.scene == Scenes.Lockscreen && !it.invisibleDueToOcclusion
99                     },
100                 SYSUI_STATE_STATUS_BAR_KEYGUARD_SHOWING_OCCLUDED to
101                     {
102                         it.scene == Scenes.Lockscreen && it.invisibleDueToOcclusion
103                     },
104             )
105     }
106 
107     data class SceneContainerPluginState(
108         val scene: SceneKey,
109         val invisibleDueToOcclusion: Boolean,
110     )
111 }
112