summaryrefslogtreecommitdiffstats
path: root/email_src/com/android/mail/providers/proto/boot/EmailAccountService.java
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 /email_src/com/android/mail/providers/proto/boot/EmailAccountService.java
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 'email_src/com/android/mail/providers/proto/boot/EmailAccountService.java')
-rw-r--r--email_src/com/android/mail/providers/proto/boot/EmailAccountService.java94
1 files changed, 94 insertions, 0 deletions
diff --git a/email_src/com/android/mail/providers/proto/boot/EmailAccountService.java b/email_src/com/android/mail/providers/proto/boot/EmailAccountService.java
new file mode 100644
index 000000000..b2122b6bf
--- /dev/null
+++ b/email_src/com/android/mail/providers/proto/boot/EmailAccountService.java
@@ -0,0 +1,94 @@
+/**
+ * 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,
+ true);
+ // 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