Update IEmailService

This is not yet finalized, but it's needed to fix push syncs
on exchange.

Change-Id: Iaff20aa0bdea9685ef6603de1f861d58fbab6ff1
This commit is contained in:
Martin Hibdon 2014-06-12 10:59:57 -07:00
parent b71fe22a93
commit fb2a3a2f77
5 changed files with 81 additions and 42 deletions

View File

@ -298,14 +298,14 @@ public class EmailServiceProxy extends ServiceProxy implements IEmailService {
if (mReturn == null) { if (mReturn == null) {
return 0; return 0;
} else { } else {
return (Integer)mReturn; return (Integer) mReturn;
} }
} }
/** /**
* Request the service to send mail in the specified account's Outbox * Request the service to send mail in the specified account's Outbox
* *
* @param accountId the account whose outgoing mail should be sent * @param accountId the account whose outgoing mail should be sent.
*/ */
@Override @Override
public void sendMail(final long accountId) throws RemoteException { public void sendMail(final long accountId) throws RemoteException {
@ -329,16 +329,26 @@ public class EmailServiceProxy extends ServiceProxy implements IEmailService {
public void run() throws RemoteException{ public void run() throws RemoteException{
mService.pushModify(accountId); mService.pushModify(accountId);
} }
}, "sendMail"); }, "pushModify");
} }
@Override @Override
public void syncFolders(final long accountId, final boolean updateFolderList, public int sync(final long accountId, final Bundle syncExtras) {
final long[] folders) {} setTask(new ProxyTask() {
@Override
@Override public void run() throws RemoteException{
public void syncMailboxType(final long accountId, final boolean updateFolderList, mReturn = mService.sync(accountId, syncExtras);
final int mailboxType) {} }
}, "sync");
waitForCompletion();
if (mReturn == null) {
// This occurs if sync times out.
// TODO: Sync may take a long time, maybe we should extend the timeout here.
return EmailServiceStatus.IO_ERROR;
} else {
return (Integer)mReturn;
}
}
@Override @Override
public IBinder asBinder() { public IBinder asBinder() {

View File

@ -51,6 +51,24 @@ public abstract class EmailServiceStatus {
// Client certificates used to authenticate cannot be retrieved from the system. // Client certificates used to authenticate cannot be retrieved from the system.
public static final int CLIENT_CERTIFICATE_ERROR = 0x21; public static final int CLIENT_CERTIFICATE_ERROR = 0x21;
// Data is invalid on the client side, sync cannot proceed.
public static final int HARD_DATA_ERROR = 0x22;
// Sync failed due to some type of IO error.
public static final int IO_ERROR = 0x23;
// The sync call encountered a protocol error.
public static final int PROTOCOL_ERROR = 0x24;
// The sync call encountered too many redirects.
public static final int TOO_MANY_REDIRECTS = 0x25;
// The sync call encountered a provisioning error.
public static final int PROVISIONING_ERROR = 0x26;
// We have encountered some sort of unexpected illegal state.
public static final int INTERNAL_ERROR = 0x27;
// Keys for the sync extras Bundle that specify the callback. // Keys for the sync extras Bundle that specify the callback.
public static final String SYNC_EXTRAS_CALLBACK_URI = "callback_uri"; public static final String SYNC_EXTRAS_CALLBACK_URI = "callback_uri";
public static final String SYNC_EXTRAS_CALLBACK_METHOD = "callback_method"; public static final String SYNC_EXTRAS_CALLBACK_METHOD = "callback_method";
@ -126,4 +144,5 @@ public abstract class EmailServiceStatus {
syncResult, null); syncResult, null);
} }
} }

View File

@ -26,15 +26,18 @@ import android.os.Bundle;
interface IEmailService { interface IEmailService {
// Core email operations. // Core email operations.
// TODO: is sendMail really necessary, or should we standardize on sync(outbox)? // Many of these functions return status codes. The valid status codes are defined in
void sendMail(long accountId); // EmailServiceStatus.java
oneway void loadAttachment(IEmailServiceCallback cb, long accountId, long attachmentId, oneway void loadAttachment(IEmailServiceCallback cb, long accountId, long attachmentId,
boolean background); boolean background);
oneway void updateFolderList(long accountId);
void syncFolders(long accountId, boolean updateFolderList, in long[] foldersToSync); void updateFolderList(long accountId);
void syncMailboxType(long accountId, boolean updateFolderList, int mailboxType); // TODO: For Eas, sync() will also sync the outbox. We should make IMAP and POP work the same
// way and get rid of sendMail().
void sendMail(long accountId);
int sync(long accountId, inout Bundle syncExtras);
// Push-related functionality. // Push-related functionality.
@ -55,7 +58,9 @@ interface IEmailService {
Bundle autoDiscover(String userName, String password); Bundle autoDiscover(String userName, String password);
// Service control operations (i.e. does not generate a client-server message). // Service control operations (i.e. does not generate a client-server message).
oneway void setLogging(int on); // TODO: We should store the logging flags in the contentProvider, and this call should just
// trigger the service to reload the flags.
oneway void setLogging(int flags);
// Needs to get moved into Email since this is NOT a client-server command. // Needs to get moved into Email since this is NOT a client-server command.
void deleteAccountPIMData(String emailAddress); void deleteAccountPIMData(String emailAddress);

View File

@ -281,9 +281,12 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
} }
@Override @Override
public void updateFolderList(long accountId) throws RemoteException { public void updateFolderList(final long accountId) throws RemoteException {
final Account account = Account.restoreAccountWithId(mContext, accountId); final Account account = Account.restoreAccountWithId(mContext, accountId);
if (account == null) return; if (account == null) {
LogUtils.e(LogUtils.TAG, "Account %d not found in updateFolderList", accountId);
return;
};
long inboxId = -1; long inboxId = -1;
TrafficStats.setThreadStatsTag(TrafficFlags.getSyncFlags(mContext, account)); TrafficStats.setThreadStatsTag(TrafficFlags.getSyncFlags(mContext, account));
Cursor localFolderCursor = null; Cursor localFolderCursor = null;
@ -350,6 +353,9 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
} catch (MessagingException me) { } catch (MessagingException me) {
LogUtils.i(Logging.LOG_TAG, me, "Error in updateFolderList"); LogUtils.i(Logging.LOG_TAG, me, "Error in updateFolderList");
// We'll hope this is temporary // We'll hope this is temporary
// TODO: Figure out what type of messaging exception it was and return an appropriate
// result. If we start doing this from sync, it's important to let the sync manager
// know if the failure was due to IO error or authentication errors.
} finally { } finally {
if (localFolderCursor != null) { if (localFolderCursor != null) {
localFolderCursor.close(); localFolderCursor.close();
@ -365,18 +371,20 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
} }
@Override @Override
public void setLogging(int on) throws RemoteException { public void setLogging(final int flags) throws RemoteException {
// Not required // Not required
} }
@Override @Override
public Bundle autoDiscover(String userName, String password) throws RemoteException { public Bundle autoDiscover(final String userName, final String password)
throws RemoteException {
// Not required // Not required
return null; return null;
} }
@Override @Override
public void sendMeetingResponse(long messageId, int response) throws RemoteException { public void sendMeetingResponse(final long messageId, final int response)
throws RemoteException {
// Not required // Not required
} }
@ -386,32 +394,35 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
} }
@Override @Override
public int searchMessages(long accountId, SearchParams params, long destMailboxId) public int searchMessages(final long accountId, final SearchParams params,
final long destMailboxId)
throws RemoteException { throws RemoteException {
// Not required // Not required
return 0; return EmailServiceStatus.SUCCESS;
} }
@Override @Override
public void pushModify(long accountId) throws RemoteException { public void pushModify(final long accountId) throws RemoteException {
LogUtils.e(Logging.LOG_TAG, "pushModify invalid for account type for %d", accountId); LogUtils.e(Logging.LOG_TAG, "pushModify invalid for account type for %d", accountId);
} }
@Override @Override
public void syncFolders(final long accountId, final boolean updateFolderList, public int sync(final long accountId, final Bundle syncExtras) {
final long[] folders) {} return EmailServiceStatus.SUCCESS;
}
@Override @Override
public void syncMailboxType(final long accountId, final boolean updateFolderList, public void sendMail(final long accountId) throws RemoteException {
final int mailboxType) {}
@Override
public void sendMail(long accountId) throws RemoteException {
sendMailImpl(mContext, accountId); sendMailImpl(mContext, accountId);
} }
public static void sendMailImpl(Context context, long accountId) { public static void sendMailImpl(final Context context, final long accountId) {
final Account account = Account.restoreAccountWithId(context, accountId); final Account account = Account.restoreAccountWithId(context, accountId);
if (account == null) {
LogUtils.e(LogUtils.TAG, "account %d not found in sendMailImpl", accountId);
return;
}
TrafficStats.setThreadStatsTag(TrafficFlags.getSmtpFlags(context, account)); TrafficStats.setThreadStatsTag(TrafficFlags.getSmtpFlags(context, account));
final NotificationController nc = NotificationController.getInstance(context); final NotificationController nc = NotificationController.getInstance(context);
// 1. Loop through all messages in the account's outbox // 1. Loop through all messages in the account's outbox
@ -503,6 +514,5 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
} finally { } finally {
c.close(); c.close();
} }
} }
} }

View File

@ -53,6 +53,7 @@ import com.android.emailcommon.provider.EmailContent.AccountColumns;
import com.android.emailcommon.provider.EmailContent.HostAuthColumns; import com.android.emailcommon.provider.EmailContent.HostAuthColumns;
import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.provider.HostAuth;
import com.android.emailcommon.service.EmailServiceProxy; import com.android.emailcommon.service.EmailServiceProxy;
import com.android.emailcommon.service.EmailServiceStatus;
import com.android.emailcommon.service.IEmailService; import com.android.emailcommon.service.IEmailService;
import com.android.emailcommon.service.IEmailServiceCallback; import com.android.emailcommon.service.IEmailServiceCallback;
import com.android.emailcommon.service.SearchParams; import com.android.emailcommon.service.SearchParams;
@ -663,11 +664,10 @@ public class EmailServiceUtils {
} }
@Override @Override
public void updateFolderList(long accountId) throws RemoteException { public void updateFolderList(long accountId) throws RemoteException {}
}
@Override @Override
public void setLogging(int on) throws RemoteException { public void setLogging(int flags) throws RemoteException {
} }
@Override @Override
@ -698,13 +698,8 @@ public class EmailServiceUtils {
} }
@Override @Override
public void syncFolders(final long accountId, final boolean updateFolderList, public int sync(final long accountId, final Bundle syncExtras) {
final long[] folders) { return EmailServiceStatus.SUCCESS;
}
@Override
public void syncMailboxType(final long accountId, final boolean updateFolderList,
final int mailboxType) {
} }
} }