Android聚合无效的问题

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

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铁定是过不去的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值