summaryrefslogtreecommitdiff
path: root/packages/SystemUI/src/com/android/systemui/shade/NotificationShadeWindowState.kt
blob: fed9b8469c4b2172b8793d1f2f930370356283b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.shade

import com.android.systemui.dump.DumpsysTableLogger
import com.android.systemui.dump.Row
import com.android.systemui.plugins.util.RingBuffer
import com.android.systemui.shade.NotificationShadeWindowState.Buffer
import com.android.systemui.statusbar.StatusBarState

/**
 * Represents state of shade window, used by [NotificationShadeWindowControllerImpl]. Contains
 * nested class [Buffer] for pretty table logging in bug reports.
 */
class NotificationShadeWindowState(
    @JvmField var keyguardShowing: Boolean = false,
    @JvmField var keyguardOccluded: Boolean = false,
    @JvmField var keyguardNeedsInput: Boolean = false,
    @JvmField var panelVisible: Boolean = false,
    /** shade panel is expanded (expansion fraction > 0) */
    @JvmField var panelExpanded: Boolean = false,
    @JvmField var notificationShadeFocusable: Boolean = false,
    @JvmField var bouncerShowing: Boolean = false,
    @JvmField var keyguardFadingAway: Boolean = false,
    @JvmField var keyguardGoingAway: Boolean = false,
    @JvmField var qsExpanded: Boolean = false,
    @JvmField var headsUpNotificationShowing: Boolean = false,
    @JvmField var lightRevealScrimOpaque: Boolean = false,
    @JvmField var forceWindowCollapsed: Boolean = false,
    @JvmField var forceDozeBrightness: Boolean = false,
    // TODO: forceUserActivity seems to be unused, delete?
    @JvmField var forceUserActivity: Boolean = false,
    @JvmField var launchingActivityFromNotification: Boolean = false,
    @JvmField var mediaBackdropShowing: Boolean = false,
    @JvmField var wallpaperSupportsAmbientMode: Boolean = false,
    @JvmField var windowNotTouchable: Boolean = false,
    @JvmField var componentsForcingTopUi: MutableSet<String> = mutableSetOf(),
    @JvmField var forceOpenTokens: MutableSet<Any> = mutableSetOf(),
    /** one of [StatusBarState] */
    @JvmField var statusBarState: Int = 0,
    @JvmField var remoteInputActive: Boolean = false,
    @JvmField var forcePluginOpen: Boolean = false,
    @JvmField var dozing: Boolean = false,
    @JvmField var dreaming: Boolean = false,
    @JvmField var scrimsVisibility: Int = 0,
    @JvmField var backgroundBlurRadius: Int = 0,
) {

    fun isKeyguardShowingAndNotOccluded(): Boolean {
        return keyguardShowing && !keyguardOccluded
    }

    /** List of [String] to be used as a [Row] with [DumpsysTableLogger]. */
    val asStringList: List<String> by lazy {
        listOf(
            keyguardShowing.toString(),
            keyguardOccluded.toString(),
            keyguardNeedsInput.toString(),
            panelVisible.toString(),
            panelExpanded.toString(),
            notificationShadeFocusable.toString(),
            bouncerShowing.toString(),
            keyguardFadingAway.toString(),
            keyguardGoingAway.toString(),
            qsExpanded.toString(),
            headsUpNotificationShowing.toString(),
            lightRevealScrimOpaque.toString(),
            forceWindowCollapsed.toString(),
            forceDozeBrightness.toString(),
            forceUserActivity.toString(),
            launchingActivityFromNotification.toString(),
            mediaBackdropShowing.toString(),
            wallpaperSupportsAmbientMode.toString(),
            windowNotTouchable.toString(),
            componentsForcingTopUi.toString(),
            forceOpenTokens.toString(),
            StatusBarState.toString(statusBarState),
            remoteInputActive.toString(),
            forcePluginOpen.toString(),
            dozing.toString(),
            scrimsVisibility.toString(),
            backgroundBlurRadius.toString()
        )
    }

    /**
     * [RingBuffer] to store [NotificationShadeWindowState]. After the buffer is full, it will
     * recycle old events.
     */
    class Buffer(capacity: Int) {

        private val buffer = RingBuffer(capacity) { NotificationShadeWindowState() }

        /** Insert a new element in the buffer. */
        fun insert(
            keyguardShowing: Boolean,
            keyguardOccluded: Boolean,
            keyguardNeedsInput: Boolean,
            panelVisible: Boolean,
            panelExpanded: Boolean,
            notificationShadeFocusable: Boolean,
            bouncerShowing: Boolean,
            keyguardFadingAway: Boolean,
            keyguardGoingAway: Boolean,
            qsExpanded: Boolean,
            headsUpShowing: Boolean,
            lightRevealScrimOpaque: Boolean,
            forceCollapsed: Boolean,
            forceDozeBrightness: Boolean,
            forceUserActivity: Boolean,
            launchingActivity: Boolean,
            backdropShowing: Boolean,
            wallpaperSupportsAmbientMode: Boolean,
            notTouchable: Boolean,
            componentsForcingTopUi: MutableSet<String>,
            forceOpenTokens: MutableSet<Any>,
            statusBarState: Int,
            remoteInputActive: Boolean,
            forcePluginOpen: Boolean,
            dozing: Boolean,
            scrimsVisibility: Int,
            backgroundBlurRadius: Int,
        ) {
            buffer.advance().apply {
                this.keyguardShowing = keyguardShowing
                this.keyguardOccluded = keyguardOccluded
                this.keyguardNeedsInput = keyguardNeedsInput
                this.panelVisible = panelVisible
                this.panelExpanded = panelExpanded
                this.notificationShadeFocusable = notificationShadeFocusable
                this.bouncerShowing = bouncerShowing
                this.keyguardFadingAway = keyguardFadingAway
                this.keyguardGoingAway = keyguardGoingAway
                this.qsExpanded = qsExpanded
                this.headsUpNotificationShowing = headsUpShowing
                this.lightRevealScrimOpaque = lightRevealScrimOpaque
                this.forceWindowCollapsed = forceCollapsed
                this.forceDozeBrightness = forceDozeBrightness
                this.forceUserActivity = forceUserActivity
                this.launchingActivityFromNotification = launchingActivity
                this.mediaBackdropShowing = backdropShowing
                this.wallpaperSupportsAmbientMode = wallpaperSupportsAmbientMode
                this.windowNotTouchable = notTouchable
                this.componentsForcingTopUi.clear()
                this.componentsForcingTopUi.addAll(componentsForcingTopUi)
                this.forceOpenTokens.clear()
                this.forceOpenTokens.addAll(forceOpenTokens)
                this.statusBarState = statusBarState
                this.remoteInputActive = remoteInputActive
                this.forcePluginOpen = forcePluginOpen
                this.dozing = dozing
                this.scrimsVisibility = scrimsVisibility
                this.backgroundBlurRadius = backgroundBlurRadius
            }
        }

        /**
         * Returns the content of the buffer (sorted from latest to newest).
         *
         * @see [NotificationShadeWindowState.asStringList]
         */
        fun toList(): List<Row> {
            return buffer.asSequence().map { it.asStringList }.toList()
        }
    }

    companion object {
        /** Headers for dumping a table using [DumpsysTableLogger]. */
        @JvmField
        val TABLE_HEADERS =
            listOf(
                "keyguardShowing",
                "keyguardOccluded",
                "keyguardNeedsInput",
                "panelVisible",
                "panelExpanded",
                "notificationShadeFocusable",
                "bouncerShowing",
                "keyguardFadingAway",
                "keyguardGoingAway",
                "qsExpanded",
                "headsUpShowing",
                "lightRevealScrimOpaque",
                "forceCollapsed",
                "forceDozeBrightness",
                "forceUserActivity",
                "launchingActivity",
                "backdropShowing",
                "wallpaperSupportsAmbientMode",
                "notTouchable",
                "componentsForcingTopUi",
                "forceOpenTokens",
                "statusBarState",
                "remoteInputActive",
                "forcePluginOpen",
                "dozing",
                "scrimsVisibility",
                "backgroundBlurRadius"
            )
    }
}