From dd6e6b850462fd8617a73dd40b5e7d32f0aaf5ed Mon Sep 17 00:00:00 2001 From: Makoto Onuki Date: Tue, 8 Mar 2011 16:36:47 -0800 Subject: [PATCH] Fix bug 3509555 make notification always open right account The problem was that: - Each account now has own new message notification - But PendingIntens for these all point to the same activity, only with different long extras (for acount IDs). - Framework merges these intents, because extras don't count as a "difference" in this case. - So when multiple new message notifications are shown, they'll all share the same intent internally, so they'll all open the same account. A quick workaround seems to be to set a unique URI to each intents. Bug 3509555 Change-Id: Ib02842bb32634cfdf01ae2d684dd04dfede23832 --- .../android/email/NotificationController.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/com/android/email/NotificationController.java b/src/com/android/email/NotificationController.java index ea6c061fd..b5d5f495e 100644 --- a/src/com/android/email/NotificationController.java +++ b/src/com/android/email/NotificationController.java @@ -39,6 +39,8 @@ import android.text.SpannableString; import android.text.TextUtils; import android.text.style.TextAppearanceSpan; +import java.util.concurrent.atomic.AtomicInteger; + /** * Class that manages notifications. * @@ -97,6 +99,7 @@ public class NotificationController { // Pending Intent PendingIntent pending = null; if (intent != null) { + intent = rewriteForPendingIntent(intent); pending = PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } @@ -198,6 +201,28 @@ public class NotificationController { return ContactStatusLoader.load(mContext, email).mPhoto; } + private static final AtomicInteger sSequenceNumber = new AtomicInteger(); + + /** + * Rewrite an intent so that it'll always look unique to {@link PendingIntent}. + * + * TODO This should be removed. Instead, use URIs which is unique to each account to open + * activities. + */ + private static Intent rewriteForPendingIntent(Intent original) { + if (original.getComponent() == null) { + return original; // Doesn't have a component set -- can't set a URI. + } + Uri.Builder builder = new Uri.Builder(); + builder.scheme("content"); + builder.authority("email-dummy"); + builder.appendEncodedPath(Integer.toString(sSequenceNumber.incrementAndGet())); + + // If a componentName is set, the data part won't be used to resolve an intent. + original.setData(builder.build()); + return original; + } + /** * Create a notification * @@ -221,8 +246,8 @@ public class NotificationController { // Intent to open inbox PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, - Welcome.createOpenAccountInboxIntent(mContext, accountId), - PendingIntent.FLAG_UPDATE_CURRENT); + rewriteForPendingIntent(Welcome.createOpenAccountInboxIntent(mContext, accountId)), + 0); Notification.Builder builder = new Notification.Builder(mContext) .setSmallIcon(R.drawable.stat_notify_email_generic)