Remove saveOrUpdate from EmailContent to prevent stale writes

  * Numerous classes modified to deal with this change
  * Fixes bugs 1993292 and 1994671
  * Renamed various setter and getter methods to reflect the underlying
    field names
  * Renamed syncFrequency to syncInterval in Account and Mailbox
  * Convenience method added to AccountSettings to save only user settings
  * Calls to content.update(context, content.toContentValues()), which save
    all fields, should be double-checked for correctness, making sure that
    content has current data and will not conflict with other threads that
    might modify that data
  * Ran all unit tests to confirm proper function

NOTE:  The logic to enforce single default account no longer works,
because that logic is in Account.save() and does not run via
Account.update().  I have patched out a small section of the relevant unit
test and will file a bug to come back for this fix.
diff --git a/src/com/android/exchange/EasSyncService.java b/src/com/android/exchange/EasSyncService.java
index 605bdff..6464502 100644
--- a/src/com/android/exchange/EasSyncService.java
+++ b/src/com/android/exchange/EasSyncService.java
@@ -20,6 +20,7 @@
 import com.android.email.mail.AuthenticationFailedException;
 import com.android.email.mail.MessagingException;
 import com.android.exchange.EmailContent.Account;
+import com.android.exchange.EmailContent.AccountColumns;
 import com.android.exchange.EmailContent.Attachment;
 import com.android.exchange.EmailContent.AttachmentColumns;
 import com.android.exchange.EmailContent.HostAuth;
@@ -74,10 +75,10 @@
     private static final String WINDOW_SIZE = "10";
     private static final String WHERE_ACCOUNT_KEY_AND_SERVER_ID =
         MailboxColumns.ACCOUNT_KEY + "=? and " + MailboxColumns.SERVER_ID + "=?";
-    private static final String WHERE_SYNC_FREQUENCY_PING =
-        Mailbox.SYNC_FREQUENCY + '=' + Account.CHECK_INTERVAL_PING;
+    private static final String WHERE_SYNC_INTERVAL_PING =
+        Mailbox.SYNC_INTERVAL + '=' + Account.CHECK_INTERVAL_PING;
     private static final String AND_FREQUENCY_PING_PUSH_AND_NOT_ACCOUNT_MAILBOX = " AND " +
-        MailboxColumns.SYNC_FREQUENCY + " IN (" + Account.CHECK_INTERVAL_PING +
+        MailboxColumns.SYNC_INTERVAL + " IN (" + Account.CHECK_INTERVAL_PING +
         ',' + Account.CHECK_INTERVAL_PUSH + ") AND " + MailboxColumns.SERVER_ID + "!=\"" +
         Eas.ACCOUNT_MAILBOX + '\"';
     
@@ -390,14 +391,16 @@
             if (mAccount.mSyncKey == null) {
                 mAccount.mSyncKey = "0";
                 userLog("Account syncKey RESET");
-                mAccount.saveOrUpdate(mContext);
+                ContentValues cv = new ContentValues();
+                cv.put(AccountColumns.SYNC_KEY, mAccount.mSyncKey);
+                mAccount.update(mContext, cv);
             }
 
             // When we first start up, change all ping mailboxes to push.
             ContentValues cv = new ContentValues();
-            cv.put(Mailbox.SYNC_FREQUENCY, Account.CHECK_INTERVAL_PUSH);
+            cv.put(Mailbox.SYNC_INTERVAL, Account.CHECK_INTERVAL_PUSH);
             if (mContentResolver.update(Mailbox.CONTENT_URI, cv,
-                    WHERE_SYNC_FREQUENCY_PING, null) > 0) {
+                    WHERE_SYNC_INTERVAL_PING, null) > 0) {
                 SyncManager.kick();
             }
 
@@ -693,7 +696,7 @@
             if (mailbox.mSyncKey == null) {
                 userLog("Mailbox syncKey RESET");
                 mailbox.mSyncKey = "0";
-                mailbox.mSyncFrequency = Account.CHECK_INTERVAL_PUSH;
+                mailbox.mSyncInterval = Account.CHECK_INTERVAL_PUSH;
             }
             String className = target.getCollectionName();
             userLog("Sending " + className + " syncKey: " + mailbox.mSyncKey);
diff --git a/src/com/android/exchange/EmailContent.java b/src/com/android/exchange/EmailContent.java
index 0adae23..f638c4b 100644
--- a/src/com/android/exchange/EmailContent.java
+++ b/src/com/android/exchange/EmailContent.java
@@ -40,7 +40,7 @@
 /**
  * This is a local copy of com.android.email.EmailProvider
  *
- * Last copied from com.android.email.EmailProvider on 7/18/09
+ * Last copied from com.android.email.EmailProvider on 7/22/09
  */
 
 /**
@@ -109,28 +109,19 @@
         return null;
     }
     
-    /**
-     * Convenience method to save or update content.  Note:  This is designed to save or update
-     * a single row, not for any bulk changes.
-     */
-    public Uri saveOrUpdate(Context context) {
-        if (!isSaved()) {
-            return save(context);
-        } else {
-            if (update(context, toContentValues()) == 1) {
-                return getUri();
-            }
-            return null;
-        }
-    }
-    
     public Uri save(Context context) {
+        if (isSaved()) {
+            throw new UnsupportedOperationException();
+        }
         Uri res = context.getContentResolver().insert(mBaseUri, toContentValues());
         mId = Long.parseLong(res.getPathSegments().get(1));
         return res;
     }
     
     public int update(Context context, ContentValues contentValues) {
+        if (!isSaved()) {
+            throw new UnsupportedOperationException();
+        }
         return context.getContentResolver().update(getUri(), contentValues, null, null);
     }
     
@@ -168,15 +159,6 @@
 
     // All classes share this
     public static final String RECORD_ID = "_id";
-
-    static ContentProviderOperation.Builder getSaveOrUpdateBuilder(boolean doSave, 
-            Uri uri, long id) {
-        if (doSave) {
-            return ContentProviderOperation.newInsert(uri);
-        } else {
-            return ContentProviderOperation.newUpdate(ContentUris.withAppendedId(uri, id));
-        }
-    }
      
     public interface SyncColumns {
         // source (account name and type) : foreign key into the AccountsProvider
@@ -244,7 +226,7 @@
             values.put(BodyColumns.TEXT_CONTENT, mTextContent);
             
             return values;
-         }
+        }
 
          private static Body restoreBodyWithCursor(Cursor cursor) {
              try {
@@ -669,8 +651,8 @@
         }
 
         public void addSaveOps(ArrayList<ContentProviderOperation> ops) {
-             // First, save the message
-            ContentProviderOperation.Builder b = getSaveOrUpdateBuilder(true, mBaseUri, -1);
+            // First, save the message
+            ContentProviderOperation.Builder b = ContentProviderOperation.newInsert(mBaseUri);
             ops.add(b.withValues(toContentValues()).build());
 
             // Create and save the body
@@ -681,7 +663,7 @@
             if (mHtml != null) {
                 cv.put(Body.HTML_CONTENT, mHtml);
             }
-            b = getSaveOrUpdateBuilder(true, Body.CONTENT_URI, 0);
+            b = ContentProviderOperation.newInsert(Body.CONTENT_URI);
             b.withValues(cv);
             ContentValues backValues = new ContentValues();
             int messageBackValue = ops.size() - 1;
@@ -691,7 +673,7 @@
             // Create the attaachments, if any
             if (mAttachments != null) {
                 for (Attachment att: mAttachments) {
-                    ops.add(getSaveOrUpdateBuilder(true, Attachment.CONTENT_URI, -1)
+                    ops.add(ContentProviderOperation.newInsert(Attachment.CONTENT_URI)
                         .withValues(att.toContentValues())
                         .withValueBackReference(Attachment.MESSAGE_KEY, messageBackValue)
                         .build());
@@ -754,7 +736,7 @@
         // The default sync lookback period for this account
         public static final String SYNC_LOOKBACK = "syncLookback";
         // The default sync frequency for this account
-        public static final String SYNC_FREQUENCY = "syncFrequency";
+        public static final String SYNC_INTERVAL = "syncInterval";
         // A foreign key into the account manager, having host, login, password, port, and ssl flags
         public static final String HOST_AUTH_KEY_RECV = "hostAuthKeyRecv";
         // (optional) A foreign key into the account manager, having host, login, password, port,
@@ -798,7 +780,7 @@
         public String mEmailAddress;
         public String mSyncKey;
         public int mSyncLookback;
-        public int mSyncFrequency;
+        public int mSyncInterval;
         public long mHostAuthKeyRecv; 
         public long mHostAuthKeySend;
         public int mFlags;
@@ -817,7 +799,7 @@
         public static final int CONTENT_EMAIL_ADDRESS_COLUMN = 2;
         public static final int CONTENT_SYNC_KEY_COLUMN = 3;
         public static final int CONTENT_SYNC_LOOKBACK_COLUMN = 4;
-        public static final int CONTENT_SYNC_FREQUENCY_COLUMN = 5;
+        public static final int CONTENT_SYNC_INTERVAL_COLUMN = 5;
         public static final int CONTENT_HOST_AUTH_KEY_RECV_COLUMN = 6;
         public static final int CONTENT_HOST_AUTH_KEY_SEND_COLUMN = 7;
         public static final int CONTENT_FLAGS_COLUMN = 8;
@@ -830,7 +812,7 @@
         public static final String[] CONTENT_PROJECTION = new String[] {
             RECORD_ID, AccountColumns.DISPLAY_NAME,
             AccountColumns.EMAIL_ADDRESS, AccountColumns.SYNC_KEY, AccountColumns.SYNC_LOOKBACK,
-            AccountColumns.SYNC_FREQUENCY, AccountColumns.HOST_AUTH_KEY_RECV,
+            AccountColumns.SYNC_INTERVAL, AccountColumns.HOST_AUTH_KEY_RECV,
             AccountColumns.HOST_AUTH_KEY_SEND, AccountColumns.FLAGS, AccountColumns.IS_DEFAULT,
             AccountColumns.COMPATIBILITY_UUID, AccountColumns.SENDER_NAME,
             AccountColumns.RINGTONE_URI, AccountColumns.PROTOCOL_VERSION
@@ -851,7 +833,7 @@
             
             // other defaults (policy)
             mRingtoneUri = "content://settings/system/notification_sound";
-            mSyncFrequency = -1;
+            mSyncInterval = -1;
             mSyncLookback = -1;
             mFlags = FLAGS_NOTIFY_NEW_MAIL;
             mCompatibilityUuid = UUID.randomUUID().toString();
@@ -899,7 +881,7 @@
             mEmailAddress = cursor.getString(CONTENT_EMAIL_ADDRESS_COLUMN);
             mSyncKey = cursor.getString(CONTENT_SYNC_KEY_COLUMN);
             mSyncLookback = cursor.getInt(CONTENT_SYNC_LOOKBACK_COLUMN);
-            mSyncFrequency = cursor.getInt(CONTENT_SYNC_FREQUENCY_COLUMN);
+            mSyncInterval = cursor.getInt(CONTENT_SYNC_INTERVAL_COLUMN);
             mHostAuthKeyRecv = cursor.getLong(CONTENT_HOST_AUTH_KEY_RECV_COLUMN);
             mHostAuthKeySend = cursor.getLong(CONTENT_HOST_AUTH_KEY_SEND_COLUMN);
             mFlags = cursor.getInt(CONTENT_FLAGS_COLUMN);
@@ -918,7 +900,7 @@
         /**
          * @return the user-visible name for the account
          */
-        public String getDescription() {
+        public String getDisplayName() {
             return mDisplayName;
         }
         
@@ -926,14 +908,14 @@
          * Set the description.  Be sure to call save() to commit to database.
          * @param description the new description
          */
-        public void setDescription(String description) {
+        public void setDisplayName(String description) {
             mDisplayName = description;
         }
         
         /**
          * @return the email address for this account
          */
-        public String getEmail() {
+        public String getEmailAddress() {
             return mEmailAddress;
         }
         
@@ -941,14 +923,14 @@
          * Set the Email address for this account.  Be sure to call save() to commit to database.
          * @param emailAddress the new email address for this account
          */
-        public void setEmail(String emailAddress) {
+        public void setEmailAddress(String emailAddress) {
             mEmailAddress = emailAddress;
         }
         
         /**
          * @return the sender's name for this account
          */
-        public String getName() {
+        public String getSenderName() {
             return mSenderName;
         }
         
@@ -956,7 +938,7 @@
          * Set the sender's name.  Be sure to call save() to commit to database.
          * @param name the new sender name
          */
-        public void setName(String name) {
+        public void setSenderName(String name) {
             mSenderName = name;
         }
         
@@ -964,9 +946,9 @@
          * @return the minutes per check (for polling)
          * TODO define sentinel values for "never", "push", etc.  See Account.java
          */
-        public int getAutomaticCheckIntervalMinutes()
+        public int getSyncInterval()
         {
-            return mSyncFrequency;
+            return mSyncInterval;
         }
         
         /**
@@ -974,16 +956,16 @@
          * TODO define sentinel values for "never", "push", etc.  See Account.java
          * @param minutes the number of minutes between polling checks
          */
-        public void setAutomaticCheckIntervalMinutes(int minutes)
+        public void setSyncInterval(int minutes)
         {
-            mSyncFrequency = minutes;
+            mSyncInterval = minutes;
         }
         
         /**
          * @return the sync lookback window in # of days
          * TODO define sentinel values for "all", "1 month", etc.  See Account.java
          */
-        public int getSyncWindow() {
+        public int getSyncLookback() {
             return mSyncLookback;
         }
         
@@ -992,7 +974,7 @@
          * TODO define sentinel values for "all", "1 month", etc.  See Account.java
          * @param days number of days to look back for syncing messages
          */
-        public void setSyncWindow(int days) {
+        public void setSyncLookback(int days) {
             mSyncLookback = days;
         }
         
@@ -1018,7 +1000,7 @@
         /**
          * @return the ringtone Uri for this account
          */
-        public String getRingtone() {
+        public String getRingtoneUri() {
             return mRingtoneUri;
         }
         
@@ -1026,7 +1008,7 @@
          * Set the ringtone Uri for this account
          * @param newUri the new URI string for the ringtone for this account
          */
-        public void setRingtone(String newUri) {
+        public void setRingtoneUri(String newUri) {
             mRingtoneUri = newUri;
         }
         
@@ -1182,22 +1164,6 @@
             }
             return acct;
         }
-
-        /**
-         * Do not use Account.save().  Use Account.saveOrUpdate()
-         */
-        @Override 
-        public Uri save(Context context) {
-            throw new UnsupportedOperationException();
-        }
-        
-        /**
-         * Do not use Account.update().  Use Account.saveOrUpdate()
-         */
-        @Override 
-        public int update(Context context, ContentValues contentValues) {
-            throw new UnsupportedOperationException();
-        }
         
         /* 
          * Override this so that we can store the HostAuth's first and link them to the Account
@@ -1205,22 +1171,15 @@
          * @see com.android.email.provider.EmailContent#save(android.content.Context)
          */
         @Override 
-        public Uri saveOrUpdate(Context context) {
-            
-            boolean doSave = !isSaved();
-            
+        public Uri save(Context context) {
+            if (isSaved()) {
+                throw new UnsupportedOperationException();
+            }
             // This logic is in place so I can (a) short circuit the expensive stuff when
             // possible, and (b) override (and throw) if anyone tries to call save() or update()
             // directly for Account, which are unsupported.
             if (mHostAuthRecv == null && mHostAuthSend == null && mIsDefault == false) {
-                if (doSave) {
                     return super.save(context);
-                } else {
-                    if (super.update(context, toContentValues()) == 1) {
-                        return getUri();
-                    }
-                    return null;
-                }
             }
             
             int index = 0;
@@ -1232,13 +1191,13 @@
             ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>();
             if (mHostAuthRecv != null) {
                 recvIndex = index++;
-                ops.add(getSaveOrUpdateBuilder(doSave, mHostAuthRecv.mBaseUri, mHostAuthRecv.mId)
+                ops.add(ContentProviderOperation.newInsert(mHostAuthRecv.mBaseUri)
                         .withValues(mHostAuthRecv.toContentValues())
                         .build());
             }
             if (mHostAuthSend != null) {
                 sendIndex = index++;
-                ops.add(getSaveOrUpdateBuilder(doSave, mHostAuthSend.mBaseUri, mHostAuthSend.mId)
+                ops.add(ContentProviderOperation.newInsert(mHostAuthRecv.mBaseUri)
                         .withValues(mHostAuthSend.toContentValues())
                         .build());
             }
@@ -1254,7 +1213,7 @@
 
             // Now do the Account
             ContentValues cv = null;
-            if (doSave && (recvIndex >= 0 || sendIndex >= 0)) {
+            if (recvIndex >= 0 || sendIndex >= 0) {
                 cv = new ContentValues();
                 if (recvIndex >= 0) {
                     cv.put(Account.HOST_AUTH_KEY_RECV, recvIndex);
@@ -1264,34 +1223,30 @@
                 }
             }
 
-            ContentProviderOperation.Builder b = getSaveOrUpdateBuilder(doSave, mBaseUri, mId);
+            ContentProviderOperation.Builder b = ContentProviderOperation.newInsert(mBaseUri);
             b.withValues(toContentValues());
             if (cv != null) {
                 b.withValueBackReferences(cv);
             }
             ops.add(b.build());
-            
+
             try {
                 ContentProviderResult[] results = 
                     context.getContentResolver().applyBatch(EmailProvider.EMAIL_AUTHORITY, ops);
                 // If saving, set the mId's of the various saved objects
-                if (doSave) {
-                    if (recvIndex >= 0) {
-                        long newId = getId(results[recvIndex].uri);
-                        mHostAuthKeyRecv = newId;
-                        mHostAuthRecv.mId = newId;
-                    }
-                    if (sendIndex >= 0) {
-                        long newId = getId(results[sendIndex].uri);
-                        mHostAuthKeySend = newId;
-                        mHostAuthSend.mId = newId;
-                    }
-                    Uri u = results[index].uri;
-                    mId = getId(u);
-                    return u;
-                } else {
-                    return null;
+                if (recvIndex >= 0) {
+                    long newId = getId(results[recvIndex].uri);
+                    mHostAuthKeyRecv = newId;
+                    mHostAuthRecv.mId = newId;
                 }
+                if (sendIndex >= 0) {
+                    long newId = getId(results[sendIndex].uri);
+                    mHostAuthKeySend = newId;
+                    mHostAuthSend.mId = newId;
+                }
+                Uri u = results[index].uri;
+                mId = getId(u);
+                return u;
             } catch (RemoteException e) {
                 // There is nothing to be done here; fail by returning null
             } catch (OperationApplicationException e) {
@@ -1307,7 +1262,7 @@
             values.put(AccountColumns.EMAIL_ADDRESS, mEmailAddress);
             values.put(AccountColumns.SYNC_KEY, mSyncKey);
             values.put(AccountColumns.SYNC_LOOKBACK, mSyncLookback);
-            values.put(AccountColumns.SYNC_FREQUENCY, mSyncFrequency);
+            values.put(AccountColumns.SYNC_INTERVAL, mSyncInterval);
             values.put(AccountColumns.HOST_AUTH_KEY_RECV, mHostAuthKeyRecv);
             values.put(AccountColumns.HOST_AUTH_KEY_SEND, mHostAuthKeySend);
             values.put(AccountColumns.FLAGS, mFlags);
@@ -1379,7 +1334,7 @@
             dest.writeString(mEmailAddress);
             dest.writeString(mSyncKey);
             dest.writeInt(mSyncLookback);
-            dest.writeInt(mSyncFrequency);
+            dest.writeInt(mSyncInterval);
             dest.writeLong(mHostAuthKeyRecv); 
             dest.writeLong(mHostAuthKeySend);
             dest.writeInt(mFlags);
@@ -1413,7 +1368,7 @@
             mEmailAddress = in.readString();
             mSyncKey = in.readString();
             mSyncLookback = in.readInt();
-            mSyncFrequency = in.readInt();
+            mSyncInterval = in.readInt();
             mHostAuthKeyRecv = in.readLong(); 
             mHostAuthKeySend = in.readLong();
             mFlags = in.readInt();
@@ -1658,7 +1613,7 @@
         // The sync lookback period for this mailbox (or null if using the account default)
         public static final String SYNC_LOOKBACK = "syncLookback";
         // The sync frequency for this mailbox (or null if using the account default)
-        public static final String SYNC_FREQUENCY = "syncFrequency";
+        public static final String SYNC_INTERVAL = "syncInterval";
         // The time of last successful sync completion (millis)
         public static final String SYNC_TIME = "syncTime";
         // Cached unread count
@@ -1683,7 +1638,7 @@
         public int mDelimiter;
         public String mSyncKey;
         public int mSyncLookback;
-        public int mSyncFrequency;
+        public int mSyncInterval;
         public long mSyncTime;
         public int mUnreadCount;
         public boolean mFlagVisible = true;
@@ -1699,7 +1654,7 @@
         public static final int CONTENT_DELIMITER_COLUMN = 6;
         public static final int CONTENT_SYNC_KEY_COLUMN = 7;
         public static final int CONTENT_SYNC_LOOKBACK_COLUMN = 8;
-        public static final int CONTENT_SYNC_FREQUENCY_COLUMN = 9;
+        public static final int CONTENT_SYNC_INTERVAL_COLUMN = 9;
         public static final int CONTENT_SYNC_TIME_COLUMN = 10;
         public static final int CONTENT_UNREAD_COUNT_COLUMN = 11;
         public static final int CONTENT_FLAG_VISIBLE_COLUMN = 12;
@@ -1709,7 +1664,7 @@
             RECORD_ID, MailboxColumns.DISPLAY_NAME, MailboxColumns.SERVER_ID,
             MailboxColumns.PARENT_SERVER_ID, MailboxColumns.ACCOUNT_KEY, MailboxColumns.TYPE,
             MailboxColumns.DELIMITER, MailboxColumns.SYNC_KEY, MailboxColumns.SYNC_LOOKBACK,
-            MailboxColumns.SYNC_FREQUENCY, MailboxColumns.SYNC_TIME,MailboxColumns.UNREAD_COUNT,
+            MailboxColumns.SYNC_INTERVAL, MailboxColumns.SYNC_TIME,MailboxColumns.UNREAD_COUNT,
             MailboxColumns.FLAG_VISIBLE, MailboxColumns.FLAGS, MailboxColumns.VISIBLE_LIMIT
         };
         public static final long NO_MAILBOX = -1;
@@ -1790,7 +1745,7 @@
             mDelimiter = cursor.getInt(CONTENT_DELIMITER_COLUMN);
             mSyncKey = cursor.getString(CONTENT_SYNC_KEY_COLUMN);
             mSyncLookback = cursor.getInt(CONTENT_SYNC_LOOKBACK_COLUMN);
-            mSyncFrequency = cursor.getInt(CONTENT_SYNC_FREQUENCY_COLUMN);
+            mSyncInterval = cursor.getInt(CONTENT_SYNC_INTERVAL_COLUMN);
             mSyncTime = cursor.getLong(CONTENT_SYNC_TIME_COLUMN);
             mUnreadCount = cursor.getInt(CONTENT_UNREAD_COUNT_COLUMN);
             mFlagVisible = cursor.getInt(CONTENT_FLAG_VISIBLE_COLUMN) == 1;
@@ -1810,7 +1765,7 @@
             values.put(MailboxColumns.DELIMITER, mDelimiter);            
             values.put(MailboxColumns.SYNC_KEY, mSyncKey);           
             values.put(MailboxColumns.SYNC_LOOKBACK, mSyncLookback);         
-            values.put(MailboxColumns.SYNC_FREQUENCY, mSyncFrequency);           
+            values.put(MailboxColumns.SYNC_INTERVAL, mSyncInterval);           
             values.put(MailboxColumns.SYNC_TIME, mSyncTime);         
             values.put(MailboxColumns.UNREAD_COUNT, mUnreadCount);           
             values.put(MailboxColumns.FLAG_VISIBLE, mFlagVisible);           
diff --git a/src/com/android/exchange/SyncManager.java b/src/com/android/exchange/SyncManager.java
index 478d0da..927342f 100644
--- a/src/com/android/exchange/SyncManager.java
+++ b/src/com/android/exchange/SyncManager.java
@@ -244,7 +244,7 @@
             main.mServerId = Eas.ACCOUNT_MAILBOX;
             main.mAccountKey = acct.mId;
             main.mType = Mailbox.TYPE_NOT_EMAIL;
-            main.mSyncFrequency = Account.CHECK_INTERVAL_PUSH;
+            main.mSyncInterval = Account.CHECK_INTERVAL_PUSH;
             main.mFlagVisible = false;
             main.save(getContext());
             INSTANCE.log("Initializing account: " + acct.mDisplayName);
@@ -692,7 +692,7 @@
                         }
                         continue;
                     }
-                    long freq = c.getInt(Mailbox.CONTENT_SYNC_FREQUENCY_COLUMN);
+                    long freq = c.getInt(Mailbox.CONTENT_SYNC_INTERVAL_COLUMN);
                     if (freq == Account.CHECK_INTERVAL_PUSH) {
                         Mailbox m = EmailContent.getContent(c, Mailbox.class);
                         startService(m, null);
@@ -902,7 +902,7 @@
 
     static public void kick(long mailboxId) {
         Mailbox m = Mailbox.restoreMailboxWithId(INSTANCE, mailboxId);
-        int syncType = m.mSyncFrequency;
+        int syncType = m.mSyncInterval;
         if (syncType == Account.CHECK_INTERVAL_PUSH) {
             SyncManager.serviceRequestImmediate(mailboxId);
         } else {
diff --git a/src/com/android/exchange/adapter/EasContentParser.java b/src/com/android/exchange/adapter/EasContentParser.java
index a7c9294..2a962ff 100644
--- a/src/com/android/exchange/adapter/EasContentParser.java
+++ b/src/com/android/exchange/adapter/EasContentParser.java
@@ -21,11 +21,14 @@
 import java.io.InputStream;
 
 import android.content.ContentResolver;
+import android.content.ContentValues;
 import android.content.Context;
 
 import com.android.exchange.EasSyncService;
 import com.android.exchange.EmailContent.Account;
+import com.android.exchange.EmailContent.AccountColumns;
 import com.android.exchange.EmailContent.Mailbox;
+import com.android.exchange.EmailContent.MailboxColumns;
 
 /**
  * Base class for the Email and PIM sync parsers
@@ -102,7 +105,7 @@
                         mMailbox.mSyncKey = "0";
                         // Make this a push box through the first sync
                         // TODO Make frequency conditional on user settings!
-                        mMailbox.mSyncFrequency = Account.CHECK_INTERVAL_PUSH;
+                        mMailbox.mSyncInterval = Account.CHECK_INTERVAL_PUSH;
                         mService.errorLog("Bad sync key; RESET and delete contacts");
                         wipe();
                         // Indicate there's more so that we'll start syncing again
@@ -122,8 +125,8 @@
                 mService.userLog("Parsed key for " + mMailbox.mDisplayName + ": " + newKey);
                 mMailbox.mSyncKey = newKey;
                 // If we were pushing (i.e. auto-start), now we'll become ping-triggered
-                if (mMailbox.mSyncFrequency == Account.CHECK_INTERVAL_PUSH) {
-                    mMailbox.mSyncFrequency = Account.CHECK_INTERVAL_PING;
+                if (mMailbox.mSyncInterval == Account.CHECK_INTERVAL_PUSH) {
+                    mMailbox.mSyncInterval = Account.CHECK_INTERVAL_PING;
                 }
            } else {
                 skipTag();
@@ -131,7 +134,10 @@
         }
 
         // Make sure we save away the new syncKey, syncFrequency, etc.
-        mMailbox.saveOrUpdate(mContext);
+        ContentValues cv = new ContentValues();
+        cv.put(MailboxColumns.SYNC_KEY, mMailbox.mSyncKey);
+        cv.put(MailboxColumns.SYNC_INTERVAL, mMailbox.mSyncInterval);
+        mMailbox.update(mContext, cv);
         mService.userLog(mMailbox.mDisplayName + " SyncKey saved as: " + mMailbox.mSyncKey);
         // Let the caller know that there's more to do
         return moreAvailable;
diff --git a/src/com/android/exchange/adapter/EasFolderSyncParser.java b/src/com/android/exchange/adapter/EasFolderSyncParser.java
index dfbd4bc..858af38 100644
--- a/src/com/android/exchange/adapter/EasFolderSyncParser.java
+++ b/src/com/android/exchange/adapter/EasFolderSyncParser.java
@@ -23,12 +23,14 @@
 import com.android.exchange.MockParserStream;
 import com.android.exchange.SyncManager;
 import com.android.exchange.EmailContent.Account;
+import com.android.exchange.EmailContent.AccountColumns;
 import com.android.exchange.EmailContent.Mailbox;
 import com.android.exchange.EmailContent.MailboxColumns;
 
 import android.content.ContentProviderOperation;
 import android.content.ContentResolver;
 import android.content.ContentUris;
+import android.content.ContentValues;
 import android.content.Context;
 import android.content.OperationApplicationException;
 import android.database.Cursor;
@@ -147,7 +149,9 @@
             } else
                 skipTag();
         }
-        mAccount.saveOrUpdate(mContext);
+        ContentValues cv = new ContentValues();
+        cv.put(AccountColumns.SYNC_KEY, mAccount.mSyncKey);
+        mAccount.update(mContext, cv);
         return res;
     }
 
@@ -216,14 +220,14 @@
             m.mServerId = serverId;
             m.mAccountKey = mAccountId;
             m.mType = Mailbox.TYPE_MAIL;
-            m.mSyncFrequency = Account.CHECK_INTERVAL_NEVER;
+            m.mSyncInterval = Account.CHECK_INTERVAL_NEVER;
             switch (type) {
                 case INBOX_TYPE:
-                    m.mSyncFrequency = Account.CHECK_INTERVAL_PUSH;
+                    m.mSyncInterval = Account.CHECK_INTERVAL_PUSH;
                     m.mType = Mailbox.TYPE_INBOX;
                     break;
                 case OUTBOX_TYPE:
-                    m.mSyncFrequency = Account.CHECK_INTERVAL_NEVER;
+                    m.mSyncInterval = Account.CHECK_INTERVAL_NEVER;
                     // TYPE_OUTBOX mailboxes are known by SyncManager to sync whenever they aren't
                     // empty.  The value of mSyncFrequency is ignored for this kind of mailbox.
                     m.mType = Mailbox.TYPE_OUTBOX;
@@ -245,7 +249,7 @@
                 case CONTACTS_TYPE:
                     m.mType = Mailbox.TYPE_CONTACTS;
                     // TODO Frequency below should depend on settings
-                    m.mSyncFrequency = Account.CHECK_INTERVAL_PUSH;
+                    m.mSyncInterval = Account.CHECK_INTERVAL_PUSH;
                     break;
             }