diff options
author | Ricardo Cerqueira <ricardo@cyngn.com> | 2014-11-10 02:45:50 +0000 |
---|---|---|
committer | Ricardo Cerqueira <ricardo@cyngn.com> | 2014-11-10 03:43:49 +0000 |
commit | 44a064e5f16ddaac25f2acfc03c118f65bc48aec (patch) | |
tree | 5681f3f44beab653cc63b39973cd8205b60b5541 | |
parent | a2b8e5edcc8ae623dba3bc75a80f243539e287c5 (diff) | |
download | android_packages_apps_Email-44a064e5f16ddaac25f2acfc03c118f65bc48aec.tar.gz android_packages_apps_Email-44a064e5f16ddaac25f2acfc03c118f65bc48aec.tar.bz2 android_packages_apps_Email-44a064e5f16ddaac25f2acfc03c118f65bc48aec.zip |
DBHelper: Support upgrades from CM11
Add the new columns when coming from v126, add the old ones when
coming from any other value (or creating) so that they're there
when the feature gets reintroduced
Change-Id: I48ec042b30afbcefd43bdad0042147b6b0d2249f
-rwxr-xr-x | emailcommon/src/com/android/emailcommon/provider/EmailContent.java | 2 | ||||
-rw-r--r-- | src/com/android/email/provider/DBHelper.java | 29 |
2 files changed, 27 insertions, 4 deletions
diff --git a/emailcommon/src/com/android/emailcommon/provider/EmailContent.java b/emailcommon/src/com/android/emailcommon/provider/EmailContent.java index 4d3fffcdf..7c3ef387f 100755 --- a/emailcommon/src/com/android/emailcommon/provider/EmailContent.java +++ b/emailcommon/src/com/android/emailcommon/provider/EmailContent.java @@ -1721,6 +1721,8 @@ public abstract class EmailContent { public static final String MAX_ATTACHMENT_SIZE = "maxAttachmentSize"; // Current duration of the Exchange ping public static final String PING_DURATION = "pingDuration"; + // Automatically fetch pop3 attachments + public static final String AUTO_FETCH_ATTACHMENTS = "autoFetchAttachments"; } public interface QuickResponseColumns extends BaseColumns { diff --git a/src/com/android/email/provider/DBHelper.java b/src/com/android/email/provider/DBHelper.java index 22ce40d76..299e8f83e 100644 --- a/src/com/android/email/provider/DBHelper.java +++ b/src/com/android/email/provider/DBHelper.java @@ -184,7 +184,7 @@ public final class DBHelper { // Version 126: Decode address lists for To, From, Cc, Bcc and Reply-To columns in Message. // Version 127: Force mFlags to contain the correct flags for EAS accounts given a protocol // version above 12.0 - public static final int DATABASE_VERSION = 127; + public static final int DATABASE_VERSION = 128; // Any changes to the database format *must* include update-in-place code. // Original version: 2 @@ -517,6 +517,7 @@ public final class DBHelper { + AccountColumns.POLICY_KEY + " integer, " + AccountColumns.MAX_ATTACHMENT_SIZE + " integer, " + AccountColumns.PING_DURATION + " integer" + + AccountColumns.AUTO_FETCH_ATTACHMENTS + " integer" + ");"; db.execSQL("create table " + Account.TABLE_NAME + s); // Deleting an account deletes associated Mailboxes and HostAuth's @@ -868,6 +869,9 @@ public final class DBHelper { @Override @SuppressWarnings("deprecation") public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + + boolean fromCM11 = false; + // For versions prior to 5, delete all data // Versions >= 5 require that data be preserved! if (oldVersion < 5) { @@ -1453,7 +1457,11 @@ public final class DBHelper { } } - if (oldVersion <= 124) { + if (oldVersion == 126) { + fromCM11 = true; + } + + if (oldVersion <= 124 || fromCM11) { createCredentialsTable(db); // Add the credentialKey column, and set it to -1 for all pre-existing hostAuths. db.execSQL("alter table " + HostAuth.TABLE_NAME @@ -1462,13 +1470,26 @@ public final class DBHelper { + HostAuthColumns.CREDENTIAL_KEY + "=-1"); } - if (oldVersion <= 125) { + if (oldVersion <= 125 || fromCM11) { upgradeFromVersion125ToVersion126(db); } - if (oldVersion <= 126) { + if (oldVersion <= 126 || fromCM11) { upgradeFromVersion126ToVersion127(mContext, db); } + if (oldVersion <= 127 && !fromCM11) { + try { + db.execSQL("alter table " + Account.TABLE_NAME + + " add column " + AccountColumns.AUTO_FETCH_ATTACHMENTS + + " integer" + ";"); + final ContentValues cv = new ContentValues(1); + cv.put(AccountColumns.AUTO_FETCH_ATTACHMENTS, 0); + db.update(Account.TABLE_NAME, cv, null, null); + } catch (final SQLException e) { + // Shouldn't be needed unless we're debugging and interrupt the process + LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v127 to v128", e); + } + } } @Override |