• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
<lambda>null2  * Copyright (C) 2025 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 android.view.Display
20 import com.android.systemui.dump.DumpManager
21 import com.android.systemui.shared.system.QuickStepContract.SystemUiStateFlags
22 import dagger.assisted.Assisted
23 import dagger.assisted.AssistedFactory
24 import dagger.assisted.AssistedInject
25 
26 /**
27  * This class is used to provide per-display overrides for only certain flags.
28  *
29  * While some of the [SystemUiStateFlags] are per display (e.g. shade expansion, dialog visible),
30  * some of them are device specific (e.g. whether it's awake or not). A [SysUIStateOverride] is
31  * created for each display that is not [Display.DEFAULT_DISPLAY], and if some flags are set on it,
32  * they will override whatever the default display state had in those.
33  */
34 class SysUIStateOverride
35 @AssistedInject
36 constructor(
37     @Assisted override val displayId: Int,
38     private val sceneContainerPlugin: SceneContainerPlugin?,
39     dumpManager: DumpManager,
40     private val defaultDisplayState: SysUiState,
41     private val stateDispatcher: SysUIStateDispatcher,
42 ) : SysUiStateImpl(displayId, sceneContainerPlugin, dumpManager, stateDispatcher) {
43 
44     private val override = StateChange()
45     private var lastSentFlags = defaultDisplayState.flags
46 
47     private val defaultFlagsChangedCallback = { _: Long, otherDisplayId: Int ->
48         if (otherDisplayId == Display.DEFAULT_DISPLAY) {
49             commitUpdate()
50         }
51     }
52 
53     override fun start() {
54         super.start()
55         stateDispatcher.registerListener(defaultFlagsChangedCallback)
56     }
57 
58     override fun destroy() {
59         super.destroy()
60         stateDispatcher.unregisterListener(defaultFlagsChangedCallback)
61     }
62 
63     override fun commitUpdate() {
64         if (flags != lastSentFlags) {
65             stateDispatcher.dispatchSysUIStateChange(flags, displayId)
66             lastSentFlags = flags
67         }
68     }
69 
70     override val flags: Long
71         get() = override.applyTo(defaultDisplayState.flags)
72 
73     override fun setFlag(@SystemUiStateFlags flag: Long, enabled: Boolean): SysUiState {
74         val toSet = flagWithOptionalOverrides(flag, enabled, displayId, sceneContainerPlugin)
75         override.setFlag(flag, toSet)
76         return this
77     }
78 
79     @AssistedFactory
80     interface Factory {
81         fun create(displayId: Int): SysUIStateOverride
82     }
83 }
84