Merge "Fix NPE in NotificationController" into honeycomb-mr1

This commit is contained in:
Makoto Onuki 2011-03-09 16:03:17 -08:00 committed by Android (Google) Code Review
commit 553037ba4e
2 changed files with 22 additions and 1 deletions

View File

@ -240,7 +240,10 @@ public class NotificationController {
return null; // no message found???
}
final String senderName = Address.toFriendly(Address.unpack(message.mFrom));
String senderName = Address.toFriendly(Address.unpack(message.mFrom));
if (senderName == null) {
senderName = ""; // Happens when a message has no from.
}
final String subject = message.mSubject;
final Bitmap senderPhoto = getSenderPhoto(message);

View File

@ -224,6 +224,24 @@ public class NotificationControllerTest extends AndroidTestCase {
// TODO Add 2 account test, if we find a way to check content
}
public void testCreateNewMessageNotificationWithEmptyFrom() {
final Context c = mProviderContext;
Notification n;
// Message with no from fields.
Account a1 = ProviderTestUtils.setupAccount("a1", true, c);
Mailbox b1 = ProviderTestUtils.setupMailbox("inbox", a1.mId, true, c, Mailbox.TYPE_INBOX);
Message m1 = ProviderTestUtils.setupMessage("message", a1.mId, b1.mId, true, false, c);
m1.mFrom = null;
m1.save(c);
// This shouldn't crash.
n = mTarget.createNewMessageNotification(a1.mId, 1);
// Minimum test for the result
assertEquals(R.drawable.stat_notify_email_generic, n.icon);
}
public void testGetNotificationTitle() {
final Context c = mProviderContext;