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

Commit 0fed9b62 authored by Walter Jang's avatar Walter Jang
Browse files

Enable group member edits for external accounts

But only if the account is also writable.
Also, only use writable accounts for new labels.

Test: Manually verified that some writable external acccount
  types (ContactsTest and MyLocalAccount) are offered as an
  option for new labels.

Bug: 31216444
Change-Id: I3dea4e76988f8d6e9be7d1bd41cda891d08999d9
parent 98d41d71
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -595,7 +595,7 @@ class AccountTypeManagerImpl extends AccountTypeManager
                                    && accountWithDataSet.dataSet == null) {
                                foundWritableGoogleAccount = true;
                            }
                        }

                            if (accountType.isGroupMembershipEditable()) {
                                groupWritableAccounts.add(accountWithDataSet);
                            }
@@ -603,6 +603,7 @@ class AccountTypeManagerImpl extends AccountTypeManager
                    }
                }
            }
        }

        final DeviceLocalAccountLocator deviceAccounts =
                new DeviceLocalAccountLocator(mContext.getContentResolver(),
@@ -632,11 +633,12 @@ class AccountTypeManagerImpl extends AccountTypeManager
            }
            if (localAccountType.areContactsWritable()) {
                contactWritableAccounts.add(localAccount);
            }

                if (localAccountType.isGroupMembershipEditable()) {
                    groupWritableAccounts.add(localAccount);
                }
            }
        }

        final AccountComparator accountComparator = new AccountComparator(null);
        Collections.sort(allAccounts, accountComparator);
+10 −0
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.provider.ContactsContract.CommonDataKinds.GroupMembership;
import android.provider.ContactsContract.CommonDataKinds.Photo;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.text.TextUtils;
@@ -101,6 +102,7 @@ public class ExternalAccountType extends BaseAccountType {
    private String mAccountTypeIconAttribute;
    private boolean mHasContactsMetadata;
    private boolean mHasEditSchema;
    private boolean mGroupMembershipEditable;

    public ExternalAccountType(Context context, String resPackageName, boolean isExtension) {
        this(context, resPackageName, isExtension, null);
@@ -172,6 +174,9 @@ public class ExternalAccountType extends BaseAccountType {
        iconRes = resolveExternalResId(context, mAccountTypeIconAttribute,
                syncAdapterPackageName, ATTR_ACCOUNT_ICON);

        final DataKind dataKind = getKindForMimetype(GroupMembership.CONTENT_ITEM_TYPE);
        mGroupMembershipEditable = dataKind != null && dataKind.editable;

        // If we reach this point, the account type has been successfully initialized.
        mIsInitialized = true;
    }
@@ -293,6 +298,11 @@ public class ExternalAccountType extends BaseAccountType {
        return mExtensionPackageNames;
    }

    @Override
    public boolean isGroupMembershipEditable() {
        return mGroupMembershipEditable;
    }

    /**
     * Inflate this {@link AccountType} from the given parser. This may only
     * load details matching the publicly-defined schema.