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

Commit 2265301d authored by Kevin Han's avatar Kevin Han
Browse files

Add listener hook before finalize filter.

Add a hook so coordinators can listen before the FinalizeFilter
stage (previously named preRenderFilter and renamed in this CL b/c
OnBeforePreRenderFilter sounds somewhat awkward).

This'll be helpful for moving inflation-related filtering after
sort/group stage.

Bug: 112656837
Test: atest ShadeListBuilderTest
Change-Id: If7c7b7375b664ddcd0bb75b0937070a03db9b0e3
parent 6d03d973
Loading
Loading
Loading
Loading
+12 −3
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.statusbar.notification.collection;

import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeFinalizeFilterListener;
import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeRenderListListener;
import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeSortListener;
import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeTransformGroupsListener;
@@ -63,7 +64,7 @@ import javax.inject.Singleton;
 *  6. Top-level entries are assigned sections by NotifSections ({@link #setSections})
 *  7. Top-level entries within the same section are sorted by NotifComparators
 *     ({@link #setComparators})
 *  8. Pre-render filters are fired on each notification ({@link #addPreRenderFilter})
 *  8. Finalize filters are fired on each notification ({@link #addFinalizeFilter})
 *  9. OnBeforeRenderListListeners are fired ({@link #addOnBeforeRenderListListener})
 *  9. The list is handed off to the view layer to be rendered
 */
@@ -168,6 +169,14 @@ public class NotifPipeline implements CommonNotifCollection {
        mShadeListBuilder.setComparators(comparators);
    }

    /**
     * Called after notifs have been filtered once, grouped, and sorted but before the final
     * filtering.
     */
    public void addOnBeforeFinalizeFilterListener(OnBeforeFinalizeFilterListener listener) {
        mShadeListBuilder.addOnBeforeFinalizeFilterListener(listener);
    }

    /**
     * Registers a filter with the pipeline to filter right before rendering the list (after
     * pre-group filtering, grouping, promoting and sorting occurs). Filters are
@@ -175,8 +184,8 @@ public class NotifPipeline implements CommonNotifCollection {
     * true, the notification is removed from the pipeline (and no other filters are called on that
     * notif).
     */
    public void addPreRenderFilter(NotifFilter filter) {
        mShadeListBuilder.addPreRenderFilter(filter);
    public void addFinalizeFilter(NotifFilter filter) {
        mShadeListBuilder.addFinalizeFilter(filter);
    }

    /**
+27 −10
Original line number Diff line number Diff line
@@ -18,11 +18,11 @@ package com.android.systemui.statusbar.notification.collection;

import static com.android.systemui.statusbar.notification.collection.GroupEntry.ROOT_ENTRY;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_BUILD_STARTED;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_FINALIZE_FILTERING;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_FINALIZING;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_GROUPING;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_IDLE;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_PRE_GROUP_FILTERING;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_PRE_RENDER_FILTERING;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_RESETTING;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_SORTING;
import static com.android.systemui.statusbar.notification.collection.listbuilder.PipelineState.STATE_TRANSFORMING;
@@ -36,6 +36,7 @@ import androidx.annotation.NonNull;

import com.android.systemui.Dumpable;
import com.android.systemui.dump.DumpManager;
import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeFinalizeFilterListener;
import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeRenderListListener;
import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeSortListener;
import com.android.systemui.statusbar.notification.collection.listbuilder.OnBeforeTransformGroupsListener;
@@ -82,7 +83,7 @@ public class ShadeListBuilder implements Dumpable {

    private final List<NotifFilter> mNotifPreGroupFilters = new ArrayList<>();
    private final List<NotifPromoter> mNotifPromoters = new ArrayList<>();
    private final List<NotifFilter> mNotifPreRenderFilters = new ArrayList<>();
    private final List<NotifFilter> mNotifFinalizeFilters = new ArrayList<>();
    private final List<NotifComparator> mNotifComparators = new ArrayList<>();
    private final List<NotifSection> mNotifSections = new ArrayList<>();

@@ -90,6 +91,8 @@ public class ShadeListBuilder implements Dumpable {
            new ArrayList<>();
    private final List<OnBeforeSortListener> mOnBeforeSortListeners =
            new ArrayList<>();
    private final List<OnBeforeFinalizeFilterListener> mOnBeforeFinalizeFilterListeners =
            new ArrayList<>();
    private final List<OnBeforeRenderListListener> mOnBeforeRenderListListeners =
            new ArrayList<>();
    @Nullable private OnRenderListListener mOnRenderListListener;
@@ -142,6 +145,13 @@ public class ShadeListBuilder implements Dumpable {
        mOnBeforeSortListeners.add(listener);
    }

    void addOnBeforeFinalizeFilterListener(OnBeforeFinalizeFilterListener listener) {
        Assert.isMainThread();

        mPipelineState.requireState(STATE_IDLE);
        mOnBeforeFinalizeFilterListeners.add(listener);
    }

    void addOnBeforeRenderListListener(OnBeforeRenderListListener listener) {
        Assert.isMainThread();

@@ -157,12 +167,12 @@ public class ShadeListBuilder implements Dumpable {
        filter.setInvalidationListener(this::onPreGroupFilterInvalidated);
    }

    void addPreRenderFilter(NotifFilter filter) {
    void addFinalizeFilter(NotifFilter filter) {
        Assert.isMainThread();
        mPipelineState.requireState(STATE_IDLE);

        mNotifPreRenderFilters.add(filter);
        filter.setInvalidationListener(this::onPreRenderFilterInvalidated);
        mNotifFinalizeFilters.add(filter);
        filter.setInvalidationListener(this::onFinalizeFilterInvalidated);
    }

    void addPromoter(NotifPromoter promoter) {
@@ -237,12 +247,12 @@ public class ShadeListBuilder implements Dumpable {
        rebuildListIfBefore(STATE_SORTING);
    }

    private void onPreRenderFilterInvalidated(NotifFilter filter) {
    private void onFinalizeFilterInvalidated(NotifFilter filter) {
        Assert.isMainThread();

        mLogger.logPreRenderFilterInvalidated(filter.getName(), mPipelineState.getState());
        mLogger.logFinalizeFilterInvalidated(filter.getName(), mPipelineState.getState());

        rebuildListIfBefore(STATE_PRE_RENDER_FILTERING);
        rebuildListIfBefore(STATE_FINALIZE_FILTERING);
    }

    private void onNotifComparatorInvalidated(NotifComparator comparator) {
@@ -298,8 +308,9 @@ public class ShadeListBuilder implements Dumpable {

        // Step 6: Filter out entries after pre-group filtering, grouping, promoting and sorting
        // Now filters can see grouping information to determine whether to filter or not.
        mPipelineState.incrementTo(STATE_PRE_RENDER_FILTERING);
        filterNotifs(mNotifList, mNewNotifList, mNotifPreRenderFilters);
        dispatchOnBeforeFinalizeFilter(mReadOnlyNotifList);
        mPipelineState.incrementTo(STATE_FINALIZE_FILTERING);
        filterNotifs(mNotifList, mNewNotifList, mNotifFinalizeFilters);
        applyNewNotifList();
        pruneIncompleteGroups(mNotifList);

@@ -772,6 +783,12 @@ public class ShadeListBuilder implements Dumpable {
        }
    }

    private void dispatchOnBeforeFinalizeFilter(List<ListEntry> entries) {
        for (int i = 0; i < mOnBeforeFinalizeFilterListeners.size(); i++) {
            mOnBeforeFinalizeFilterListeners.get(i).onBeforeFinalizeFilter(entries);
        }
    }

    private void dispatchOnBeforeRenderList(List<ListEntry> entries) {
        for (int i = 0; i < mOnBeforeRenderListListeners.size(); i++) {
            mOnBeforeRenderListListeners.get(i).onBeforeRenderList(entries);
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ public class BubbleCoordinator implements Coordinator {
    public void attach(NotifPipeline pipeline) {
        mNotifPipeline = pipeline;
        mNotifPipeline.addNotificationDismissInterceptor(mDismissInterceptor);
        mNotifPipeline.addPreRenderFilter(mNotifFilter);
        mNotifPipeline.addFinalizeFilter(mNotifFilter);
        mBubbleController.addNotifCallback(mNotifCallback);
    }

+1 −1
Original line number Diff line number Diff line
@@ -87,7 +87,7 @@ public class KeyguardCoordinator implements Coordinator {
    @Override
    public void attach(NotifPipeline pipeline) {
        setupInvalidateNotifListCallbacks();
        pipeline.addPreRenderFilter(mNotifFilter);
        pipeline.addFinalizeFilter(mNotifFilter);
    }

    private final NotifFilter mNotifFilter = new NotifFilter(TAG) {
+2 −2
Original line number Diff line number Diff line
@@ -69,8 +69,8 @@ public class PreparationCoordinator implements Coordinator {
    @Override
    public void attach(NotifPipeline pipeline) {
        pipeline.addCollectionListener(mNotifCollectionListener);
        pipeline.addPreRenderFilter(mNotifInflationErrorFilter);
        pipeline.addPreRenderFilter(mNotifInflatingFilter);
        pipeline.addFinalizeFilter(mNotifInflationErrorFilter);
        pipeline.addFinalizeFilter(mNotifInflatingFilter);
    }

    private final NotifCollectionListener mNotifCollectionListener = new NotifCollectionListener() {
Loading