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

Commit f9e82999 authored by Beverly's avatar Beverly
Browse files

Suppress group changes in group pruning

If they are suppressed by the visual stability manager
Also fix VSM logic - actually remove the notifications from its parent
when we're suppressing its new group

Test: atest ShadeListBuilderTest
Test: atest VisualStabilityCoordinatorTest
Test: manual, atest SystemUITest
Change-Id: I4ca9905a2347173a3871de43c11df3a2a1da623b
parent 56a78405
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -110,4 +110,11 @@ public abstract class ListEntry {
        mPreviousAttachState.clone(mAttachState);
        mAttachState.reset();
    }

    /**
     * True if this entry was attached in the last pass, else false.
     */
    public boolean wasAttachedInPreviousPass() {
        return getPreviousAttachState().getParent() != null;
    }
}
+68 −13
Original line number Diff line number Diff line
@@ -513,26 +513,64 @@ public class ShadeListBuilder implements Dumpable {
        }
    }

    private void stabilizeGroupingNotifs(List<ListEntry> list) {
    private void stabilizeGroupingNotifs(List<ListEntry> topLevelList) {
        if (mNotifStabilityManager == null) {
            return;
        }

        for (int i = 0; i < list.size(); i++) {
            final ListEntry tle = list.get(i);
            if (tle.getPreviousAttachState().getParent() == null) {
                continue; // new entries are allowed
        for (int i = 0; i < topLevelList.size(); i++) {
            final ListEntry tle = topLevelList.get(i);
            if (tle instanceof GroupEntry) {
                // maybe put children back into their old group (including moving back to top-level)
                GroupEntry groupEntry = (GroupEntry) tle;
                List<NotificationEntry> children = groupEntry.getRawChildren();
                for (int j = 0; j < groupEntry.getChildren().size(); j++) {
                    if (maybeSuppressGroupChange(children.get(j), topLevelList)) {
                        // child was put back into its previous group, so we remove it from this
                        // group
                        children.remove(j);
                        j--;
                    }
                }
            } else {
                // maybe put top-level-entries back into their previous groups
                if (maybeSuppressGroupChange(tle.getRepresentativeEntry(), topLevelList)) {
                    // entry was put back into its previous group, so we remove it from the list of
                    // top-level-entries
                    topLevelList.remove(i);
                    i--;
                }
            }
        }
    }

            final GroupEntry prevParent = tle.getPreviousAttachState().getParent();
            final GroupEntry assignedParent = tle.getParent();
            if (prevParent != assignedParent) {
                if (!mNotifStabilityManager.isGroupChangeAllowed(tle.getRepresentativeEntry())) {
                    tle.getAttachState().getSuppressedChanges().setParent(assignedParent);
                    tle.setParent(prevParent);
    /**
     * Returns true if the group change was suppressed, else false
     */
    private boolean maybeSuppressGroupChange(NotificationEntry entry, List<ListEntry> out) {
        if (!entry.wasAttachedInPreviousPass()) {
            return false; // new entries are allowed
        }

        final GroupEntry prevParent = entry.getPreviousAttachState().getParent();
        final GroupEntry assignedParent = entry.getParent();
        if (prevParent != assignedParent
                && !mNotifStabilityManager.isGroupChangeAllowed(entry.getRepresentativeEntry())) {
            entry.getAttachState().getSuppressedChanges().setParent(assignedParent);
            entry.setParent(prevParent);
            if (prevParent == ROOT_ENTRY) {
                out.add(entry);
            } else if (prevParent != null) {
                prevParent.addChild(entry);
                if (!mGroups.containsKey(prevParent.getKey())) {
                    mGroups.put(prevParent.getKey(), prevParent);
                }
            }

            return true;
        }

        return false;
    }

    private void promoteNotifs(List<ListEntry> list) {
@@ -577,6 +615,17 @@ public class ShadeListBuilder implements Dumpable {

                } else if (group.getSummary() == null
                        || children.size() < MIN_CHILDREN_FOR_GROUP) {

                    if (group.getSummary() != null
                            && group.wasAttachedInPreviousPass()
                            && mNotifStabilityManager != null
                            && !mNotifStabilityManager.isGroupChangeAllowed(group.getSummary())) {
                        // if this group was previously attached and group changes aren't
                        // allowed, keep it around until group changes are allowed again
                        group.getAttachState().getSuppressedChanges().setWasPruneSuppressed(true);
                        continue;
                    }

                    // If the group doesn't provide a summary or is too small, ignore it and add
                    // its children (if any) directly to top-level.

@@ -718,6 +767,12 @@ public class ShadeListBuilder implements Dumpable {
                        curr.getParent());
            }

            if (curr.getSuppressedChanges().getWasPruneSuppressed()) {
                mLogger.logGroupPruningSuppressed(
                        mIterationCount,
                        curr.getParent());
            }

            if (curr.getExcludingFilter() != prev.getExcludingFilter()) {
                mLogger.logFilterChanged(
                        mIterationCount,
@@ -867,9 +922,9 @@ public class ShadeListBuilder implements Dumpable {

        NotifSection finalSection = newSection;

        // are we changing sections of this entry?
        // have we seen this entry before and are we changing its section?
        if (mNotifStabilityManager != null
                && prevAttachState.getParent() != null
                && entry.wasAttachedInPreviousPass()
                && newSection != prevAttachState.getSection()) {

            // are section changes allowed?
+16 −6
Original line number Diff line number Diff line
@@ -24,28 +24,37 @@ import com.android.systemui.statusbar.notification.collection.listbuilder.NotifS
 */
data class SuppressedAttachState private constructor(
    /**
     * Null if not attached to the current shade list. If top-level, then the shade list root. If
     * part of a group, then that group's GroupEntry.
     * The suppressed section assignment for this ListEntry.
     * Null if no section change was suppressed.
     */
    var section: NotifSection?,

    /**
     * The suppressed parent assignment for this ListEntry.
     *  - Null if no parent change was suppressed.
     *  - Root if suppressing group change to top-level
     *  - GroupEntry if suppressing group change to a different group
     */
    var parent: GroupEntry?,

    /**
     * The assigned section for this ListEntry. If the child of the group, this will be the
     * parent's section. Null if not attached to the list.
     * Whether the ListEntry would have been pruned had its group change not been suppressed.
     */
    var section: NotifSection?
    var wasPruneSuppressed: Boolean
) {

    /** Copies the state of another instance. */
    fun clone(other: SuppressedAttachState) {
        parent = other.parent
        section = other.section
        wasPruneSuppressed = other.wasPruneSuppressed
    }

    /** Resets back to a "clean" state (the same as created by the factory method) */
    fun reset() {
        parent = null
        section = null
        wasPruneSuppressed = false
    }

    companion object {
@@ -53,7 +62,8 @@ data class SuppressedAttachState private constructor(
        fun create(): SuppressedAttachState {
            return SuppressedAttachState(
                null,
                null)
                null,
                false)
        }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ public class VisualStabilityCoordinator implements Coordinator {
                public boolean isGroupChangeAllowed(NotificationEntry entry) {
                    final boolean isGroupChangeAllowedForEntry =
                            mReorderingAllowed || mHeadsUpManager.isAlerting(entry.getKey());
                    mIsSuppressingGroupChange |= isGroupChangeAllowedForEntry;
                    mIsSuppressingGroupChange |= !isGroupChangeAllowedForEntry;
                    return isGroupChangeAllowedForEntry;
                }

+13 −2
Original line number Diff line number Diff line
@@ -174,8 +174,19 @@ class ShadeListBuilderLogger @Inject constructor(
            str1 = suppressedParent?.key
            str2 = keepingParent?.key
        }, {
            "(Build $long1)     Change of parent to '$str1' suppressed; " +
                "keeping parent '$str2'"
            "(Build $long1)     Change of parent to '$str1' suppressed; keeping parent '$str2'"
        })
    }

    fun logGroupPruningSuppressed(
        buildId: Int,
        keepingParent: GroupEntry?
    ) {
        buffer.log(TAG, INFO, {
            int1 = buildId
            str1 = keepingParent?.key
        }, {
            "(Build $long1)     Group pruning suppressed; keeping parent '$str1'"
        })
    }

Loading