am dd6e6b85: Fix bug 3509555 make notification always open right account

* commit 'dd6e6b850462fd8617a73dd40b5e7d32f0aaf5ed':
  Fix bug 3509555 make notification always open right account
This commit is contained in:
Makoto Onuki 2011-03-09 16:06:48 -08:00 committed by Android Git Automerger
commit 27372998d6

View File

@ -39,6 +39,8 @@ import android.text.SpannableString;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.style.TextAppearanceSpan; import android.text.style.TextAppearanceSpan;
import java.util.concurrent.atomic.AtomicInteger;
/** /**
* Class that manages notifications. * Class that manages notifications.
* *
@ -97,6 +99,7 @@ public class NotificationController {
// Pending Intent // Pending Intent
PendingIntent pending = null; PendingIntent pending = null;
if (intent != null) { if (intent != null) {
intent = rewriteForPendingIntent(intent);
pending = pending =
PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent.getActivity(mContext, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
} }
@ -198,6 +201,28 @@ public class NotificationController {
return ContactStatusLoader.load(mContext, email).mPhoto; 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 * Create a notification
* *
@ -221,8 +246,8 @@ public class NotificationController {
// Intent to open inbox // Intent to open inbox
PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0, PendingIntent contentIntent = PendingIntent.getActivity(mContext, 0,
Welcome.createOpenAccountInboxIntent(mContext, accountId), rewriteForPendingIntent(Welcome.createOpenAccountInboxIntent(mContext, accountId)),
PendingIntent.FLAG_UPDATE_CURRENT); 0);
Notification.Builder builder = new Notification.Builder(mContext) Notification.Builder builder = new Notification.Builder(mContext)
.setSmallIcon(R.drawable.stat_notify_email_generic) .setSmallIcon(R.drawable.stat_notify_email_generic)