Plumb send-message status callbacks from service

* Make sure service callbacks are installed
* Route from service sent-message callback to controller results

This sends the callback information back to listeners who care about
sent messages.  Note, due to impedance mismatch between the service
and the controller, this should not be used for much more than an
indication that outbox status has changed.

Bug # 2158497

Change-Id: I8d013d97ef53dcca85216f9b8c027ba3917c1e85
This commit is contained in:
Andrew Stadler 2009-10-01 03:12:40 -07:00
parent 3ea49f2151
commit f9ccc0ba88
1 changed files with 43 additions and 6 deletions

View File

@ -391,10 +391,20 @@ public class Controller {
Uri uri = ContentUris.withAppendedId(EmailContent.Message.CONTENT_URI, messageId);
resolver.update(uri, cv, null, null);
// for IMAP & POP only, (attempt to) send the message now
final EmailContent.Account account =
EmailContent.Account.restoreAccountWithId(mProviderContext, accountId);
if (this.isMessagingController(account)) {
// Split here for target type (Service or MessagingController)
IEmailService service = getServiceForMessage(messageId);
if (service != null) {
// We just need to be sure the callback is installed, if this is the first call
// to the service.
try {
service.setCallback(mServiceCallback);
} catch (RemoteException re) {
// OK - not a critical callback here
}
} else {
// for IMAP & POP only, (attempt to) send the message now
final EmailContent.Account account =
EmailContent.Account.restoreAccountWithId(mProviderContext, accountId);
final long sentboxId = findOrCreateMailboxOfType(accountId, Mailbox.TYPE_SENT);
new Thread() {
@Override
@ -1064,10 +1074,37 @@ 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.
*/
public void sendMessageStatus(long messageId, String subject, int statusCode,
int progress) {
// TODO Auto-generated method stub
// Log.d(Email.LOG_TAG, "sendMessageStatus: messageId=" + messageId
// + " statusCode=" + statusCode + " progress=" + progress);
// Log.d(Email.LOG_TAG, "sendMessageStatus: subject=" + subject);
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;
}
// Log.d(Email.LOG_TAG, "result=" + result + " messageId=" + messageId
// + " progress=" + progress);
synchronized(mListeners) {
for (Result listener : mListeners) {
listener.sendMailCallback(result, accountId, messageId, progress);
}
}
}
public void syncMailboxListStatus(long accountId, int statusCode, int progress) {