From: http://blog.csdn.net/baimy1985/article/details/7820024
There is a previous article about the information on the card (Android information (MMS) (7)-SIM card text message). There is also a very important information on the SIM card, that is, the contacts on the card. I don't know if you have noticed that Android phones, especially those with carrier IDs, are slow to boot. This is irrelevant to the contacts and information on the boot guide card, the operator requires that the card be redirected when the device is started. However, in public speaking, the slow boot may be related to the card, but it cannot be totally attributed to the card. (Android phones also load a lot of things when the device is started ), of course, there must be another reason if your mobile phone is too slow to boot without a card.
Of course, the android source code does not guide the card when it is started. If we need to view the contacts on the card, we need to manually import them, and apply contactslistactivity from the contact. in the menu of the Java class, find import and export, and select the import SIM card contact to enter simcontactsselectactivity. java class, in which the query () method is executed, and the corresponding provider and Uri are iccprovider. java and Uri. parse (content: // ICC/ADN), enter iccprovider. the code after Java is a part of attention in this article, starting from the query () method
[Java]View plaincopy
- Public cursor query (uri url, string [] projection, string selection,
- String [] selectionargs, string sort ){
- Arraylist <arraylist> results;
- Switch (url_matcher.match (URL )){
- Case ADN:
- Results = loadfromef (iccconstants. ef_adn );
- Break;
We are concerned about this loadfromef () method. The value of iccconstants. ef_and is 6f3a, which tells us to first find the content at this position on the card.
[Java]View plaincopy
- Private arraylist <arraylist> loadfromef (INT eftype ){
- Arraylist <arraylist> Results = new arraylist <arraylist> ();
- List <adnrecord> adnrecords = NULL;
- Try {
- Iiccphonebook iccipb = iiccphonebook. stub. asinterface (// binder comes servicemanager. getservice ("simphonebook "));
- If (iccipb! = NULL ){
- Adnrecords = iccipb. getadnrecordsinef (eftype); // proxy Mode
- }
- }... Omitting the secondary code .... }
Next, the code goes to the getadnrecordsinef (intefid) method of the iccphonebookinterfacemanager. Java class, which involves the proxy mode. iccphonebookinterfacemanagerproxy. Java performs a conversion in the middle. In the getadnrecordsinef (intefid) method, call updateefforicctype (efid) to determine whether it is a SIM card or a USIM card, and then determine whether the efid below uses iccconstants. ef_and or iccconstants. ef_pbr: the true query is requestloadalladnlike (). Pay attention to the event_load_done mark and use it to receive query results.
[Java]View plaincopy
- Requestloadalladnlike (INT efid, int extensionef, message response ){
- Arraylist <message> waiters;
- Arraylist <adnrecord> result;
- If (efid = ef_pbr) {// USIM card, here let's look at this method
- Result = musimphonebookmanager. loadeffilesfromusim ();
- } Else {// SIM card
- Result = getrecordsifloaded (efid );
- }.
Let's take a look at the loadeffilesfromusim () method and read it cyclically until all files are read and then returned. There are two types in it: one is the contact of the phone number and the other is the contact of the email address, mailbox is more troublesome than phone number.
[Java]View plaincopy
- Public arraylist <adnrecord> loadeffilesfromusim (){
- Synchronized (mlock ){
- //... Omitting the secondary code ....
- Numrecs = mpbrfile. mfileids. Size ();
- For (INT I = 0; I <numrecs; I ++ ){
- Readadnfileandwait (I );
- Reademailfileandwait (I );
- } // All EF files are loaded, post the response.
- }
Readadnfileandwait (I) and reademailfileandwait (I) call the mphone. geticcfilehandler (). loadeflinearfixedall () method at the end, but the specific parameters are different. Check the loadeflinearfixedall () code.
[Java]View plaincopy
- Public void loadeflinearfixedall (INT fileid, message onloaded ){
- Message response = obtainmessage (event_get_record_size_done,
- New loadlinearfixedcontext (fileid, onloaded ));
- Phone. mcm. iccio (command_get_response, fileid, getefpath (fileid ),
- 0, 0, get_response_ef_size_bytes, null, null, response );
- }
The iccio () method shows that the Code ran to RIL. java. The information code on the reading card also came here.
[Java]View plaincopy
- Public void iccio (INT command, int fileid, string path, int P1, int P2, int P3,
- String data, string pin2, message result ){
- Rilrequest RR = rilrequest. Obtain (ril_request_sim_io, result); // follow this tag flag
- Rr. MP. writeint (command );
- Rr. MP. writeint (fileid );
- Rr. MP. writestring (PATH );
- Rr. MP. writeint (P1 );
- Rr. MP. writeint (P2 );
- Rr. MP. writeint (P3 );
- Rr. MP. writestring (data );
- Rr. MP. writestring (pin2 );
- Send (RR );
- }
- According to the tag above, you can find this branch in the Reference-ril.c.
- Case ril_request_sim_io:
- Requestsim_io (data, datalen, t );
- Break;
Read the requestsim_io () method to see how the android Source Code reads contacts from the SIM card. The source code uses the at + crsm command. For the AT command, see the 3GPP 27.007 document. When the read is complete, you will receive the event_pbr_load_done message. In the createpbrfile () method, you can parse the string to obtain the contact information.
[Java]View plaincopy
- Public void handlemessage (Message MSG ){
- ... Omitting code ....
- Switch (msg. What ){
- Case event_pbr_load_done:
- If (AR. Exception = NULL ){
- Createpbrfile (arraylist <byte []>) Ar. Result );
- }... Omitting code ....
- Break;
At this point, most of the processes for importing card contacts are completed, and some other operations for writing to the contact database are relatively simple, so the overall process is clear, but there are many cycles, remote debugging is not very convenient. Generally, a SIM card can store 250 contacts, and a USIM card can store more contacts, but the number is not fixed, the email address of the read/write contact is troublesome. Because of the bucket restrictions, you need to find the corresponding index multiple times to find what we want. For specific examples of reading and writing card contacts, add them separately. The last figure shows the truth.