From e0d4cab353b84fd632d5609d4780f597c8d56092 Mon Sep 17 00:00:00 2001 From: Scott Kennedy Date: Mon, 15 Apr 2013 12:57:35 -0700 Subject: [PATCH] Populate the account object with the type This is needed for prioritizing contact results Bug: 8587925 Change-Id: I093f0914060a01f37b175ae5877b27e0e16e9eaf --- .../android/email/provider/EmailProvider.java | 48 ++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/src/com/android/email/provider/EmailProvider.java b/src/com/android/email/provider/EmailProvider.java index f940b23aa..ad07f0343 100644 --- a/src/com/android/email/provider/EmailProvider.java +++ b/src/com/android/email/provider/EmailProvider.java @@ -67,6 +67,7 @@ import com.android.emailcommon.provider.EmailContent.Attachment; import com.android.emailcommon.provider.EmailContent.AttachmentColumns; import com.android.emailcommon.provider.EmailContent.Body; import com.android.emailcommon.provider.EmailContent.BodyColumns; +import com.android.emailcommon.provider.EmailContent.HostAuthColumns; import com.android.emailcommon.provider.EmailContent.MailboxColumns; import com.android.emailcommon.provider.EmailContent.Message; import com.android.emailcommon.provider.EmailContent.MessageColumns; @@ -374,6 +375,8 @@ public class EmailProvider extends ContentProvider { public static Uri ACCOUNT_BACKUP_URI; private static Uri FOLDER_STATUS_URI; + private static Map sProtocolTypeMap; + private SQLiteDatabase mDatabase; private SQLiteDatabase mBodyDatabase; @@ -2822,6 +2825,7 @@ outer: final long accountId = Long.parseLong(id); final Context context = getContext(); + // TODO: If uiProjection is null, this will NPE. We should do everything here if it's null. final Set projectionColumns = ImmutableSet.copyOf(uiProjection); if (projectionColumns.contains(UIProvider.AccountColumns.CAPABILITIES)) { @@ -2916,6 +2920,31 @@ outer: } } } + if (projectionColumns.contains(UIProvider.AccountColumns.TYPE)) { + final String query = "SELECT ha." + HostAuthColumns.PROTOCOL + + " FROM " + Account.TABLE_NAME + " a INNER JOIN " + HostAuth.TABLE_NAME + + " ha ON a." + AccountColumns.HOST_AUTH_KEY_RECV + " = ha." + + HostAuthColumns.ID + + " WHERE a." + AccountColumns.ID + " = ?"; + final Cursor cursor = mDatabase.rawQuery(query, new String[] { id }); + final String type; + if (cursor.moveToFirst()) { + loadProtocolTypeMap(context); + final String protocol = cursor.getString(0); + if (protocol != null && sProtocolTypeMap.containsKey(protocol)) { + type = sProtocolTypeMap.get(protocol); + } else { + type = "unknown"; + } + } else { + type = "unknown"; + } + + cursor.close(); + + values.put(UIProvider.AccountColumns.TYPE, type); + } + final StringBuilder sb = genSelect(getAccountListMap(getContext()), uiProjection, values); sb.append(" FROM " + Account.TABLE_NAME + " WHERE " + AccountColumns.ID + "=?"); return sb.toString(); @@ -3014,7 +3043,6 @@ outer: private void addCombinedAccountRow(MatrixCursor mc) { final long id = Account.getDefaultAccountId(getContext()); if (id == Account.NO_ACCOUNT) return; - final String idString = Long.toString(id); // Build a map of the requested columns to the appropriate positions final ImmutableMap.Builder builder = @@ -3041,6 +3069,9 @@ outer: values[colPosMap.get(UIProvider.AccountColumns.NAME)] = getContext().getString( R.string.mailbox_list_account_selector_combined_view); } + if (colPosMap.containsKey(UIProvider.AccountColumns.TYPE)) { + values[colPosMap.get(UIProvider.AccountColumns.TYPE)] = "unknown"; + } if (colPosMap.containsKey(UIProvider.AccountColumns.UNDO_URI)) { values[colPosMap.get(UIProvider.AccountColumns.UNDO_URI)] = "'content://" + EmailContent.AUTHORITY + "/uiundo'"; @@ -4702,4 +4733,19 @@ outer: cursor.close(); } } + + private void loadProtocolTypeMap(final Context context) { + if (sProtocolTypeMap == null) { + final ImmutableMap.Builder builder = ImmutableMap.builder(); + + builder.put(context.getString(R.string.protocol_eas), + context.getString(R.string.account_manager_type_exchange)); + builder.put(context.getString(R.string.protocol_imap), + context.getString(R.string.account_manager_type_imap)); + builder.put(context.getString(R.string.protocol_pop3), + context.getString(R.string.account_manager_type_pop3)); + + sProtocolTypeMap = builder.build(); + } + } }