Only show "add connection" button if relevant

- We don't want to present the user with the "add connection"
button if the user doesn't use the account that provides the
service

- Check if app contributing the account type is disabled or not

- Check if there is an activity to handle the "add connection"
intent

- Check if there are raw contacts in the database with that
account type

- Store this in a cache, and refresh it after a certain
period of time (i.e. 1 second) using an AsyncTask.
This is to prevent computing the list each time the contact
is loaded (which can happen many times especially when looking
at a detail page during a sync).

- Make sure public AccountTypeManager methods
first check ensureAccountsLoaded()

Bug: 5398529
Change-Id: I004f9562a587035a3168aaddb6eb43710fd201e6
diff --git a/src/com/android/contacts/ContactLoader.java b/src/com/android/contacts/ContactLoader.java
index 007c1e0..c9fbeae 100644
--- a/src/com/android/contacts/ContactLoader.java
+++ b/src/com/android/contacts/ContactLoader.java
@@ -850,17 +850,15 @@
 
         /**
          * Sets the "invitable" account types to {@link Result#mInvitableAccountTypes}.
-         *
-         * TODO Exclude the ones with no raw contacts in the database.
          */
         private void loadInvitableAccountTypes(Result contactData) {
-            Map<AccountTypeWithDataSet, AccountType> allInvitables =
-                    AccountTypeManager.getInstance(getContext()).getInvitableAccountTypes();
-            if (allInvitables.isEmpty()) {
+            Map<AccountTypeWithDataSet, AccountType> invitables =
+                    AccountTypeManager.getInstance(getContext()).getUsableInvitableAccountTypes();
+            if (invitables.isEmpty()) {
                 return;
             }
 
-            HashMap<AccountTypeWithDataSet, AccountType> result = Maps.newHashMap(allInvitables);
+            HashMap<AccountTypeWithDataSet, AccountType> result = Maps.newHashMap(invitables);
 
             // Remove the ones that already have a raw contact in the current contact
             for (Entity entity : contactData.getEntities()) {