由於不同的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();
... ...