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
diff --git a/Android.mk b/Android.mk
index 92084fc..71fc13e 100644
--- a/Android.mk
+++ b/Android.mk
@@ -22,7 +22,7 @@
 # Build APK
 include $(CLEAR_VARS)
 
-src_dirs := src
+src_dirs := src unified_src email_src gmail_src
 LOCAL_PACKAGE_NAME := UnifiedEmail
 
 LOCAL_STATIC_JAVA_LIBRARIES := android-common-chips
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 6206d4e..cd78cc2 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -64,7 +64,7 @@
             android:authorities="com.android.mail.conversation.provider"
             android:label="@string/conversation_content_provider"
             android:multiprocess="false"
-            android:name=".browse.ConversationCursor$ConversationProvider" >
+            android:name=".browse.UnifiedConversationProvider" >
             <grant-uri-permission android:pathPattern=".*" />
         </provider>
 
@@ -72,7 +72,7 @@
             android:authorities="com.android.mail.accountcache"
             android:label="@string/account_cache_provider"
             android:multiprocess="false"
-            android:name=".providers.AccountCacheProvider" >
+            android:name=".providers.UnifiedAccountCacheProvider" >
             <grant-uri-permission android:pathPattern=".*" />
         </provider>
 
diff --git a/src/com/android/mail/providers/protos/boot/README b/email_src/README
similarity index 100%
rename from src/com/android/mail/providers/protos/boot/README
rename to email_src/README
diff --git a/src/com/android/mail/providers/protos/boot/EmailAccountService.java b/email_src/com/android/mail/providers/proto/boot/EmailAccountService.java
similarity index 97%
rename from src/com/android/mail/providers/protos/boot/EmailAccountService.java
rename to email_src/com/android/mail/providers/proto/boot/EmailAccountService.java
index 682a070..b2122b6 100644
--- a/src/com/android/mail/providers/protos/boot/EmailAccountService.java
+++ b/email_src/com/android/mail/providers/proto/boot/EmailAccountService.java
@@ -65,7 +65,8 @@
             int i = 0;
             while (c.moveToNext()) {
                 final Map<String, Object> mockAccountMap =
-                    MockUiProvider.createAccountDetailsMap(i % MockUiProvider.NUM_MOCK_ACCOUNTS);
+                    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 =
diff --git a/gmail_src/README b/gmail_src/README
new file mode 100644
index 0000000..ea96076
--- /dev/null
+++ b/gmail_src/README
@@ -0,0 +1,9 @@
+This is a temporary directory that is being used to enable email and 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/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/boot/GmailAccountService.java b/gmail_src/com/android/mail/providers/proto/boot/GmailAccountService.java
similarity index 98%
rename from src/com/android/mail/providers/protos/boot/GmailAccountService.java
rename to gmail_src/com/android/mail/providers/proto/boot/GmailAccountService.java
index 62524c5..f7d935d 100644
--- a/src/com/android/mail/providers/protos/boot/GmailAccountService.java
+++ b/gmail_src/com/android/mail/providers/proto/boot/GmailAccountService.java
@@ -107,7 +107,8 @@
             // 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);
+                    MockUiProvider.createAccountDetailsMap(i % MockUiProvider.NUM_MOCK_ACCOUNTS,
+                            false /* don't cache */);
             // TODO: where should this really be stored?
             long capabilities = Long.valueOf(
                     AccountCapabilities.SYNCABLE_FOLDERS |
diff --git a/src/com/android/mail/providers/protos/gmail/DummyGmailProvider.java b/gmail_src/com/android/mail/providers/proto/gmail/DummyGmailProvider.java
similarity index 100%
rename from src/com/android/mail/providers/protos/gmail/DummyGmailProvider.java
rename to gmail_src/com/android/mail/providers/proto/gmail/DummyGmailProvider.java
diff --git a/src/com/android/mail/browse/ConversationCursor.java b/src/com/android/mail/browse/ConversationCursor.java
index 05c1e69..30f7ddd 100644
--- a/src/com/android/mail/browse/ConversationCursor.java
+++ b/src/com/android/mail/browse/ConversationCursor.java
@@ -52,10 +52,6 @@
     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 @@
      */
     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 @@
      * 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 8f1fcb8..e2120bf 100644
--- a/src/com/android/mail/providers/AccountCacheProvider.java
+++ b/src/com/android/mail/providers/AccountCacheProvider.java
@@ -41,19 +41,25 @@
  * 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/mock/MockUiProvider.java b/src/com/android/mail/providers/protos/mock/MockUiProvider.java
index 80b7272..1d73020 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 @@
 
     // 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 @@
         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 @@
     }
 
     // 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 @@
         accountMap.put(AccountColumns.EXPUNGE_MESSAGE_URI, accountUri + "/expungeMessage");
         accountMap.put(AccountColumns.UNDO_URI, accountUri + "/undo");
 
-        addAccountInfoToAccountCache(accountMap);
+        if (cacheMap) {
+            addAccountInfoToAccountCache(accountMap);
+        }
         return accountMap;
     }
 
diff --git a/unified_src/README b/unified_src/README
new file mode 100644
index 0000000..ea96076
--- /dev/null
+++ b/unified_src/README
@@ -0,0 +1,9 @@
+This is a temporary directory that is being used to enable email and 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/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/unified_src/com/android/mail/browse/UnifiedConversationProvider.java b/unified_src/com/android/mail/browse/UnifiedConversationProvider.java
new file mode 100644
index 0000000..bde2a20
--- /dev/null
+++ b/unified_src/com/android/mail/browse/UnifiedConversationProvider.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ *      Copyright (C) 2012 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.browse;
+
+import com.android.mail.browse.ConversationCursor.ConversationProvider;
+
+import java.lang.Override;
+
+public class UnifiedConversationProvider extends ConversationProvider {
+    // 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";
+
+    @Override
+    protected String getAuthority() {
+        return sAuthority;
+    }
+}
\ No newline at end of file
diff --git a/unified_src/com/android/mail/providers/UnifiedAccountCacheProvider.java b/unified_src/com/android/mail/providers/UnifiedAccountCacheProvider.java
new file mode 100644
index 0000000..2308e96
--- /dev/null
+++ b/unified_src/com/android/mail/providers/UnifiedAccountCacheProvider.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ *      Copyright (C) 2012 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;
+
+
+import java.lang.Override;
+
+public class UnifiedAccountCacheProvider extends AccountCacheProvider {
+    // 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.accountcache";
+
+    @Override
+    protected String getAuthority() {
+        return sAuthority;
+    }
+}
\ No newline at end of file
diff --git a/src/com/android/mail/providers/protos/boot/AccountReceiver.java b/unified_src/com/android/mail/providers/protos/boot/AccountReceiver.java
similarity index 92%
rename from src/com/android/mail/providers/protos/boot/AccountReceiver.java
rename to unified_src/com/android/mail/providers/protos/boot/AccountReceiver.java
index 8e67ea5..dafc03f 100644
--- a/src/com/android/mail/providers/protos/boot/AccountReceiver.java
+++ b/unified_src/com/android/mail/providers/protos/boot/AccountReceiver.java
@@ -15,6 +15,7 @@
  */
 package com.android.mail.providers.protos.boot;
 
+import com.android.mail.providers.protos.mock.MockUiProvider;
 import android.content.BroadcastReceiver;
 import android.content.Context;
 import android.content.Intent;
@@ -28,6 +29,7 @@
 
     @Override
     public void onReceive(Context context, Intent intent) {
+        MockUiProvider.initializeMockProvider();
         intent.setClass(context, GmailAccountService.class);
         context.startService(intent);
         intent.setClass(context, EmailAccountService.class);