[HOWTO] Fix CallerID matching issues in JB Phone and Messaging

Search This thread

htcgr

Senior Member
Mar 14, 2009
168
3
How to fix CallerID matching issues in JellyBean Phone and Messaging apps

Introduction
This guide is for everyone who has problems with incorrect Caller ID
matching in Phone and Messaging that happens mainly on stock JellyBean ROMs.
This can be easily fixed in the source code, I know, but this guide is dedicated to devices
that have no source code available. That's why we will be dealing with some smali hacking.

For devs: It took me couple of hours to identify the problem and fix it,
so please, if you decide to use this how-to to fix stuff in your custom roms,
I expect you to give proper credits. Thanks in advance.


The guide does not cover things like deodexing/decompiling/compiling/odexing jars and apks.
It expects you already are familiar with these processes.
There are already many guides for those out there.

Symptoms
As you already know, operator often sends the full Caller ID including country prefix
when receiving a call. If your contacts are stored without country prefix (in local format),
Phone app is unable to match the number provided by the operator to one in the Contacts database.
Example: you have a contact defined with phone number 0902 xxx yyy.
Operator sends +421 902 xxx yyy - you get mismatch and no caller indicated while ringing.

In Messaging, when you send SMS to contact that has not country prefix, and receive response,
operator will most likely use full number with country prefix in a received SMS.
The messaging app is unable to associate arriving message to existing conversation because of
a number mismatch and thus creates a new conversation thread.

Cause
General
Contacts are stored within Contacts Provider. One of the attribute for contact is a "min_match"
attribute which stores a part of the whole number (from right to left) that has to be used when matching Caller ID to
contact. The length of the min_match attribute is defined in the telephony framework.
It is good practice to keep the MIN_MATCH length to max 7 (typically it takes 6 numbers from the right
+ 1 number from local prefix - for our example above min_match would be: 2xxxyyy
However, some official ROMs have the MIN_MATCH constant too high making it impossible to match
numbers stored in local format to full caller ID received from operator. (It was 11 in my case!!!)
(+421 902 xxx yyy != 0902 xxx yyy)

Apart from this, there is also one boolean constant that defines the method of caller ID comparation:
Code:
config_use_strict_phone_number_comparation
If this constant is set to "true" MIN_MATCH doesn't play role and always full numbers have to match to
correctly map caller to contact - this is something we don't want.

Messaging app specific
Apart from min_match thing I've alredy described, there's another part in Messaging that plays role.
Contacts in messaging app are cached in a local cache. Each cached contact is identified by a key, which
is typically a phone number. Again, there's a constant that defines how much characters from right to left
of the phone number have to be used as a key. If this constant is too big (10 in my case!!!), you will get mismatch when
Messaging app is trying to associate arriving SMS with existing conversation resulting in creating new thread.
It is good practice to keep this constant at the length of 5.


Solution
I) Check for and fix comparation method
Firstly, we must assure that strict checking is turned off.

1) Decompile framework-res.apk
2) Open res/values/bools.xml and search for config_use_strict_phone_number_comparation variable
3) Make sure it's false
Code:
<bool name="config_use_strict_phone_number_comparation">false</bool>
4) Recompile farmework-res.apk if you had to change the variable

II) Check for and fix MIN_MATCH constant in telephony framework
1) Decompile framework.jar
2) Open smali/android/telephony/PhoneNumberUtils.smali
3) Search for MIN_MATCH constant and set it to 0x7
Code:
.field static final MIN_MATCH:I = 0x7 (was 0xb in my case)
4) Since in smali, constant names are not used but they are translated to explicit values, we have
to search for all occurences where old MIN_MATCH constant is used (0xb in my case) and change the values to 0x7
a) one is in "compareLoosly" method:
Code:
.local v7, minMatchLen:I
const/16 v7, 0x7 (was 0xb in my case)
b) another one in "toCallerIDMinMatch" method:
Code:
.local v0, minMatchLen:I
const/16 v0, 0x7 (was 0xb in my case)
5) Save the file and recompile framework.jar

III) Fix messaging app
1) Decompile Mms.apk
2) Open smali/com/android/mms/data/Contact$ContactsCache.smali
3) Search for STATIC_KEY_BUFFER_MAXIMUM_LENGTH and set it to 0x5
Code:
.field static final STATIC_KEY_BUFFER_MAXIMUM_LENGTH:I = 0x5 (was 0xa in my case)
4) Search for all occurences where old STATIC_KEY_BUFFER_MAXIMUM_LENGTH constant is used (0xa in my case) and change the values to 0x5
a) one is in "key" method
Code:
const/16 v2, 0x5 (was 0xa in my case)
b) another one in "getKey" method (it is possible there is no such method, then ignore it)
Code:
const/16 v4, 0x5 (was 0xa in my case)
c) another one in "internalGet" method
Code:
const/16 v10, 0x5 (was 0xa in my case)
5) Save the file and recompile Mms.apk

IMPORTANT:
After pushing your new files to phone it is necessary to re-add all of the contacts for fix to take effect.
This is because your contacts are still stored in a database with wrong min_match number.
It needs to be re-initialized according to new MIN_MATCH constant we have modified.
The fastest way is to go to Settings/Apps, locate Contacts Storage, open it and Clear data.
(this will delete all contacts from phone so make sure you have a backup).
In case you have your contacts synced to Google account, no backup is necessary.
Your contacts will be synced a while after you clear data for Contacts Storage.

For Messaging it is necessary to delete all the old threads that are incorrectly splitted.
All new conversations created after fix has been applied will be grouped OK.
do you know where can i find in NUBIA Z7 mini the framework.res (res/values/bools.xml) ?????
 

ibshar

Senior Member
Sep 10, 2011
1,128
1,194
Bangalore
Xiaomi Mi A2
@C3C076 : Hi, thanks for the detailed tutorial. I have this same caller id issue in a new Kitkat Rom for my phone. I tried checking the framework.jar file, but the value given there is already 0x7 and even the framework-res bool file has the value set to false, and there is no option for this fix in your GravityBox for KK. Can you please help out in this.?
 

ponnex

Senior Member
Nov 5, 2010
486
367
Cagayan de Oro
Finally i FIXED IT.. thanks to my memory sundenly i had a flash back about reading having to change sqlite.so lib... the first time i readed it i said... bull...t thought its not possible a module for handling sql queries to have such kind of limits..

after trying everything i gave it a shot, trying from random roms sqlite.so's.. and with one that i found its ok.!!

just for the record, i replaced sqlite.so and sqlite_jini.so from. pfff i had enough of this

replace libsqlite.so and libsqlite_jni.so should follow strick android version? If im on Kitkat should I find libsqlite.so and libsqlite_jni.so on a Kitkat also? I cant seem to make and libsqlite.so and libsqlite_jni.so on a JB that we had, It stuck on boot loop =.=
 

frapedas

Senior Member
Jan 28, 2013
100
41
salonica
replace libsqlite.so and libsqlite_jni.so should follow strick android version? If im on Kitkat should I find libsqlite.so and libsqlite_jni.so on a Kitkat also? I cant seem to make and libsqlite.so and libsqlite_jni.so on a JB that we had, It stuck on boot loop =.=

Long time by the issue i faced. you are now on kit kat maybe your problem you are facing now isn't even listed on this topic yet.

But for the record.. yes you need to steal those 2 modules from another kit kat rom and the same proccessor.

Step 1. Just find other famus phones with the same CPU that also have kit kat

step 2. Download the rom from this other smartphone

step 3. take system.img file and search on google and download <ext4 extract android tool>

extract the files you need. done.
 
  • Like
Reactions: ponnex

ponnex

Senior Member
Nov 5, 2010
486
367
Cagayan de Oro
Long time by the issue i faced. you are now on kit kat maybe your problem you are facing now isn't even listed on this topic yet.

But for the record.. yes you need to steal those 2 modules from another kit kat rom and the same proccessor.

Step 1. Just find other famus phones with the same CPU that also have kit kat

step 2. Download the rom from this other smartphone

step 3. take system.img file and search on google and download <ext4 extract android tool>

extract the files you need. done.

Thanks! :good: thats all I need to know :D
 

dedalos91

Senior Member
Jun 23, 2011
340
83
PLEASE HELP, no call id, my phone does not recognize the international country code
Please you can see this post?
http://xdaforums.com/general/help/p...-recognize-t3435071/post68090972#post68090972
Thanks in advance.
PLEASE HELP...
My phone is TCL M3G, LEWA OS, version 3.1 (multi language LEWA ROM ), android version 5.0.2 64bit.
(i know chinese phone etc, but ....)
I have call id problems (on phone and sms/mms), my phone does not recognize the international country code (prefixes).
Stock phone application in my phone, when I call my a number from my contacts for example +300123456789 all fine, but when I called the (same) number 0123456789 is unknown (because there is no +30 or +7).
What can I do?
Can I delete the stock phone app? Try TruePhone application and other applications, but nothing when there is an incoming or outgoing call ( from my contacts) does not have the call identifier.
So when I called the number with the international code of the country that my phone does not recognize the international country code .... and the number is unknown.
It is difficult to add at all my contacts number with country code and the number without the country code ..
Try different thinks of the Internet, but nothing....https://www.google.gr/search?hl=el&...=android+phone+doesn't+recognize+country+code and https://www.google.gr/search?biw=12......1c.1.64.serp..9.6.1460...30i10.nuNIzki2YMg
Try to make all my contacts in the international format, but when I call a number from my contacts, without international format (without a country code in the national format) does not have the call identifier.
This is a common problem for android phones, but the solution is deferent on deferent android versions .... I think. It is necessary to make changes on android system components, to make modifications on the ROM.
PLEASE HELP...
Hello,
Finally in my case this is the solution (tested on my phone and work fine)....
After so much searching and reading on Internet the solution is the editing of the system file build.prop ("/system/build.prop").
This is the editing (edit some code and adding some new code):

# lewa begin, for number match
persist.env.c.phone.matchnum=10
# lewa end

# Country code fix,phone,sms
ro.phone.min_match=10
# Fix end


editing
persist.env.c.phone.matchnum=10 > change the number from 11 to 10
10 in my country is the total numbers of a phone number without international country code (+39 or 0039 etc), put the correct number for you...how match digits is on your country?
and
adding new code
# Country code fix,phone,sms
ro.phone.min_match=10
# Fix end

the text after "#" it is just a free text message.
After editing reboot your phone and maybe must delete your contacts (or clear data contacts storage) and restore contacts form SD card or from your Google account (synchronizing your contacts).
You must sure the changes on build.prop has saved (please check, open it via root explorer as text).
Make the changes like that:
via root explorer you can see the permissions of build.prop (save a copy of original file) > copy the build.prop on yous SD card > open it via text editor and make the editing > then delete the system/build.prop file > copy the editing build.prop file from your SD card to system/ > give it the correct permissions > clear call log > reboot your phone.
The solution is from here https://code.google.com/p/android/issues/detail?id=23092
THANKS
 
Last edited:

Top Liked Posts

  • There are no posts matching your filters.
  • 24
    How to fix CallerID matching issues in JellyBean Phone and Messaging apps

    Introduction
    This guide is for everyone who has problems with incorrect Caller ID
    matching in Phone and Messaging that happens mainly on stock JellyBean ROMs.
    This can be easily fixed in the source code, I know, but this guide is dedicated to devices
    that have no source code available. That's why we will be dealing with some smali hacking.

    For devs: It took me couple of hours to identify the problem and fix it,
    so please, if you decide to use this how-to to fix stuff in your custom roms,
    I expect you to give proper credits. Thanks in advance.


    The guide does not cover things like deodexing/decompiling/compiling/odexing jars and apks.
    It expects you already are familiar with these processes.
    There are already many guides for those out there.

    Symptoms
    As you already know, operator often sends the full Caller ID including country prefix
    when receiving a call. If your contacts are stored without country prefix (in local format),
    Phone app is unable to match the number provided by the operator to one in the Contacts database.
    Example: you have a contact defined with phone number 0902 xxx yyy.
    Operator sends +421 902 xxx yyy - you get mismatch and no caller indicated while ringing.

    In Messaging, when you send SMS to contact that has not country prefix, and receive response,
    operator will most likely use full number with country prefix in a received SMS.
    The messaging app is unable to associate arriving message to existing conversation because of
    a number mismatch and thus creates a new conversation thread.

    Cause
    General
    Contacts are stored within Contacts Provider. One of the attribute for contact is a "min_match"
    attribute which stores a part of the whole number (from right to left) that has to be used when matching Caller ID to
    contact. The length of the min_match attribute is defined in the telephony framework.
    It is good practice to keep the MIN_MATCH length to max 7 (typically it takes 6 numbers from the right
    + 1 number from local prefix - for our example above min_match would be: 2xxxyyy
    However, some official ROMs have the MIN_MATCH constant too high making it impossible to match
    numbers stored in local format to full caller ID received from operator. (It was 11 in my case!!!)
    (+421 902 xxx yyy != 0902 xxx yyy)

    Apart from this, there is also one boolean constant that defines the method of caller ID comparation:
    Code:
    config_use_strict_phone_number_comparation
    If this constant is set to "true" MIN_MATCH doesn't play role and always full numbers have to match to
    correctly map caller to contact - this is something we don't want.

    Messaging app specific
    Apart from min_match thing I've alredy described, there's another part in Messaging that plays role.
    Contacts in messaging app are cached in a local cache. Each cached contact is identified by a key, which
    is typically a phone number. Again, there's a constant that defines how much characters from right to left
    of the phone number have to be used as a key. If this constant is too big (10 in my case!!!), you will get mismatch when
    Messaging app is trying to associate arriving SMS with existing conversation resulting in creating new thread.
    It is good practice to keep this constant at the length of 5.


    Solution
    I) Check for and fix comparation method
    Firstly, we must assure that strict checking is turned off.

    1) Decompile framework-res.apk
    2) Open res/values/bools.xml and search for config_use_strict_phone_number_comparation variable
    3) Make sure it's false
    Code:
    <bool name="config_use_strict_phone_number_comparation">false</bool>
    4) Recompile farmework-res.apk if you had to change the variable

    II) Check for and fix MIN_MATCH constant in telephony framework
    1) Decompile framework.jar
    2) Open smali/android/telephony/PhoneNumberUtils.smali
    3) Search for MIN_MATCH constant and set it to 0x7
    Code:
    .field static final MIN_MATCH:I = 0x7 (was 0xb in my case)
    4) Since in smali, constant names are not used but they are translated to explicit values, we have
    to search for all occurences where old MIN_MATCH constant is used (0xb in my case) and change the values to 0x7
    a) one is in "compareLoosly" method:
    Code:
    .local v7, minMatchLen:I
    const/16 v7, 0x7 (was 0xb in my case)
    b) another one in "toCallerIDMinMatch" method:
    Code:
    .local v0, minMatchLen:I
    const/16 v0, 0x7 (was 0xb in my case)
    5) Save the file and recompile framework.jar

    III) Fix messaging app
    1) Decompile Mms.apk
    2) Open smali/com/android/mms/data/Contact$ContactsCache.smali
    3) Search for STATIC_KEY_BUFFER_MAXIMUM_LENGTH and set it to 0x5
    Code:
    .field static final STATIC_KEY_BUFFER_MAXIMUM_LENGTH:I = 0x5 (was 0xa in my case)
    4) Search for all occurences where old STATIC_KEY_BUFFER_MAXIMUM_LENGTH constant is used (0xa in my case) and change the values to 0x5
    a) one is in "key" method
    Code:
    const/16 v2, 0x5 (was 0xa in my case)
    b) another one in "getKey" method (it is possible there is no such method, then ignore it)
    Code:
    const/16 v4, 0x5 (was 0xa in my case)
    c) another one in "internalGet" method
    Code:
    const/16 v10, 0x5 (was 0xa in my case)
    5) Save the file and recompile Mms.apk

    IMPORTANT:
    After pushing your new files to phone it is necessary to re-add all of the contacts for fix to take effect.
    This is because your contacts are still stored in a database with wrong min_match number.
    It needs to be re-initialized according to new MIN_MATCH constant we have modified.
    The fastest way is to go to Settings/Apps, locate Contacts Storage, open it and Clear data.
    (this will delete all contacts from phone so make sure you have a backup).
    In case you have your contacts synced to Google account, no backup is necessary.
    Your contacts will be synced a while after you clear data for Contacts Storage.

    For Messaging it is necessary to delete all the old threads that are incorrectly splitted.
    All new conversations created after fix has been applied will be grouped OK.
    2
    Finally i FIXED IT.. thanks to my memory sundenly i had a flash back about reading having to change sqlite.so lib... the first time i readed it i said... bull...t thought its not possible a module for handling sql queries to have such kind of limits..

    after trying everything i gave it a shot, trying from random roms sqlite.so's.. and with one that i found its ok.!!

    just for the record, i replaced sqlite.so and sqlite_jini.so from. pfff i had enough of this
    2
    Hi.

    I made this guide prior to starting developing GravityBox (which already includes this fix).
    Yes, I noticed some users within Xposed framework thread mentioning that strange "jex" format which prevents Xposed framework from working at all.
    Couple of days ago, somebody posted info that it is possible to deodex such ROMs and make xposed framework work for them.
    Unfortunately, I have no experience with such format so I cannot give you the necessary info how to decompile/change/recompile stuff or how to deodex. You might try to search the xposed framework thread and get in touch with one of the users that managed to get xposed framework working on ROM with jex files.
    1
    What about config_use_strict_phone_number_comparation
    Global setting?

    Ok guys.. i toke it a bit further.. its not an issue of my phone is an issue of Android 2.3.3 default sources!!!

    Firstly to make sure isn't the framework, i downloaded the android source code, i extracted the class PhoneNumberUtils.Java and i didn't had to edit it because it was already 7 .. then i used dex2jar and converted framework (classes.dex) to framework.jar so i can link it to the compiler and i can compile from the start the java file, the class was compiled ok without any problems, i re-placed it back to the jar, i converted it back to dex, etc etc and placed it to my phone...guess what?????

    SAME BEHAVIOUR!!!! only up to 11..

    Then i think.. WTF this is from the original android sourcecode compiled... and i installed android SDK 2.3.3 and i run an emulator from the virtual device manager... guess what???

    ORIGINAL android 2.3.3 as it is provided from Google, it parses only contacts up to 11 numbers, even its MIN_MATCH is 7!! both in sms app again and in phone app...

    This is a good thing and a bad thing, it is a good because we can download the whole source code including the one of apks and spot wtf is doing this.. is a bad because still didn't found a fix for 2.3.3

    After some researching ive started suspecting that TelephonyProperties.PROPERTY_ICC_OPERATOR_ISO_COUNTRY or TelephonyProperties.PROPERTY_IDP_STRING or TelephonyProperties.PROPERTY_OPERATOR_ISO_COUNTRY since those strings can be defined in build.prop file.. and i really cant find any information about these settings on google or anywere.. i mean whats ICC ? whats IDP string? what they mean?

    So if anybody of you want to see that behaviour as a proof and you have android SDK just run a virtual emulator of 2.3.3 add a contact of +xxNNNNNNNNNN ( 2 country code + 10 numbers) and just try to dial only the 10 numbers without the code.. BOOM.. nothing happens! even its min_match is 7 and its compireloosely on its settings!

    if you manage to fix this at least on your virtual emulator i will be really greateful.. im still trying...