Use system SyncManager for Exchange.
Change-Id: I77e4e75c94c532d22a28cf97e6f55f1259b8bdde
This commit is contained in:
parent
c726d4fa6c
commit
9e7f5a2a33
|
@ -32,6 +32,15 @@ import com.android.emailcommon.provider.EmailContent.MailboxColumns;
|
|||
import com.android.emailcommon.utility.Utility;
|
||||
|
||||
public class Mailbox extends EmailContent implements MailboxColumns, Parcelable {
|
||||
/**
|
||||
* Sync extras key when syncing a mailbox to specify which mailbox to sync.
|
||||
*/
|
||||
public static final String SYNC_EXTRA_MAILBOX_ID = "__mailboxId__";
|
||||
/**
|
||||
* Sync extras key when syncing a mailbox to specify how many additional messages to sync.
|
||||
*/
|
||||
public static final String SYNC_EXTRA_DELTA_MESSAGE_COUNT = "__deltaMessageCount__";
|
||||
|
||||
public static final String TABLE_NAME = "Mailbox";
|
||||
|
||||
public static Uri CONTENT_URI;
|
||||
|
|
|
@ -154,11 +154,13 @@ public class EmailServiceProxy extends ServiceProxy implements IEmailService {
|
|||
* Request the sync of a mailbox; the service MUST send the syncMailboxStatus callback
|
||||
* indicating "starting" and "finished" (or error), regardless of whether the mailbox is
|
||||
* actually syncable.
|
||||
* TODO: Remove this from IEmailService in favor of ContentResolver.requestSync.
|
||||
*
|
||||
* @param mailboxId the id of the mailbox record
|
||||
* @param userRequest whether or not the user specifically asked for the sync
|
||||
* @param deltaMessageCount amount by which to change the number of messages synced.
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public void startSync(final long mailboxId, final boolean userRequest,
|
||||
final int deltaMessageCount) throws RemoteException {
|
||||
|
|
|
@ -137,7 +137,7 @@ public abstract class SyncManager extends Service implements Runnable {
|
|||
private static final String WHERE_MAILBOX_KEY = Message.MAILBOX_KEY + "=?";
|
||||
private static final String WHERE_NOT_INTERVAL_NEVER_AND_ACCOUNT_KEY_IN =
|
||||
"(" + MailboxColumns.TYPE + '=' + Mailbox.TYPE_OUTBOX
|
||||
+ " or " + MailboxColumns.SYNC_INTERVAL + "!=" + Mailbox.CHECK_INTERVAL_NEVER + ')'
|
||||
+ " or " + MailboxColumns.SYNC_INTERVAL + "<" + Mailbox.CHECK_INTERVAL_NEVER + ')'
|
||||
+ " and " + MailboxColumns.ACCOUNT_KEY + " in (";
|
||||
|
||||
public static final int SEND_FAILED = 1;
|
||||
|
@ -1930,6 +1930,7 @@ public abstract class SyncManager extends Service implements Runnable {
|
|||
startServiceThread(getServiceForMailbox(this, m));
|
||||
}
|
||||
} else if (syncInterval > 0 && syncInterval <= ONE_DAY_MINUTES) {
|
||||
// TODO: Migrating to use system SyncManager, so this should be dead code.
|
||||
long lastSync = c.getLong(Mailbox.CONTENT_SYNC_TIME_COLUMN);
|
||||
long sinceLastSync = now - lastSync;
|
||||
long toNextSync = syncInterval*MINUTES - sinceLastSync;
|
||||
|
|
|
@ -314,8 +314,6 @@ public class EmailProvider extends ContentProvider {
|
|||
public static Uri ACCOUNT_BACKUP_URI;
|
||||
private static Uri FOLDER_STATUS_URI;
|
||||
|
||||
private static Map<String, String> sProtocolTypeMap;
|
||||
|
||||
private SQLiteDatabase mDatabase;
|
||||
private SQLiteDatabase mBodyDatabase;
|
||||
|
||||
|
@ -2499,6 +2497,8 @@ public class EmailProvider extends ContentProvider {
|
|||
final long accountId = Long.parseLong(id);
|
||||
final Context context = getContext();
|
||||
|
||||
EmailServiceInfo info = null;
|
||||
|
||||
// TODO: If uiProjection is null, this will NPE. We should do everything here if it's null.
|
||||
final Set<String> projectionColumns = ImmutableSet.copyOf(uiProjection);
|
||||
|
||||
|
@ -2584,8 +2584,7 @@ public class EmailProvider extends ContentProvider {
|
|||
// TODO We should clarify/document the trash/setup relationship
|
||||
long trashId = Mailbox.findMailboxOfType(context, accountId, Mailbox.TYPE_TRASH);
|
||||
if (trashId == Mailbox.NO_MAILBOX) {
|
||||
EmailServiceInfo info = EmailServiceUtils.getServiceInfoForAccount(context,
|
||||
accountId);
|
||||
info = EmailServiceUtils.getServiceInfoForAccount(context, accountId);
|
||||
if (info != null && info.requiresSetup) {
|
||||
values.put(UIProvider.AccountColumns.SettingsColumns.SETUP_INTENT_URI,
|
||||
getExternalUriString("setup", id));
|
||||
|
@ -2593,27 +2592,16 @@ public class EmailProvider extends ContentProvider {
|
|||
}
|
||||
}
|
||||
if (projectionColumns.contains(UIProvider.AccountColumns.TYPE)) {
|
||||
final String query = "SELECT ha." + HostAuthColumns.PROTOCOL
|
||||
+ " FROM " + Account.TABLE_NAME + " a INNER JOIN " + HostAuth.TABLE_NAME
|
||||
+ " ha ON a." + AccountColumns.HOST_AUTH_KEY_RECV + " = ha."
|
||||
+ HostAuthColumns.ID
|
||||
+ " WHERE a." + AccountColumns.ID + " = ?";
|
||||
final Cursor cursor = mDatabase.rawQuery(query, new String[] { id });
|
||||
final String type;
|
||||
if (cursor.moveToFirst()) {
|
||||
loadProtocolTypeMap(context);
|
||||
final String protocol = cursor.getString(0);
|
||||
if (protocol != null && sProtocolTypeMap.containsKey(protocol)) {
|
||||
type = sProtocolTypeMap.get(protocol);
|
||||
} else {
|
||||
type = "unknown";
|
||||
}
|
||||
if (info == null) {
|
||||
info = EmailServiceUtils.getServiceInfoForAccount(context, accountId);
|
||||
}
|
||||
if (info != null) {
|
||||
type = info.accountType;
|
||||
} else {
|
||||
type = "unknown";
|
||||
}
|
||||
|
||||
cursor.close();
|
||||
|
||||
values.put(UIProvider.AccountColumns.TYPE, type);
|
||||
}
|
||||
|
||||
|
@ -3514,12 +3502,7 @@ public class EmailProvider extends ContentProvider {
|
|||
}
|
||||
}
|
||||
if (mailbox.mType == Mailbox.TYPE_OUTBOX) {
|
||||
final EmailServiceProxy service = EmailServiceUtils.getServiceForAccount(context,
|
||||
mServiceCallback, mailbox.mAccountKey);
|
||||
try {
|
||||
service.startSync(mailbox.mId, true, 0);
|
||||
} catch (RemoteException e) {
|
||||
}
|
||||
startSync(mailbox, 0);
|
||||
final long originalMsgId = msg.mSourceKey;
|
||||
if (originalMsgId != 0) {
|
||||
final Message originalMsg = Message.restoreMessageWithId(context, originalMsgId);
|
||||
|
@ -4114,11 +4097,9 @@ public class EmailProvider extends ContentProvider {
|
|||
final Context context = getContext();
|
||||
final Account account = Account.restoreAccountWithId(context, accountId);
|
||||
if (account == null) return null;
|
||||
final String protocol = account.getProtocol(context);
|
||||
loadProtocolTypeMap(context);
|
||||
final String type = sProtocolTypeMap.get(protocol);
|
||||
if (type == null) return null;
|
||||
return new android.accounts.Account(account.mEmailAddress, type);
|
||||
EmailServiceInfo info =
|
||||
EmailServiceUtils.getServiceInfo(context, account.getProtocol(context));
|
||||
return new android.accounts.Account(account.mEmailAddress, info.accountType);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4169,13 +4150,22 @@ public class EmailProvider extends ContentProvider {
|
|||
}
|
||||
}
|
||||
|
||||
private void startSync(final Mailbox mailbox, final int deltaMessageCount) {
|
||||
android.accounts.Account account = getAccountManagerAccount(mailbox.mAccountKey);
|
||||
Bundle extras = new Bundle();
|
||||
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
|
||||
extras.putBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, true);
|
||||
extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
|
||||
extras.putLong(Mailbox.SYNC_EXTRA_MAILBOX_ID, mailbox.mId);
|
||||
if (deltaMessageCount != 0) {
|
||||
extras.putInt(Mailbox.SYNC_EXTRA_DELTA_MESSAGE_COUNT, deltaMessageCount);
|
||||
}
|
||||
ContentResolver.requestSync(account, EmailContent.AUTHORITY, extras);
|
||||
}
|
||||
|
||||
private Cursor uiFolderRefresh(final Mailbox mailbox, final int deltaMessageCount) {
|
||||
if (mailbox == null) return null;
|
||||
EmailServiceProxy service = EmailServiceUtils.getServiceForAccount(getContext(),
|
||||
mServiceCallback, mailbox.mAccountKey);
|
||||
try {
|
||||
service.startSync(mailbox.mId, true, deltaMessageCount);
|
||||
} catch (RemoteException e) {
|
||||
if (mailbox != null) {
|
||||
startSync(mailbox, deltaMessageCount);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -4464,21 +4454,4 @@ public class EmailProvider extends ContentProvider {
|
|||
cursor.close();
|
||||
}
|
||||
}
|
||||
|
||||
private void loadProtocolTypeMap(final Context context) {
|
||||
if (sProtocolTypeMap == null) {
|
||||
final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
|
||||
|
||||
builder.put(context.getString(R.string.protocol_eas),
|
||||
context.getString(R.string.account_manager_type_exchange));
|
||||
builder.put(context.getString(R.string.protocol_imap),
|
||||
context.getString(R.string.account_manager_type_imap));
|
||||
builder.put(context.getString(R.string.protocol_legacy_imap),
|
||||
context.getString(R.string.account_manager_type_legacy_imap));
|
||||
builder.put(context.getString(R.string.protocol_pop3),
|
||||
context.getString(R.string.account_manager_type_pop3));
|
||||
|
||||
sProtocolTypeMap = builder.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,9 +78,6 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
|||
private static final int MAILBOX_COLUMN_SERVER_ID = 1;
|
||||
private static final int MAILBOX_COLUMN_TYPE = 2;
|
||||
|
||||
public static final String SYNC_EXTRA_MAILBOX_ID = "__mailboxId__";
|
||||
public static final String SYNC_EXTRA_DELTA_MESSAGE_COUNT = "__deltaMessageCount__";
|
||||
|
||||
/** System folders that should always exist. */
|
||||
private final int[] DEFAULT_FOLDERS = {
|
||||
Mailbox.TYPE_INBOX,
|
||||
|
@ -111,6 +108,7 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
|||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public void startSync(long mailboxId, boolean userRequest, int deltaMessageCount)
|
||||
throws RemoteException {
|
||||
|
@ -127,9 +125,9 @@ public abstract class EmailServiceStub extends IEmailService.Stub implements IEm
|
|||
extras.putBoolean(ContentResolver.SYNC_EXTRAS_DO_NOT_RETRY, true);
|
||||
extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
|
||||
}
|
||||
extras.putLong(SYNC_EXTRA_MAILBOX_ID, mailboxId);
|
||||
extras.putLong(Mailbox.SYNC_EXTRA_MAILBOX_ID, mailboxId);
|
||||
if (deltaMessageCount != 0) {
|
||||
extras.putInt(SYNC_EXTRA_DELTA_MESSAGE_COUNT, deltaMessageCount);
|
||||
extras.putInt(Mailbox.SYNC_EXTRA_DELTA_MESSAGE_COUNT, deltaMessageCount);
|
||||
}
|
||||
ContentResolver.requestSync(acct, EmailContent.AUTHORITY, extras);
|
||||
}
|
||||
|
|
|
@ -208,8 +208,8 @@ public class PopImapSyncAdapterService extends Service {
|
|||
} else {
|
||||
Log.d(TAG, "Sync request for " + acct.mDisplayName);
|
||||
Log.d(TAG, extras.toString());
|
||||
long mailboxId = extras.getLong(EmailServiceStub.SYNC_EXTRA_MAILBOX_ID,
|
||||
Mailbox.NO_MAILBOX);
|
||||
long mailboxId =
|
||||
extras.getLong(Mailbox.SYNC_EXTRA_MAILBOX_ID, Mailbox.NO_MAILBOX);
|
||||
boolean isInbox = false;
|
||||
if (mailboxId == Mailbox.NO_MAILBOX) {
|
||||
// Update folders.
|
||||
|
@ -224,7 +224,7 @@ public class PopImapSyncAdapterService extends Service {
|
|||
boolean uiRefresh =
|
||||
extras.getBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, false);
|
||||
int deltaMessageCount =
|
||||
extras.getInt(EmailServiceStub.SYNC_EXTRA_DELTA_MESSAGE_COUNT, 0);
|
||||
extras.getInt(Mailbox.SYNC_EXTRA_DELTA_MESSAGE_COUNT, 0);
|
||||
sync(context, mailboxId, syncResult, uiRefresh, deltaMessageCount);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue