Android聚合无效的问题

时间:2023-02-04 17:38:13

新增或者修改联系人不会自动聚合

packages/apps/ContactsCommon/src/com/android/contacts/common/model/RawContactDelta.java

    public void buildDiff(ArrayList<ContentProviderOperation> buildInto) {

if (isContactInsert) {
// TODO: for now simply disabling aggregation when a new contact is
// created on the phone. In the future, will show aggregation suggestions
// after saving the contact.
mValues.put(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_SUSPENDED);
}

...

final boolean addedOperations = buildInto.size() > firstIndex;
if (addedOperations && isContactUpdate) {
// Suspend aggregation while persisting updates
builder = buildSetAggregationMode(beforeId, RawContacts.AGGREGATION_MODE_SUSPENDED);
buildInto.add(firstIndex, builder.build());

// Restore aggregation mode as last operation
builder = buildSetAggregationMode(beforeId, RawContacts.AGGREGATION_MODE_DEFAULT);
buildInto.add(builder.build());
} else if (isContactInsert) {
// Restore aggregation mode as last operation
builder = ContentProviderOperation.newUpdate(mContactsQueryUri);
builder.withValue(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_DEFAULT);
...
}
}
可以看出插入或者删除的时候是会先关闭聚合,然后再开启聚合。这个就避免了效率的问题。我手头只有mtk的代码,所以不确定这个是mtk的修改还是google就是这种意图,个人猜google的源码就是这样。

想要达到标题的效果的话修改下代码即可,不过其他后果未知。

导入卡联系人时不会自动聚合的问题

packages/apps/Contacts/src/com/mediatek/contacts/simservice/SIMImportProcessor.java

      private int actuallyImportOneSimContact(Context context, final Cursor cursor,
final ContentResolver resolver, int subId, int simType, long indexInSim,
boolean importSdnContacts, ArrayList<ContentProviderOperation> operationList,
int loopCheck, AccountWithDataSetEx account, boolean isUsim, int accountSubId,
String countryCode) {
...
values.put(RawContacts.AGGREGATION_MODE, RawContacts.AGGREGATION_MODE_DISABLED);
...
}
这个就纯粹是mtk的问题,导入的时候全部设置成禁止合并了。

其它

1. 从代码和日常使用来看,同名联系人聚合的情况只有一种,就是批量导入联系人的时候(还得是非mtk的手机,mtk貌似把合并全关了)。

2. packages/providers/ContactsProvider/src/com/android/providers/contacts/aggregation/AbstractContactAggregator.java

    public final void setEnabled(boolean enabled) {
mEnabled = enabled;
}
AbstractContactAggregator中有个禁止或开启聚合的方法,我见过有的代码把这个直接就设置成false的....不过这个要关闭了CTS铁定是过不去的。