Allow setting of the sync window for IMAP accounts

b/13362667
Really this is just for testing, the only window setting
that has any affect is SYNC_WINDOW_ALL. At some point we
should revisit the imap sync window strategy, right now
we will sync up to the oldest message currently on the
device, which is potentially a large amount of data.

Change-Id: I00dd59bd084e85bdf80f3991062b84fcd6a12362
This commit is contained in:
Martin Hibdon 2014-03-28 13:05:22 -07:00
parent ca7df3f234
commit c0d94a44ea
2 changed files with 24 additions and 1 deletions

View File

@ -45,6 +45,7 @@ import com.android.email.service.EmailServiceUtils;
import com.android.emailcommon.VendorPolicyLoader;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.HostAuth;
import com.android.emailcommon.service.SyncWindow;
import com.android.mail.utils.LogUtils;
import java.net.URISyntaxException;
@ -102,6 +103,10 @@ public class AccountSetupFinal extends AccountSetupActivity
private static final String EXTRA_CREATE_ACCOUNT_PASSWORD = "PASSWORD";
private static final String EXTRA_CREATE_ACCOUNT_INCOMING = "INCOMING";
private static final String EXTRA_CREATE_ACCOUNT_OUTGOING = "OUTGOING";
private static final String EXTRA_CREATE_ACCOUNT_SYNC_LOOKBACK = "SYNC_LOOKBACK";
private static final String CREATE_ACCOUNT_SYNC_ALL_VALUE = "ALL";
private static final Boolean DEBUG_ALLOW_NON_TEST_HARNESS_CREATION = false;
protected static final String ACTION_JUMP_TO_INCOMING = "jumpToIncoming";
@ -277,6 +282,13 @@ public class AccountSetupFinal extends AccountSetupActivity
final String password = intent.getStringExtra(EXTRA_CREATE_ACCOUNT_PASSWORD);
final String incoming = intent.getStringExtra(EXTRA_CREATE_ACCOUNT_INCOMING);
final String outgoing = intent.getStringExtra(EXTRA_CREATE_ACCOUNT_OUTGOING);
final String syncLookbackText = intent.getStringExtra(EXTRA_CREATE_ACCOUNT_SYNC_LOOKBACK);
final int syncLookback;
if (TextUtils.equals(syncLookbackText, CREATE_ACCOUNT_SYNC_ALL_VALUE)) {
syncLookback = SyncWindow.SYNC_WINDOW_ALL;
} else {
syncLookback = -1;
}
// If we've been explicitly provided with all the details to fill in the account, we
// can use them
final boolean explicitForm = !(TextUtils.isEmpty(user) ||
@ -326,6 +338,12 @@ public class AccountSetupFinal extends AccountSetupActivity
}
populateSetupData(user, email);
// We need to do this after calling populateSetupData(), because that will
// overwrite it with the default values.
if (syncLookback >= SyncWindow.SYNC_WINDOW_ACCOUNT &&
syncLookback <= SyncWindow.SYNC_WINDOW_ALL) {
account.mSyncLookback = syncLookback;
}
}
mState = STATE_OPTIONS;

View File

@ -58,6 +58,7 @@ import com.android.emailcommon.provider.EmailContent.SyncColumns;
import com.android.emailcommon.provider.Mailbox;
import com.android.emailcommon.service.EmailServiceStatus;
import com.android.emailcommon.service.SearchParams;
import com.android.emailcommon.service.SyncWindow;
import com.android.emailcommon.utility.AttachmentUtilities;
import com.android.mail.providers.UIProvider;
import com.android.mail.utils.LogUtils;
@ -379,7 +380,11 @@ public class ImapService extends Service {
final boolean fullSync = (uiRefresh || loadMore ||
timeSinceLastFullSync >= FULL_SYNC_INTERVAL_MILLIS || timeSinceLastFullSync < 0);
if (fullSync) {
if (account.mSyncLookback == SyncWindow.SYNC_WINDOW_ALL) {
// This is really for testing. There is no UI that allows setting the sync window for
// IMAP, but it can be set by sending a special intent to AccountSetupFinal activity.
endDate = 0;
} else if (fullSync) {
// Find the oldest message in the local store. We need our time window to include
// all messages that are currently present locally.
endDate = System.currentTimeMillis() - FULL_SYNC_WINDOW_MILLIS;