Add back attachment loading callbacks for IMAP
* Remove newly unused code Change-Id: Ifea2193deaf35734a031500c807ce9e3abd88fb1
This commit is contained in:
parent
59e10b6b3d
commit
9227dbbf0f
|
@ -1141,39 +1141,6 @@ public class Controller {
|
|||
public void serviceCheckMailCallback(MessagingException result, long accountId,
|
||||
long mailboxId, int progress, long tag) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for sending pending messages. This will be called once to start the
|
||||
* group, multiple times for messages, and once to complete the group.
|
||||
*
|
||||
* Unfortunately this callback works differently on SMTP and EAS.
|
||||
*
|
||||
* On SMTP:
|
||||
*
|
||||
* First, we get this.
|
||||
* result == null, messageId == -1, progress == 0: start batch send
|
||||
*
|
||||
* Then we get these callbacks per message.
|
||||
* (Exchange backend may skip "start sending one message".)
|
||||
* result == null, messageId == xx, progress == 0: start sending one message
|
||||
* result == xxxx, messageId == xx, progress == 0; failed sending one message
|
||||
*
|
||||
* Finally we get this.
|
||||
* result == null, messageId == -1, progres == 100; finish sending batch
|
||||
*
|
||||
* On EAS: Almost same as above, except:
|
||||
*
|
||||
* - There's no first ("start batch send") callback.
|
||||
* - accountId is always -1.
|
||||
*
|
||||
* @param result If null, the operation completed without error
|
||||
* @param accountId The account being operated on
|
||||
* @param messageId The being sent (may be unknown at start)
|
||||
* @param progress 0 for "starting", 100 for complete
|
||||
*/
|
||||
public void sendMailCallback(MessagingException result, long accountId,
|
||||
long messageId, int progress) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1206,32 +1173,11 @@ public class Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* Note, this is an incomplete implementation of this callback, because we are
|
||||
* not getting things back from Service in quite the same way as from MessagingController.
|
||||
* However, this is sufficient for basic "progress=100" notification that message send
|
||||
* has just completed.
|
||||
* Unused
|
||||
*/
|
||||
@Override
|
||||
public void sendMessageStatus(long messageId, String subject, int statusCode,
|
||||
int progress) {
|
||||
long accountId = -1; // This should be in the callback
|
||||
MessagingException result = mapStatusToException(statusCode);
|
||||
switch (statusCode) {
|
||||
case EmailServiceStatus.SUCCESS:
|
||||
progress = 100;
|
||||
break;
|
||||
case EmailServiceStatus.IN_PROGRESS:
|
||||
// discard progress reports that look like sentinels
|
||||
if (progress < 0 || progress >= 100) {
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
synchronized(mListeners) {
|
||||
for (Result listener : mListeners) {
|
||||
listener.sendMailCallback(result, accountId, messageId, progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -84,17 +84,6 @@ public class ControllerResultUiThreadWrapper<T extends Result> extends Result {
|
|||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMailCallback(final MessagingException result, final long accountId,
|
||||
final long messageId, final int progress) {
|
||||
run(new Runnable() {
|
||||
public void run() {
|
||||
if (!isRegistered()) return;
|
||||
mWrappee.sendMailCallback(result, accountId, messageId, progress);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serviceCheckMailCallback(final MessagingException result, final long accountId,
|
||||
final long mailboxId, final int progress, final long tag) {
|
||||
|
|
|
@ -1,203 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.email;
|
||||
|
||||
import com.android.emailcommon.mail.MessagingException;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class GroupMessagingListener extends MessagingListener {
|
||||
/* The synchronization of the methods in this class
|
||||
is not needed because we use ConcurrentHashMap.
|
||||
|
||||
Nevertheless, let's keep the "synchronized" for a while in the case
|
||||
we may want to change the implementation to use something else
|
||||
than ConcurrentHashMap.
|
||||
*/
|
||||
|
||||
private ConcurrentHashMap<MessagingListener, Object> mListenersMap =
|
||||
new ConcurrentHashMap<MessagingListener, Object>();
|
||||
|
||||
private Set<MessagingListener> mListeners = mListenersMap.keySet();
|
||||
|
||||
synchronized public void addListener(MessagingListener listener) {
|
||||
// we use "this" as a dummy non-null value
|
||||
mListenersMap.put(listener, this);
|
||||
}
|
||||
|
||||
synchronized public void removeListener(MessagingListener listener) {
|
||||
mListenersMap.remove(listener);
|
||||
}
|
||||
|
||||
synchronized public boolean isActiveListener(MessagingListener listener) {
|
||||
return mListenersMap.containsKey(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void listFoldersStarted(long accountId) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.listFoldersStarted(accountId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void listFoldersFailed(long accountId, String message) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.listFoldersFailed(accountId, message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void listFoldersFinished(long accountId) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.listFoldersFinished(accountId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void synchronizeMailboxStarted(long accountId, long mailboxId) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.synchronizeMailboxStarted(accountId, mailboxId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void synchronizeMailboxFinished(long accountId, long mailboxId,
|
||||
int totalMessagesInMailbox, int numNewMessages, ArrayList<Long> addedMessages) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.synchronizeMailboxFinished(accountId, mailboxId,
|
||||
totalMessagesInMailbox, numNewMessages, addedMessages);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void synchronizeMailboxFailed(long accountId, long mailboxId, Exception e) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.synchronizeMailboxFailed(accountId, mailboxId, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void loadMessageForViewStarted(long messageId) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.loadMessageForViewStarted(messageId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void loadMessageForViewFinished(long messageId) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.loadMessageForViewFinished(messageId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void loadMessageForViewFailed(long messageId, String message) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.loadMessageForViewFailed(messageId, message);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void checkMailStarted(Context context, long accountId, long tag) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.checkMailStarted(context, accountId, tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void checkMailFinished(Context context, long accountId, long folderId,
|
||||
long tag) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.checkMailFinished(context, accountId, folderId, tag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void sendPendingMessagesStarted(long accountId, long messageId) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.sendPendingMessagesStarted(accountId, messageId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void sendPendingMessagesCompleted(long accountId) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.sendPendingMessagesCompleted(accountId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void sendPendingMessagesFailed(long accountId, long messageId,
|
||||
Exception reason) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.sendPendingMessagesFailed(accountId, messageId, reason);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void messageUidChanged(long accountId, long mailboxId,
|
||||
String oldUid, String newUid) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.messageUidChanged(accountId, mailboxId, oldUid, newUid);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void loadAttachmentStarted(
|
||||
long accountId,
|
||||
long messageId,
|
||||
long attachmentId,
|
||||
boolean requiresDownload) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.loadAttachmentStarted(accountId, messageId, attachmentId, requiresDownload);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void loadAttachmentFinished(
|
||||
long accountId,
|
||||
long messageId,
|
||||
long attachmentId) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.loadAttachmentFinished(accountId, messageId, attachmentId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void loadAttachmentFailed(
|
||||
long accountId,
|
||||
long messageId,
|
||||
long attachmentId,
|
||||
MessagingException me,
|
||||
boolean background) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.loadAttachmentFailed(accountId, messageId, attachmentId, me, background);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
synchronized public void controllerCommandCompleted(boolean moreCommandsToRun) {
|
||||
for (MessagingListener l : mListeners) {
|
||||
l.controllerCommandCompleted(moreCommandsToRun);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -355,7 +355,6 @@ public class RefreshManager {
|
|||
}
|
||||
|
||||
private class ControllerResult extends Controller.Result {
|
||||
private boolean mSendMailExceptionReported = false;
|
||||
|
||||
private String exceptionToString(MessagingException exception) {
|
||||
if (exception == null) {
|
||||
|
@ -426,33 +425,5 @@ public class RefreshManager {
|
|||
}
|
||||
notifyRefreshStatusChanged(accountId, mailboxId);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Send message progress callback.
|
||||
*
|
||||
* We don't keep track of the status of outboxes, but we monitor this to catch
|
||||
* errors.
|
||||
*/
|
||||
@Override
|
||||
public void sendMailCallback(MessagingException exception, long accountId, long messageId,
|
||||
int progress) {
|
||||
if (LOG_ENABLED) {
|
||||
Log.d(Logging.LOG_TAG, "sendMailCallback " + accountId + ", "
|
||||
+ messageId + ", " + progress + ", " + exceptionToString(exception));
|
||||
}
|
||||
if (progress == 0 && messageId == -1) {
|
||||
mSendMailExceptionReported = false;
|
||||
}
|
||||
if (exception != null && !mSendMailExceptionReported) {
|
||||
// Only the first error in a batch will be reported.
|
||||
mSendMailExceptionReported = true;
|
||||
reportError(accountId, messageId,
|
||||
MessagingExceptionStrings.getErrorString(mContext, exception));
|
||||
}
|
||||
if (progress == 100) {
|
||||
mSendMailExceptionReported = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ package com.android.email.activity;
|
|||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
|
@ -350,12 +349,6 @@ public class EmailActivity extends Activity implements View.OnClickListener, Fra
|
|||
* A {@link Controller.Result} to detect connection status.
|
||||
*/
|
||||
private class ControllerResult extends Controller.Result {
|
||||
@Override
|
||||
public void sendMailCallback(
|
||||
MessagingException result, long accountId, long messageId, int progress) {
|
||||
handleError(result, accountId, progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serviceCheckMailCallback(
|
||||
MessagingException result, long accountId, long mailboxId, int progress, long tag) {
|
||||
|
|
|
@ -27,10 +27,10 @@ import android.os.RemoteException;
|
|||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.email.Controller.Result;
|
||||
import com.android.email.Email;
|
||||
import com.android.email.LegacyConversions;
|
||||
import com.android.email.NotificationController;
|
||||
import com.android.email.Controller.Result;
|
||||
import com.android.email.mail.Sender;
|
||||
import com.android.email.mail.Store;
|
||||
import com.android.email.provider.Utilities;
|
||||
|
@ -44,17 +44,17 @@ import com.android.emailcommon.internet.MimeMultipart;
|
|||
import com.android.emailcommon.mail.AuthenticationFailedException;
|
||||
import com.android.emailcommon.mail.FetchProfile;
|
||||
import com.android.emailcommon.mail.Folder;
|
||||
import com.android.emailcommon.mail.Message;
|
||||
import com.android.emailcommon.mail.MessagingException;
|
||||
import com.android.emailcommon.mail.Folder.MessageRetrievalListener;
|
||||
import com.android.emailcommon.mail.Folder.OpenMode;
|
||||
import com.android.emailcommon.mail.Message;
|
||||
import com.android.emailcommon.mail.MessagingException;
|
||||
import com.android.emailcommon.provider.Account;
|
||||
import com.android.emailcommon.provider.EmailContent;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
import com.android.emailcommon.provider.EmailContent.Attachment;
|
||||
import com.android.emailcommon.provider.EmailContent.MailboxColumns;
|
||||
import com.android.emailcommon.provider.EmailContent.MessageColumns;
|
||||
import com.android.emailcommon.provider.HostAuth;
|
||||
import com.android.emailcommon.provider.Mailbox;
|
||||
import com.android.emailcommon.service.EmailServiceStatus;
|
||||
import com.android.emailcommon.service.IEmailService;
|
||||
import com.android.emailcommon.service.IEmailServiceCallback;
|
||||
|
@ -176,6 +176,15 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
|||
}
|
||||
}
|
||||
|
||||
private void doProgressCallback(long messageId, long attachmentId, int progress) {
|
||||
try {
|
||||
mCallback.loadAttachmentStatus(messageId, attachmentId,
|
||||
EmailServiceStatus.IN_PROGRESS, progress);
|
||||
} catch (RemoteException e) {
|
||||
// No danger if the client is no longer around
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAttachment(long attachmentId, boolean background) throws RemoteException {
|
||||
try {
|
||||
|
@ -183,28 +192,38 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
|||
Attachment attachment =
|
||||
Attachment.restoreAttachmentWithId(mContext, attachmentId);
|
||||
if (attachment == null) {
|
||||
// mListeners.loadAttachmentFailed(accountId, messageId, attachmentId,
|
||||
// new MessagingException("The attachment is null"),
|
||||
// background);
|
||||
return;
|
||||
}
|
||||
if (Utility.attachmentExists(mContext, attachment)) {
|
||||
// mListeners.loadAttachmentFinished(accountId, messageId, attachmentId);
|
||||
mCallback.loadAttachmentStatus(0, attachmentId,
|
||||
EmailServiceStatus.ATTACHMENT_NOT_FOUND, 0);
|
||||
return;
|
||||
}
|
||||
long messageId = attachment.mMessageKey;
|
||||
|
||||
EmailContent.Message message =
|
||||
EmailContent.Message.restoreMessageWithId(mContext, attachment.mMessageKey);
|
||||
EmailContent.Message.restoreMessageWithId(mContext, attachment.mMessageKey);
|
||||
if (message == null) {
|
||||
mCallback.loadAttachmentStatus(messageId, attachmentId,
|
||||
EmailServiceStatus.MESSAGE_NOT_FOUND, 0);
|
||||
}
|
||||
|
||||
// If the message is loaded, just report that we're finished
|
||||
if (Utility.attachmentExists(mContext, attachment)) {
|
||||
mCallback.loadAttachmentStatus(messageId, attachmentId, EmailServiceStatus.SUCCESS,
|
||||
0);
|
||||
return;
|
||||
}
|
||||
|
||||
// Say we're starting...
|
||||
doProgressCallback(messageId, attachmentId, 0);
|
||||
|
||||
// 2. Open the remote folder.
|
||||
// TODO all of these could be narrower projections
|
||||
Account account = Account.restoreAccountWithId(mContext, message.mAccountKey);
|
||||
Mailbox mailbox = Mailbox.restoreMailboxWithId(mContext, message.mMailboxKey);
|
||||
|
||||
if (account == null || mailbox == null || message == null) {
|
||||
// mListeners.loadAttachmentFailed(accountId, messageId, attachmentId,
|
||||
// new MessagingException(
|
||||
// "Account, mailbox, message or attachment are null"),
|
||||
// background);
|
||||
if (account == null || mailbox == null) {
|
||||
// If the account/mailbox are gone, just report success; the UI handles this
|
||||
mCallback.loadAttachmentStatus(messageId, attachmentId,
|
||||
EmailServiceStatus.SUCCESS, 0);
|
||||
return;
|
||||
}
|
||||
TrafficStats.setThreadStatsTag(
|
||||
|
@ -240,7 +259,7 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
|||
FetchProfile fp = new FetchProfile();
|
||||
fp.add(storePart);
|
||||
remoteFolder.fetch(new Message[] { storeMessage }, fp,
|
||||
new MessageRetrievalListenerBridge(message.mId, attachmentId));
|
||||
new MessageRetrievalListenerBridge(messageId, attachmentId));
|
||||
|
||||
// If we failed to load the attachment, throw an Exception here, so that
|
||||
// AttachmentDownloadService knows that we failed
|
||||
|
@ -253,18 +272,41 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
|||
message.mAccountKey);
|
||||
|
||||
// 6. Report success
|
||||
// mListeners.loadAttachmentFinished(accountId, messageId, attachmentId);
|
||||
mCallback.loadAttachmentStatus(messageId, attachmentId, EmailServiceStatus.SUCCESS, 0);
|
||||
}
|
||||
catch (MessagingException me) {
|
||||
if (Logging.LOGD) Log.v(Logging.LOG_TAG, "", me);
|
||||
// mListeners.loadAttachmentFailed(
|
||||
// accountId, messageId, attachmentId, me, background);
|
||||
// TODO: Fix this up; consider the best approach
|
||||
mCallback.loadAttachmentStatus(0, attachmentId, EmailServiceStatus.CONNECTION_ERROR, 0);
|
||||
} catch (IOException ioe) {
|
||||
Log.e(Logging.LOG_TAG, "Error while storing attachment." + ioe.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Bridge to intercept {@link MessageRetrievalListener#loadAttachmentProgress} and
|
||||
* pass down to {@link Result}.
|
||||
*/
|
||||
public class MessageRetrievalListenerBridge implements MessageRetrievalListener {
|
||||
private final long mMessageId;
|
||||
private final long mAttachmentId;
|
||||
|
||||
public MessageRetrievalListenerBridge(long messageId, long attachmentId) {
|
||||
mMessageId = messageId;
|
||||
mAttachmentId = attachmentId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAttachmentProgress(int progress) {
|
||||
doProgressCallback(mMessageId, mAttachmentId, progress);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageRetrieved(com.android.emailcommon.mail.Message message) {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Implement callback
|
||||
@Override
|
||||
public void updateFolderList(long accountId) throws RemoteException {
|
||||
|
@ -412,9 +454,6 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
|||
if (c.getCount() <= 0) {
|
||||
return;
|
||||
}
|
||||
// 3. do one-time setup of the Sender & other stuff
|
||||
//mListeners.sendPendingMessagesStarted(account.mId, -1);
|
||||
|
||||
Sender sender = Sender.getInstance(mContext, account);
|
||||
Store remoteStore = Store.getInstance(account, mContext);
|
||||
boolean requireMoveMessageToSentFolder = remoteStore.requireCopyMessageToSentFolder();
|
||||
|
@ -426,12 +465,11 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
|||
moveToSentValues.put(MessageColumns.MAILBOX_KEY, sentFolder.mId);
|
||||
}
|
||||
|
||||
// 4. loop through the available messages and send them
|
||||
// 3. loop through the available messages and send them
|
||||
while (c.moveToNext()) {
|
||||
long messageId = -1;
|
||||
try {
|
||||
messageId = c.getLong(0);
|
||||
//mListeners.sendPendingMessagesStarted(account.mId, messageId);
|
||||
// Don't send messages with unloaded attachments
|
||||
if (Utility.hasUnloadedAttachments(mContext, messageId)) {
|
||||
if (Email.DEBUG) {
|
||||
|
@ -446,10 +484,9 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
|||
if (me instanceof AuthenticationFailedException) {
|
||||
nc.showLoginFailedNotification(account.mId);
|
||||
}
|
||||
//mListeners.sendPendingMessagesFailed(account.mId, messageId, me);
|
||||
continue;
|
||||
}
|
||||
// 5. move to sent, or delete
|
||||
// 4. move to sent, or delete
|
||||
Uri syncedUri =
|
||||
ContentUris.withAppendedId(EmailContent.Message.SYNCED_CONTENT_URI, messageId);
|
||||
if (requireMoveMessageToSentFolder) {
|
||||
|
@ -472,46 +509,13 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
|||
resolver.delete(syncedUri, null, null);
|
||||
}
|
||||
}
|
||||
// 6. report completion/success
|
||||
//mListeners.sendPendingMessagesCompleted(account.mId);
|
||||
nc.cancelLoginFailedNotification(account.mId);
|
||||
} catch (MessagingException me) {
|
||||
if (me instanceof AuthenticationFailedException) {
|
||||
nc.showLoginFailedNotification(account.mId);
|
||||
}
|
||||
//mListeners.sendPendingMessagesFailed(account.mId, -1, me);
|
||||
} finally {
|
||||
c.close();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Bridge to intercept {@link MessageRetrievalListener#loadAttachmentProgress} and
|
||||
* pass down to {@link Result}.
|
||||
*/
|
||||
public class MessageRetrievalListenerBridge implements MessageRetrievalListener {
|
||||
private final long mMessageId;
|
||||
// private final long mAttachmentId;
|
||||
// private final long mAccountId;
|
||||
|
||||
public MessageRetrievalListenerBridge(long messageId, long attachmentId) {
|
||||
mMessageId = messageId;
|
||||
// mAttachmentId = attachmentId;
|
||||
// mAccountId = Account.getAccountIdForMessageId(mContext, mMessageId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadAttachmentProgress(int progress) {
|
||||
// synchronized (mListeners) {
|
||||
// for (Result listener : mListeners) {
|
||||
// listener.loadAttachmentCallback(null, mAccountId, mMessageId, mAttachmentId,
|
||||
// progress);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@Override
|
||||
public void messageRetrieved(com.android.emailcommon.mail.Message message) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
/*
|
||||
* Copyright (C) 2009 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.email;
|
||||
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* This is a series of unit tests for the GroupMessagingListener class.
|
||||
*/
|
||||
@SmallTest
|
||||
public class GroupMessagingListenerUnitTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Tests adding and removing elements from the listener
|
||||
*/
|
||||
public void testAddRemove() {
|
||||
GroupMessagingListener groupListener = new GroupMessagingListener();
|
||||
|
||||
MessagingListener listener1 = new MessagingListener();
|
||||
MessagingListener listener2 = new MessagingListener();
|
||||
|
||||
groupListener.addListener(listener1);
|
||||
groupListener.addListener(listener2);
|
||||
|
||||
groupListener.removeListener(listener1);
|
||||
groupListener.removeListener(listener2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests isActiveListener()
|
||||
*/
|
||||
public void testIsActiveListener() {
|
||||
GroupMessagingListener groupListener = new GroupMessagingListener();
|
||||
|
||||
MessagingListener listener1 = new MessagingListener();
|
||||
MessagingListener listener2 = new MessagingListener();
|
||||
|
||||
assertFalse(groupListener.isActiveListener(listener1));
|
||||
assertFalse(groupListener.isActiveListener(listener2));
|
||||
|
||||
groupListener.addListener(listener1);
|
||||
assertTrue(groupListener.isActiveListener(listener1));
|
||||
assertFalse(groupListener.isActiveListener(listener2));
|
||||
|
||||
groupListener.addListener(listener2);
|
||||
assertTrue(groupListener.isActiveListener(listener1));
|
||||
assertTrue(groupListener.isActiveListener(listener2));
|
||||
|
||||
groupListener.removeListener(listener1);
|
||||
assertFalse(groupListener.isActiveListener(listener1));
|
||||
assertTrue(groupListener.isActiveListener(listener2));
|
||||
|
||||
groupListener.removeListener(listener2);
|
||||
assertFalse(groupListener.isActiveListener(listener1));
|
||||
assertFalse(groupListener.isActiveListener(listener2));
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO: Test that if you add a set of listeners, they will be called
|
||||
*/
|
||||
}
|
|
@ -16,16 +16,14 @@
|
|||
|
||||
package com.android.email;
|
||||
|
||||
import com.android.email.provider.ProviderTestUtils;
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.mail.MessagingException;
|
||||
import com.android.emailcommon.provider.Account;
|
||||
|
||||
import android.content.Context;
|
||||
import android.test.InstrumentationTestCase;
|
||||
import android.test.suitebuilder.annotation.LargeTest;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.emailcommon.Logging;
|
||||
import com.android.emailcommon.mail.MessagingException;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
@LargeTest
|
||||
|
@ -311,95 +309,6 @@ public class RefreshManagerTest extends InstrumentationTestCase {
|
|||
assertFalse(mTarget.isRefreshingAnyMessageListForTest());
|
||||
}
|
||||
|
||||
public void testSendPendingMessages() {
|
||||
// request sending for account 1
|
||||
assertTrue(mTarget.sendPendingMessages(ACCOUNT_1));
|
||||
|
||||
assertTrue(mListener.mCalledOnRefreshStatusChanged);
|
||||
assertFalse(mListener.mCalledOnConnectionError);
|
||||
assertEquals(ACCOUNT_1, mListener.mAccountId);
|
||||
assertEquals(-1, mListener.mMailboxId);
|
||||
mListener.reset();
|
||||
assertTrue(mController.mCalledSendPendingMessages);
|
||||
assertEquals(ACCOUNT_1, mController.mAccountId);
|
||||
assertEquals(-1, mController.mMailboxId);
|
||||
mController.reset();
|
||||
|
||||
// request sending for account 2
|
||||
assertTrue(mTarget.sendPendingMessages(ACCOUNT_2));
|
||||
|
||||
assertFalse(mListener.mCalledOnConnectionError);
|
||||
assertEquals(ACCOUNT_2, mListener.mAccountId);
|
||||
assertEquals(-1, mListener.mMailboxId);
|
||||
mListener.reset();
|
||||
assertTrue(mController.mCalledSendPendingMessages);
|
||||
assertEquals(ACCOUNT_2, mController.mAccountId);
|
||||
assertEquals(-1, mController.mMailboxId);
|
||||
mController.reset();
|
||||
|
||||
// Sending start for account 1...
|
||||
// batch send start. (message id == -1, progress == 0)
|
||||
mController.mListener.sendMailCallback(null, ACCOUNT_1, -1, 0);
|
||||
|
||||
assertFalse(mListener.mCalledOnConnectionError);
|
||||
mListener.reset();
|
||||
|
||||
// Per message callback
|
||||
mController.mListener.sendMailCallback(null, ACCOUNT_1, 100, 0);
|
||||
mController.mListener.sendMailCallback(null, ACCOUNT_1, 101, 0);
|
||||
|
||||
assertFalse(mListener.mCalledOnConnectionError);
|
||||
mListener.reset();
|
||||
|
||||
// Exception -- first error will be reported.
|
||||
mController.mListener.sendMailCallback(EXCEPTION, ACCOUNT_1, 102, 0);
|
||||
|
||||
assertTrue(mListener.mCalledOnConnectionError);
|
||||
assertEquals(MessagingExceptionStrings.getErrorString(mContext, EXCEPTION),
|
||||
mListener.mMessage);
|
||||
mListener.reset();
|
||||
|
||||
// Exception again -- no more error callbacks
|
||||
mController.mListener.sendMailCallback(null, ACCOUNT_1, 103, 0);
|
||||
mController.mListener.sendMailCallback(EXCEPTION, ACCOUNT_1, 104, 0);
|
||||
|
||||
assertFalse(mListener.mCalledOnConnectionError);
|
||||
mListener.reset();
|
||||
|
||||
// Done.
|
||||
Log.w(Logging.LOG_TAG, "" + mController.mListener.getClass());
|
||||
mController.mListener.sendMailCallback(null, ACCOUNT_1, -1, 100);
|
||||
|
||||
assertFalse(mListener.mCalledOnConnectionError);
|
||||
mListener.reset();
|
||||
}
|
||||
|
||||
public void testSendPendingMessagesForAllAccounts() throws Throwable {
|
||||
Account acct1 = ProviderTestUtils.setupAccount("acct1", true, mProviderContext);
|
||||
Account acct2 = ProviderTestUtils.setupAccount("acct2", true, mProviderContext);
|
||||
|
||||
// AsyncTask needs to be created on the UI thread.
|
||||
runTestOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mTarget.sendPendingMessagesForAllAccounts();
|
||||
}
|
||||
});
|
||||
|
||||
// sendPendingMessagesForAllAccounts uses Utility.ForEachAccount, which has it's own test,
|
||||
// so we don't really have to check everything.
|
||||
// Here, we just check if sendPendingMessages() has been called at least for once,
|
||||
// which is a enough check.
|
||||
TestUtils.waitUntil(new TestUtils.Condition() {
|
||||
@Override
|
||||
public boolean isMet() {
|
||||
// The write to this is done on the UI thread, but we're checking it here
|
||||
// on the test thread, so mCalledSendPendingMessages needs to be volatile.
|
||||
return mController.mCalledSendPendingMessages;
|
||||
}
|
||||
}, WAIT_UNTIL_TIMEOUT_SECONDS);
|
||||
}
|
||||
|
||||
public void testLoadMoreMessages() {
|
||||
final long ACCOUNT_ID = 123;
|
||||
final long MAILBOX_ID = 456;
|
||||
|
@ -416,7 +325,6 @@ public class RefreshManagerTest extends InstrumentationTestCase {
|
|||
private static class MockController extends Controller {
|
||||
public volatile long mAccountId = -1;
|
||||
public volatile long mMailboxId = -1;
|
||||
public volatile boolean mCalledSendPendingMessages;
|
||||
public volatile boolean mCalledUpdateMailbox;
|
||||
public volatile boolean mCalledUpdateMailboxList;
|
||||
public volatile boolean mCalledLoadMoreMessages;
|
||||
|
@ -429,14 +337,12 @@ public class RefreshManagerTest extends InstrumentationTestCase {
|
|||
public void reset() {
|
||||
mAccountId = -1;
|
||||
mMailboxId = -1;
|
||||
mCalledSendPendingMessages = false;
|
||||
mCalledUpdateMailbox = false;
|
||||
mCalledUpdateMailboxList = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPendingMessages(long accountId) {
|
||||
mCalledSendPendingMessages = true;
|
||||
mAccountId = accountId;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue