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 Original line 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;
import static android.service.notification.NotificationListenerService.REASON_APP_CANCEL_ALL;
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_CANCEL_ALL;
import static android.service.notification.NotificationListenerService.REASON_CHANNEL_BANNED;
import static android.service.notification.NotificationListenerService.REASON_CHANNEL_BANNED;
import static android.service.notification.NotificationListenerService.REASON_CLICK;
import static android.service.notification.NotificationListenerService.REASON_CLICK;
@@ -459,8 +460,7 @@ public class NotifCollection implements Dumpable {
                            + ": has not been marked for removal"));
                            + ": has not been marked for removal"));
        }
        }


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


    private void cancelLocalDismissal(NotificationEntry entry) {
    private void cancelLocalDismissal(NotificationEntry entry) {
        if (isDismissedByUser(entry)) {
        if (entry.getDismissState() != NOT_DISMISSED) {
            entry.setDismissState(NOT_DISMISSED);
            entry.setDismissState(NOT_DISMISSED);
            if (entry.getSbn().getNotification().isGroupSummary()) {
            if (entry.getSbn().getNotification().isGroupSummary()) {
                for (NotificationEntry otherEntry : mNotificationSet.values()) {
                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
     * immediately removed from the collection, but can sometimes stick around due to lifetime
     * extenders.
     * extenders.
     */
     */
    private static boolean isCanceled(NotificationEntry entry) {
    private boolean isCanceled(NotificationEntry entry) {
        return entry.mCancellationReason != REASON_NOT_CANCELED;
        return entry.mCancellationReason != REASON_NOT_CANCELED;
    }
    }


    private static boolean isDismissedByUser(NotificationEntry entry) {
    private boolean cannotBeLifetimeExtended(NotificationEntry entry) {
        return entry.getDismissState() != NOT_DISMISSED;
        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 Original line 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.NotificationEntryManager;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.NotificationEntry;
import com.android.systemui.statusbar.notification.collection.notifcollection.DismissedByUserStats;
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.logging.NotificationLogger;
import com.android.systemui.statusbar.notification.row.OnUserInteractionCallback;
import com.android.systemui.statusbar.notification.row.OnUserInteractionCallback;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import com.android.systemui.statusbar.policy.HeadsUpManager;
@@ -38,17 +39,20 @@ public class OnUserInteractionCallbackImplLegacy implements OnUserInteractionCal
    private final HeadsUpManager mHeadsUpManager;
    private final HeadsUpManager mHeadsUpManager;
    private final StatusBarStateController mStatusBarStateController;
    private final StatusBarStateController mStatusBarStateController;
    private final VisualStabilityManager mVisualStabilityManager;
    private final VisualStabilityManager mVisualStabilityManager;
    private final GroupMembershipManager mGroupMembershipManager;


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


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


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

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

    }
    }


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


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


    /** */
    /** */
+0 −15
Original line number Original line Diff line number Diff line
@@ -817,13 +817,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        return mNotificationParent != null;
        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() {
    public ExpandableNotificationRow getNotificationParent() {
        return mNotificationParent;
        return mNotificationParent;
    }
    }
@@ -1425,14 +1418,6 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    }
    }


    public void performDismiss(boolean fromAccessibility) {
    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);
        dismiss(fromAccessibility);
        if (mEntry.isClearable()) {
        if (mEntry.isClearable()) {
            if (mOnUserInteractionCallback != null) {
            if (mOnUserInteractionCallback != null) {
+10 −4
Original line number Original line 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.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.statusbar.notification.NotificationEntryManager;
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.dagger.NotificationsModule;
import com.android.systemui.statusbar.notification.logging.NotificationCounters;
import com.android.systemui.statusbar.notification.logging.NotificationCounters;


@@ -48,6 +50,7 @@ public class NotificationBlockingHelperManager {
    private final NotificationGutsManager mNotificationGutsManager;
    private final NotificationGutsManager mNotificationGutsManager;
    private final NotificationEntryManager mNotificationEntryManager;
    private final NotificationEntryManager mNotificationEntryManager;
    private final MetricsLogger mMetricsLogger;
    private final MetricsLogger mMetricsLogger;
    private final GroupMembershipManager mGroupMembershipManager;
    /** Row that the blocking helper will be shown in (via {@link NotificationGuts}. */
    /** Row that the blocking helper will be shown in (via {@link NotificationGuts}. */
    private ExpandableNotificationRow mBlockingHelperRow;
    private ExpandableNotificationRow mBlockingHelperRow;
    private Set<String> mNonBlockablePkgs;
    private Set<String> mNonBlockablePkgs;
@@ -65,7 +68,8 @@ public class NotificationBlockingHelperManager {
            Context context,
            Context context,
            NotificationGutsManager notificationGutsManager,
            NotificationGutsManager notificationGutsManager,
            NotificationEntryManager notificationEntryManager,
            NotificationEntryManager notificationEntryManager,
            MetricsLogger metricsLogger) {
            MetricsLogger metricsLogger,
            GroupMembershipManager groupMembershipManager) {
        mContext = context;
        mContext = context;
        mNotificationGutsManager = notificationGutsManager;
        mNotificationGutsManager = notificationGutsManager;
        mNotificationEntryManager = notificationEntryManager;
        mNotificationEntryManager = notificationEntryManager;
@@ -73,6 +77,7 @@ public class NotificationBlockingHelperManager {
        mNonBlockablePkgs = new HashSet<>();
        mNonBlockablePkgs = new HashSet<>();
        Collections.addAll(mNonBlockablePkgs, mContext.getResources().getStringArray(
        Collections.addAll(mNonBlockablePkgs, mContext.getResources().getStringArray(
                com.android.internal.R.array.config_nonBlockableNotificationPackages));
                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 row is blockable (i.e. not non-blockable)
        // - The dismissed row is a valid group (>1 or 0 children from the same channel)
        // - The dismissed row is a valid group (>1 or 0 children from the same channel)
        // or the only child in the group
        // 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
                && mIsShadeExpanded
                && !row.getIsNonblockable()
                && !row.getIsNonblockable()
                && ((!row.isChildInGroup() || row.isOnlyChildInGroup())
                && ((!row.isChildInGroup() || mGroupMembershipManager.isOnlyChildInGroup(entry))
                    && row.getNumUniqueChannels() <= 1)) {
                    && row.getNumUniqueChannels() <= 1)) {
            // Dismiss any current blocking helper before continuing forward (only one can be shown
            // Dismiss any current blocking helper before continuing forward (only one can be shown
            // at a given time).
            // at a given time).
Loading