Add a cache for the list of accounts.

Now the EmailActivity doesn't need to know about where the results
are coming from, but can get it from the AccoutnCacheProvider

Also, this CL has the start of the integration with the Gmail mail content
At app start up, the Gmail accounts are added to the cache of accounts.

Change-Id: Iffd91d42753f35b85720c9c0a6f0a5bb7be5c3e3
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 64510ef..45d7dd9 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -19,6 +19,8 @@
     android:versionCode="1"
     android:versionName="1.0" >
 
+    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
+
     <application
         android:icon="@mipmap/ic_launcher_mail"
         android:label="@string/app_name"
@@ -48,6 +50,30 @@
             android:name=".providers.protos.mock.MockUiProvider" >
             <grant-uri-permission android:pathPattern=".*" />
         </provider>
+
+        <provider
+            android:authorities="com.android.mail.accountcache"
+            android:label="@string/account_cache_provider"
+            android:multiprocess="false"
+            android:name=".providers.AccountCacheProvider" >
+            <grant-uri-permission android:pathPattern=".*" />
+        </provider>
+
+        <provider
+            android:authorities="com.android.mail.dummygmailprovider"
+            android:label="@string/dummy_gmail_provider"
+            android:multiprocess="false"
+            android:name=".providers.protos.gmail.DummyGmailProvider" >
+            <grant-uri-permission android:pathPattern=".*" />
+        </provider>
+
+        <receiver android:name=".providers.protos.gmail.GmailIntentReceiver">
+          <intent-filter>
+            <action android:name="com.android.email.providers.protos.gmail.intent.ACTION_PROVIDER_CREATED" />
+          </intent-filter>
+        </receiver>
+
+        <service android:name=".providers.protos.gmail.GmailIntentService"/>
     </application>
 
 </manifest>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 8490794..000990e 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -24,6 +24,8 @@
     <string name="test_conversationitems" translate="false">Test Conversation Items</string>
     <string name="test_endtoend" translate="false">Test End to End with provider</string>
     <string name="mock_content_provider">Mock Content Provider</string>
+    <string name="account_cache_provider">Account Cache Provider</string>
+    <string name="dummy_gmail_provider">Dummy Gmail Provider</string>
     <string name="test_actionbar" translate="false">Test Actionbar Layout</string>
 
     <string name="app_name">Unified Email</string>
diff --git a/src/com/android/email/EmailActivity.java b/src/com/android/email/EmailActivity.java
index 315a4c7..f2cd84b 100644
--- a/src/com/android/email/EmailActivity.java
+++ b/src/com/android/email/EmailActivity.java
@@ -41,8 +41,8 @@
 import com.android.email.browse.ConversationItemView;
 import com.android.email.browse.ConversationItemViewModel;
 import com.android.email.browse.ConversationViewActivity;
+import com.android.email.providers.AccountCacheProvider;
 import com.android.email.providers.UIProvider;
-import com.android.email.providers.protos.mock.MockUiProvider;
 
 public class EmailActivity extends Activity implements OnItemSelectedListener, OnItemClickListener {
 
@@ -60,7 +60,7 @@
         mListView.setOnItemClickListener(this);
         mAccountsSpinner = (Spinner) findViewById(R.id.accounts_spinner);
         mResolver = getContentResolver();
-        Cursor cursor = mResolver.query(MockUiProvider.getAccountsUri(),
+        Cursor cursor = mResolver.query(AccountCacheProvider.getAccountsUri(),
                 UIProvider.ACCOUNTS_PROJECTION, null, null, null);
         mAccountsAdapter = new AccountsSpinnerAdapter(this, cursor);
         mAccountsSpinner.setAdapter(mAccountsAdapter);
diff --git a/src/com/android/email/providers/AccountCacheProvider.java b/src/com/android/email/providers/AccountCacheProvider.java
new file mode 100644
index 0000000..2d744fc
--- /dev/null
+++ b/src/com/android/email/providers/AccountCacheProvider.java
@@ -0,0 +1,215 @@
+/**
+ * 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.email.providers;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.database.MatrixCursor;
+import android.net.Uri;
+import android.provider.BaseColumns;
+import android.text.TextUtils;
+
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
+import com.google.common.base.Objects;
+
+import java.lang.IllegalArgumentException;
+import java.lang.Integer;
+import java.lang.String;
+import java.util.Map;
+import java.util.Set;
+
+
+/**
+ * The Account Cache provider allows email providers to register "accounts" and the UI has a single
+ * place to query for the list of accounts.
+ *
+ * During development this will allow new account types to be added, and allow them to be shown in
+ * the application.  For example, the mock accounts can be enabled/disabled.
+ * 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;
+
+    private final static Map<String, CachedAccount> ACCOUNT_CACHE = Maps.newHashMap();
+
+    private final static Set<String> VALID_ACCOUNT_PROJECTION_VALUES =
+            ImmutableSet.of(UIProvider.ACCOUNTS_PROJECTION);
+
+    public static Uri getAccountsUri() {
+        return Uri.parse(BASE_URI_STRING + "/");
+    }
+
+    @Override
+    public boolean onCreate() {
+        return true;
+    }
+
+    @Override
+    public Cursor query(Uri url, String[] projection, String selection, String[] selectionArgs,
+            String sortOrder) {
+        // This content provider currently only supports one query (to return the list of accounts).
+        // No reason to check the uri.  Currently only checking the projections
+
+        // Validates and returns the projection that should be used.
+        final String[] resultProjection = getResultProjection(projection);
+        final MatrixCursor cursor = new MatrixCursor(resultProjection);
+
+        for (CachedAccount account : ACCOUNT_CACHE.values()) {
+            final MatrixCursor.RowBuilder builder = cursor.newRow();
+
+            for (String column : resultProjection) {
+                if (TextUtils.equals(column, BaseColumns._ID)) {
+                    builder.add(Integer.valueOf((int)account.mId));
+                } else if (TextUtils.equals(column, UIProvider.AccountColumns.NAME)) {
+                    builder.add(account.mName);
+                } else if (TextUtils.equals(column, UIProvider.AccountColumns.PROVIDER_VERSION)) {
+                    // TODO fix this
+                    builder.add(Integer.valueOf(0));
+                } else if (TextUtils.equals(column, UIProvider.AccountColumns.URI)) {
+                    builder.add(account.mUri);
+                } else if (TextUtils.equals(column, UIProvider.AccountColumns.CAPABILITIES)) {
+                    builder.add(Integer.valueOf((int)account.mCapabilities));
+                } else if (TextUtils.equals(column, UIProvider.AccountColumns.FOLDER_LIST_URI)) {
+                    builder.add(account.mFolderListUri);
+                } else if (TextUtils.equals(column, UIProvider.AccountColumns.SEARCH_URI)) {
+                    builder.add(account.mSearchUri);
+                } else if (TextUtils.equals(column,
+                        UIProvider.AccountColumns.ACCOUNT_FROM_ADDRESSES_URI)) {
+                    builder.add(account.mAccountFromAddressesUri);
+                } else if (TextUtils.equals(column, UIProvider.AccountColumns.SAVE_NEW_DRAFT_URI)) {
+                    builder.add(account.mSaveDraftUri);
+                } else if (TextUtils.equals(column, UIProvider.AccountColumns.SEND_MESSAGE_URI)) {
+                    builder.add(account.mSendMessageUri);
+                }
+            }
+
+        }
+        return cursor;
+    }
+
+    private String[] getResultProjection(String[] projection) throws IllegalArgumentException {
+        final String[] resultProjection;
+        if (projection != null) {
+            for (String column : projection) {
+                if (!VALID_ACCOUNT_PROJECTION_VALUES.contains(column)) {
+                    throw new IllegalArgumentException("Invalid projection");
+                }
+            }
+            resultProjection = projection;
+        } else {
+            resultProjection = UIProvider.ACCOUNTS_PROJECTION;
+        }
+        return resultProjection;
+    }
+
+    @Override
+    public Uri insert(Uri url, ContentValues values) {
+        return url;
+    }
+
+    @Override
+    public int update(Uri url, ContentValues values, String selection,
+            String[] selectionArgs) {
+        return 0;
+    }
+
+    @Override
+    public int delete(Uri url, String selection, String[] selectionArgs) {
+        return 0;
+    }
+
+    @Override
+    public String getType(Uri uri) {
+        return null;
+    }
+
+
+    public static void addAccount(CachedAccount account) {
+        synchronized (ACCOUNT_CACHE) {
+            if (account != null) {
+                ACCOUNT_CACHE.put(account.mUri, account);
+            }
+        }
+    }
+
+    public static void removeAccount(String accountUri) {
+        synchronized (ACCOUNT_CACHE) {
+            final CachedAccount account = ACCOUNT_CACHE.get(accountUri);
+
+            if (account != null) {
+                ACCOUNT_CACHE.remove(account);
+            }
+        }
+    }
+
+    public static class CachedAccount {
+        private final long mId;
+        private final String mName;
+        private final String mUri;
+        private final long mCapabilities;
+        private final String mFolderListUri;
+        private final String mSearchUri;
+        private final String mAccountFromAddressesUri;
+        private final String mSaveDraftUri;
+        private final String mSendMessageUri;
+
+        public CachedAccount(long id, String name, String uri, long capabilities,
+                String folderListUri, String searchUri, String fromAddressesUri,
+                String saveDraftUri, String sendMessageUri) {
+            mId = id;
+            mName = name;
+            mUri = uri;
+            mCapabilities = capabilities;
+            mFolderListUri = folderListUri;
+            mSearchUri = searchUri;
+            mAccountFromAddressesUri = fromAddressesUri;
+            mSaveDraftUri = saveDraftUri;
+            mSendMessageUri = sendMessageUri;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (o == this) {
+                return true;
+            }
+
+            if ((o == null) || (o.getClass() != this.getClass())) {
+                return false;
+            }
+
+            CachedAccount other = (CachedAccount) o;
+            return mId == other.mId && TextUtils.equals(mName, other.mName) &&
+                    TextUtils.equals(mUri, other.mUri) && mCapabilities == other.mCapabilities &&
+                    TextUtils.equals(mFolderListUri, other.mFolderListUri) &&
+                    TextUtils.equals(mSearchUri, other.mSearchUri) &&
+                    TextUtils.equals(mAccountFromAddressesUri, other.mAccountFromAddressesUri) &&
+                    TextUtils.equals(mSaveDraftUri, other.mSaveDraftUri) &&
+                    TextUtils.equals(mSendMessageUri, other.mSendMessageUri);
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hashCode(mId, mName, mUri, mCapabilities, mFolderListUri, mSearchUri,
+                    mAccountFromAddressesUri, mSaveDraftUri, mSendMessageUri);
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/com/android/email/providers/protos/gmail/DummyGmailProvider.java b/src/com/android/email/providers/protos/gmail/DummyGmailProvider.java
new file mode 100644
index 0000000..2e50d1e
--- /dev/null
+++ b/src/com/android/email/providers/protos/gmail/DummyGmailProvider.java
@@ -0,0 +1,78 @@
+/**
+ * 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.email.providers.protos.gmail;
+
+import android.content.ContentProvider;
+import android.content.ContentValues;
+import android.content.Intent;
+import android.database.Cursor;
+import android.net.Uri;
+
+/**
+ * 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 {
+
+    /**
+     * Intent used to notify interested parties that the Mail provbider has been created.
+     */
+    static final String ACTION_PROVIDER_CREATED
+            = "com.android.email.providers.protos.gmail.intent.ACTION_PROVIDER_CREATED";
+
+    @Override
+    public boolean onCreate() {
+
+        final Intent intent = new Intent(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/email/providers/protos/gmail/GmailIntentReceiver.java b/src/com/android/email/providers/protos/gmail/GmailIntentReceiver.java
new file mode 100644
index 0000000..3676f1b
--- /dev/null
+++ b/src/com/android/email/providers/protos/gmail/GmailIntentReceiver.java
@@ -0,0 +1,28 @@
+/**
+ * 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.email.providers.protos.gmail;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+
+public class GmailIntentReceiver extends BroadcastReceiver {
+    @Override
+    public void onReceive(Context context, Intent intent) {
+        intent.setClass(context, GmailIntentService.class);
+        context.startService(intent);
+    }
+}
diff --git a/src/com/android/email/providers/protos/gmail/GmailIntentService.java b/src/com/android/email/providers/protos/gmail/GmailIntentService.java
new file mode 100644
index 0000000..57f2291
--- /dev/null
+++ b/src/com/android/email/providers/protos/gmail/GmailIntentService.java
@@ -0,0 +1,108 @@
+/**
+ * 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.email.providers.protos.gmail;
+
+import com.android.email.providers.AccountCacheProvider;
+import com.android.email.providers.protos.mock.MockUiProvider;
+import com.android.email.providers.UIProvider.AccountCapabilities;
+import com.android.email.providers.UIProvider.AccountColumns;
+import com.android.email.providers.UIProvider.AttachmentColumns;
+import com.android.email.providers.UIProvider.ConversationColumns;
+import com.android.email.providers.UIProvider.FolderCapabilities;
+import com.android.email.providers.UIProvider.FolderColumns;
+import com.android.email.providers.UIProvider.MessageColumns;
+
+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 java.io.IOException;
+import java.util.Map;
+
+
+/**
+ * A service to handle various intents asynchronously.
+ */
+public class GmailIntentService extends IntentService {
+    public GmailIntentService() {
+        super("GmailIntentService");
+    }
+
+    @Override
+    protected void onHandleIntent(Intent intent) {
+        final String action = intent.getAction();
+        if (DummyGmailProvider.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);
+            final AccountCacheProvider.CachedAccount cachedAccount =
+                    new AccountCacheProvider.CachedAccount(gmailAccountId,
+                            account.name,
+                            MockUiProvider.getMockAccountUri(gmailAccountId),
+                            (Long)mockAccountMap.get(AccountColumns.CAPABILITIES),
+                            (String)mockAccountMap.get(AccountColumns.FOLDER_LIST_URI),
+                            (String)mockAccountMap.get(AccountColumns.SEARCH_URI),
+                            (String)mockAccountMap.get(AccountColumns.ACCOUNT_FROM_ADDRESSES_URI),
+                            (String)mockAccountMap.get(AccountColumns.SAVE_NEW_DRAFT_URI),
+                            (String)mockAccountMap.get(AccountColumns.SEND_MESSAGE_URI));
+
+            AccountCacheProvider.addAccount(cachedAccount);
+        }
+    }
+}
\ No newline at end of file
diff --git a/src/com/android/email/providers/protos/gmail/README b/src/com/android/email/providers/protos/gmail/README
new file mode 100644
index 0000000..c54da65
--- /dev/null
+++ b/src/com/android/email/providers/protos/gmail/README
@@ -0,0 +1,9 @@
+This is a temporary directory that is being used to enable Gmail 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 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 the logged in Gmail account from the device with the
+AccountCacheProvider.  All subsequent uris will actually be handled by the Gmail application.
diff --git a/src/com/android/email/providers/protos/mock/MockUiProvider.java b/src/com/android/email/providers/protos/mock/MockUiProvider.java
index a7eb0f2..2e93cc1 100644
--- a/src/com/android/email/providers/protos/mock/MockUiProvider.java
+++ b/src/com/android/email/providers/protos/mock/MockUiProvider.java
@@ -16,6 +16,7 @@
 
 package com.android.email.providers.protos.mock;
 
+import com.android.email.providers.AccountCacheProvider;
 import com.android.email.providers.UIProvider.AccountCapabilities;
 import com.android.email.providers.UIProvider.AccountColumns;
 import com.android.email.providers.UIProvider.AttachmentColumns;
@@ -32,6 +33,7 @@
 import android.provider.BaseColumns;
 import android.text.Html;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.ImmutableList;
@@ -53,6 +55,8 @@
 
     static final String BASE_URI_STRING = "content://" + AUTHORITY;
 
+    public static final int NUM_MOCK_ACCOUNTS = 2;
+
     // 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;
@@ -219,8 +223,9 @@
         return folderMap;
     }
 
-    private static Map<String, Object> createAccountDetailsMap(int accountId) {
-        final String accountUri =  "content://" + AUTHORITY + "/account/" + accountId;
+    // Temporarily made this public to allow the Gmail accounts to use the mock ui provider uris
+    public static Map<String, Object> createAccountDetailsMap(int accountId) {
+        final String accountUri = getMockAccountUri(accountId);
         Map<String, Object> accountMap = Maps.newHashMap();
         accountMap.put(BaseColumns._ID, Long.valueOf(accountId));
         accountMap.put(AccountColumns.NAME, "Account " + accountId);
@@ -245,9 +250,15 @@
         accountMap.put(AccountColumns.ACCOUNT_FROM_ADDRESSES_URI, accountUri + "/fromAddresses");
         accountMap.put(AccountColumns.SAVE_NEW_DRAFT_URI, accountUri + "/saveDraft");
         accountMap.put(AccountColumns.SEND_MESSAGE_URI, accountUri + "/sendMessage");
+
+        addAccountInfoToAccountCache(accountMap);
         return accountMap;
     }
 
+    public static String getMockAccountUri(int accountId) {
+        return "content://" + AUTHORITY + "/account/" + accountId;
+    }
+
     @Override
     public boolean onCreate() {
         return true;
@@ -302,9 +313,26 @@
         return null;
     }
 
-    public static Uri getAccountsUri() {
+    @VisibleForTesting
+    static Uri getAccountsUri() {
         // TODO: this should probably return a different specific to the mock account list
         return Uri.parse(BASE_URI_STRING + "/");
     }
+
+    private static void addAccountInfoToAccountCache(Map<String, Object> accountInfo) {
+        final AccountCacheProvider.CachedAccount account =
+                new AccountCacheProvider.CachedAccount((Long)accountInfo.get(BaseColumns._ID),
+                        (String)accountInfo.get(AccountColumns.NAME),
+                        (String)accountInfo.get(AccountColumns.URI),
+                        (Long)accountInfo.get(AccountColumns.CAPABILITIES),
+                        (String)accountInfo.get(AccountColumns.FOLDER_LIST_URI),
+                        (String)accountInfo.get(AccountColumns.SEARCH_URI),
+                        (String)accountInfo.get(AccountColumns.ACCOUNT_FROM_ADDRESSES_URI),
+                        (String)accountInfo.get(AccountColumns.SAVE_NEW_DRAFT_URI),
+                        (String)accountInfo.get(AccountColumns.SEND_MESSAGE_URI));
+
+
+        AccountCacheProvider.addAccount(account);
+    }
 }