On removing notification, mark it's ID no longer in use (#1677)
On removing notification, mark it's ID no longer in use Fixes #1662
This commit is contained in:
parent
c7b5a50636
commit
302b668d58
2 changed files with 18 additions and 3 deletions
|
@ -85,6 +85,10 @@ class NotificationData {
|
|||
notificationIdsInUse.put(notificationId, true);
|
||||
}
|
||||
|
||||
private void markNotificationIdAsFree(int notificationId) {
|
||||
notificationIdsInUse.delete(notificationId);
|
||||
}
|
||||
|
||||
NotificationHolder createNotificationHolder(int notificationId, NotificationContent content) {
|
||||
return new NotificationHolder(notificationId, content);
|
||||
}
|
||||
|
@ -165,6 +169,8 @@ class NotificationData {
|
|||
activeNotifications.remove(holder);
|
||||
|
||||
int notificationId = holder.notificationId;
|
||||
markNotificationIdAsFree(notificationId);
|
||||
|
||||
if (!additionalNotifications.isEmpty()) {
|
||||
NotificationContent newContent = additionalNotifications.removeFirst();
|
||||
NotificationHolder replacement = createNotificationHolder(notificationId, newContent);
|
||||
|
|
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||
|
||||
import com.fsck.k9.Account;
|
||||
import com.fsck.k9.activity.MessageReference;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -52,8 +53,7 @@ public class NotificationDataTest {
|
|||
|
||||
@Test
|
||||
public void testAddNotificationContentWithReplacingNotification() throws Exception {
|
||||
NotificationContent content = createNotificationContent("1");
|
||||
notificationData.addNotificationContent(content);
|
||||
notificationData.addNotificationContent(createNotificationContent("1"));
|
||||
notificationData.addNotificationContent(createNotificationContent("2"));
|
||||
notificationData.addNotificationContent(createNotificationContent("3"));
|
||||
notificationData.addNotificationContent(createNotificationContent("4"));
|
||||
|
@ -107,6 +107,15 @@ public class NotificationDataTest {
|
|||
assertEquals(content, holder.content);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveDoesNotLeakNotificationIds() {
|
||||
for (int i = 1; i <= NotificationData.MAX_NUMBER_OF_STACKED_NOTIFICATIONS + 1; i++) {
|
||||
NotificationContent content = createNotificationContent("" + i);
|
||||
notificationData.addNotificationContent(content);
|
||||
notificationData.removeNotificationForMessage(content.messageReference);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewMessagesCount() throws Exception {
|
||||
assertEquals(0, notificationData.getNewMessagesCount());
|
||||
|
@ -267,7 +276,7 @@ public class NotificationDataTest {
|
|||
private MessageReference createMessageReference(String uid) {
|
||||
return new MessageReference(ACCOUNT_UUID, FOLDER_NAME, uid, null);
|
||||
}
|
||||
|
||||
|
||||
private NotificationContent createNotificationContent(String uid) {
|
||||
MessageReference messageReference = createMessageReference(uid);
|
||||
return createNotificationContent(messageReference);
|
||||
|
|
Loading…
Reference in a new issue