b/9564335. Add support for a maxAttachmentSize column in the Account
table and connect the data to the Settings object in the existing
location (SettingsColumns.MAX_ATTACHMENT_SIZE).

Change-Id: Iaf48995757511e1dfb65aa35ff6d81bbc47187bd
diff --git a/emailcommon/src/com/android/emailcommon/provider/Account.java b/emailcommon/src/com/android/emailcommon/provider/Account.java
index 1f152cf..bd9998c 100755
--- a/emailcommon/src/com/android/emailcommon/provider/Account.java
+++ b/emailcommon/src/com/android/emailcommon/provider/Account.java
@@ -166,6 +166,7 @@
     public static final int CONTENT_SIGNATURE_COLUMN = 15;
     public static final int CONTENT_POLICY_KEY_COLUMN = 16;
     public static final int CONTENT_PING_DURATION_COLUMN = 17;
+    public static final int CONTENT_MAX_ATTACHMENT_SIZE_COLUMN = 18;
 
     public static final String[] CONTENT_PROJECTION = new String[] {
         RECORD_ID, AccountColumns.DISPLAY_NAME,
@@ -175,7 +176,8 @@
         AccountColumns.COMPATIBILITY_UUID, AccountColumns.SENDER_NAME,
         AccountColumns.RINGTONE_URI, AccountColumns.PROTOCOL_VERSION,
         AccountColumns.NEW_MESSAGE_COUNT, AccountColumns.SECURITY_SYNC_KEY,
-        AccountColumns.SIGNATURE, AccountColumns.POLICY_KEY, AccountColumns.PING_DURATION
+        AccountColumns.SIGNATURE, AccountColumns.POLICY_KEY, AccountColumns.PING_DURATION,
+        AccountColumns.MAX_ATTACHMENT_SIZE
     };
 
     public static final int CONTENT_MAILBOX_TYPE_COLUMN = 1;
diff --git a/emailcommon/src/com/android/emailcommon/provider/EmailContent.java b/emailcommon/src/com/android/emailcommon/provider/EmailContent.java
index 0abaa79..936fcca 100755
--- a/emailcommon/src/com/android/emailcommon/provider/EmailContent.java
+++ b/emailcommon/src/com/android/emailcommon/provider/EmailContent.java
@@ -1619,6 +1619,8 @@
         public static final String SIGNATURE = "signature";
         // A foreign key into the Policy table
         public static final String POLICY_KEY = "policyKey";
+        // Max upload attachment size.
+        public static final String MAX_ATTACHMENT_SIZE = "maxAttachmentSize";
         // Current duration of the Exchange ping
         public static final String PING_DURATION = "pingDuration";
     }
diff --git a/src/com/android/email/provider/DBHelper.java b/src/com/android/email/provider/DBHelper.java
index 3a29c4a..c9c0cf0 100644
--- a/src/com/android/email/provider/DBHelper.java
+++ b/src/com/android/email/provider/DBHelper.java
@@ -163,7 +163,8 @@
     // Version 122: Need to update Message_Updates and Message_Deletes to match previous.
     // Version 123: Changed the duplicateMesage deletion trigger to ignore accounts that aren't
     //              exchange accounts.
-    public static final int DATABASE_VERSION = 123;
+    // Version 124: Added MAX_ATTACHMENT_SIZE to the account table
+    public static final int DATABASE_VERSION = 124;
 
     // Any changes to the database format *must* include update-in-place code.
     // Original version: 2
@@ -481,6 +482,7 @@
             + AccountColumns.SECURITY_SYNC_KEY + " text, "
             + AccountColumns.SIGNATURE + " text, "
             + AccountColumns.POLICY_KEY + " integer, "
+            + AccountColumns.MAX_ATTACHMENT_SIZE + " integer, "
             + AccountColumns.PING_DURATION + " integer"
             + ");";
         db.execSQL("create table " + Account.TABLE_NAME + s);
@@ -1317,6 +1319,19 @@
                 }
                 createDeleteDuplicateMessagesTrigger(mContext, db);
             }
+
+            if (oldVersion <= 123) {
+                try {
+                    db.execSQL("alter table " + Account.TABLE_NAME
+                            + " add column " + AccountColumns.MAX_ATTACHMENT_SIZE +" integer" + ";");
+                    final ContentValues cv = new ContentValues(1);
+                    cv.put(AccountColumns.MAX_ATTACHMENT_SIZE, 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 v123 to v124", e);
+                }
+            }
         }
 
         @Override
diff --git a/src/com/android/email/provider/EmailProvider.java b/src/com/android/email/provider/EmailProvider.java
index 9555fcc..165cc0f 100644
--- a/src/com/android/email/provider/EmailProvider.java
+++ b/src/com/android/email/provider/EmailProvider.java
@@ -2463,6 +2463,8 @@
                     .add(UIProvider.AccountColumns.SettingsColumns.CONFIRM_ARCHIVE, "0")
                     .add(UIProvider.AccountColumns.SettingsColumns.CONVERSATION_VIEW_MODE,
                             Integer.toString(UIProvider.ConversationViewMode.UNDEFINED))
+                    .add(UIProvider.AccountColumns.SettingsColumns.MAX_ATTACHMENT_SIZE,
+                            AccountColumns.MAX_ATTACHMENT_SIZE)
                     .add(UIProvider.AccountColumns.SettingsColumns.VEILED_ADDRESS_PATTERN, null);
 
             final String feedbackUri = context.getString(R.string.email_feedback_uri);