From 9f5a089d5ce4e91d1fcce741d4e9c3186bd3ac4f Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 21 Apr 2017 15:13:08 +0200 Subject: [PATCH] reworked unique id generation for notification intents --- .../services/NotificationService.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 2256f528b..ee0d23e63 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -53,9 +53,11 @@ public class NotificationService { private final LinkedHashMap> notifications = new LinkedHashMap<>(); - public static final int NOTIFICATION_ID = 0x2342; - public static final int FOREGROUND_NOTIFICATION_ID = 0x8899; - public static final int ERROR_NOTIFICATION_ID = 0x5678; + private static final int NOTIFICATION_ID_MULTIPLIER = 1024 * 1024; + + public static final int NOTIFICATION_ID = 2 * NOTIFICATION_ID_MULTIPLIER; + public static final int FOREGROUND_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 4; + public static final int ERROR_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 6; private Conversation mOpenConversation; private boolean mIsInForeground; @@ -524,12 +526,12 @@ public class NotificationService { if (downloadMessageUuid != null) { viewConversationIntent.putExtra(ConversationActivity.EXTRA_DOWNLOAD_UUID, downloadMessageUuid); return PendingIntent.getActivity(mXmppConnectionService, - conversationUuid.hashCode() % 389782, + (conversationUuid.hashCode() % NOTIFICATION_ID_MULTIPLIER) + 8 * NOTIFICATION_ID_MULTIPLIER, viewConversationIntent, PendingIntent.FLAG_UPDATE_CURRENT); } else { return PendingIntent.getActivity(mXmppConnectionService, - conversationUuid.hashCode() % 936236, + (conversationUuid.hashCode() % NOTIFICATION_ID_MULTIPLIER) + 10 * NOTIFICATION_ID_MULTIPLIER, viewConversationIntent, PendingIntent.FLAG_UPDATE_CURRENT); } @@ -548,7 +550,7 @@ public class NotificationService { intent.setAction(XmppConnectionService.ACTION_CLEAR_NOTIFICATION); if (conversation != null) { intent.putExtra("uuid", conversation.getUuid()); - return PendingIntent.getService(mXmppConnectionService, conversation.getUuid().hashCode() % 247527, intent, 0); + return PendingIntent.getService(mXmppConnectionService, (conversation.getUuid().hashCode() % NOTIFICATION_ID_MULTIPLIER) + 12 * NOTIFICATION_ID_MULTIPLIER, intent, 0); } return PendingIntent.getService(mXmppConnectionService, 0, intent, 0); } @@ -558,7 +560,7 @@ public class NotificationService { intent.setAction(XmppConnectionService.ACTION_REPLY_TO_CONVERSATION); intent.putExtra("uuid",conversation.getUuid()); intent.putExtra("dismiss_notification",dismissAfterReply); - int id = conversation.getUuid().hashCode() % (dismissAfterReply ? 402359 : 426583); + int id = (conversation.getUuid().hashCode() % NOTIFICATION_ID_MULTIPLIER) + (dismissAfterReply ? 12 : 14) * NOTIFICATION_ID_MULTIPLIER; return PendingIntent.getService(mXmppConnectionService, id, intent, 0); } @@ -567,7 +569,7 @@ public class NotificationService { intent.setAction(XmppConnectionService.ACTION_MARK_AS_READ); intent.putExtra("uuid", conversation.getUuid()); intent.setPackage(mXmppConnectionService.getPackageName()); - return PendingIntent.getService(mXmppConnectionService, conversation.getUuid().hashCode() % 247527, intent, PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getService(mXmppConnectionService, (conversation.getUuid().hashCode() % NOTIFICATION_ID_MULTIPLIER) + 16 * NOTIFICATION_ID_MULTIPLIER, intent, PendingIntent.FLAG_UPDATE_CURRENT); } private PendingIntent createDisableForeground() {