Check for null/invalid attachment Uris in compose intents
b/14834660
Change-Id: I89165173a5a6a73b17e424ff39b8ab61dbe44549
diff --git a/src/com/android/mail/compose/ComposeActivity.java b/src/com/android/mail/compose/ComposeActivity.java
index 41049de..8f0bb19 100644
--- a/src/com/android/mail/compose/ComposeActivity.java
+++ b/src/com/android/mail/compose/ComposeActivity.java
@@ -1706,6 +1706,9 @@
.getParcelableArrayList(Intent.EXTRA_STREAM);
ArrayList<Attachment> attachments = new ArrayList<Attachment>();
for (Parcelable uri : uris) {
+ if (uri == null || !(uri instanceof Uri)) {
+ continue;
+ }
try {
final Attachment a = mAttachmentsView.generateLocalAttachment(
(Uri) uri);
@@ -1725,20 +1728,22 @@
}
totalSize += addAttachments(attachments);
} else {
- final Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
- long size = 0;
- try {
- final Attachment a = mAttachmentsView.generateLocalAttachment(uri);
- size = mAttachmentsView.addAttachment(mAccount, a);
+ final Parcelable uri = extras.getParcelable(Intent.EXTRA_STREAM);
+ if (uri != null && uri instanceof Uri) {
+ long size = 0;
+ try {
+ final Attachment a = mAttachmentsView.generateLocalAttachment((Uri)uri);
+ size = mAttachmentsView.addAttachment(mAccount, a);
- Analytics.getInstance().sendEvent("send_intent_attachment",
- Utils.normalizeMimeType(a.getContentType()), null, size);
+ Analytics.getInstance().sendEvent("send_intent_attachment",
+ Utils.normalizeMimeType(a.getContentType()), null, size);
- } catch (AttachmentFailureException e) {
- LogUtils.e(LOG_TAG, e, "Error adding attachment");
- showAttachmentTooBigToast(e.getErrorRes());
+ } catch (AttachmentFailureException e) {
+ LogUtils.e(LOG_TAG, e, "Error adding attachment");
+ showAttachmentTooBigToast(e.getErrorRes());
+ }
+ totalSize += size;
}
- totalSize += size;
}
}