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

Commit 5d3cdb4e authored by Beverly's avatar Beverly
Browse files

Update removal logic for notifications

New pipeline:
Cancel the lifetime extension for notifications that are manually
dismissed by the user whether this is via manually dismissal or if the
user is clicking on an autoCancellable notification

Old pipeline:
Move the logic for dismissing the summary of a notification if the
user is dismissing the last child of a notification group to the
OnUserInteraction callback.

Test: atest NotifCollectionTest
Test: manual
Fixes: 166784583
Change-Id: I55398075ad9733b73d8ff900cd465fee9a4f01d1
parent fb94cc52
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.statusbar.notification.collection;

import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL;
import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL_ALL;
import static android.service.notification.NotificationListenerService.REASON_CANCEL;
import static android.service.notification.NotificationListenerService.REASON_CANCEL_ALL;
import static android.service.notification.NotificationListenerService.REASON_CHANNEL_BANNED;
import static android.service.notification.NotificationListenerService.REASON_CLICK;
@@ -459,8 +460,7 @@ public class NotifCollection implements Dumpable {
                            + ": has not been marked for removal"));
        }

        if (isDismissedByUser(entry)) {
            // User-dismissed notifications cannot be lifetime-extended
        if (cannotBeLifetimeExtended(entry)) {
            cancelLifetimeExtension(entry);
        } else {
            updateLifetimeExtension(entry);
@@ -583,7 +583,7 @@ public class NotifCollection implements Dumpable {
    }

    private void cancelLocalDismissal(NotificationEntry entry) {
        if (isDismissedByUser(entry)) {
        if (entry.getDismissState() != NOT_DISMISSED) {
            entry.setDismissState(NOT_DISMISSED);
            if (entry.getSbn().getNotification().isGroupSummary()) {
                for (NotificationEntry otherEntry : mNotificationSet.values()) {
@@ -669,12 +669,16 @@ public class NotifCollection implements Dumpable {
     * immediately removed from the collection, but can sometimes stick around due to lifetime
     * extenders.
     */
    private static boolean isCanceled(NotificationEntry entry) {
    private boolean isCanceled(NotificationEntry entry) {
        return entry.mCancellationReason != REASON_NOT_CANCELED;
    }

    private static boolean isDismissedByUser(NotificationEntry entry) {
        return entry.getDismissState() != NOT_DISMISSED;
    private boolean cannotBeLifetimeExtended(NotificationEntry entry) {
        final boolean locallyDismissedByUser = entry.getDismissState() != NOT_DISMISSED;
        final boolean systemServerReportedUserCancel =
                entry.mCancellationReason == REASON_CLICK
                        || entry.mCancellationReason == REASON_CANCEL;
        return locallyDismissedByUser || systemServerReportedUserCancel;
    }

    /**
+13 −1
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.notifcollection.DismissedByUserStats;
import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager;
import com.android.systemui.statusbar.notification.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.row.OnUserInteractionCallback;
import com.android.systemui.statusbar.policy.HeadsUpManager;
@@ -38,17 +39,20 @@ public class OnUserInteractionCallbackImplLegacy implements OnUserInteractionCal
    private final HeadsUpManager mHeadsUpManager;
    private final StatusBarStateController mStatusBarStateController;
    private final VisualStabilityManager mVisualStabilityManager;
    private final GroupMembershipManager mGroupMembershipManager;

    public OnUserInteractionCallbackImplLegacy(
            NotificationEntryManager notificationEntryManager,
            HeadsUpManager headsUpManager,
            StatusBarStateController statusBarStateController,
            VisualStabilityManager visualStabilityManager
            VisualStabilityManager visualStabilityManager,
            GroupMembershipManager groupMembershipManager
    ) {
        mNotificationEntryManager = notificationEntryManager;
        mHeadsUpManager = headsUpManager;
        mStatusBarStateController = statusBarStateController;
        mVisualStabilityManager = visualStabilityManager;
        mGroupMembershipManager = groupMembershipManager;
    }

    /**
@@ -69,6 +73,13 @@ public class OnUserInteractionCallbackImplLegacy implements OnUserInteractionCal
            dismissalSurface = NotificationStats.DISMISSAL_AOD;
        }

        if (mGroupMembershipManager.isOnlyChildInGroup(entry)) {
            NotificationEntry groupSummary = mGroupMembershipManager.getLogicalGroupSummary(entry);
            if (groupSummary.isClearable()) {
                onDismiss(groupSummary, cancellationReason);
            }
        }

        mNotificationEntryManager.performRemoveNotification(
                entry.getSbn(),
                new DismissedByUserStats(
@@ -82,6 +93,7 @@ public class OnUserInteractionCallbackImplLegacy implements OnUserInteractionCal
                                NotificationLogger.getNotificationLocation(entry))),
                cancellationReason
        );

    }

    @Override
+8 −4
Original line number Diff line number Diff line
@@ -205,9 +205,11 @@ public interface NotificationsModule {
            Context context,
            NotificationGutsManager notificationGutsManager,
            NotificationEntryManager notificationEntryManager,
            MetricsLogger metricsLogger) {
            MetricsLogger metricsLogger,
            GroupMembershipManager groupMembershipManager) {
        return new NotificationBlockingHelperManager(
                context, notificationGutsManager, notificationEntryManager, metricsLogger);
                context, notificationGutsManager, notificationEntryManager, metricsLogger,
                groupMembershipManager);
    }

    /** Provides an instance of {@link GroupMembershipManager} */
@@ -273,7 +275,8 @@ public interface NotificationsModule {
            Lazy<NotifCollection> notifCollection,
            Lazy<VisualStabilityCoordinator> visualStabilityCoordinator,
            NotificationEntryManager entryManager,
            VisualStabilityManager visualStabilityManager) {
            VisualStabilityManager visualStabilityManager,
            Lazy<GroupMembershipManager> groupMembershipManagerLazy) {
        return featureFlags.isNewNotifPipelineRenderingEnabled()
                ? new OnUserInteractionCallbackImpl(
                        pipeline.get(),
@@ -285,7 +288,8 @@ public interface NotificationsModule {
                        entryManager,
                        headsUpManager,
                        statusBarStateController,
                        visualStabilityManager);
                        visualStabilityManager,
                        groupMembershipManagerLazy.get());
    }

    /** */
+0 −15
Original line number Diff line number Diff line
@@ -817,13 +817,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        return mNotificationParent != null;
    }

    /**
     * @return whether this notification is the only child in the group summary
     */
    public boolean isOnlyChildInGroup() {
        return mGroupMembershipManager.isOnlyChildInGroup(mEntry);
    }

    public ExpandableNotificationRow getNotificationParent() {
        return mNotificationParent;
    }
@@ -1425,14 +1418,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    }

    public void performDismiss(boolean fromAccessibility) {
        if (isOnlyChildInGroup()) {
            NotificationEntry groupSummary = mGroupMembershipManager.getLogicalGroupSummary(mEntry);
            if (groupSummary.isClearable()) {
                // If this is the only child in the group, dismiss the group, but don't try to show
                // the blocking helper affordance!
                groupSummary.getRow().performDismiss(fromAccessibility);
            }
        }
        dismiss(fromAccessibility);
        if (mEntry.isClearable()) {
            if (mOnUserInteractionCallback != null) {
+10 −4
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.render.GroupMembershipManager;
import com.android.systemui.statusbar.notification.dagger.NotificationsModule;
import com.android.systemui.statusbar.notification.logging.NotificationCounters;

@@ -48,6 +50,7 @@ public class NotificationBlockingHelperManager {
    private final NotificationGutsManager mNotificationGutsManager;
    private final NotificationEntryManager mNotificationEntryManager;
    private final MetricsLogger mMetricsLogger;
    private final GroupMembershipManager mGroupMembershipManager;
    /** Row that the blocking helper will be shown in (via {@link NotificationGuts}. */
    private ExpandableNotificationRow mBlockingHelperRow;
    private Set<String> mNonBlockablePkgs;
@@ -65,7 +68,8 @@ public class NotificationBlockingHelperManager {
            Context context,
            NotificationGutsManager notificationGutsManager,
            NotificationEntryManager notificationEntryManager,
            MetricsLogger metricsLogger) {
            MetricsLogger metricsLogger,
            GroupMembershipManager groupMembershipManager) {
        mContext = context;
        mNotificationGutsManager = notificationGutsManager;
        mNotificationEntryManager = notificationEntryManager;
@@ -73,6 +77,7 @@ public class NotificationBlockingHelperManager {
        mNonBlockablePkgs = new HashSet<>();
        Collections.addAll(mNonBlockablePkgs, mContext.getResources().getStringArray(
                com.android.internal.R.array.config_nonBlockableNotificationPackages));
        mGroupMembershipManager = groupMembershipManager;
    }

    /**
@@ -92,10 +97,11 @@ public class NotificationBlockingHelperManager {
        // - The row is blockable (i.e. not non-blockable)
        // - The dismissed row is a valid group (>1 or 0 children from the same channel)
        // or the only child in the group
        if ((row.getEntry().getUserSentiment() == USER_SENTIMENT_NEGATIVE || DEBUG)
        final NotificationEntry entry = row.getEntry();
        if ((entry.getUserSentiment() == USER_SENTIMENT_NEGATIVE || DEBUG)
                && mIsShadeExpanded
                && !row.getIsNonblockable()
                && ((!row.isChildInGroup() || row.isOnlyChildInGroup())
                && ((!row.isChildInGroup() || mGroupMembershipManager.isOnlyChildInGroup(entry))
                    && row.getNumUniqueChannels() <= 1)) {
            // Dismiss any current blocking helper before continuing forward (only one can be shown
            // at a given time).
Loading