Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3928a462 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Crash if the shade list is accessed during the build process.

Test: ran on my device a bit -- no crashes
Change-Id: I74e2b5b2a19ac946503e9a62288f6fd19ad5c75d
parent c273e395
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
@@ -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<ListEntry>
        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<NotificationEntry> = 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
+3 −0
Original line number Diff line number Diff line
@@ -253,6 +253,9 @@ public class ShadeListBuilder implements Dumpable {

    List<ListEntry> 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;
    }