1 /* 2 * Copyright (C) 2022 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.shade 18 19 import com.android.systemui.common.buffer.RingBuffer 20 import com.android.systemui.dump.DumpsysTableLogger 21 import com.android.systemui.dump.Row 22 import com.android.systemui.shade.NotificationShadeWindowState.Buffer 23 import com.android.systemui.statusbar.StatusBarState 24 25 /** 26 * Represents state of shade window, used by [NotificationShadeWindowControllerImpl]. Contains 27 * nested class [Buffer] for pretty table logging in bug reports. 28 */ 29 class NotificationShadeWindowState( 30 @JvmField var keyguardShowing: Boolean = false, 31 @JvmField var keyguardOccluded: Boolean = false, 32 @JvmField var keyguardNeedsInput: Boolean = false, 33 @JvmField var panelVisible: Boolean = false, 34 /** shade panel is expanded (expansion fraction > 0) */ 35 @JvmField var shadeOrQsExpanded: Boolean = false, 36 @JvmField var notificationShadeFocusable: Boolean = false, 37 @JvmField var bouncerShowing: Boolean = false, 38 @JvmField var glanceableHubShowing: Boolean = false, 39 @JvmField var glanceableHubOrientationAware: Boolean = false, 40 @JvmField var keyguardFadingAway: Boolean = false, 41 @JvmField var keyguardGoingAway: Boolean = false, 42 @JvmField var qsExpanded: Boolean = false, 43 @JvmField var headsUpNotificationShowing: Boolean = false, 44 @JvmField var lightRevealScrimOpaque: Boolean = false, 45 @JvmField var isSwitchingUsers: Boolean = false, 46 @JvmField var forceWindowCollapsed: Boolean = false, 47 @JvmField var forceDozeBrightness: Boolean = false, 48 // TODO: forceUserActivity seems to be unused, delete? 49 @JvmField var forceUserActivity: Boolean = false, 50 @JvmField var launchingActivityFromNotification: Boolean = false, 51 @JvmField var mediaBackdropShowing: Boolean = false, 52 @JvmField var windowNotTouchable: Boolean = false, 53 @JvmField var componentsForcingTopUi: MutableSet<String> = mutableSetOf(), 54 @JvmField var forceOpenTokens: MutableSet<Any> = mutableSetOf(), 55 /** one of [StatusBarState] */ 56 @JvmField var statusBarState: Int = 0, 57 @JvmField var remoteInputActive: Boolean = false, 58 @JvmField var forcePluginOpen: Boolean = false, 59 @JvmField var dozing: Boolean = false, 60 @JvmField var dreaming: Boolean = false, 61 @JvmField var scrimsVisibility: Int = 0, 62 @JvmField var backgroundBlurRadius: Int = 0, 63 @JvmField var communalVisible: Boolean = false, 64 ) { 65 isKeyguardShowingAndNotOccludednull66 fun isKeyguardShowingAndNotOccluded(): Boolean { 67 return keyguardShowing && !keyguardOccluded 68 } 69 isCommunalVisibleAndNotOccludednull70 fun isCommunalVisibleAndNotOccluded(): Boolean { 71 return communalVisible && !keyguardOccluded 72 } 73 74 /** List of [String] to be used as a [Row] with [DumpsysTableLogger]. */ <lambda>null75 val asStringList: List<String> by lazy { 76 listOf( 77 keyguardShowing.toString(), 78 keyguardOccluded.toString(), 79 keyguardNeedsInput.toString(), 80 panelVisible.toString(), 81 shadeOrQsExpanded.toString(), 82 notificationShadeFocusable.toString(), 83 bouncerShowing.toString(), 84 glanceableHubShowing.toString(), 85 glanceableHubOrientationAware.toString(), 86 keyguardFadingAway.toString(), 87 keyguardGoingAway.toString(), 88 qsExpanded.toString(), 89 headsUpNotificationShowing.toString(), 90 lightRevealScrimOpaque.toString(), 91 isSwitchingUsers.toString(), 92 forceWindowCollapsed.toString(), 93 forceDozeBrightness.toString(), 94 forceUserActivity.toString(), 95 launchingActivityFromNotification.toString(), 96 mediaBackdropShowing.toString(), 97 windowNotTouchable.toString(), 98 componentsForcingTopUi.toString(), 99 forceOpenTokens.toString(), 100 StatusBarState.toString(statusBarState), 101 remoteInputActive.toString(), 102 forcePluginOpen.toString(), 103 dozing.toString(), 104 scrimsVisibility.toString(), 105 backgroundBlurRadius.toString(), 106 communalVisible.toString(), 107 ) 108 } 109 110 /** 111 * [RingBuffer] to store [NotificationShadeWindowState]. After the buffer is full, it will 112 * recycle old events. 113 */ 114 class Buffer(capacity: Int) { 115 <lambda>null116 private val buffer = RingBuffer(capacity) { NotificationShadeWindowState() } 117 118 /** Insert a new element in the buffer. */ insertnull119 fun insert( 120 keyguardShowing: Boolean, 121 keyguardOccluded: Boolean, 122 keyguardNeedsInput: Boolean, 123 panelVisible: Boolean, 124 panelExpanded: Boolean, 125 notificationShadeFocusable: Boolean, 126 glanceableHubShowing: Boolean, 127 glanceableHubOrientationAware: Boolean, 128 bouncerShowing: Boolean, 129 keyguardFadingAway: Boolean, 130 keyguardGoingAway: Boolean, 131 qsExpanded: Boolean, 132 headsUpShowing: Boolean, 133 lightRevealScrimOpaque: Boolean, 134 isSwitchingUsers: Boolean, 135 forceCollapsed: Boolean, 136 forceDozeBrightness: Boolean, 137 forceUserActivity: Boolean, 138 launchingActivity: Boolean, 139 backdropShowing: Boolean, 140 notTouchable: Boolean, 141 componentsForcingTopUi: MutableSet<String>, 142 forceOpenTokens: MutableSet<Any>, 143 statusBarState: Int, 144 remoteInputActive: Boolean, 145 forcePluginOpen: Boolean, 146 dozing: Boolean, 147 scrimsVisibility: Int, 148 backgroundBlurRadius: Int, 149 communalVisible: Boolean, 150 ) { 151 buffer.advance().apply { 152 this.keyguardShowing = keyguardShowing 153 this.keyguardOccluded = keyguardOccluded 154 this.keyguardNeedsInput = keyguardNeedsInput 155 this.panelVisible = panelVisible 156 this.shadeOrQsExpanded = panelExpanded 157 this.notificationShadeFocusable = notificationShadeFocusable 158 this.glanceableHubShowing = glanceableHubShowing 159 this.glanceableHubOrientationAware = glanceableHubOrientationAware 160 this.bouncerShowing = bouncerShowing 161 this.keyguardFadingAway = keyguardFadingAway 162 this.keyguardGoingAway = keyguardGoingAway 163 this.qsExpanded = qsExpanded 164 this.headsUpNotificationShowing = headsUpShowing 165 this.lightRevealScrimOpaque = lightRevealScrimOpaque 166 this.isSwitchingUsers = isSwitchingUsers 167 this.forceWindowCollapsed = forceCollapsed 168 this.forceDozeBrightness = forceDozeBrightness 169 this.forceUserActivity = forceUserActivity 170 this.launchingActivityFromNotification = launchingActivity 171 this.mediaBackdropShowing = backdropShowing 172 this.windowNotTouchable = notTouchable 173 this.componentsForcingTopUi.clear() 174 this.componentsForcingTopUi.addAll(componentsForcingTopUi) 175 this.forceOpenTokens.clear() 176 this.forceOpenTokens.addAll(forceOpenTokens) 177 this.statusBarState = statusBarState 178 this.remoteInputActive = remoteInputActive 179 this.forcePluginOpen = forcePluginOpen 180 this.dozing = dozing 181 this.scrimsVisibility = scrimsVisibility 182 this.backgroundBlurRadius = backgroundBlurRadius 183 this.communalVisible = communalVisible 184 } 185 } 186 187 /** 188 * Returns the content of the buffer (sorted from latest to newest). 189 * 190 * @see [NotificationShadeWindowState.asStringList] 191 */ toListnull192 fun toList(): List<Row> { 193 return buffer.map { it.asStringList } 194 } 195 } 196 197 companion object { 198 /** Headers for dumping a table using [DumpsysTableLogger]. */ 199 @JvmField 200 val TABLE_HEADERS = 201 listOf( 202 "keyguardShowing", 203 "keyguardOccluded", 204 "keyguardNeedsInput", 205 "panelVisible", 206 "panelExpanded", 207 "notificationShadeFocusable", 208 "glanceableHubShowing", 209 "glanceableHubOrientationAware", 210 "bouncerShowing", 211 "keyguardFadingAway", 212 "keyguardGoingAway", 213 "qsExpanded", 214 "headsUpShowing", 215 "lightRevealScrimOpaque", 216 "isSwitchingUsers", 217 "forceCollapsed", 218 "forceDozeBrightness", 219 "forceUserActivity", 220 "launchingActivity", 221 "backdropShowing", 222 "notTouchable", 223 "componentsForcingTopUi", 224 "forceOpenTokens", 225 "statusBarState", 226 "remoteInputActive", 227 "forcePluginOpen", 228 "dozing", 229 "scrimsVisibility", 230 "backgroundBlurRadius", 231 "communalVisible", 232 ) 233 } 234 } 235