summaryrefslogtreecommitdiffstats
path: root/src/com/android/mail
diff options
context:
space:
mode:
authorPaul Westbrook <pwestbro@google.com>2012-02-07 15:23:42 -0800
committerPaul Westbrook <pwestbro@google.com>2012-02-08 10:28:08 -0800
commit77177b171c483d485bdbff0178564394e8f57d0f (patch)
tree516f9c43c4d0ad02d66cd92124aad62603c5eadf /src/com/android/mail
parente7a2422ebff93a73340aceab4c006909bccca8a9 (diff)
downloadandroid_packages_apps_UnifiedEmail-77177b171c483d485bdbff0178564394e8f57d0f.tar.gz
android_packages_apps_UnifiedEmail-77177b171c483d485bdbff0178564394e8f57d0f.tar.bz2
android_packages_apps_UnifiedEmail-77177b171c483d485bdbff0178564394e8f57d0f.zip
Start of restructuring to allow overlays include subset of providers
This allows us to build a UnifiedEmail that supports all providers and use this base to build applications that only supports a subset of the providers Made AccountCacheProvider and ConversationProvider abstract. This allows the extending class to specify the authority that should be used (This allows both UnifiedEmail and Gmail to be installed at the same time) Change-Id: I31295f4630906e7182e423fcbb7b47c33ba4cd4f
Diffstat (limited to 'src/com/android/mail')
-rw-r--r--src/com/android/mail/browse/ConversationCursor.java17
-rw-r--r--src/com/android/mail/providers/AccountCacheProvider.java16
-rw-r--r--src/com/android/mail/providers/protos/boot/AccountReceiver.java36
-rw-r--r--src/com/android/mail/providers/protos/boot/EmailAccountService.java93
-rw-r--r--src/com/android/mail/providers/protos/boot/GmailAccountService.java141
-rw-r--r--src/com/android/mail/providers/protos/boot/README9
-rw-r--r--src/com/android/mail/providers/protos/gmail/DummyGmailProvider.java75
-rw-r--r--src/com/android/mail/providers/protos/mock/MockUiProvider.java15
8 files changed, 30 insertions, 372 deletions
diff --git a/src/com/android/mail/browse/ConversationCursor.java b/src/com/android/mail/browse/ConversationCursor.java
index 05c1e69cb..30f7dddf1 100644
--- a/src/com/android/mail/browse/ConversationCursor.java
+++ b/src/com/android/mail/browse/ConversationCursor.java
@@ -52,10 +52,6 @@ public final class ConversationCursor implements Cursor {
private static final String TAG = "ConversationCursor";
private static final boolean DEBUG = true; // STOPSHIP Set to false before shipping
- // The authority of our conversation provider (a forwarding provider)
- // This string must match the declaration in AndroidManifest.xml
- private static final String sAuthority = "com.android.mail.conversation.provider";
-
// The cursor instantiator's activity
private static Activity sActivity;
// The cursor underlying the caching cursor
@@ -243,7 +239,8 @@ public final class ConversationCursor implements Cursor {
*/
private static String uriToCachingUriString (Uri uri) {
String provider = uri.getAuthority();
- return uri.getScheme() + "://" + sAuthority + "/" + provider + uri.getPath();
+ return uri.getScheme() + "://" + ConversationProvider.AUTHORITY
+ + "/" + provider + uri.getPath();
}
/**
@@ -653,12 +650,18 @@ public final class ConversationCursor implements Cursor {
* and inserts directly, and caches updates/deletes before passing them through. The caching
* will cause a redraw of the list with updated values.
*/
- public static class ConversationProvider extends ContentProvider {
- public static final String AUTHORITY = sAuthority;
+ public abstract static class ConversationProvider extends ContentProvider {
+ public static String AUTHORITY;
+
+ /**
+ * Allows the implmenting provider to specify the authority that should be used.
+ */
+ protected abstract String getAuthority();
@Override
public boolean onCreate() {
sProvider = this;
+ AUTHORITY = getAuthority();
return true;
}
diff --git a/src/com/android/mail/providers/AccountCacheProvider.java b/src/com/android/mail/providers/AccountCacheProvider.java
index 8f1fcb810..e2120bf25 100644
--- a/src/com/android/mail/providers/AccountCacheProvider.java
+++ b/src/com/android/mail/providers/AccountCacheProvider.java
@@ -41,19 +41,25 @@ import java.util.Map;
* In the future, once other processes can add new accounts, this could allow other "mail"
* applications have their content appear within the application
*/
-public final class AccountCacheProvider extends ContentProvider {
-
- private static final String AUTHORITY = "com.android.mail.accountcache";
- private static final String BASE_URI_STRING = "content://" + AUTHORITY;
+public abstract class AccountCacheProvider extends ContentProvider {
private final static Map<String, CachedAccount> ACCOUNT_CACHE = Maps.newHashMap();
+ private static String sAuthority;
+
+ /**
+ * Allows the implmenting provider to specify the authority that should be used.
+ */
+ protected abstract String getAuthority();
+
+
public static Uri getAccountsUri() {
- return Uri.parse(BASE_URI_STRING + "/");
+ return Uri.parse("content://" + sAuthority + "/");
}
@Override
public boolean onCreate() {
+ sAuthority = getAuthority();
return true;
}
diff --git a/src/com/android/mail/providers/protos/boot/AccountReceiver.java b/src/com/android/mail/providers/protos/boot/AccountReceiver.java
deleted file mode 100644
index 8e67ea5e1..000000000
--- a/src/com/android/mail/providers/protos/boot/AccountReceiver.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/**
- * Copyright (c) 2011, Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.mail.providers.protos.boot;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-
-public class AccountReceiver extends BroadcastReceiver {
- /**
- * Intent used to notify interested parties that the Mail provider has been created.
- */
- public static final String ACTION_PROVIDER_CREATED
- = "com.android.mail.providers.protos.boot.intent.ACTION_PROVIDER_CREATED";
-
- @Override
- public void onReceive(Context context, Intent intent) {
- intent.setClass(context, GmailAccountService.class);
- context.startService(intent);
- intent.setClass(context, EmailAccountService.class);
- context.startService(intent);
- }
-}
diff --git a/src/com/android/mail/providers/protos/boot/EmailAccountService.java b/src/com/android/mail/providers/protos/boot/EmailAccountService.java
deleted file mode 100644
index 682a07024..000000000
--- a/src/com/android/mail/providers/protos/boot/EmailAccountService.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Copyright (c) 2011, Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.mail.providers.protos.boot;
-
-import com.android.emailcommon.provider.Account;
-import com.android.emailcommon.provider.EmailContent;
-import com.android.mail.providers.UIProvider.AccountCapabilities;
-import com.android.mail.providers.UIProvider.AccountColumns;
-import com.android.mail.providers.protos.mock.MockUiProvider;
-import com.android.mail.providers.AccountCacheProvider;
-
-import java.util.Map;
-
-import android.app.IntentService;
-import android.content.Intent;
-import android.database.Cursor;
-
-/**
- * A service to handle various intents asynchronously.
- */
-public class EmailAccountService extends IntentService {
- private static final long BASE_EAS_CAPABILITIES =
- AccountCapabilities.SYNCABLE_FOLDERS |
- AccountCapabilities.FOLDER_SERVER_SEARCH |
- AccountCapabilities.SANITIZED_HTML |
- AccountCapabilities.SMART_REPLY |
- AccountCapabilities.SERVER_SEARCH;
-
- private static String getUriString(String type, String accountName) {
- return EmailContent.CONTENT_URI.toString() + "/" + type + "/" + accountName;
- }
-
- public EmailAccountService() {
- super("EmailAccountService");
- }
-
- @Override
- protected void onHandleIntent(Intent intent) {
- final String action = intent.getAction();
- if (AccountReceiver.ACTION_PROVIDER_CREATED.equals(action)) {
- // Register all Email accounts
- getAndRegisterEmailAccounts();
- }
- }
-
- private void getAndRegisterEmailAccounts() {
- // Use EmailProvider to get our accounts
- Cursor c = getContentResolver().query(Account.CONTENT_URI, Account.CONTENT_PROJECTION, null,
- null, null);
- if (c == null) return;
- try {
- int i = 0;
- while (c.moveToNext()) {
- final Map<String, Object> mockAccountMap =
- MockUiProvider.createAccountDetailsMap(i % MockUiProvider.NUM_MOCK_ACCOUNTS);
- // Send our account information to the cache provider
- String accountName = c.getString(Account.CONTENT_EMAIL_ADDRESS_COLUMN);
- final AccountCacheProvider.CachedAccount cachedAccount =
- new AccountCacheProvider.CachedAccount(
- c.getLong(Account.CONTENT_ID_COLUMN),
- accountName,
- getUriString("uiaccount", accountName),
- // TODO: Check actual account protocol and return proper values
- BASE_EAS_CAPABILITIES,
- getUriString("uifolders", accountName),
- (String)mockAccountMap.get(AccountColumns.SEARCH_URI),
- (String)mockAccountMap.get(AccountColumns.ACCOUNT_FROM_ADDRESSES_URI),
- getUriString("uisavedraft", accountName),
- getUriString("uisendmail", accountName),
- (String)mockAccountMap.get(AccountColumns.EXPUNGE_MESSAGE_URI),
- getUriString("uiundo", accountName));
-
- AccountCacheProvider.addAccount(cachedAccount);
- i++;
- }
- } finally {
- c.close();
- }
- }
-} \ No newline at end of file
diff --git a/src/com/android/mail/providers/protos/boot/GmailAccountService.java b/src/com/android/mail/providers/protos/boot/GmailAccountService.java
deleted file mode 100644
index 62524c59f..000000000
--- a/src/com/android/mail/providers/protos/boot/GmailAccountService.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/**
- * Copyright (c) 2011, Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.mail.providers.protos.boot;
-
-import com.android.mail.providers.AccountCacheProvider;
-import com.android.mail.providers.protos.mock.MockUiProvider;
-import com.android.mail.providers.UIProvider.AccountCapabilities;
-import com.android.mail.providers.UIProvider.AccountColumns;
-
-import android.accounts.Account;
-import android.accounts.AccountManager;
-import android.accounts.AccountManagerFuture;
-import android.accounts.AuthenticatorException;
-import android.accounts.OperationCanceledException;
-
-import android.app.IntentService;
-import android.content.Intent;
-import android.net.Uri;
-
-import java.io.IOException;
-import java.util.Map;
-
-
-/**
- * A service to handle various intents asynchronously.
- */
-public class GmailAccountService extends IntentService {
-
- private static final String GMAIL_UI_PROVIDER_AUTHORITY = "com.android.gmail.ui";
- private static final String GMAIL_UI_PROVIDER_BASE_URI_STRING =
- "content://" + GMAIL_UI_PROVIDER_AUTHORITY;
-
- private static Uri getAccountUri(String account) {
- return Uri.parse(GMAIL_UI_PROVIDER_BASE_URI_STRING + "/account/" + account);
- }
-
- private static Uri getAccountFoldersUri(String account) {
- return Uri.parse(GMAIL_UI_PROVIDER_BASE_URI_STRING + "/" + account + "/labels");
- }
-
- private static Uri getAccountSendMailUri(String account) {
- return Uri.parse(GMAIL_UI_PROVIDER_BASE_URI_STRING + "/" + account + "/sendNewMessage");
- }
-
- private static Uri getAccountSaveDraftUri(String account) {
- return Uri.parse(GMAIL_UI_PROVIDER_BASE_URI_STRING + "/" + account + "/saveNewMessage");
- }
-
- public GmailAccountService() {
- super("GmailAccountService");
- }
-
- @Override
- protected void onHandleIntent(Intent intent) {
- final String action = intent.getAction();
- if (AccountReceiver.ACTION_PROVIDER_CREATED.equals(action)) {
- // Register all Gmail accounts
- getAndRegisterGmailAccounts();
- }
- }
-
- private void getAndRegisterGmailAccounts() {
- // Get the list of Google accounts that have the mail feature, and register thiese with
- // the AccountCacheProvider
- AccountManagerFuture<Account[]> future;
- future = AccountManager.get(this).getAccountsByTypeAndFeatures(
- "com.google",
- // Ideally we would call GoogleLoginServiceConstants.featureForService("mail") here,
- // but we can't depend on Google code from this project. Just use the resulting
- // value
- new String[] { "service_mail" },
- null, null);
- try {
- // Block this IntentService on the result because this thread may not be around later
- // to handle anything if it's killed in the interim. This is a blockable non-UI thread.
- Account[] accounts = future.getResult();
-
- registerGmailAccounts(accounts);
- } catch (OperationCanceledException oce) {
- // should not happen.
- } catch (IOException ioe) {
- // should not happen
- } catch (AuthenticatorException ae) {
- // should not happen
- }
- }
-
- private void registerGmailAccounts(Account[] accounts) {
- for (int i = 0; i < accounts.length; i++) {
- final Account account = accounts[i];
-
- final int gmailAccountId = account.hashCode();
-
- // NOTE: This doesn't completely populate the provider. A query for the account uri
- // will not return a cursor.
- final Map<String, Object> mockAccountMap =
- MockUiProvider.createAccountDetailsMap(i % MockUiProvider.NUM_MOCK_ACCOUNTS);
- // TODO: where should this really be stored?
- long capabilities = Long.valueOf(
- AccountCapabilities.SYNCABLE_FOLDERS |
- AccountCapabilities.REPORT_SPAM |
- AccountCapabilities.ARCHIVE |
- AccountCapabilities.MUTE |
- AccountCapabilities.SERVER_SEARCH |
- AccountCapabilities.FOLDER_SERVER_SEARCH |
- AccountCapabilities.SANITIZED_HTML |
- AccountCapabilities.DRAFT_SYNCHRONIZATION |
- AccountCapabilities.MULTIPLE_FROM_ADDRESSES |
- AccountCapabilities.LOCAL_SEARCH |
- AccountCapabilities.THREADED_CONVERSATIONS |
- AccountCapabilities.MULTIPLE_FOLDERS_PER_CONV);
- final AccountCacheProvider.CachedAccount cachedAccount =
- new AccountCacheProvider.CachedAccount(gmailAccountId,
- account.name,
- getAccountUri(account.name).toString(),
- capabilities,
- getAccountFoldersUri(account.name).toString(),
- (String)mockAccountMap.get(AccountColumns.SEARCH_URI),
- (String)mockAccountMap.get(AccountColumns.ACCOUNT_FROM_ADDRESSES_URI),
- getAccountSaveDraftUri(account.name).toString(),
- getAccountSendMailUri(account.name).toString(),
- (String)mockAccountMap.get(AccountColumns.EXPUNGE_MESSAGE_URI),
- (String)mockAccountMap.get(AccountColumns.UNDO_URI));
-
- AccountCacheProvider.addAccount(cachedAccount);
- }
- }
-} \ No newline at end of file
diff --git a/src/com/android/mail/providers/protos/boot/README b/src/com/android/mail/providers/protos/boot/README
deleted file mode 100644
index 2c8088384..000000000
--- a/src/com/android/mail/providers/protos/boot/README
+++ /dev/null
@@ -1,9 +0,0 @@
-This is a temporary directory that is being used to enable content to be shown in the
-UnifiedEmail application
-
-This code should only be used for development. For shipping, this code (or something similar)
-should go in the Gmail/Email overlay of UnifiedEmail. But for now, this allows us to use a single
-application to test multiple content sources
-
-This code is just a shim to register existing accounts (Gmail and Email) from the device with the
-AccountCacheProvider. All subsequent uris will actually be handled by the appropriate application.
diff --git a/src/com/android/mail/providers/protos/gmail/DummyGmailProvider.java b/src/com/android/mail/providers/protos/gmail/DummyGmailProvider.java
deleted file mode 100644
index ed9a0759f..000000000
--- a/src/com/android/mail/providers/protos/gmail/DummyGmailProvider.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2011 Google Inc.
- * Licensed to The Android Open Source Project.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *******************************************************************************/
-package com.android.mail.providers.protos.gmail;
-
-import android.content.ContentProvider;
-import android.content.ContentValues;
-import android.content.Intent;
-import android.database.Cursor;
-import android.net.Uri;
-
-import com.android.mail.providers.protos.boot.AccountReceiver;
-
-/**
- * The sole purpose of this provider is to leverage on the fact the the system will create any
- * listed content providers when the app starts up. We use this fact to initiate the load of the
- * Gmail accounts, to cache them in the AccountCacheProvider.
- *
- * Ideally, this wouldn't be nessary, and instead the code that registers the Gmail accounts could
- * use static initialization to kick off the process to cache the accounts. Unfortunately
- * at that time, there is not valid context
- */
-public final class DummyGmailProvider extends ContentProvider {
-
- @Override
- public boolean onCreate() {
-
- final Intent intent = new Intent(AccountReceiver.ACTION_PROVIDER_CREATED);
- getContext().sendBroadcast(intent);
-
- // TODO(pwestbro): consider putting the retrieval of the account list here. This would
- // allow us to handle queries for the account uris
- return true;
- }
-
- @Override
- public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs,
- String sortOrder) {
- throw new IllegalArgumentException("Don't Use this provider");
- }
-
- @Override
- public Uri insert(Uri url, ContentValues values) {
- throw new IllegalArgumentException("Don't Use this provider");
- }
-
- @Override
- public int update(Uri url, ContentValues values, String selection,
- String[] selectionArgs) {
- throw new IllegalArgumentException("Don't Use this provider");
- }
-
- @Override
- public int delete(Uri url, String selection, String[] selectionArgs) {
- throw new IllegalArgumentException("Don't Use this provider");
- }
-
- @Override
- public String getType(Uri uri) {
- throw new IllegalArgumentException("Don't Use this provider");
- }
-}
diff --git a/src/com/android/mail/providers/protos/mock/MockUiProvider.java b/src/com/android/mail/providers/protos/mock/MockUiProvider.java
index 80b72729b..1d7302094 100644
--- a/src/com/android/mail/providers/protos/mock/MockUiProvider.java
+++ b/src/com/android/mail/providers/protos/mock/MockUiProvider.java
@@ -59,9 +59,10 @@ public final class MockUiProvider extends ContentProvider {
// A map of query result for uris
// TODO(pwestbro) read this map from an external
- private static final Map<String, List<Map<String, Object>>> MOCK_QUERY_RESULTS;
+ private static Map<String, List<Map<String, Object>>> MOCK_QUERY_RESULTS = Maps.newHashMap();
- static {
+
+ public static void initializeMockProvider() {
ImmutableMap.Builder<String, List<Map<String, Object>>> builder = ImmutableMap.builder();
// Add results for account list
@@ -69,14 +70,14 @@ public final class MockUiProvider extends ContentProvider {
Map<String, Object> accountDetailsMap0;
// Account 1
- accountDetailsMap0 = createAccountDetailsMap(0);
+ accountDetailsMap0 = createAccountDetailsMap(0, true);
accountList.add(accountDetailsMap0);
String accountUri1 = (String)accountDetailsMap0.get(AccountColumns.URI);
builder.put(accountUri1, ImmutableList.of(accountDetailsMap0));
// Account 2
- Map<String, Object> accountDetailsMap1 = createAccountDetailsMap(1);
+ Map<String, Object> accountDetailsMap1 = createAccountDetailsMap(1, true);
accountList.add(accountDetailsMap1);
String accountUri2 = (String) accountDetailsMap1.get(AccountColumns.URI);
@@ -241,7 +242,7 @@ public final class MockUiProvider extends ContentProvider {
}
// Temporarily made this public to allow the Gmail accounts to use the mock ui provider uris
- public static Map<String, Object> createAccountDetailsMap(int accountId) {
+ public static Map<String, Object> createAccountDetailsMap(int accountId, boolean cacheMap) {
final String accountUri = getMockAccountUri(accountId);
Map<String, Object> accountMap = Maps.newHashMap();
accountMap.put(BaseColumns._ID, Long.valueOf(accountId));
@@ -271,7 +272,9 @@ public final class MockUiProvider extends ContentProvider {
accountMap.put(AccountColumns.EXPUNGE_MESSAGE_URI, accountUri + "/expungeMessage");
accountMap.put(AccountColumns.UNDO_URI, accountUri + "/undo");
- addAccountInfoToAccountCache(accountMap);
+ if (cacheMap) {
+ addAccountInfoToAccountCache(accountMap);
+ }
return accountMap;
}