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

Commit f5ce2124 authored by Mady Mellor's avatar Mady Mellor Committed by Android (Google) Code Review
Browse files

Merge "Visually suppress summaries & keep track of them so they may be removed...

Merge "Visually suppress summaries & keep track of them so they may be removed when needed" into qt-r1-bubbles-dev
parents 5395ba09 e28fe10f
Loading
Loading
Loading
Loading
+42 −6
Original line number Diff line number Diff line
@@ -424,14 +424,21 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
    }

    /**
     * Whether (1) there is a bubble associated with the provided key and
     *         (2) if the notification for that bubble is hidden from the shade.
     * True if either:
     * (1) There is a bubble associated with the provided key and if its notification is hidden
     *     from the shade.
     * (2) There is a group summary associated with the provided key that is hidden from the shade
     *     because it has been dismissed but still has child bubbles active.
     *
     * False if there isn't a bubble or if the notification for that bubble appears in the shade.
     * False otherwise.
     */
    public boolean isBubbleNotificationSuppressedFromShade(String key) {
        return mBubbleData.hasBubbleWithKey(key)
        boolean isBubbleAndSuppressed = mBubbleData.hasBubbleWithKey(key)
                && !mBubbleData.getBubbleWithKey(key).showInShadeWhenBubble();
        NotificationEntry entry = mNotificationEntryManager.getNotificationData().get(key);
        String groupKey = entry != null ? entry.notification.getGroupKey() : null;
        boolean isSuppressedSummary = mBubbleData.isSummarySuppressed(groupKey);
        return isSuppressedSummary || isBubbleAndSuppressed;
    }

    void selectBubble(Bubble bubble) {
@@ -515,10 +522,12 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                ArrayList<Bubble> bubbleChildren = mBubbleData.getBubblesInGroup(groupKey);

                boolean inBubbleData = mBubbleData.hasBubbleWithKey(key);
                boolean isSuppressedSummary = (mBubbleData.isSummarySuppressed(groupKey)
                        && mBubbleData.getSummaryKey(groupKey).equals(key));
                boolean isSummary = entry != null
                        && entry.notification.getNotification().isGroupSummary();
                boolean isSummaryOfBubbles = isSummary && bubbleChildren != null
                        && !bubbleChildren.isEmpty();
                boolean isSummaryOfBubbles = (isSuppressedSummary || isSummary)
                        && bubbleChildren != null && !bubbleChildren.isEmpty();

                if (!inBubbleData && !isSummaryOfBubbles) {
                    return false;
@@ -585,8 +594,17 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
            // because apps can't cancel it; so we only intercept & suppress real summaries.
            boolean isAutogroupSummary = (summary.notification.getNotification().flags
                    & FLAG_AUTOGROUP_SUMMARY) != 0;
            if (!isAutogroupSummary) {
                mBubbleData.addSummaryToSuppress(summary.notification.getGroupKey(),
                        summary.key);
                // Tell shade to update for the suppression
                mNotificationEntryManager.updateNotifications();
            }
            return !isAutogroupSummary;
        } else {
            // If it's not a user dismiss it's a cancel.
            mBubbleData.removeSuppressedSummary(groupKey);

            // Remove any associated bubble children.
            for (int i = 0; i < bubbleChildren.size(); i++) {
                Bubble bubbleChild = bubbleChildren.get(i);
@@ -686,6 +704,24 @@ public class BubbleController implements ConfigurationController.ConfigurationLi
                        }
                    }

                    // Check if removed bubble has an associated suppressed group summary that needs
                    // to be removed now.
                    final String groupKey = bubble.getEntry().notification.getGroupKey();
                    if (mBubbleData.isSummarySuppressed(groupKey)
                            && mBubbleData.getBubblesInGroup(groupKey).isEmpty()) {
                        // Time to actually remove the summary.
                        String notifKey = mBubbleData.getSummaryKey(groupKey);
                        mBubbleData.removeSuppressedSummary(groupKey);
                        NotificationEntry entry =
                                mNotificationEntryManager.getNotificationData().get(notifKey);
                        if (entry == null) {
                            Log.w("mady", "WTF summary isn't in data... " + notifKey);
                            return;
                        }
                        mNotificationEntryManager.performRemoveNotification(
                                entry.notification, UNDEFINED_DISMISS_REASON);
                    }

                    // Check if summary should be removed from NoManGroup
                    NotificationEntry summary = mNotificationGroupManager.getLogicalGroupSummary(
                            bubble.getEntry().notification);
+51 −0
Original line number Diff line number Diff line
@@ -126,6 +126,19 @@ public class BubbleData {
    @Nullable
    private Listener mListener;

    /**
     * We track groups with summaries that aren't visibly displayed but still kept around because
     * the bubble(s) associated with the summary still exist.
     *
     * The summary must be kept around so that developers can cancel it (and hence the bubbles
     * associated with it). This list is used to check if the summary should be hidden from the
     * shade.
     *
     * Key: group key of the NotificationEntry
     * Value: key of the NotificationEntry
     */
    private HashMap<String, String> mSuppressedGroupKeys = new HashMap<>();

    @Inject
    public BubbleData(Context context) {
        mContext = context;
@@ -229,6 +242,40 @@ public class BubbleData {
        dispatchPendingChanges();
    }

    /**
     * Adds a group key indicating that the summary for this group should be suppressed.
     *
     * @param groupKey the group key of the group whose summary should be suppressed.
     * @param notifKey the notification entry key of that summary.
     */
    void addSummaryToSuppress(String groupKey, String notifKey) {
        mSuppressedGroupKeys.put(groupKey, notifKey);
    }

    /**
     * Retrieves the notif entry key of the summary associated with the provided group key.
     *
     * @param groupKey the group to look up
     * @return the key for the {@link NotificationEntry} that is the summary of this group.
     */
    String getSummaryKey(String groupKey) {
        return mSuppressedGroupKeys.get(groupKey);
    }

    /**
     * Removes a group key indicating that summary for this group should no longer be suppressed.
     */
    void removeSuppressedSummary(String groupKey) {
        mSuppressedGroupKeys.remove(groupKey);
    }

    /**
     * Whether the summary for the provided group key is suppressed.
     */
    boolean isSummarySuppressed(String groupKey) {
        return mSuppressedGroupKeys.containsKey(groupKey);
    }

    /**
     * Retrieves any bubbles that are part of the notification group represented by the provided
     * group key.
@@ -622,5 +669,9 @@ public class BubbleData {
        for (Bubble bubble : mBubbles) {
            bubble.dump(fd, pw, args);
        }
        pw.print("summaryKeys: "); pw.println(mSuppressedGroupKeys.size());
        for (String key : mSuppressedGroupKeys.keySet()) {
            pw.println("   suppressing: " + key);
        }
    }
}