From 52135c6e8750f19084695cdda78ffe34719c4b6c Mon Sep 17 00:00:00 2001 From: Martin Hibdon Date: Wed, 21 Aug 2013 10:46:55 -0700 Subject: [PATCH] Add PingDuration to the Account table b/10328857 this is so that we can keep the current ping duration and restore it on startup. Change-Id: I7ae11fd21687cb9013222924934154c5ebe1f7e7 --- .../android/emailcommon/provider/Account.java | 24 ++++++++++++++++--- .../emailcommon/provider/EmailContent.java | 2 ++ src/com/android/email/provider/DBHelper.java | 23 ++++++++++++++---- 3 files changed, 42 insertions(+), 7 deletions(-) diff --git a/emailcommon/src/com/android/emailcommon/provider/Account.java b/emailcommon/src/com/android/emailcommon/provider/Account.java index 0e5f01520..c6959e407 100755 --- a/emailcommon/src/com/android/emailcommon/provider/Account.java +++ b/emailcommon/src/com/android/emailcommon/provider/Account.java @@ -121,6 +121,7 @@ public final class Account extends EmailContent implements AccountColumns, Parce public String mSecuritySyncKey; public String mSignature; public long mPolicyKey; + public long mPingDuration; // Convenience for creating/working with an account public transient HostAuth mHostAuthRecv; @@ -144,7 +145,8 @@ public final class Account extends EmailContent implements AccountColumns, Parce public static final int CONTENT_NEW_MESSAGE_COUNT_COLUMN = 12; public static final int CONTENT_SECURITY_SYNC_KEY_COLUMN = 13; public static final int CONTENT_SIGNATURE_COLUMN = 14; - public static final int CONTENT_POLICY_KEY = 15; + public static final int CONTENT_POLICY_KEY_COLUMN = 15; + public static final int CONTENT_PING_DURATION_COLUMN = 16; public static final String[] CONTENT_PROJECTION = new String[] { RECORD_ID, AccountColumns.DISPLAY_NAME, @@ -154,7 +156,7 @@ public final class Account extends EmailContent implements AccountColumns, Parce AccountColumns.COMPATIBILITY_UUID, AccountColumns.SENDER_NAME, AccountColumns.PROTOCOL_VERSION, AccountColumns.NEW_MESSAGE_COUNT, AccountColumns.SECURITY_SYNC_KEY, - AccountColumns.SIGNATURE, AccountColumns.POLICY_KEY + AccountColumns.SIGNATURE, AccountColumns.POLICY_KEY, AccountColumns.PING_DURATION }; public static final int CONTENT_MAILBOX_TYPE_COLUMN = 1; @@ -248,7 +250,8 @@ public final class Account extends EmailContent implements AccountColumns, Parce mNewMessageCount = cursor.getInt(CONTENT_NEW_MESSAGE_COUNT_COLUMN); mSecuritySyncKey = cursor.getString(CONTENT_SECURITY_SYNC_KEY_COLUMN); mSignature = cursor.getString(CONTENT_SIGNATURE_COLUMN); - mPolicyKey = cursor.getLong(CONTENT_POLICY_KEY); + mPolicyKey = cursor.getLong(CONTENT_POLICY_KEY_COLUMN); + mPingDuration = cursor.getLong(CONTENT_PING_DURATION_COLUMN); } private static long getId(Uri u) { @@ -347,6 +350,20 @@ public final class Account extends EmailContent implements AccountColumns, Parce mSyncLookback = value; } + /** + * @return the current ping duration. + */ + public long getPingDuration() { + return mPingDuration; + } + + /** + * Set the ping duration. Be sure to call save() to commit to database. + */ + public void setPingDuration(long value) { + mPingDuration = value; + } + /** * @return the flags for this account */ @@ -762,6 +779,7 @@ public final class Account extends EmailContent implements AccountColumns, Parce values.put(AccountColumns.SECURITY_SYNC_KEY, mSecuritySyncKey); values.put(AccountColumns.SIGNATURE, mSignature); values.put(AccountColumns.POLICY_KEY, mPolicyKey); + values.put(AccountColumns.PING_DURATION, mPingDuration); return values; } diff --git a/emailcommon/src/com/android/emailcommon/provider/EmailContent.java b/emailcommon/src/com/android/emailcommon/provider/EmailContent.java index 0d8525b1f..5b7a60646 100755 --- a/emailcommon/src/com/android/emailcommon/provider/EmailContent.java +++ b/emailcommon/src/com/android/emailcommon/provider/EmailContent.java @@ -1579,6 +1579,8 @@ public abstract class EmailContent { public static final String SIGNATURE = "signature"; // A foreign key into the Policy table public static final String POLICY_KEY = "policyKey"; + // Current duration of the Exchange ping + public static final String PING_DURATION = "pingDuration"; } public interface QuickResponseColumns { diff --git a/src/com/android/email/provider/DBHelper.java b/src/com/android/email/provider/DBHelper.java index 34f38146e..6f47439f6 100644 --- a/src/com/android/email/provider/DBHelper.java +++ b/src/com/android/email/provider/DBHelper.java @@ -147,8 +147,9 @@ public final class DBHelper { // syncs along with the account). // Version 113: Restore message_count to being useful. // Version 114: Add lastFullSyncTime column + // Version 115: Add pingDuration column - public static final int DATABASE_VERSION = 114; + public static final int DATABASE_VERSION = 115; // Any changes to the database format *must* include update-in-place code. // Original version: 2 @@ -344,7 +345,8 @@ public final class DBHelper { + AccountColumns.SECURITY_FLAGS + " integer, " + AccountColumns.SECURITY_SYNC_KEY + " text, " + AccountColumns.SIGNATURE + " text, " - + AccountColumns.POLICY_KEY + " integer" + + AccountColumns.POLICY_KEY + " integer, " + + AccountColumns.PING_DURATION + " integer" + ");"; db.execSQL("create table " + Account.TABLE_NAME + s); // Deleting an account deletes associated Mailboxes and HostAuth's @@ -1064,10 +1066,23 @@ public final class DBHelper { try { db.execSQL("alter table " + Mailbox.TABLE_NAME + " add column " + MailboxColumns.LAST_FULL_SYNC_TIME +" integer" + ";"); - ContentValues cv = new ContentValues(); + final ContentValues cv = new ContentValues(1); cv.put(MailboxColumns.LAST_FULL_SYNC_TIME, 0); db.update(Mailbox.TABLE_NAME, cv, null, null); - } catch (SQLException e) { + } catch (final SQLException e) { + // Shouldn't be needed unless we're debugging and interrupt the process + LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v113 to v114", e); + } + } + + if (oldVersion <= 114) { + try { + db.execSQL("alter table " + Account.TABLE_NAME + + " add column " + AccountColumns.PING_DURATION +" integer" + ";"); + final ContentValues cv = new ContentValues(1); + cv.put(AccountColumns.PING_DURATION, 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 v113 to v114", e); }