android 加入MCCMNC自己主动号码匹配后拨号匹配不到联系人
因为不同的sim卡相应不同的mccmnc, 导致min_match的值发生变化。
新的min_match值与之前phone_lookup表中保存的min_match不一直,导致无法匹配上。
改动例如以下:
1. 加入URI
改动ContactsProvider2.java,
private static final int PHONE_LOOKUP = 4000;
以下增加一行:
private static final int PHONE_LOOKUP2 = 4001; // New Add
matcher.addURI(ContactsContract.AUTHORITY, "provider_status", PROVIDER_STATUS);
以下增加一行:
matcher.addURI(ContactsContract.AUTHORITY, "phone_lookup2", PHONE_LOOKUP2); // New Add
2. 实现处理相应URI的方法
改动contactsProvider2.java 的 updateInTransaction().
case PHONE_LOOKUP2:
final SQLiteDatabase mDb = mDbHelper.get().getWritableDatabase(); // mDb
Cursor c = mDb.query(Tables.PHONE_LOOKUP,
new String[]{ PhoneLookupColumns.DATA_ID,
PhoneLookupColumns.RAW_CONTACT_ID,
PhoneLookupColumns.NORMALIZED_NUMBER,
PhoneLookupColumns.MIN_MATCH },
null, null, null, null, null);
while(c.moveToNext()) {
long dataId = c.getLong(0);
long rawContactId = c.getLong(1);
String normalizeNumber = c.getString(2);
String oldMinMatch = c.getString(3);
ContentValues phoneValues = new ContentValues();
phoneValues.put(PhoneLookupColumns.RAW_CONTACT_ID, rawContactId);
phoneValues.put(PhoneLookupColumns.DATA_ID, dataId);
phoneValues.put(PhoneLookupColumns.NORMALIZED_NUMBER, normalizeNumber);
// get minMatch
Log.d(TAG, "[PHONE_LOOKUP2]1.normalizeNumber:" + normalizeNumber);
String minMatch = PhoneNumberUtils.toCallerIDMinMatch(normalizeNumber);
phoneValues.put(PhoneLookupColumns.MIN_MATCH, minMatch);
Log.d(TAG, "[PHONE_LOOKUP2]2.normalizeNumber:" + normalizeNumber + " oldMinMatch:" + oldMinMatch + " minMatch:" + minMatch);
mDb.update(Tables.PHONE_LOOKUP, phoneValues, PhoneLookupColumns.DATA_ID + "=" + dataId + " AND " + PhoneLookupColumns.RAW_CONTACT_ID + "=" + rawContactId, null);
}
c.close();
break;
3. 启动更新phone_lookup表的min_match
------------[JB 4.2]------------
改动Contacts包下的AbstractStartSIMService.java
Case FINISH_IMPORTING 这个case以下的 break 前面的 canStopSelf()之前增加例如以下代码:
... ...
if (canStopSelf) {
Log.i(TAG, "Will call stopSelf here.")
// New add
ContentResolver contentResolver = mContext.getContentResolver();
Uri uri = Uri.parse("content://com.android.contacts/phone_lookup2");
contentResolver.update(uri, new ContentValues(), null, null);
// End
stopSelf();
}
------------[KK 4.4]------------
改动SIMProcessorManager.java,SIMProcessorManager() --> handleMessage(),
在callStopService()之前增加例如以下代码:
... ...
LogUtils.d(TAG, "handleMessage MSF_SEND_STOP_SERVICE");
// New add
ContentResolver contentResolver = mContext.getContentResolver();
Uri uri = Uri.parse("content://com.android.contacts/phone_lookup2");
contentResolver.update(uri, new ContentValues(), null, null);
// End
callStopService();
... ...
新的min_match值与之前phone_lookup表中保存的min_match不一直,导致无法匹配上。
改动例如以下:
1. 加入URI
改动ContactsProvider2.java,
private static final int PHONE_LOOKUP = 4000;
以下增加一行:
private static final int PHONE_LOOKUP2 = 4001; // New Add
matcher.addURI(ContactsContract.AUTHORITY, "provider_status", PROVIDER_STATUS);
以下增加一行:
matcher.addURI(ContactsContract.AUTHORITY, "phone_lookup2", PHONE_LOOKUP2); // New Add
2. 实现处理相应URI的方法
改动contactsProvider2.java 的 updateInTransaction().
case PHONE_LOOKUP2:
final SQLiteDatabase mDb = mDbHelper.get().getWritableDatabase(); // mDb
Cursor c = mDb.query(Tables.PHONE_LOOKUP,
new String[]{ PhoneLookupColumns.DATA_ID,
PhoneLookupColumns.RAW_CONTACT_ID,
PhoneLookupColumns.NORMALIZED_NUMBER,
PhoneLookupColumns.MIN_MATCH },
null, null, null, null, null);
while(c.moveToNext()) {
long dataId = c.getLong(0);
long rawContactId = c.getLong(1);
String normalizeNumber = c.getString(2);
String oldMinMatch = c.getString(3);
ContentValues phoneValues = new ContentValues();
phoneValues.put(PhoneLookupColumns.RAW_CONTACT_ID, rawContactId);
phoneValues.put(PhoneLookupColumns.DATA_ID, dataId);
phoneValues.put(PhoneLookupColumns.NORMALIZED_NUMBER, normalizeNumber);
// get minMatch
Log.d(TAG, "[PHONE_LOOKUP2]1.normalizeNumber:" + normalizeNumber);
String minMatch = PhoneNumberUtils.toCallerIDMinMatch(normalizeNumber);
phoneValues.put(PhoneLookupColumns.MIN_MATCH, minMatch);
Log.d(TAG, "[PHONE_LOOKUP2]2.normalizeNumber:" + normalizeNumber + " oldMinMatch:" + oldMinMatch + " minMatch:" + minMatch);
mDb.update(Tables.PHONE_LOOKUP, phoneValues, PhoneLookupColumns.DATA_ID + "=" + dataId + " AND " + PhoneLookupColumns.RAW_CONTACT_ID + "=" + rawContactId, null);
}
c.close();
break;
3. 启动更新phone_lookup表的min_match
------------[JB 4.2]------------
改动Contacts包下的AbstractStartSIMService.java
Case FINISH_IMPORTING 这个case以下的 break 前面的 canStopSelf()之前增加例如以下代码:
... ...
if (canStopSelf) {
Log.i(TAG, "Will call stopSelf here.")
// New add
ContentResolver contentResolver = mContext.getContentResolver();
Uri uri = Uri.parse("content://com.android.contacts/phone_lookup2");
contentResolver.update(uri, new ContentValues(), null, null);
// End
stopSelf();
}
------------[KK 4.4]------------
改动SIMProcessorManager.java,SIMProcessorManager() --> handleMessage(),
在callStopService()之前增加例如以下代码:
... ...
LogUtils.d(TAG, "handleMessage MSF_SEND_STOP_SERVICE");
// New add
ContentResolver contentResolver = mContext.getContentResolver();
Uri uri = Uri.parse("content://com.android.contacts/phone_lookup2");
contentResolver.update(uri, new ContentValues(), null, null);
// End
callStopService();
... ...