summaryrefslogtreecommitdiffstats
path: root/src/com/android/contacts/common/model/account
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/contacts/common/model/account')
-rw-r--r--src/com/android/contacts/common/model/account/BaseAccountType.java52
-rw-r--r--src/com/android/contacts/common/model/account/ExchangeAccountType.java8
-rw-r--r--src/com/android/contacts/common/model/account/ExternalAccountType.java62
-rw-r--r--src/com/android/contacts/common/model/account/GoogleAccountType.java4
4 files changed, 65 insertions, 61 deletions
diff --git a/src/com/android/contacts/common/model/account/BaseAccountType.java b/src/com/android/contacts/common/model/account/BaseAccountType.java
index 8b4c955c..1ead103f 100644
--- a/src/com/android/contacts/common/model/account/BaseAccountType.java
+++ b/src/com/android/contacts/common/model/account/BaseAccountType.java
@@ -99,20 +99,20 @@ public abstract class BaseAccountType extends AccountType {
static final String TYPE = "type";
}
- private interface Weight {
+ protected interface Weight {
static final int NONE = -1;
- static final int ORGANIZATION = 5;
static final int PHONE = 10;
static final int EMAIL = 15;
- static final int IM = 20;
static final int STRUCTURED_POSTAL = 25;
- static final int NOTE = 110;
- static final int NICKNAME = 115;
- static final int WEBSITE = 120;
- static final int SIP_ADDRESS = 130;
- static final int EVENT = 150;
- static final int RELATIONSHIP = 160;
- static final int GROUP_MEMBERSHIP = 999;
+ static final int NICKNAME = 111;
+ static final int EVENT = 120;
+ static final int ORGANIZATION = 125;
+ static final int NOTE = 130;
+ static final int IM = 140;
+ static final int SIP_ADDRESS = 145;
+ static final int GROUP_MEMBERSHIP = 150;
+ static final int WEBSITE = 160;
+ static final int RELATIONSHIP = 999;
}
public BaseAccountType() {
@@ -148,7 +148,7 @@ public abstract class BaseAccountType extends AccountType {
protected DataKind addDataKindStructuredName(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(StructuredName.CONTENT_ITEM_TYPE,
- R.string.nameLabelsGroup, -1, true));
+ R.string.nameLabelsGroup, Weight.NONE, true));
kind.actionHeader = new SimpleInflater(R.string.nameLabelsGroup);
kind.actionBody = new SimpleInflater(Nickname.NAME);
kind.typeOverallMax = 1;
@@ -178,7 +178,7 @@ public abstract class BaseAccountType extends AccountType {
protected DataKind addDataKindDisplayName(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME,
- R.string.nameLabelsGroup, -1, true));
+ R.string.nameLabelsGroup, Weight.NONE, true));
kind.actionHeader = new SimpleInflater(R.string.nameLabelsGroup);
kind.actionBody = new SimpleInflater(Nickname.NAME);
kind.typeOverallMax = 1;
@@ -219,7 +219,7 @@ public abstract class BaseAccountType extends AccountType {
protected DataKind addDataKindPhoneticName(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME,
- R.string.name_phonetic, -1, true));
+ R.string.name_phonetic, Weight.NONE, true));
kind.actionHeader = new SimpleInflater(R.string.nameLabelsGroup);
kind.actionBody = new SimpleInflater(Nickname.NAME);
kind.typeOverallMax = 1;
@@ -239,7 +239,7 @@ public abstract class BaseAccountType extends AccountType {
protected DataKind addDataKindNickname(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(Nickname.CONTENT_ITEM_TYPE,
- R.string.nicknameLabelsGroup, 115, true));
+ R.string.nicknameLabelsGroup, Weight.NICKNAME, true));
kind.typeOverallMax = 1;
kind.actionHeader = new SimpleInflater(R.string.nicknameLabelsGroup);
kind.actionBody = new SimpleInflater(Nickname.NAME);
@@ -255,7 +255,7 @@ public abstract class BaseAccountType extends AccountType {
protected DataKind addDataKindPhone(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(Phone.CONTENT_ITEM_TYPE, R.string.phoneLabelsGroup,
- 10, true));
+ Weight.PHONE, true));
kind.iconAltRes = R.drawable.ic_text_holo_light;
kind.iconAltDescriptionRes = R.string.sms;
kind.actionHeader = new PhoneActionInflater();
@@ -294,7 +294,7 @@ public abstract class BaseAccountType extends AccountType {
protected DataKind addDataKindEmail(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(Email.CONTENT_ITEM_TYPE, R.string.emailLabelsGroup,
- 15, true));
+ Weight.EMAIL, true));
kind.actionHeader = new EmailActionInflater();
kind.actionBody = new SimpleInflater(Email.DATA);
kind.typeColumn = Email.TYPE;
@@ -314,7 +314,7 @@ public abstract class BaseAccountType extends AccountType {
protected DataKind addDataKindStructuredPostal(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(StructuredPostal.CONTENT_ITEM_TYPE,
- R.string.postalLabelsGroup, 25, true));
+ R.string.postalLabelsGroup, Weight.STRUCTURED_POSTAL, true));
kind.actionHeader = new PostalActionInflater();
kind.actionBody = new SimpleInflater(StructuredPostal.FORMATTED_ADDRESS);
kind.typeColumn = StructuredPostal.TYPE;
@@ -336,8 +336,8 @@ public abstract class BaseAccountType extends AccountType {
}
protected DataKind addDataKindIm(Context context) throws DefinitionException {
- DataKind kind = addKind(new DataKind(Im.CONTENT_ITEM_TYPE, R.string.imLabelsGroup, 20,
- true));
+ DataKind kind = addKind(new DataKind(Im.CONTENT_ITEM_TYPE, R.string.imLabelsGroup,
+ Weight.IM, true));
kind.actionHeader = new ImActionInflater();
kind.actionBody = new SimpleInflater(Im.DATA);
@@ -368,7 +368,7 @@ public abstract class BaseAccountType extends AccountType {
protected DataKind addDataKindOrganization(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(Organization.CONTENT_ITEM_TYPE,
- R.string.organizationLabelsGroup, 5, true));
+ R.string.organizationLabelsGroup, Weight.ORGANIZATION, true));
kind.actionHeader = new SimpleInflater(R.string.organizationLabelsGroup);
kind.actionBody = ORGANIZATION_BODY_INFLATER;
kind.typeOverallMax = 1;
@@ -383,7 +383,7 @@ public abstract class BaseAccountType extends AccountType {
}
protected DataKind addDataKindPhoto(Context context) throws DefinitionException {
- DataKind kind = addKind(new DataKind(Photo.CONTENT_ITEM_TYPE, -1, -1, true));
+ DataKind kind = addKind(new DataKind(Photo.CONTENT_ITEM_TYPE, -1, Weight.NONE, true));
kind.typeOverallMax = 1;
kind.fieldList = Lists.newArrayList();
kind.fieldList.add(new EditField(Photo.PHOTO, -1, -1));
@@ -391,8 +391,8 @@ public abstract class BaseAccountType extends AccountType {
}
protected DataKind addDataKindNote(Context context) throws DefinitionException {
- DataKind kind = addKind(new DataKind(Note.CONTENT_ITEM_TYPE, R.string.label_notes, 110,
- true));
+ DataKind kind = addKind(new DataKind(Note.CONTENT_ITEM_TYPE, R.string.label_notes,
+ Weight.NOTE, true));
kind.typeOverallMax = 1;
kind.actionHeader = new SimpleInflater(R.string.label_notes);
kind.actionBody = new SimpleInflater(Note.NOTE);
@@ -406,7 +406,7 @@ public abstract class BaseAccountType extends AccountType {
protected DataKind addDataKindWebsite(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(Website.CONTENT_ITEM_TYPE,
- R.string.websiteLabelsGroup, 120, true));
+ R.string.websiteLabelsGroup, Weight.WEBSITE, true));
kind.actionHeader = new SimpleInflater(R.string.websiteLabelsGroup);
kind.actionBody = new SimpleInflater(Website.URL);
kind.defaultValues = new ContentValues();
@@ -420,7 +420,7 @@ public abstract class BaseAccountType extends AccountType {
protected DataKind addDataKindSipAddress(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(SipAddress.CONTENT_ITEM_TYPE,
- R.string.label_sip_address, 130, true));
+ R.string.label_sip_address, Weight.SIP_ADDRESS, true));
kind.typeOverallMax = 1;
kind.actionHeader = new SimpleInflater(R.string.label_sip_address);
@@ -434,7 +434,7 @@ public abstract class BaseAccountType extends AccountType {
protected DataKind addDataKindGroupMembership(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(GroupMembership.CONTENT_ITEM_TYPE,
- R.string.groupsLabel, 999, true));
+ R.string.groupsLabel, Weight.GROUP_MEMBERSHIP, true));
kind.actionHeader = new SimpleInflater(R.string.label_groups);
kind.actionBody = new SimpleInflater(GroupMembership.GROUP_ROW_ID);
diff --git a/src/com/android/contacts/common/model/account/ExchangeAccountType.java b/src/com/android/contacts/common/model/account/ExchangeAccountType.java
index 04b5263a..7020836d 100644
--- a/src/com/android/contacts/common/model/account/ExchangeAccountType.java
+++ b/src/com/android/contacts/common/model/account/ExchangeAccountType.java
@@ -80,7 +80,7 @@ public class ExchangeAccountType extends BaseAccountType {
@Override
protected DataKind addDataKindStructuredName(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(StructuredName.CONTENT_ITEM_TYPE,
- R.string.nameLabelsGroup, -1, true));
+ R.string.nameLabelsGroup, Weight.NONE, true));
kind.actionHeader = new SimpleInflater(R.string.nameLabelsGroup);
kind.actionBody = new SimpleInflater(Nickname.NAME);
@@ -109,7 +109,7 @@ public class ExchangeAccountType extends BaseAccountType {
@Override
protected DataKind addDataKindDisplayName(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(DataKind.PSEUDO_MIME_TYPE_DISPLAY_NAME,
- R.string.nameLabelsGroup, -1, true));
+ R.string.nameLabelsGroup, Weight.NONE, true));
boolean displayOrderPrimary =
context.getResources().getBoolean(R.bool.config_editor_field_order_primary);
@@ -142,7 +142,7 @@ public class ExchangeAccountType extends BaseAccountType {
@Override
protected DataKind addDataKindPhoneticName(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME,
- R.string.name_phonetic, -1, true));
+ R.string.name_phonetic, Weight.NONE, true));
kind.actionHeader = new SimpleInflater(R.string.nameLabelsGroup);
kind.actionBody = new SimpleInflater(Nickname.NAME);
@@ -307,7 +307,7 @@ public class ExchangeAccountType extends BaseAccountType {
protected DataKind addDataKindEvent(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(Event.CONTENT_ITEM_TYPE, R.string.eventLabelsGroup,
- 150, true));
+ Weight.EVENT, true));
kind.actionHeader = new EventActionInflater();
kind.actionBody = new SimpleInflater(Event.START_DATE);
diff --git a/src/com/android/contacts/common/model/account/ExternalAccountType.java b/src/com/android/contacts/common/model/account/ExternalAccountType.java
index e4cef522..53089b84 100644
--- a/src/com/android/contacts/common/model/account/ExternalAccountType.java
+++ b/src/com/android/contacts/common/model/account/ExternalAccountType.java
@@ -17,9 +17,10 @@
package com.android.contacts.common.model.account;
import android.content.Context;
-import android.content.pm.PackageInfo;
+import android.content.Intent;
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;
@@ -48,12 +49,15 @@ import java.util.List;
public class ExternalAccountType extends BaseAccountType {
private static final String TAG = "ExternalAccountType";
+ private static final String SYNC_META_DATA = "android.content.SyncAdapter";
+
/**
* The metadata name for so-called "contacts.xml".
*
* On LMP and later, we also accept the "alternate" name.
* This is to allow sync adapters to have a contacts.xml without making it visible on older
- * platforms.
+ * platforms. If you modify this also update the corresponding list in
+ * ContactsProvider/PhotoPriorityResolver
*/
private static final String[] METADATA_CONTACTS_NAMES = new String[] {
"android.provider.ALTERNATE_CONTACTS_STRUCTURE",
@@ -114,15 +118,9 @@ public class ExternalAccountType extends BaseAccountType {
this.resourcePackageName = packageName;
this.syncAdapterPackageName = packageName;
- final PackageManager pm = context.getPackageManager();
final XmlResourceParser parser;
if (injectedMetadata == null) {
- try {
- parser = loadContactsXml(context, packageName);
- } catch (NameNotFoundException e1) {
- // If the package name is not found, we can't initialize this account type.
- return;
- }
+ parser = loadContactsXml(context, packageName);
} else {
parser = injectedMetadata;
}
@@ -181,35 +179,41 @@ public class ExternalAccountType extends BaseAccountType {
/**
* Returns the CONTACTS_STRUCTURE metadata (aka "contacts.xml") in the given apk package.
*
- * Unfortunately, there's no public way to determine which service defines a sync service for
- * which account type, so this method looks through all services in the package, and just
- * returns the first CONTACTS_STRUCTURE metadata defined in any of them.
+ * This method looks through all services in the package that handle sync adapter
+ * intents for the first one that contains CONTACTS_STRUCTURE metadata. We have to look
+ * through all sync adapters in the package in case there are contacts and other sync
+ * adapters (eg, calendar) in the same package.
*
* Returns {@code null} if the package has no CONTACTS_STRUCTURE metadata. In this case
* the account type *will* be initialized with minimal configuration.
- *
- * On the other hand, if the package is not found, it throws a {@link NameNotFoundException},
- * in which case the account type will *not* be initialized.
*/
- private XmlResourceParser loadContactsXml(Context context, String resPackageName)
- throws NameNotFoundException {
+ public static XmlResourceParser loadContactsXml(Context context, String resPackageName) {
final PackageManager pm = context.getPackageManager();
- PackageInfo packageInfo = pm.getPackageInfo(resPackageName,
- PackageManager.GET_SERVICES|PackageManager.GET_META_DATA);
- for (ServiceInfo serviceInfo : packageInfo.services) {
- for (String metadataName : METADATA_CONTACTS_NAMES) {
- final XmlResourceParser parser = serviceInfo.loadXmlMetaData(pm,
- metadataName);
- if (parser != null) {
- if (Log.isLoggable(TAG, Log.DEBUG)) {
- Log.d(TAG, String.format("Metadata loaded from: %s, %s, %s",
- serviceInfo.packageName, serviceInfo.name,
- metadataName));
+ final Intent intent = new Intent(SYNC_META_DATA).setPackage(resPackageName);
+ final List<ResolveInfo> intentServices = pm.queryIntentServices(intent,
+ PackageManager.GET_SERVICES | PackageManager.GET_META_DATA);
+
+ if (intentServices != null) {
+ for (final ResolveInfo resolveInfo : intentServices) {
+ final ServiceInfo serviceInfo = resolveInfo.serviceInfo;
+ if (serviceInfo == null) {
+ continue;
+ }
+ for (String metadataName : METADATA_CONTACTS_NAMES) {
+ final XmlResourceParser parser = serviceInfo.loadXmlMetaData(
+ pm, metadataName);
+ if (parser != null) {
+ if (Log.isLoggable(TAG, Log.DEBUG)) {
+ Log.d(TAG, String.format("Metadata loaded from: %s, %s, %s",
+ serviceInfo.packageName, serviceInfo.name,
+ metadataName));
+ }
+ return parser;
}
- return parser;
}
}
}
+
// Package was found, but that doesn't contain the CONTACTS_STRUCTURE metadata.
return null;
}
diff --git a/src/com/android/contacts/common/model/account/GoogleAccountType.java b/src/com/android/contacts/common/model/account/GoogleAccountType.java
index 8705ae34..68771874 100644
--- a/src/com/android/contacts/common/model/account/GoogleAccountType.java
+++ b/src/com/android/contacts/common/model/account/GoogleAccountType.java
@@ -122,7 +122,7 @@ public class GoogleAccountType extends BaseAccountType {
private DataKind addDataKindRelation(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(Relation.CONTENT_ITEM_TYPE,
- R.string.relationLabelsGroup, 160, true));
+ R.string.relationLabelsGroup, Weight.RELATIONSHIP, true));
kind.actionHeader = new RelationActionInflater();
kind.actionBody = new SimpleInflater(Relation.NAME);
@@ -157,7 +157,7 @@ public class GoogleAccountType extends BaseAccountType {
private DataKind addDataKindEvent(Context context) throws DefinitionException {
DataKind kind = addKind(new DataKind(Event.CONTENT_ITEM_TYPE,
- R.string.eventLabelsGroup, 150, true));
+ R.string.eventLabelsGroup, Weight.EVENT, true));
kind.actionHeader = new EventActionInflater();
kind.actionBody = new SimpleInflater(Event.START_DATE);