diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifPipeline.kt b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifPipeline.kt index 9ae9fe5089441..23ecdd1302f0b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifPipeline.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/NotifPipeline.kt @@ -218,8 +218,8 @@ class NotifPipeline @Inject constructor( /** * Returns a read-only view in to the current shade list, i.e. the list of notifications that - * are currently present in the shade. If this method is called during pipeline execution it - * will return the current state of the list, which will likely be only partially-generated. + * are currently present in the shade. + * @throws IllegalStateException if called during pipeline execution. */ val shadeList: List get() = mShadeListBuilder.shadeList @@ -227,21 +227,20 @@ class NotifPipeline @Inject constructor( /** * Constructs a flattened representation of the notification tree, where each group will have * the summary (if present) followed by the children. + * @throws IllegalStateException if called during pipeline execution. */ fun getFlatShadeList(): List = shadeList.flatMap { entry -> when (entry) { is NotificationEntry -> sequenceOf(entry) - is GroupEntry -> (entry.summary?.let { sequenceOf(it) }.orEmpty() + - entry.children) + is GroupEntry -> sequenceOf(entry.summary).filterNotNull() + entry.children else -> throw RuntimeException("Unexpected entry $entry") } } /** * Returns the number of notifications currently shown in the shade. This includes all - * children and summary notifications. If this method is called during pipeline execution it - * will return the number of notifications in its current state, which will likely be only - * partially-generated. + * children and summary notifications. + * @throws IllegalStateException if called during pipeline execution. */ fun getShadeListCount(): Int = shadeList.sumOf { entry -> // include the summary in the count diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilder.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilder.java index 72cd95128779b..2787975c019a5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilder.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/collection/ShadeListBuilder.java @@ -253,6 +253,9 @@ public class ShadeListBuilder implements Dumpable { List getShadeList() { Assert.isMainThread(); + // NOTE: Accessing this method when the pipeline is running is generally going to provide + // incorrect results, and indicates a poorly behaved component of the pipeline. + mPipelineState.requireState(STATE_IDLE); return mReadOnlyNotifList; }