diff options
| author | Jorge Ruesga <jorge@ruesga.com> | 2015-03-01 22:02:40 +0100 |
|---|---|---|
| committer | LorDClockaN <davor@losinj.com> | 2015-03-11 11:58:27 +0100 |
| commit | f6881909cc3a64aef6e6dae25d90c14a06caad5b (patch) | |
| tree | c70a0e50ff9f5a949cde2abeaff5902abdc5ef29 /src/com/android/email/provider/DBHelper.java | |
| parent | 1b01e8936e140f3247f0a0f9210aff86ca095aef (diff) | |
This change adds support for suggested contacts (email addresses not in the contact
provider and received via email). The implementation creates a new separate
"extras" database (to avoid conflicts with future aosp changes). In the table
SuggestedContacts are stored every email address present in every email inserted
in the database.
This allow to display this contacts in the RecipientEditTextView when compose an email.
Suggested contacts are selected by account (only those ones received by that account).
This features is opt-out by default, but it can be activated in general settings by
choosing the suggested contact mode:
* none: Not active
* recents: Those received within the last 7 days
* all: All the suggested contacts
Change-Id: I156c3b1e2c4e4cff985a2183bc72b805bd596f3b
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src/com/android/email/provider/DBHelper.java')
| -rw-r--r-- | src/com/android/email/provider/DBHelper.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/src/com/android/email/provider/DBHelper.java b/src/com/android/email/provider/DBHelper.java index 299e8f83e..2798ef9e1 100644 --- a/src/com/android/email/provider/DBHelper.java +++ b/src/com/android/email/provider/DBHelper.java @@ -48,6 +48,7 @@ import com.android.emailcommon.provider.EmailContent.Message; import com.android.emailcommon.provider.EmailContent.MessageColumns; import com.android.emailcommon.provider.EmailContent.PolicyColumns; import com.android.emailcommon.provider.EmailContent.QuickResponseColumns; +import com.android.emailcommon.provider.EmailContent.SuggestedContactColumns; import com.android.emailcommon.provider.EmailContent.SyncColumns; import com.android.emailcommon.provider.HostAuth; import com.android.emailcommon.provider.Mailbox; @@ -56,6 +57,7 @@ import com.android.emailcommon.provider.MessageMove; 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.LegacyPolicySet; import com.android.emailcommon.service.SyncWindow; import com.android.mail.providers.UIProvider; @@ -198,6 +200,11 @@ public final class DBHelper { // Version 101: Move body contents to external files public static final int BODY_DATABASE_VERSION = 101; + // Any changes to the database format *must* include update-in-place code. + // Original version: 1 + // Version 1: Suggested contacts + public static final int EXTRAS_DATABASE_VERSION = 1; + /* * Internal helper method for index creation. * Example: @@ -686,6 +693,24 @@ public final class DBHelper { db.execSQL(createIndex(Body.TABLE_NAME, BodyColumns.MESSAGE_KEY)); } + private static void createSuggestedContactTable(SQLiteDatabase db) { + String s = " (" + SuggestedContactColumns._ID + " integer primary key autoincrement, " + + SuggestedContactColumns.ACCOUNT_KEY + " integer, " + + SuggestedContactColumns.ADDRESS + " text, " + + SuggestedContactColumns.NAME + " text, " + + SuggestedContactColumns.DISPLAY_NAME + " text, " + + SuggestedContactColumns.LAST_SEEN + " integer" + + ");"; + db.execSQL("create table " + SuggestedContact.TABLE_NAME + s); + + // Create a unique index for account-address + String indexDDL = "create unique index " + SuggestedContact.TABLE_NAME.toLowerCase() + + "_account_address" + " on " + SuggestedContact.TABLE_NAME + + " (" + SuggestedContactColumns.ACCOUNT_KEY + ", " + + SuggestedContactColumns.ADDRESS + ");"; + db.execSQL(indexDDL); + } + private static void upgradeBodyToVersion5(final SQLiteDatabase db) { try { db.execSQL("drop table " + Body.TABLE_NAME); @@ -824,6 +849,29 @@ public final class DBHelper { } } + protected static class ExtrasDatabaseHelper extends SQLiteOpenHelper { + final Context mContext; + + ExtrasDatabaseHelper(Context context, String name) { + super(context, name, null, EXTRAS_DATABASE_VERSION); + mContext = context; + } + + @Override + public void onCreate(SQLiteDatabase db) { + LogUtils.d(TAG, "Creating EmailProviderExtras database"); + createSuggestedContactTable(db); + } + + @Override + public void onUpgrade(final SQLiteDatabase db, final int oldVersion, final int newVersion) { + } + + @Override + public void onOpen(SQLiteDatabase db) { + } + } + /** Counts the number of messages in each mailbox, and updates the message count column. */ @VisibleForTesting static void recalculateMessageCount(SQLiteDatabase db) { |
