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

Commit 8545ec4d authored by Makoto Onuki's avatar Makoto Onuki
Browse files

Only load extension packages with contacts.xml

It's still okay for non-extension packages to not have contacts.xml.
Enforcing it for them may break backward compatibility.

Bug 5173717

Change-Id: I1ff914f24f08f5bba9cb956e516a78de8144bd2b
parent 5a7063d7
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -338,6 +338,17 @@ class AccountTypeManagerImpl extends AccountTypeManager
                        // Skip external account types that couldn't be initialized.
                        continue;
                    }
                    if (!accountType.hasContactsMetadata()) {
                        Log.w(TAG, "Skipping extension package " + extensionPackage + " because"
                                + " it doesn't have the CONTACTS_STRUCTURE metadata");
                        continue;
                    }
                    if (TextUtils.isEmpty(accountType.accountType)) {
                        Log.w(TAG, "Skipping extension package " + extensionPackage + " because"
                                + " the CONTACTS_STRUCTURE metadata doesn't have the accountType"
                                + " attribute");
                        continue;
                    }
                    Log.d(TAG, "Registering extension package account type="
                            + accountType.accountType + ", dataSet=" + accountType.dataSet
                            + ", packageName=" + extensionPackage);
+10 −3
Original line number Diff line number Diff line
@@ -22,11 +22,9 @@ import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.content.res.TypedArray;
@@ -46,7 +44,6 @@ import java.util.List;
public class ExternalAccountType extends BaseAccountType {
    private static final String TAG = "ExternalAccountType";

    private static final String ACTION_SYNC_ADAPTER = "android.content.SyncAdapter";
    private static final String METADATA_CONTACTS = "android.provider.CONTACTS_STRUCTURE";

    private static final String TAG_CONTACTS_SOURCE_LEGACY = "ContactsSource";
@@ -85,6 +82,7 @@ public class ExternalAccountType extends BaseAccountType {
    private String mAccountTypeLabelAttribute;
    private String mAccountTypeIconAttribute;
    private boolean mInitSuccessful;
    private boolean mHasContactsMetadata;

    public ExternalAccountType(Context context, String resPackageName) {
        this.resPackageName = resPackageName;
@@ -137,6 +135,13 @@ public class ExternalAccountType extends BaseAccountType {
        return mInitSuccessful;
    }

    /**
     * Whether this account type has the android.provider.CONTACTS_STRUCTURE metadata xml.
     */
    public boolean hasContactsMetadata() {
        return mHasContactsMetadata;
    }

    @Override
    public String getEditContactActivityClassName() {
        return mEditContactActivityClassName;
@@ -207,6 +212,8 @@ public class ExternalAccountType extends BaseAccountType {
                        + TAG_CONTACTS_ACCOUNT_TYPE + ", not " + rootTag);
            }

            mHasContactsMetadata = true;

            int attributeCount = parser.getAttributeCount();
            for (int i = 0; i < attributeCount; i++) {
                String attr = parser.getAttributeName(i);