Home | History | Annotate | Download | only in service

Lines Matching refs:Attachment

41 import com.android.emailcommon.provider.EmailContent.Attachment;
82 // Try to download an attachment in the background this many times before giving up
132 // A map of attachment storage used per account as we have account based maximums to follow.
138 // A map of attachment ids to the number of failed attempts to download the attachment
144 // Keeps tracks of downloads in progress based on an attachment ID to DownloadRequest mapping.
165 * an attachment. These objects are constructed and either placed in the {@link DownloadQueue}
188 * @param attPriority The priority of this attachment
189 * @param attId The id of the row in the attachment table.
201 private DownloadRequest(final Context context, final Attachment attachment) {
202 mAttachmentId = attachment.mId;
203 final Message msg = Message.restoreMessageWithId(context, attachment.mMessageKey);
210 mPriority = getAttachmentPriority(attachment);
235 * Two download requests are equals if their attachment id's are equals
307 LogUtils.d(LOG_TAG, "Not adding a DownloadRequest with an invalid attachment id");
368 attachment ID)
478 // TODO: Should we also mark the attachment as failed at this point in time?
504 * Simple routine to generate updated status values for the Attachment based on the
508 ContentValues getAttachmentUpdateValues(final Attachment attachment,
511 if (attachment != null) {
518 attachment.mSize * progress / 100);
527 debugTrace(LOG_TAG, "ServiceCallback for attachment #%d", attachmentId);
545 // Update the attachment status in the provider.
546 final Attachment attachment =
547 Attachment.restoreAttachmentWithId(AttachmentService.this, attachmentId);
548 final ContentValues values = getAttachmentUpdateValues(attachment, statusCode,
551 attachment.update(AttachmentService.this, values);
559 // Either way, the final updates to the DownloadRequest and attachment
561 LogUtils.d(LOG_TAG, "Attachment #%d is done", attachmentId);
567 // an attachment that doesn't exist is if it was cancelled due to the
569 // marked this attachment as failed/cancelled.
575 * Called directly by EmailProvider whenever an attachment is inserted or changed. Since this
579 * @param id the attachment's id
580 * @param flags the new flags for the attachment
583 LogUtils.d(LOG_TAG, "Attachment with id: %d will potentially be queued for download", id);
584 // Throw this info into an intent and send it to the attachment service.
593 * The main entry point for this service, the attachment to download can be identified
666 final int mask = Attachment.FLAG_DOWNLOAD_FORWARD | Attachment.FLAG_DOWNLOAD_USER_REQUEST;
667 final Cursor c = getContentResolver().query(Attachment.CONTENT_URI,
674 final Attachment attachment = Attachment.restoreAttachmentWithId(
676 if (attachment != null) {
677 debugTrace("Attempting to download attachment #%d again.", attachment.mId);
678 onChange(this, attachment);
689 // Here's where we run our attachment loading logic...
745 * EmailProvider that an attachment has been inserted or modified. It's not strictly
746 * necessary that we detect a deleted attachment, as the code always checks for the
747 * existence of an attachment before acting on it.
749 public synchronized void onChange(final Context context, final Attachment att) {
750 debugTrace("onChange() for Attachment: #%d", att.mId);
754 LogUtils.d(LOG_TAG, "Attachment #%d has no priority and will not be downloaded",
756 // In this case, there is no download priority for this attachment
765 debugTrace("Attachment #%d was already in the queue", att.mId);
770 LogUtils.d(LOG_TAG, "Attachment #%d is a new download request", att.mId);
774 LogUtils.w(LOG_TAG, "Attachment #%d is not eligible for download", att.mId);
777 if (((att.mFlags & Attachment.FLAG_DOWNLOAD_USER_REQUEST) != 0) ||
778 ((att.mFlags & Attachment.FLAG_POLICY_DISALLOWS_DOWNLOAD) != 0)) {
779 LogUtils.w(LOG_TAG, "Attachment #%d cannot be downloaded ever", att.mId);
783 // 1. The user explicitly wants to download this attachment from the
786 // 2. The user is forwarding an email and the attachment has been
787 // marked as a policy violation. If the attachment is non viewable
792 // If we get this far it a forward of an attachment that is only
802 "Attachment #%d queued for download, priority: %d, created time: %d",
811 * @param att The attachment that failed to download.
813 void markAttachmentAsFailed(final Attachment att) {
815 final int flags = Attachment.FLAG_DOWNLOAD_FORWARD | Attachment.FLAG_DOWNLOAD_USER_REQUEST;
823 * @param att The attachment that was downloaded.
825 void markAttachmentAsCompleted(final Attachment att) {
827 final int flags = Attachment.FLAG_DOWNLOAD_FORWARD | Attachment.FLAG_DOWNLOAD_USER_REQUEST;
847 final Attachment attachment = Attachment.restoreAttachmentWithId(this, id);
848 if (attachment == null) {
849 LogUtils.w(LOG_TAG, "Could not restore attachment #%d", id);
851 attachment.mFlags = (int) flags;
852 onChange(this, attachment);
871 if (Attachment.restoreAttachmentWithId(this, req.mAttachmentId) == null) {
872 LogUtils.e(LOG_TAG, "Could not load attachment: #%d", req.mAttachmentId);
878 debugTrace("Need to wait before retrying attachment #%d", req.mAttachmentId);
918 final Uri lookupUri = EmailContent.uriWithLimit(Attachment.CONTENT_URI,
921 Attachment.CONTENT_PROJECTION,
922 EmailContent.Attachment.PRECACHE_INBOX_SELECTION,
927 final Attachment att = new Attachment();
931 // Clean up this orphaned attachment; there's no point in keeping it
933 debugTrace("Found orphaned attachment #%d", att.mId);
934 EmailContent.delete(this, Attachment.CONTENT_URI, att.mId);
936 // Check that the attachment meets system requirements for download
937 // Note that there couple be policy that does not allow this attachment
942 // an inline attachment.
946 // move onto the next attachment
948 "Too many failed attempts for attachment #%d ", att.mId);
957 // If this attachment was ineligible for download
961 // as the inability to view the attachment. In that case, let's just
963 LogUtils.w(LOG_TAG, "Skipping attachment #%d, it is ineligible", att.mId);
982 // Do not download the same attachment multiple times
985 debugTrace("This attachment #%d is already in progress", req.mAttachmentId);
1000 * Do the work of starting an attachment download using the EmailService interface, and
1009 LogUtils.d(LOG_TAG, "Starting download for Attachment #%d", req.mAttachmentId);
1019 LogUtils.d(LOG_TAG, "Cancelling download for Attachment #%d", req.mAttachmentId);
1026 LogUtils.w(LOG_TAG, "Too many failures giving up on Attachment #%d", req.mAttachmentId);
1041 * @param attachmentId the id of the attachment whose download is finished
1055 // Update the attachment failure list if needed
1063 LogUtils.w(LOG_TAG, "This attachment failed, adding #%d to failure map", attachmentId);
1074 // Not that we do not flag this attachment with any special flags so the
1075 // AttachmentService will try to download this attachment again the next time
1080 // Note that we are not doing anything with the attachment right now
1118 debugTrace("Download finished for attachment #%d; %d seconds from request, status: %s",
1122 final Attachment attachment = Attachment.restoreAttachmentWithId(this, attachmentId);
1123 if (attachment != null) {
1124 final long accountId = attachment.mAccountKey;
1125 // Update our attachment storage for this account
1130 mAttachmentStorageMap.put(accountId, currentStorage + attachment.mSize);
1132 if ((attachment.mFlags & Attachment.FLAG_DOWNLOAD_FORWARD) != 0) {
1134 // If this is a forwarding download, and the attachment doesn't exist (or
1137 EmailContent.delete(this, Attachment.CONTENT_URI, attachment.mId);
1142 nc.showDownloadForwardFailedNotificationSynchronous(attachment);
1145 LogUtils.w(LOG_TAG, "Deleting forwarded attachment #%d for message #%d",
1146 attachmentId, attachment.mMessageKey);
1148 // If we're an attachment on forwarded mail, and if we're not still blocked,
1151 !Utility.hasUnloadedAttachments(this, attachment.mMessageKey)) {
1164 Message msg = Message.restoreMessageWithId(this, attachment.mMessageKey);
1166 LogUtils.w(LOG_TAG, "Deleting attachment #%d with no associated message #%d",
1167 attachment.mId, attachment.mMessageKey);
1168 // If there's no associated message, delete the attachment
1169 EmailContent.delete(this, Attachment.CONTENT_URI, attachment.mId);
1173 LogUtils.w(LOG_TAG, "Retrying attachment #%d with associated message #%d",
1174 attachment.mId, attachment.mMessageKey);
1184 LogUtils.d(LOG_TAG, "Attachment #%d successfully downloaded!", attachment.mId);
1185 markAttachmentAsCompleted(attachment);
1208 * Calculate the download priority of an Attachment. A priority of zero means that the
1209 * attachment is not marked for download.
1210 * @param att the Attachment
1211 * @return the priority key of the Attachment
1213 private static int getAttachmentPriority(final Attachment att) {
1216 if ((flags & Attachment.FLAG_DOWNLOAD_FORWARD) != 0) {
1218 } else if ((flags & Attachment.FLAG_DOWNLOAD_USER_REQUEST) != 0) {
1225 * Determine whether an attachment can be prefetched for the given account based on
1256 // Retrieve our idea of currently used attachment storage; since we don't track deletions,
1261 // Calculate the exact figure for attachment storage for this account
1299 LogUtils.d(LOG_TAG, "Attachment: #%d", req.mAttachmentId);
1331 pw.println(" Account: " + req.mAccountId + ", Attachment: " + req.mAttachmentId);
1334 final Attachment att = Attachment.restoreAttachmentWithId(this, req.mAttachmentId);
1336 pw.println(" Attachment not in database?");