From 7f44b029fe14024be451e9698e32edcda7c94df3 Mon Sep 17 00:00:00 2001 From: Andy Irving Date: Tue, 3 Dec 2013 21:48:16 +0000 Subject: [PATCH 1/2] use PendingIntent.FLAG_UPDATE_CURRENT in calls to PendingIntent.getActivity() to avoid re-using the same extra data on every intent. --- .../thoughtcrime/securesms/notifications/NotificationItem.java | 2 +- .../thoughtcrime/securesms/notifications/NotificationState.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationItem.java b/src/org/thoughtcrime/securesms/notifications/NotificationItem.java index 7f2ea8a652..3b64f4e0db 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationItem.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationItem.java @@ -77,7 +77,7 @@ public class NotificationItem { intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); - return PendingIntent.getActivity(context, 0, intent, 0); + return PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } } diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationState.java b/src/org/thoughtcrime/securesms/notifications/NotificationState.java index 0b4c9ecfc5..36db7a9f38 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationState.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationState.java @@ -62,6 +62,6 @@ public class NotificationState { Log.w("NotificationState", "Pending array off intent length: " + intent.getLongArrayExtra("thread_ids").length); - return PendingIntent.getBroadcast(context, 0, intent, 0); + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } } From 91b52bed18e4b661eda5659ffa0b16bcaf84329a Mon Sep 17 00:00:00 2001 From: Andy Irving Date: Sat, 14 Dec 2013 16:55:24 +0000 Subject: [PATCH 2/2] Don't stick thread IDs in the Intent extra data. Always mark all threads read from notification. --- .../notifications/MarkReadReceiver.java | 10 ++-------- .../notifications/NotificationItem.java | 1 - .../notifications/NotificationState.java | 16 ---------------- 3 files changed, 2 insertions(+), 25 deletions(-) diff --git a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java index 4338a7a42c..a0637b9284 100644 --- a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java @@ -5,7 +5,6 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.os.AsyncTask; -import android.util.Log; import org.thoughtcrime.securesms.crypto.MasterSecret; import org.thoughtcrime.securesms.database.DatabaseFactory; @@ -19,11 +18,9 @@ public class MarkReadReceiver extends BroadcastReceiver { if (!intent.getAction().equals(CLEAR_ACTION)) return; - final long[] threadIds = intent.getLongArrayExtra("thread_ids"); final MasterSecret masterSecret = intent.getParcelableExtra("master_secret"); - if (threadIds != null && masterSecret != null) { - Log.w("MarkReadReceiver", "threadIds length: " + threadIds.length); + if (masterSecret != null) { ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)) .cancel(MessageNotifier.NOTIFICATION_ID); @@ -31,10 +28,7 @@ public class MarkReadReceiver extends BroadcastReceiver { new AsyncTask() { @Override protected Void doInBackground(Void... params) { - for (long threadId : threadIds) { - Log.w("MarkReadReceiver", "Marking as read: " + threadId); - DatabaseFactory.getThreadDatabase(context).setRead(threadId); - } + DatabaseFactory.getThreadDatabase(context).setAllThreadsRead(); MessageNotifier.updateNotification(context, masterSecret); return null; diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationItem.java b/src/org/thoughtcrime/securesms/notifications/NotificationItem.java index 3b64f4e0db..fc52ac1b76 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationItem.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationItem.java @@ -72,7 +72,6 @@ public class NotificationItem { if (recipients != null) { intent.putExtra("recipients", recipients); - intent.putExtra("thread_id", threadId); } intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationState.java b/src/org/thoughtcrime/securesms/notifications/NotificationState.java index 36db7a9f38..966894f188 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationState.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationState.java @@ -4,7 +4,6 @@ import android.app.PendingIntent; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; -import android.util.Log; import org.thoughtcrime.securesms.crypto.MasterSecret; @@ -43,25 +42,10 @@ public class NotificationState { } public PendingIntent getMarkAsReadIntent(Context context, MasterSecret masterSecret) { - long[] threadArray = new long[threads.size()]; - int index = 0; - - for (long thread : threads) { - Log.w("NotificationState", "Added thread: " + thread); - threadArray[index++] = thread; - } - Intent intent = new Intent(MarkReadReceiver.CLEAR_ACTION); - intent.putExtra("thread_ids", threadArray); intent.putExtra("master_secret", masterSecret); intent.setPackage(context.getPackageName()); - // XXX : This is an Android bug. If we don't pull off the extra - // once before handing off the PendingIntent, the array will be - // truncated to one element when the PendingIntent fires. Thanks guys! - Log.w("NotificationState", "Pending array off intent length: " + - intent.getLongArrayExtra("thread_ids").length); - return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } }