Skip to content

Commit 4cb7305

Browse files
authored
Merge pull request #1711 from OneSignal/fix/individually_clear_notifications
Fix individually clearing notifications
2 parents d8125db + 7c199a6 commit 4cb7305

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

OneSignalSDK/onesignal/src/main/java/com/onesignal/NotificationSummaryManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ private static Cursor internalUpdateSummaryNotificationAfterChildRemoved(Context
6565
// If all individual notifications consumed
6666
// - Remove summary notification from the shade.
6767
// - Mark summary notification as consumed.
68-
if (notificationsInGroup == 0) {
68+
if (notificationsInGroup == 0 && !group.equals(OneSignalNotificationManager.getGrouplessSummaryKey())) {
6969
cursor.close();
7070

7171
Integer androidNotifId = getSummaryNotificationId(db, group);

OneSignalSDK/unittest/src/test/java/com/test/onesignal/GenerateNotificationRunner.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@
7474
import android.net.Uri;
7575
import android.os.Build;
7676
import android.os.Bundle;
77-
import android.os.SystemClock;
7877
import android.util.Log;
7978

8079
import androidx.annotation.NonNull;
@@ -450,6 +449,34 @@ public void testGrouplessSummaryNotificationIsDismissedOnClear() throws Exceptio
450449
assertEquals(0, postedNotifs.size());
451450
}
452451

452+
@Test
453+
@Config(sdk = Build.VERSION_CODES.N, shadows = { ShadowGenerateNotification.class })
454+
public void testIndividualGrouplessSummaryNotificationDismissal() throws Exception {
455+
OneSignal.setAppId("b2f7f966-d8cc-11e4-bed1-df8f05be55ba");
456+
OneSignal.initWithContext(blankActivity.getApplicationContext());
457+
threadAndTaskWait();
458+
459+
// Add 4 groupless notifications
460+
postNotificationWithOptionalGroup(4, null);
461+
threadAndTaskWait();
462+
463+
// Obtain the posted notifications
464+
Map<Integer, PostedNotification> postedNotifs = ShadowRoboNotificationManager.notifications;
465+
Iterator<Map.Entry<Integer, PostedNotification>> iterator = postedNotifs.entrySet().iterator();
466+
Map.Entry<Integer, PostedNotification> entry = iterator.next();
467+
Map.Entry<Integer, PostedNotification> entry2 = iterator.next();
468+
Map.Entry<Integer, PostedNotification> entry3 = iterator.next();
469+
Map.Entry<Integer, PostedNotification> entry4 = iterator.next();
470+
Integer id4 = entry4.getKey();
471+
assertNotNull(id4);
472+
473+
assertEquals(5, postedNotifs.size());
474+
// Clear a OneSignal Notification
475+
OneSignal.removeNotification(id4);
476+
threadAndTaskWait();
477+
assertEquals(4, postedNotifs.size());
478+
}
479+
453480
@Test
454481
@Config(sdk = Build.VERSION_CODES.LOLLIPOP, shadows = { ShadowGenerateNotification.class })
455482
public void testNotifDismissAllOnGroupSummaryClickForAndroidUnderM() throws Exception {

0 commit comments

Comments
 (0)