am e1f01694: Merge "Remove auto sync windows." into jb-ub-mail-ur10

* commit 'e1f0169419f06ce5c96006c944491155470dc729':
  Remove auto sync windows.
This commit is contained in:
Yu Ping Hu 2013-06-17 09:58:49 -07:00 committed by Android Git Automerger
commit 33780e4182
7 changed files with 55 additions and 61 deletions

View File

@ -24,9 +24,7 @@ import android.database.Cursor;
import android.text.TextUtils;
import com.android.emailcommon.Logging;
import com.android.emailcommon.provider.Account;
import com.android.emailcommon.provider.EmailContent.MailboxColumns;
import com.android.emailcommon.provider.Mailbox;
import com.android.mail.utils.LogUtils;
import java.util.HashMap;
@ -43,6 +41,7 @@ public class MailboxUtilities {
* @param context the caller's context
* @param parentCursor a cursor to a mailbox that requires fixup
*/
@Deprecated
public static void setFlagsAndChildrensParentKey(Context context, Cursor parentCursor,
String accountSelector) {
ContentResolver resolver = context.getContentResolver();
@ -103,6 +102,7 @@ public class MailboxUtilities {
* @param accountSelector (see description below in fixupUninitializedParentKeys)
* @param serverId the server id of an individual mailbox
*/
@Deprecated
public static void setFlagsAndChildrensParentKey(Context context, String accountSelector,
String serverId) {
Cursor cursor = context.getContentResolver().query(Mailbox.CONTENT_URI,
@ -125,6 +125,7 @@ public class MailboxUtilities {
* @param accountSelector a sqlite WHERE clause expression to be used in determining the
* mailboxes to be acted upon, e.g. accountKey IN (1, 2), accountKey = 12, etc.
*/
@Deprecated
public static void fixupUninitializedParentKeys(Context context, String accountSelector) {
// Sanity check first on our arguments
if (accountSelector == null) throw new IllegalArgumentException();
@ -192,6 +193,7 @@ public class MailboxUtilities {
* @param context the caller's context
* @param accountId the account whose mailboxes are to be checked
*/
@Deprecated
public static void checkMailboxConsistency(Context context, long accountId) {
// If our temporary flag is set, we were interrupted during an update
// First, make sure we're current (really fast w/ caching)

View File

@ -17,7 +17,6 @@
package com.android.emailcommon.service;
public class SyncWindow {
public static final int SYNC_WINDOW_AUTO = -2;
public static final int SYNC_WINDOW_USER = -1;
public static final int SYNC_WINDOW_UNKNOWN = 0;
public static final int SYNC_WINDOW_1_DAY = 1;
@ -42,7 +41,6 @@ public class SyncWindow {
case SYNC_WINDOW_ALL:
return 365*10;
case SYNC_WINDOW_UNKNOWN:
case SYNC_WINDOW_AUTO:
default:
return 14;
}

View File

@ -63,7 +63,6 @@
<!-- Mail sync window sizes for EAS accounts -->
<string-array name="account_settings_mail_window_entries">
<item>@string/account_setup_options_mail_window_auto</item>
<item>@string/account_setup_options_mail_window_1day</item>
<item>@string/account_setup_options_mail_window_3days</item>
<item>@string/account_setup_options_mail_window_1week</item>
@ -74,7 +73,6 @@
<!-- Mail sync window size codes for EAS accounts -->
<string-array name="account_settings_mail_window_values" translatable="false">
<item>-2</item>
<item>1</item>
<item>2</item>
<item>3</item>
@ -87,7 +85,6 @@
account_settings_mail_window_entries, but has 0=default. -->
<string-array name="account_settings_mail_window_entries_with_default">
<item>@string/account_setup_options_mail_window_default</item>
<item>@string/account_setup_options_mail_window_auto</item>
<item>@string/account_setup_options_mail_window_1day</item>
<item>@string/account_setup_options_mail_window_3days</item>
<item>@string/account_setup_options_mail_window_1week</item>
@ -100,7 +97,6 @@
account_settings_mail_window_values, but has 0=default. -->
<string-array name="account_settings_mail_window_values_with_default" translatable="false">
<item>0</item>
<item>-2</item>
<item>1</item>
<item>2</item>
<item>3</item>

View File

@ -652,7 +652,7 @@ public class AccountSettingsFragment extends EmailPreferenceFragment
mSyncWindow.setTitle(R.string.account_setup_options_mail_window_label);
mSyncWindow.setValue(String.valueOf(mAccount.getSyncLookback()));
mSyncWindow.setSummary(mSyncWindow.getEntry());
MailboxSettings.setupLookbackPreferenceOptions(mContext, mSyncWindow, mAccount);
MailboxSettings.setupLookbackPreferenceOptions(mContext, mSyncWindow, mAccount, false);
// Must correspond to the hole in the XML file that's reserved.
mSyncWindow.setOrder(2);

View File

@ -72,7 +72,7 @@ public class AccountSetupOptions extends AccountSetupActivity implements OnClick
public static final int REQUEST_CODE_ACCEPT_POLICIES = 1;
/** Default sync window for new EAS accounts */
private static final int SYNC_WINDOW_EAS_DEFAULT = SyncWindow.SYNC_WINDOW_AUTO;
private static final int SYNC_WINDOW_EAS_DEFAULT = SyncWindow.SYNC_WINDOW_1_WEEK;
public static void actionOptions(Activity fromActivity) {
fromActivity.startActivity(new ForwardingIntent(fromActivity, AccountSetupOptions.class));

View File

@ -44,6 +44,8 @@ import com.android.mail.utils.LogUtils;
import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import java.util.Arrays;
/**
* "Mailbox settings" activity.
*
@ -182,30 +184,33 @@ public class MailboxSettings extends PreferenceActivity {
* @param context the caller's context
* @param pref a ListPreference to be set up
* @param account the Account (or owner of a Mailbox) whose preference is being set
* @param showWithDefault Whether to show the version with default, or without.
*/
public static void setupLookbackPreferenceOptions(Context context, ListPreference pref,
Account account) {
Resources resources = context.getResources();
public static void setupLookbackPreferenceOptions(final Context context,
final ListPreference pref, final Account account, final boolean showWithDefault) {
final Resources resources = context.getResources();
// Load the complete list of entries/values
CharSequence[] entries =
resources.getTextArray(R.array.account_settings_mail_window_entries);
CharSequence[] values =
resources.getTextArray(R.array.account_settings_mail_window_values);
CharSequence[] entries;
CharSequence[] values;
final int offset;
if (showWithDefault) {
entries = resources.getTextArray(
R.array.account_settings_mail_window_entries_with_default);
values = resources.getTextArray(
R.array.account_settings_mail_window_values_with_default);
offset = 1;
} else {
entries = resources.getTextArray(R.array.account_settings_mail_window_entries);
values = resources.getTextArray(R.array.account_settings_mail_window_values);
offset = 0;
}
// If we have a maximum lookback policy, enforce it
if (account.mPolicyKey > 0) {
Policy policy = Policy.restorePolicyWithId(context, account.mPolicyKey);
if (policy != null && (policy.mMaxEmailLookback != 0)) {
int maxEntry = policy.mMaxEmailLookback + 1;
// Copy the proper number of values into new entries/values array
CharSequence[] policyEntries = new CharSequence[maxEntry];
CharSequence[] policyValues = new CharSequence[maxEntry];
for (int i = 0; i < maxEntry; i++) {
policyEntries[i] = entries[i];
policyValues[i] = values[i];
}
// Point entries/values to the new arrays
entries = policyEntries;
values = policyValues;
final int size = policy.mMaxEmailLookback + offset;
entries = Arrays.copyOf(entries, size);
values = Arrays.copyOf(values, size);
}
}
// Set up the preference
@ -231,7 +236,8 @@ public class MailboxSettings extends PreferenceActivity {
setTitle(getString(R.string.mailbox_settings_activity_title_with_mailbox, mailboxName));
}
setupLookbackPreferenceOptions(this, mSyncLookbackPref, mAccount);
setupLookbackPreferenceOptions(this, mSyncLookbackPref, mAccount,
mMailbox.mType != Mailbox.TYPE_INBOX);
// Set default value & update summary
mSyncIntervalPref.setValue(String.valueOf(getSyncInterval()));

View File

@ -50,6 +50,7 @@ import com.android.emailcommon.provider.Mailbox;
import com.android.emailcommon.provider.Policy;
import com.android.emailcommon.provider.QuickResponse;
import com.android.emailcommon.service.LegacyPolicySet;
import com.android.emailcommon.service.SyncWindow;
import com.android.mail.providers.UIProvider;
import com.android.mail.utils.LogUtils;
import com.google.common.annotations.VisibleForTesting;
@ -139,8 +140,10 @@ public final class DBHelper {
// Version 107: Add a SEEN column to the message table
// Version 108: Add a cachedFile column to the attachments table
// Version 109: Migrate the account so they have the correct account manager types
// Version 110: Stop updating message_count, don't use auto lookback, and don't use
// ping/push_hold sync states.
public static final int DATABASE_VERSION = 109;
public static final int DATABASE_VERSION = 110;
// Any changes to the database format *must* include update-in-place code.
// Original version: 2
@ -272,35 +275,6 @@ public final class DBHelper {
" when 0 then -1 else 1 end" +
" where " + EmailContent.RECORD_ID + "=OLD." + MessageColumns.MAILBOX_KEY +
"; end");
// Add triggers to update message count per mailbox
// Insert a message.
db.execSQL("create trigger message_count_message_insert after insert on " +
Message.TABLE_NAME +
" begin update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.MESSAGE_COUNT +
'=' + MailboxColumns.MESSAGE_COUNT + "+1" +
" where " + EmailContent.RECORD_ID + "=NEW." + MessageColumns.MAILBOX_KEY +
"; end");
// Delete a message; if flagRead is zero, decrement the unread count of the msg's mailbox
db.execSQL("create trigger message_count_message_delete after delete on " +
Message.TABLE_NAME +
" begin update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.MESSAGE_COUNT +
'=' + MailboxColumns.MESSAGE_COUNT + "-1" +
" where " + EmailContent.RECORD_ID + "=OLD." + MessageColumns.MAILBOX_KEY +
"; end");
// Change a message's mailbox
db.execSQL("create trigger message_count_message_move after update of " +
MessageColumns.MAILBOX_KEY + " on " + Message.TABLE_NAME +
" begin update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.MESSAGE_COUNT +
'=' + MailboxColumns.MESSAGE_COUNT + "-1" +
" where " + EmailContent.RECORD_ID + "=OLD." + MessageColumns.MAILBOX_KEY +
"; update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.MESSAGE_COUNT +
'=' + MailboxColumns.MESSAGE_COUNT + "+1" +
" where " + EmailContent.RECORD_ID + "=NEW." + MessageColumns.MAILBOX_KEY +
"; end");
}
static void resetMessageTable(SQLiteDatabase db, int oldVersion, int newVersion) {
@ -1040,18 +1014,36 @@ public final class DBHelper {
try {
db.execSQL("alter table " + Attachment.TABLE_NAME
+ " add column " + Attachment.CACHED_FILE +" text" + ";");
oldVersion = 108;
} catch (SQLException e) {
// Shouldn't be needed unless we're debugging and interrupt the process
LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v107 to v108", e);
}
oldVersion = 108;
}
if (oldVersion == 108) {
// Migrate the accounts with the correct account type
migrateLegacyAccounts(db, mContext);
oldVersion = 109;
}
if (oldVersion == 109) {
// Delete the triggers that maintained message_count.
db.execSQL("drop trigger message_count_message_insert");
db.execSQL("drop trigger message_count_message_delete");
db.execSQL("drop trigger message_count_message_move");
// Fix any mailboxes that have ping or push_hold states.
db.execSQL("update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.SYNC_INTERVAL
+ "=" + Mailbox.CHECK_INTERVAL_PUSH + " where "
+ MailboxColumns.SYNC_INTERVAL + "<" + Mailbox.CHECK_INTERVAL_PUSH);
// Fix invalid syncLookback values.
db.execSQL("update " + Account.TABLE_NAME + " set " + AccountColumns.SYNC_LOOKBACK
+ "=null where " + AccountColumns.SYNC_LOOKBACK +"<"
+ SyncWindow.SYNC_WINDOW_1_DAY);
db.execSQL("update " + Mailbox.TABLE_NAME + " set " + MailboxColumns.SYNC_LOOKBACK
+ "=null where " + MailboxColumns.SYNC_LOOKBACK + "<"
+ SyncWindow.SYNC_WINDOW_1_DAY);
}
}
@Override