Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49ea2d29 authored by Daniel Lehmann's avatar Daniel Lehmann
Browse files

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

Bug:6349078
Change-Id: I8258e58fa5f5666c9d37bb51da2f282d92c3108b
parent ecb8d294
Loading
Loading
Loading
Loading
+21 −17
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import com.android.contacts.util.StreamItemEntry;
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 @@ public class ContactLoader extends AsyncTaskLoader<ContactLoader.Result> {
                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,13 +855,13 @@ public class ContactLoader extends AsyncTaskLoader<ContactLoader.Result> {
     * Sets the "invitable" account types to {@link Result#mInvitableAccountTypes}.
     */
    private void loadInvitableAccountTypes(Result contactData) {
        final ArrayList<AccountType> resultList = Lists.newArrayList();
        if (!contactData.isUserProfile()) {
            Map<AccountTypeWithDataSet, AccountType> invitables =
                    AccountTypeManager.getInstance(getContext()).getUsableInvitableAccountTypes();
        if (invitables.isEmpty()) {
            return;
        }

        Map<AccountTypeWithDataSet, AccountType> result = Maps.newHashMap(invitables);
            if (!invitables.isEmpty()) {
                final Map<AccountTypeWithDataSet, AccountType> resultMap =
                        Maps.newHashMap(invitables);

                // Remove the ones that already have a raw contact in the current contact
                for (Entity entity : contactData.getEntities()) {
@@ -869,11 +869,15 @@ public class ContactLoader extends AsyncTaskLoader<ContactLoader.Result> {
                    final AccountTypeWithDataSet type = AccountTypeWithDataSet.get(
                            values.getAsString(RawContacts.ACCOUNT_TYPE),
                            values.getAsString(RawContacts.DATA_SET));
            result.remove(type);
                    resultMap.remove(type);
                }

                resultList.addAll(resultMap.values());
            }
        }

        // Set to mInvitableAccountTypes
        contactData.mInvitableAccountTypes = new ArrayList<AccountType>(result.values());
        contactData.mInvitableAccountTypes = resultList;
    }

    /**