diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2015-05-01 21:35:23 +0200 |
---|---|---|
committer | Steve Kondik <steve@cyngn.com> | 2015-10-18 14:05:32 -0700 |
commit | 08ace26ed605946d788ce56f5c9aefc65131a63b (patch) | |
tree | f1014dc39087078bf19111b76427ab58ba78ad4b /provider_src/com/android/email/provider | |
parent | 3b1b30873e9c07139e2cc9fdaa796151592fea69 (diff) | |
download | android_packages_apps_Email-08ace26ed605946d788ce56f5c9aefc65131a63b.tar.gz android_packages_apps_Email-08ace26ed605946d788ce56f5c9aefc65131a63b.tar.bz2 android_packages_apps_Email-08ace26ed605946d788ce56f5c9aefc65131a63b.zip |
email: imap push
Change-Id: I8a184a5644e4322ee65d969e14cd47fe119f5df2
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'provider_src/com/android/email/provider')
3 files changed, 133 insertions, 10 deletions
diff --git a/provider_src/com/android/email/provider/DBHelper.java b/provider_src/com/android/email/provider/DBHelper.java index 18a4548fe..fa70e6f4f 100644 --- a/provider_src/com/android/email/provider/DBHelper.java +++ b/provider_src/com/android/email/provider/DBHelper.java @@ -58,6 +58,7 @@ import com.android.emailcommon.provider.MessageStateChange; import com.android.emailcommon.provider.Policy; import com.android.emailcommon.provider.QuickResponse; import com.android.emailcommon.provider.SuggestedContact; +import com.android.emailcommon.service.EmailServiceProxy; import com.android.emailcommon.service.LegacyPolicySet; import com.android.emailcommon.service.SyncWindow; import com.android.mail.providers.UIProvider; @@ -187,7 +188,8 @@ public final class DBHelper { // Version 127: Force mFlags to contain the correct flags for EAS accounts given a protocol // version above 12.0 // Version 129: Update all IMAP INBOX mailboxes to force synchronization - public static final int DATABASE_VERSION = 129; + // Version 130: Account capabilities (check EmailServiceProxy#CAPABILITY_*) + public static final int DATABASE_VERSION = 130; // Any changes to the database format *must* include update-in-place code. // Original version: 2 @@ -525,7 +527,8 @@ public final class DBHelper { + AccountColumns.POLICY_KEY + " integer, " + AccountColumns.MAX_ATTACHMENT_SIZE + " integer, " + AccountColumns.PING_DURATION + " integer, " - + AccountColumns.AUTO_FETCH_ATTACHMENTS + " integer" + + AccountColumns.AUTO_FETCH_ATTACHMENTS + " integer, " + + AccountColumns.CAPABILITIES + " integer default 0" + ");"; db.execSQL("create table " + Account.TABLE_NAME + s); // Deleting an account deletes associated Mailboxes and HostAuth's @@ -1562,6 +1565,52 @@ public final class DBHelper { + HostAuth.TABLE_NAME + "." + HostAuthColumns.PROTOCOL + "='imap'));"); } + if (oldVersion <= 130) { + //Account capabilities (check EmailServiceProxy#CAPABILITY_*) + try { + // Create capabilities field + db.execSQL("alter table " + Account.TABLE_NAME + + " add column " + AccountColumns.CAPABILITIES + + " integer" + " default 0;"); + + // Update all accounts with the appropriate capabilities + Cursor c = db.rawQuery("select " + Account.TABLE_NAME + "." + + AccountColumns._ID + ", " + HostAuth.TABLE_NAME + "." + + HostAuthColumns.PROTOCOL + " from " + Account.TABLE_NAME + ", " + + HostAuth.TABLE_NAME + " where " + Account.TABLE_NAME + "." + + AccountColumns.HOST_AUTH_KEY_RECV + " = " + HostAuth.TABLE_NAME + + "." + HostAuthColumns._ID + ";", null); + if (c != null) { + try { + while(c.moveToNext()) { + long id = c.getLong(c.getColumnIndexOrThrow(AccountColumns._ID)); + String protocol = c.getString(c.getColumnIndexOrThrow( + HostAuthColumns.PROTOCOL)); + + int capabilities = 0; + if (protocol.equals(LEGACY_SCHEME_IMAP) + || protocol.equals(LEGACY_SCHEME_EAS)) { + // Don't know yet if the imap server supports the IDLE + // capability, but since this is upgrading the account, + // just assume that all imap servers supports the push + // capability and let disable it by the IMAP service + capabilities |= EmailServiceProxy.CAPABILITY_PUSH; + } + final ContentValues cv = new ContentValues(1); + cv.put(AccountColumns.CAPABILITIES, capabilities); + db.update(Account.TABLE_NAME, cv, AccountColumns._ID + " = ?", + new String[]{String.valueOf(id)}); + } + } finally { + c.close(); + } + } + } catch (final SQLException e) { + // Shouldn't be needed unless we're debugging and interrupt the process + LogUtils.w(TAG, "Exception upgrading EmailProvider.db from v129 to v130", e); + } + } + // Due to a bug in commit 44a064e5f16ddaac25f2acfc03c118f65bc48aec, // AUTO_FETCH_ATTACHMENTS column could not be available in the Account table. // Since cm12 and up doesn't use this column, we are leave as is it. In case diff --git a/provider_src/com/android/email/provider/EmailProvider.java b/provider_src/com/android/email/provider/EmailProvider.java index 338c9fc4b..8e4e7b6a1 100644 --- a/provider_src/com/android/email/provider/EmailProvider.java +++ b/provider_src/com/android/email/provider/EmailProvider.java @@ -189,11 +189,11 @@ public class EmailProvider extends ContentProvider "vnd.android.cursor.item/email-attachment"; /** Appended to the notification URI for delete operations */ - private static final String NOTIFICATION_OP_DELETE = "delete"; + public static final String NOTIFICATION_OP_DELETE = "delete"; /** Appended to the notification URI for insert operations */ - private static final String NOTIFICATION_OP_INSERT = "insert"; + public static final String NOTIFICATION_OP_INSERT = "insert"; /** Appended to the notification URI for update operations */ - private static final String NOTIFICATION_OP_UPDATE = "update"; + public static final String NOTIFICATION_OP_UPDATE = "update"; /** The query string to trigger a folder refresh. */ protected static String QUERY_UIREFRESH = "uirefresh"; @@ -833,6 +833,7 @@ public class EmailProvider extends ContentProvider // Notify all notifier cursors sendNotifierChange(getBaseNotificationUri(match), NOTIFICATION_OP_DELETE, id); + sendSyncSettingChanged(getBaseSyncSettingChangedUri(match), NOTIFICATION_OP_DELETE, id); // Notify all email content cursors notifyUI(EmailContent.CONTENT_URI, null); @@ -1075,6 +1076,7 @@ public class EmailProvider extends ContentProvider // Notify all notifier cursors sendNotifierChange(getBaseNotificationUri(match), NOTIFICATION_OP_INSERT, id); + sendSyncSettingChanged(getBaseSyncSettingChangedUri(match), NOTIFICATION_OP_INSERT, id); // Notify all existing cursors. notifyUI(EmailContent.CONTENT_URI, null); @@ -1924,7 +1926,7 @@ public class EmailProvider extends ContentProvider private static final int INDEX_SYNC_KEY = 2; /** - * Restart push if we need it (currently only for Exchange accounts). + * Restart push if we need it. * @param context A {@link Context}. * @param db The {@link SQLiteDatabase}. * @param id The id of the thing we're looking for. @@ -1937,9 +1939,13 @@ public class EmailProvider extends ContentProvider try { if (c.moveToFirst()) { final String protocol = c.getString(INDEX_PROTOCOL); - // Only restart push for EAS accounts that have completed initial sync. - if (context.getString(R.string.protocol_eas).equals(protocol) && - !EmailContent.isInitialSyncKey(c.getString(INDEX_SYNC_KEY))) { + final String syncKey = c.getString(INDEX_SYNC_KEY); + final boolean supportsPush = + context.getString(R.string.protocol_eas).equals(protocol) || + context.getString(R.string.protocol_legacy_imap).equals(protocol); + + // Only restart push for EAS or IMAP accounts that have completed initial sync. + if (supportsPush && !EmailContent.isInitialSyncKey(syncKey)) { final String emailAddress = c.getString(INDEX_EMAIL_ADDRESS); final android.accounts.Account account = getAccountManagerAccount(context, emailAddress, protocol); @@ -2010,6 +2016,7 @@ public class EmailProvider extends ContentProvider final SQLiteDatabase db = getDatabase(context); final int table = match >> BASE_SHIFT; int result; + boolean syncSettingChanged = false; // We do NOT allow setting of unreadCount/messageCount via the provider // These columns are maintained via triggers @@ -2159,6 +2166,14 @@ public class EmailProvider extends ContentProvider } } else if (match == MESSAGE_ID) { db.execSQL(UPDATED_MESSAGE_DELETE + id); + } else if (match == MAILBOX_ID) { + if (values.containsKey(MailboxColumns.SYNC_INTERVAL)) { + syncSettingChanged = true; + } + } else if (match == ACCOUNT_ID) { + if (values.containsKey(AccountColumns.SYNC_INTERVAL)) { + syncSettingChanged = true; + } } result = db.update(tableName, values, whereWithId(id, selection), selectionArgs); @@ -2293,6 +2308,10 @@ public class EmailProvider extends ContentProvider TextUtils.isEmpty(values.getAsString(AttachmentColumns.LOCATION))) { LogUtils.w(TAG, new Throwable(), "attachment with blank location"); } + } else if (match == MAILBOX) { + if (values.containsKey(MailboxColumns.SYNC_INTERVAL)) { + syncSettingChanged = true; + } } result = db.update(tableName, values, selection, selectionArgs); break; @@ -2314,6 +2333,10 @@ public class EmailProvider extends ContentProvider // Notify all notifier cursors if some records where changed in the database if (result > 0) { sendNotifierChange(getBaseNotificationUri(match), NOTIFICATION_OP_UPDATE, id); + if (syncSettingChanged) { + sendSyncSettingChanged(getBaseSyncSettingChangedUri(match), + NOTIFICATION_OP_UPDATE, id); + } notifyUI(notificationUri, null); } return result; @@ -2544,6 +2567,21 @@ public class EmailProvider extends ContentProvider return baseUri; } + private static Uri getBaseSyncSettingChangedUri(int match) { + Uri baseUri = null; + switch (match) { + case ACCOUNT: + case ACCOUNT_ID: + baseUri = Account.SYNC_SETTING_CHANGED_URI; + break; + case MAILBOX: + case MAILBOX_ID: + baseUri = Mailbox.SYNC_SETTING_CHANGED_URI; + break; + } + return baseUri; + } + /** * Sends a change notification to any cursors observers of the given base URI. The final * notification URI is dynamically built to contain the specified information. It will be @@ -2582,6 +2620,25 @@ public class EmailProvider extends ContentProvider } } + private void sendSyncSettingChanged(Uri baseUri, String op, String id) { + if (baseUri == null) return; + + // Append the operation, if specified + if (op != null) { + baseUri = baseUri.buildUpon().appendEncodedPath(op).build(); + } + + long longId = 0L; + try { + longId = Long.valueOf(id); + } catch (NumberFormatException ignore) {} + if (longId > 0) { + notifyUI(baseUri, id); + } else { + notifyUI(baseUri, null); + } + } + private void sendMessageListDataChangedNotification() { final Context context = getContext(); final Intent intent = new Intent(ACTION_NOTIFY_MESSAGE_LIST_DATASET_CHANGED); diff --git a/provider_src/com/android/email/provider/Utilities.java b/provider_src/com/android/email/provider/Utilities.java index c3b7ec93a..e28c873c4 100644 --- a/provider_src/com/android/email/provider/Utilities.java +++ b/provider_src/com/android/email/provider/Utilities.java @@ -40,6 +40,7 @@ import com.android.emailcommon.utility.ConversionUtilities; import com.android.mail.utils.LogUtils; import com.android.mail.utils.Utils; +import java.io.InputStream; import java.io.IOException; import java.util.ArrayList; @@ -118,8 +119,9 @@ public class Utilities { ArrayList<Part> attachments = new ArrayList<Part>(); MimeUtility.collectParts(message, viewables, attachments); + // Don't close the viewables attachment InputStream yet final ConversionUtilities.BodyFieldData data = - ConversionUtilities.parseBodyFields(viewables); + ConversionUtilities.parseBodyFields(viewables, false); // set body and local message values localMessage.setFlags(data.isQuotedReply, data.isQuotedForward); @@ -166,6 +168,21 @@ public class Utilities { localMessage.mFlagAttachment = true; } + // Close any parts that may still be open + for (final Part part : viewables) { + if (part.getBody() == null) { + continue; + } + try { + InputStream is = part.getBody().getInputStream(); + if (is != null) { + is.close(); + } + } catch (IOException io) { + // Ignore + } + } + // One last update of message with two updated flags localMessage.mFlagLoaded = loadStatus; |