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

Commit aaa58d1c authored by Chris Wren's avatar Chris Wren
Browse files

Handle Zen Mode computations correctly for updated notifications.

Updates to intercepted notifications come in through addNotificatiom
instead of updateNotification, because the intercepted notifications
are not in mNotificationData.

If an update causes a notification to surface, we need to notice and
remove it from the synthetic notification.  However, addNotification
is called from within InterceptedNotifications inside loops over
mIntercepted, and we cannot remove items from mIntercepted while
looping, so we split addNotification into two parts, one part is only
used by InterceptedNotifications to unconditionally surface previously
intercepted notifications.

Bug: 15389069
Change-Id: I7b0952a337f15d4009e3e61360344012345eac95
parent c936ea39
Loading
Loading
Loading
Loading
+7 −12
Original line number Diff line number Diff line
@@ -52,7 +52,7 @@ public class InterceptedNotifications {
        for (int i = 0; i < n; i++) {
            final StatusBarNotification sbn = mIntercepted.valueAt(i);
            mReleased.add(sbn.getKey());
            mBar.addNotificationInternal(sbn, null);
            mBar.displayNotification(sbn, null);
        }
        mIntercepted.clear();
        updateSyntheticNotification();
@@ -71,16 +71,17 @@ public class InterceptedNotifications {
    public void retryIntercepts(Ranking ranking) {
        if (ranking == null) return;

        boolean changed = false;
        final int N = mIntercepted.size();
        final ArraySet<String> removed = new ArraySet<String>(N);
        for (int i = 0; i < N; i++) {
            final StatusBarNotification sbn = mIntercepted.valueAt(i);
            if (!tryIntercept(sbn, ranking)) {
                changed = true;
                mBar.addNotificationInternal(sbn, ranking);
                removed.add(sbn.getKey());
                mBar.displayNotification(sbn, ranking);
            }
        }
        if (changed) {
        if (!removed.isEmpty()) {
            mIntercepted.removeAll(removed);
            updateSyntheticNotification();
        }
    }
@@ -96,12 +97,6 @@ public class InterceptedNotifications {
        return ent.key.equals(mSynKey);
    }

    public void update(StatusBarNotification notification) {
        if (mIntercepted.containsKey(notification.getKey())) {
            mIntercepted.put(notification.getKey(), notification);
        }
    }

    private boolean shouldDisplayIntercepted() {
        return Settings.Secure.getInt(mContext.getContentResolver(),
                Settings.Secure.DISPLAY_INTERCEPTED_NOTIFICATIONS, 0) != 0;
@@ -129,7 +124,7 @@ public class InterceptedNotifications {
                mBar.getCurrentUserHandle());
        if (mSynKey == null) {
            mSynKey = sbn.getKey();
            mBar.addNotificationInternal(sbn, null);
            mBar.displayNotification(sbn, null);
        } else {
           mBar.updateNotificationInternal(sbn, null);
        }
+13 −6
Original line number Diff line number Diff line
@@ -1059,16 +1059,22 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,

    @Override
    public void addNotificationInternal(StatusBarNotification notification, Ranking ranking) {
        if (DEBUG) Log.d(TAG, "addNotification score=" + notification.getScore());
        Entry shadeEntry = createNotificationViews(notification);
        if (shadeEntry == null) {
            return;
        }
        if (DEBUG) Log.d(TAG, "addNotification key=" + notification.getKey());
        if (mZenMode != Global.ZEN_MODE_OFF && mIntercepted.tryIntercept(notification, ranking)) {
            // Forward the ranking so we can sort the new notification.
            mNotificationData.updateRanking(ranking);
            return;
        }
        mIntercepted.remove(notification.getKey());
        displayNotification(notification, ranking);
    }

    public void displayNotification(StatusBarNotification notification,
            Ranking ranking) {
        Entry shadeEntry = createNotificationViews(notification);
        if (shadeEntry == null) {
            return;
        }
        if (mUseHeadsUp && shouldInterrupt(notification)) {
            if (DEBUG) Log.d(TAG, "launching notification in heads up mode");
            Entry interruptionCandidate = new Entry(notification, null);
@@ -1124,7 +1130,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
    @Override
    public void updateNotificationInternal(StatusBarNotification notification, Ranking ranking) {
        super.updateNotificationInternal(notification, ranking);
        mIntercepted.update(notification);
        // if we're here, then the notification is already in the shade
        mIntercepted.remove(notification.getKey());
    }

    @Override