From 7fbf9f957cf1d27de60f1b06e6c14e07ea7d63cc Mon Sep 17 00:00:00 2001 From: Ricardo Cerqueira Date: Mon, 10 Nov 2014 02:45:50 +0000 Subject: [PATCH] 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 --- .../emailcommon/provider/EmailContent.java | 2 ++ .../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 28826fd85..745a161e0 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/provider_src/com/android/email/provider/DBHelper.java b/provider_src/com/android/email/provider/DBHelper.java index dbeca637c..f6a0f2de3 100644 --- a/provider_src/com/android/email/provider/DBHelper.java +++ b/provider_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