Don't display toast for background download failures
When downloading attachments in the background, do not display any errors on the display. NOTE: This is a partial fix for general background attachment downloading issues bug 3373982 Change-Id: I874ed902bde293303e10308f38b992b2bb15b6aa
This commit is contained in:
parent
d5c6717eeb
commit
f92dd2bf3e
@ -1329,13 +1329,13 @@ public class Controller {
|
||||
|
||||
@Override
|
||||
public void loadAttachmentFailed(long accountId, long messageId, long attachmentId,
|
||||
MessagingException me) {
|
||||
MessagingException me, boolean background) {
|
||||
try {
|
||||
// If the cause of the MessagingException is an IOException, we send a status of
|
||||
// CONNECTION_ERROR; in this case, AttachmentDownloadService will try again to
|
||||
// download the attachment. Otherwise, the error is considered non-recoverable.
|
||||
int status = EmailServiceStatus.ATTACHMENT_NOT_FOUND;
|
||||
if (me.getCause() instanceof IOException) {
|
||||
if (me != null && me.getCause() instanceof IOException) {
|
||||
status = EmailServiceStatus.CONNECTION_ERROR;
|
||||
}
|
||||
mCallbackProxy.loadAttachmentStatus(messageId, attachmentId, status, 0);
|
||||
@ -1343,7 +1343,15 @@ public class Controller {
|
||||
}
|
||||
synchronized (mListeners) {
|
||||
for (Result listener : mListeners) {
|
||||
listener.loadAttachmentCallback(me, accountId, messageId, attachmentId, 0);
|
||||
// TODO We are overloading the exception here. The UI listens for this
|
||||
// callback and displays a toast if the exception is not null. Since we
|
||||
// want to avoid displaying toast for background operations, we force
|
||||
// the exception to be null. This needs to be re-worked so the UI will
|
||||
// only receive (or at least pays attention to) responses for requests
|
||||
// it explicitly cares about. Then we would not need to overload the
|
||||
// exception parameter.
|
||||
listener.loadAttachmentCallback(background ? null : me, accountId, messageId,
|
||||
attachmentId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1600,7 +1608,7 @@ public class Controller {
|
||||
}
|
||||
|
||||
public void loadAttachment(long attachmentId, String destinationFile,
|
||||
String contentUriString) throws RemoteException {
|
||||
String contentUriString, boolean background) throws RemoteException {
|
||||
if (Email.DEBUG) {
|
||||
Log.d(TAG, "loadAttachment: " + attachmentId + " to " + destinationFile);
|
||||
}
|
||||
@ -1629,7 +1637,7 @@ public class Controller {
|
||||
MessagingController legacyController = sInstance.mLegacyController;
|
||||
LegacyListener legacyListener = sInstance.mLegacyListener;
|
||||
legacyController.loadAttachment(msg.mAccountKey, msg.mId, msg.mMailboxKey,
|
||||
attachmentId, legacyListener);
|
||||
attachmentId, legacyListener, background);
|
||||
} else {
|
||||
// Send back the specific error status for this case
|
||||
sInstance.mCallbackProxy.loadAttachmentStatus(att.mMessageKey, attachmentId,
|
||||
|
@ -98,7 +98,7 @@ public class ExchangeUtils {
|
||||
}
|
||||
|
||||
public void loadAttachment(long attachmentId, String destinationFile,
|
||||
String contentUriString) throws RemoteException {
|
||||
String contentUriString, boolean background) throws RemoteException {
|
||||
}
|
||||
|
||||
public void loadMore(long messageId) throws RemoteException {
|
||||
|
@ -186,9 +186,10 @@ public class GroupMessagingListener extends MessagingListener {
|
||||
long accountId,
|
||||
long messageId,
|
||||
long attachmentId,
|
||||
MessagingException me) {
|
||||
MessagingException me,
|
||||
boolean background) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.loadAttachmentFailed(accountId, messageId, attachmentId, me);
|
||||
l.loadAttachmentFailed(accountId, messageId, attachmentId, me, background);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1870,7 +1870,7 @@ public class MessagingController implements Runnable {
|
||||
* @param listener
|
||||
*/
|
||||
public void loadAttachment(final long accountId, final long messageId, final long mailboxId,
|
||||
final long attachmentId, MessagingListener listener) {
|
||||
final long attachmentId, MessagingListener listener, final boolean background) {
|
||||
mListeners.loadAttachmentStarted(accountId, messageId, attachmentId, true);
|
||||
|
||||
put("loadAttachment", listener, new Runnable() {
|
||||
@ -1881,7 +1881,8 @@ public class MessagingController implements Runnable {
|
||||
Attachment.restoreAttachmentWithId(mContext, attachmentId);
|
||||
if (attachment == null) {
|
||||
mListeners.loadAttachmentFailed(accountId, messageId, attachmentId,
|
||||
new MessagingException("The attachment is null"));
|
||||
new MessagingException("The attachment is null"),
|
||||
background);
|
||||
return;
|
||||
}
|
||||
if (Utility.attachmentExists(mContext, attachment)) {
|
||||
@ -1901,7 +1902,8 @@ public class MessagingController implements Runnable {
|
||||
if (account == null || mailbox == null || message == null) {
|
||||
mListeners.loadAttachmentFailed(accountId, messageId, attachmentId,
|
||||
new MessagingException(
|
||||
"Account, mailbox, message or attachment are null"));
|
||||
"Account, mailbox, message or attachment are null"),
|
||||
background);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1954,7 +1956,8 @@ public class MessagingController implements Runnable {
|
||||
}
|
||||
catch (MessagingException me) {
|
||||
if (Email.LOGD) Log.v(Email.LOG_TAG, "", me);
|
||||
mListeners.loadAttachmentFailed(accountId, messageId, attachmentId, me);
|
||||
mListeners.loadAttachmentFailed(
|
||||
accountId, messageId, attachmentId, me, background);
|
||||
} catch (IOException ioe) {
|
||||
Log.e(Email.LOG_TAG, "Error while storing attachment." + ioe.toString());
|
||||
}
|
||||
|
@ -96,7 +96,8 @@ public class MessagingListener {
|
||||
long accountId,
|
||||
long messageId,
|
||||
long attachmentId,
|
||||
MessagingException me) {
|
||||
MessagingException me,
|
||||
boolean background) {
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,11 +68,11 @@ public class AttachmentDownloadService extends Service implements Runnable {
|
||||
private static final int PRIORITY_NONE = -1;
|
||||
@SuppressWarnings("unused")
|
||||
// Low priority will be used for opportunistic downloads
|
||||
private static final int PRIORITY_LOW = 0;
|
||||
private static final int PRIORITY_BACKGROUND = 0;
|
||||
// Normal priority is for forwarded downloads in outgoing mail
|
||||
private static final int PRIORITY_NORMAL = 1;
|
||||
private static final int PRIORITY_SEND_MAIL = 1;
|
||||
// High priority is for user requests
|
||||
private static final int PRIORITY_HIGH = 2;
|
||||
private static final int PRIORITY_FOREGROUND = 2;
|
||||
|
||||
// Minimum free storage in order to perform prefetch (25% of total memory)
|
||||
private static final float PREFETCH_MINIMUM_STORAGE_AVAILABLE = 0.25F;
|
||||
@ -416,7 +416,7 @@ public class AttachmentDownloadService extends Service implements Runnable {
|
||||
new EmailServiceProxy(mContext, serviceClass, mServiceCallback);
|
||||
proxy.loadAttachment(req.attachmentId, file.getAbsolutePath(),
|
||||
AttachmentProvider.getAttachmentUri(req.accountId, req.attachmentId)
|
||||
.toString());
|
||||
.toString(), req.priority != PRIORITY_FOREGROUND);
|
||||
// Lazily initialize our (reusable) pending intent
|
||||
if (mWatchdogPendingIntent == null) {
|
||||
Intent alarmIntent = new Intent(mContext, Watchdog.class);
|
||||
@ -563,9 +563,9 @@ public class AttachmentDownloadService extends Service implements Runnable {
|
||||
int priorityClass = PRIORITY_NONE;
|
||||
int flags = att.mFlags;
|
||||
if ((flags & Attachment.FLAG_DOWNLOAD_FORWARD) != 0) {
|
||||
priorityClass = PRIORITY_NORMAL;
|
||||
priorityClass = PRIORITY_SEND_MAIL;
|
||||
} else if ((flags & Attachment.FLAG_DOWNLOAD_USER_REQUEST) != 0) {
|
||||
priorityClass = PRIORITY_HIGH;
|
||||
priorityClass = PRIORITY_FOREGROUND;
|
||||
}
|
||||
return priorityClass;
|
||||
}
|
||||
|
@ -160,12 +160,13 @@ public class EmailServiceProxy implements IEmailService {
|
||||
}
|
||||
|
||||
public void loadAttachment(final long attachmentId, final String destinationFile,
|
||||
final String contentUriString) throws RemoteException {
|
||||
final String contentUriString, final boolean background) throws RemoteException {
|
||||
setTask(new Runnable () {
|
||||
public void run() {
|
||||
try {
|
||||
if (mCallback != null) mService.setCallback(mCallback);
|
||||
mService.loadAttachment(attachmentId, destinationFile, contentUriString);
|
||||
mService.loadAttachment(
|
||||
attachmentId, destinationFile, contentUriString, background);
|
||||
} catch (RemoteException e) {
|
||||
try {
|
||||
// Try to send a callback (if set)
|
||||
|
@ -27,7 +27,8 @@ interface IEmailService {
|
||||
void stopSync(long mailboxId);
|
||||
|
||||
void loadMore(long messageId);
|
||||
void loadAttachment(long attachmentId, String destinationFile, String contentUriString);
|
||||
void loadAttachment(long attachmentId, String destinationFile, String contentUriString,
|
||||
boolean background);
|
||||
|
||||
void updateFolderList(long accountId);
|
||||
|
||||
|
@ -379,7 +379,7 @@ public class ExchangeService extends Service implements Runnable {
|
||||
}
|
||||
|
||||
public void loadAttachment(long attachmentId, String destinationFile,
|
||||
String contentUriString) throws RemoteException {
|
||||
String contentUriString, boolean background) throws RemoteException {
|
||||
if (Email.DEBUG) {
|
||||
Log.d(TAG, "loadAttachment: " + attachmentId + " to " + destinationFile);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user