Make sure that invitable account types is set to an empty list

Bug:6349078
Change-Id: I8258e58fa5f5666c9d37bb51da2f282d92c3108b
diff --git a/src/com/android/contacts/ContactLoader.java b/src/com/android/contacts/ContactLoader.java
index 405ba6f..17cd1e7 100644
--- a/src/com/android/contacts/ContactLoader.java
+++ b/src/com/android/contacts/ContactLoader.java
@@ -25,6 +25,7 @@
 import com.android.contacts.util.StreamItemPhotoEntry;
 import com.android.contacts.util.UriUtils;
 import com.google.common.annotations.VisibleForTesting;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 
@@ -732,8 +733,7 @@
                 if (!resultIsCached) loadPhotoBinaryData(result);
 
                 // Note ME profile should never have "Add connection"
-                if (mLoadInvitableAccountTypes && result.getInvitableAccountTypes() == null &&
-                        !result.isUserProfile()) {
+                if (mLoadInvitableAccountTypes && result.getInvitableAccountTypes() == null) {
                     loadInvitableAccountTypes(result);
                 }
             }
@@ -855,25 +855,29 @@
      * Sets the "invitable" account types to {@link Result#mInvitableAccountTypes}.
      */
     private void loadInvitableAccountTypes(Result contactData) {
-        Map<AccountTypeWithDataSet, AccountType> invitables =
-                AccountTypeManager.getInstance(getContext()).getUsableInvitableAccountTypes();
-        if (invitables.isEmpty()) {
-            return;
-        }
+        final ArrayList<AccountType> resultList = Lists.newArrayList();
+        if (!contactData.isUserProfile()) {
+            Map<AccountTypeWithDataSet, AccountType> invitables =
+                    AccountTypeManager.getInstance(getContext()).getUsableInvitableAccountTypes();
+            if (!invitables.isEmpty()) {
+                final Map<AccountTypeWithDataSet, AccountType> resultMap =
+                        Maps.newHashMap(invitables);
 
-        Map<AccountTypeWithDataSet, AccountType> result = Maps.newHashMap(invitables);
+                // Remove the ones that already have a raw contact in the current contact
+                for (Entity entity : contactData.getEntities()) {
+                    final ContentValues values = entity.getEntityValues();
+                    final AccountTypeWithDataSet type = AccountTypeWithDataSet.get(
+                            values.getAsString(RawContacts.ACCOUNT_TYPE),
+                            values.getAsString(RawContacts.DATA_SET));
+                    resultMap.remove(type);
+                }
 
-        // Remove the ones that already have a raw contact in the current contact
-        for (Entity entity : contactData.getEntities()) {
-            final ContentValues values = entity.getEntityValues();
-            final AccountTypeWithDataSet type = AccountTypeWithDataSet.get(
-                    values.getAsString(RawContacts.ACCOUNT_TYPE),
-                    values.getAsString(RawContacts.DATA_SET));
-            result.remove(type);
+                resultList.addAll(resultMap.values());
+            }
         }
 
         // Set to mInvitableAccountTypes
-        contactData.mInvitableAccountTypes = new ArrayList<AccountType>(result.values());
+        contactData.mInvitableAccountTypes = resultList;
     }
 
     /**