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

Commit 948c590c authored by Sara Ting's avatar Sara Ting
Browse files

Removed use of notification framework's cancelAll so we don't affect SyncAdapter's alerts.

Bug:7076340
Change-Id: If4e864099850389cda6e0e5786560102bab9aed6
parent fa1149d1
Loading
Loading
Loading
Loading
+2 −19
Original line number Diff line number Diff line
@@ -144,7 +144,7 @@ public class AlertService extends Service {
    }

    // Added wrapper for testing
    public static class NotificationMgrWrapper implements NotificationMgr {
    public static class NotificationMgrWrapper extends NotificationMgr {
        NotificationManager mNm;

        public NotificationMgrWrapper(NotificationManager nm) {
@@ -156,25 +156,10 @@ public class AlertService extends Service {
            mNm.cancel(id);
        }

        @Override
        public void cancel(String tag, int id) {
            mNm.cancel(tag, id);
        }

        @Override
        public void cancelAll() {
            mNm.cancelAll();
        }

        @Override
        public void notify(int id, NotificationWrapper nw) {
            mNm.notify(id, nw.mNotification);
        }

        @Override
        public void notify(String tag, int id, NotificationWrapper nw) {
            mNm.notify(tag, id, nw.mNotification);
        }
    }

    void processMessage(Message msg) {
@@ -354,9 +339,7 @@ public class AlertService extends Service {

        // Remove the notifications that are hanging around from the previous refresh.
        if (currentNotificationId <= maxNotifications) {
            for (int i = currentNotificationId; i <= maxNotifications; i++) {
                nm.cancel(i);
            }
            nm.cancelAllBetween(currentNotificationId, maxNotifications);
            if (DEBUG) {
                Log.d(TAG, "Canceling leftover notification IDs " + currentNotificationId + "-"
                        + maxNotifications);
+20 −6
Original line number Diff line number Diff line
@@ -2,10 +2,24 @@ package com.android.calendar.alerts;

import com.android.calendar.alerts.AlertService.NotificationWrapper;

public interface NotificationMgr {
    public void cancel(int id);
    public void cancel(String tag, int id);
    public void cancelAll();
    public void notify(int id, NotificationWrapper notification);
    public void notify(String tag, int id, NotificationWrapper notification);
public abstract class NotificationMgr {
    public abstract void notify(int id, NotificationWrapper notification);
    public abstract void cancel(int id);

    /**
     * Don't actually use the notification framework's cancelAll since the SyncAdapter
     * might post notifications and we don't want to affect those.
     */
    public void cancelAll() {
        cancelAllBetween(0, AlertService.MAX_NOTIFICATIONS);
    }

    /**
     * Cancels IDs between the specified bounds, inclusively.
     */
    public void cancelAllBetween(int from, int to) {
        for (int i = from; i <= to; i++) {
            cancel(i);
        }
    }
}
+1 −27
Original line number Diff line number Diff line
@@ -252,7 +252,7 @@ public class AlertServiceTest extends AndroidTestCase {

    }

    class NotificationTestManager implements NotificationMgr {
    class NotificationTestManager extends NotificationMgr {
        // Expected notifications
        NotificationInstance[] mNotifications;

@@ -324,27 +324,6 @@ public class AlertServiceTest extends AndroidTestCase {
            assertNull("Unexpected cancel for id " + id, mNotifications[id]);
        }

        @Override
        public void cancel(String tag, int id) {
            throw new IllegalArgumentException();
        }

        @Override
        public void cancelAll() {
            for (int i = 0; i < mNotifications.length; i++) {
                assertNull("Expecting notification id " + i + ". Got cancelAll", mNotifications[i]);

                if (mDone != null) {
                    assertFalse("Notification id " + i + " is done but got cancelAll", mDone[i]);
                }
            }

            assertNull(mDone); // this should have been null since nothing
                               // should have been posted
            mDone = new boolean[mNotifications.length];
            Arrays.fill(mDone, true);
        }

        @Override
        public void notify(int id, NotificationWrapper nw) {
            if (mDone == null) {
@@ -359,11 +338,6 @@ public class AlertServiceTest extends AndroidTestCase {

            verifyNotification(id, nw);
        }

        @Override
        public void notify(String tag, int id, NotificationWrapper nw) {
            throw new IllegalArgumentException();
        }
    }

    // TODO