From f484751e060620ddf4e2dfe38f2b9f46f472ac9d Mon Sep 17 00:00:00 2001 From: Martin Hibdon Date: Mon, 30 Sep 2013 15:06:33 -0700 Subject: [PATCH] Make draft attachments work correctly b/10968838 The main problem here is that Ui Attachment was always using a content Uri that was generated using the attachment's account Id and rowId. This works correctly for attachments in messages we have received, but it does not work for drafts: Draft attachments are not stored in the normal place, rather, they are stored in the cache directory. There is an additional column in the Attachment table, called cachedFile, which is not replicated in the Ui attachment. That's okay though, if we have a cachedFile, then when we are populating a Ui Attachment, we should just use that for content Uri. Also, I discoverd that for draft attachments, we were not correctly setting the account key. That didn't turn out to be the problem, but I'm fixing it anyway because it will cause problems later on. Change-Id: I0143ba824f3a5bfcd77f32828931b94d6977626f --- src/com/android/email/provider/EmailProvider.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/com/android/email/provider/EmailProvider.java b/src/com/android/email/provider/EmailProvider.java index 93d4f476b..147504828 100644 --- a/src/com/android/email/provider/EmailProvider.java +++ b/src/com/android/email/provider/EmailProvider.java @@ -3695,6 +3695,9 @@ public class EmailProvider extends ContentProvider { final long id = Long.parseLong(uri.getLastPathSegment()); final Attachment att = Attachment.restoreAttachmentWithId(mContext, id); if (att == null) return ""; + if (!TextUtils.isEmpty(att.getCachedFileUri())) { + return att.getCachedFileUri(); + } final String contentUri; // Until the package installer can handle opening apks from a content:// uri, for @@ -3709,6 +3712,7 @@ public class EmailProvider extends ContentProvider { AttachmentUtilities.getAttachmentUri(att.mAccountKey, id).toString(); } return contentUri; + } else { return super.getString(column); } @@ -4008,9 +4012,12 @@ public class EmailProvider extends ContentProvider { */ // TODO(pwestbro): once the Attachment contains the cached uri, the second parameter can be // removed + // TODO(mhibdon): if the UI Attachment containded the account key, the third parameter could + // be removed. private static Attachment convertUiAttachmentToAttachment( - com.android.mail.providers.Attachment uiAtt, String cachedFile) { + com.android.mail.providers.Attachment uiAtt, String cachedFile, long accountKey) { final Attachment att = new Attachment(); + att.setContentUri(uiAtt.contentUri.toString()); if (!TextUtils.isEmpty(cachedFile)) { @@ -4020,7 +4027,7 @@ public class EmailProvider extends ContentProvider { cachedFileBuilder.appendQueryParameter(Attachment.CACHED_FILE_QUERY_PARAM, cachedFile); att.setCachedFileUri(cachedFileBuilder.build().toString()); } - + att.mAccountKey = accountKey; att.mFileName = uiAtt.getName(); att.mMimeType = uiAtt.getContentType(); att.mSize = uiAtt.size; @@ -4168,12 +4175,12 @@ public class EmailProvider extends ContentProvider { } } else { // Cache the attachment. This will allow us to send it, if the permissions are - // revoked + // revoked. final String cachedFileUri = AttachmentUtils.cacheAttachmentUri(context, uiAtt, attachmentFds); // Convert external attachment to one of ours and add to the list - atts.add(convertUiAttachmentToAttachment(uiAtt, cachedFileUri)); + atts.add(convertUiAttachmentToAttachment(uiAtt, cachedFileUri, msg.mAccountKey)); } } if (!atts.isEmpty()) {